FreeCalypso > hg > ueda-linux
comparison ueda/libueda/filesearch.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
| author | Space Falcon <falcon@ivan.Harhan.ORG> |
|---|---|
| date | Mon, 20 Jul 2015 00:24:37 +0000 |
| parents | |
| children | c91e7a30fab3 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:cd92449fdb51 |
|---|---|
| 1 /* | |
| 2 * These routines implement searching for symbol and pinout files. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/param.h> | |
| 6 #include <ctype.h> | |
| 7 #include <stdio.h> | |
| 8 #include <strings.h> | |
| 9 | |
| 10 extern char *copystr(); | |
| 11 | |
| 12 #define MAXDIRS 15 | |
| 13 static char *dirlist[MAXDIRS+1]; | |
| 14 static int ndirs; | |
| 15 | |
| 16 /* This var is global so that interested parties can grab and copy it */ | |
| 17 char sought_libfile_fullpath[MAXPATHLEN]; | |
| 18 | |
| 19 add_symfile_dir(dir) | |
| 20 char *dir; | |
| 21 { | |
| 22 if (ndirs >= MAXDIRS) { | |
| 23 fprintf(stderr, | |
| 24 "Too many symbol file search directories specified\n"); | |
| 25 exit(1); | |
| 26 } | |
| 27 dirlist[ndirs++] = dir; | |
| 28 } | |
| 29 | |
| 30 set_default_sympath() | |
| 31 { | |
| 32 register FILE *f; | |
| 33 char line[MAXPATHLEN]; | |
| 34 register char *cp, *np; | |
| 35 int lineno; | |
| 36 | |
| 37 if (ndirs) | |
| 38 return; | |
| 39 f = fopen("sympath", "r"); | |
| 40 if (!f) | |
| 41 return; | |
| 42 for (lineno = 1; fgets(line, sizeof line, f); lineno++) { | |
| 43 for (cp = line; isspace(*cp); cp++) | |
| 44 ; | |
| 45 if (*cp == '\0' || *cp == '#') | |
| 46 continue; | |
| 47 if (!isgraph(*cp)) { | |
| 48 inv: fprintf(stderr, | |
| 49 "sympath: line %d: invalid syntax (one directory per line expected)\n", | |
| 50 lineno); | |
| 51 exit(1); | |
| 52 } | |
| 53 for (np = cp; isgraph(*cp); cp++) | |
| 54 ; | |
| 55 if (isspace(*cp)) | |
| 56 *cp++ = '\0'; | |
| 57 while (isspace(*cp)) | |
| 58 cp++; | |
| 59 if (*cp) | |
| 60 goto inv; | |
| 61 if (ndirs >= MAXDIRS) { | |
| 62 fprintf(stderr, | |
| 63 "sympath: too many symbol file search directories specified\n"); | |
| 64 exit(1); | |
| 65 } | |
| 66 dirlist[ndirs++] = copystr(np); | |
| 67 } | |
| 68 fclose(f); | |
| 69 } | |
| 70 | |
| 71 FILE * | |
| 72 find_symlib_file(basename, suffix) | |
| 73 char *basename, *suffix; | |
| 74 { | |
| 75 register int i; | |
| 76 register FILE *f; | |
| 77 | |
| 78 for (i = 0; dirlist[i]; i++) { | |
| 79 sprintf(sought_libfile_fullpath, "%s/%s", dirlist[i], basename); | |
| 80 if (suffix) | |
| 81 strcat(sought_libfile_fullpath, suffix); | |
| 82 f = fopen(sought_libfile_fullpath, "r"); | |
| 83 if (f) | |
| 84 return(f); | |
| 85 } | |
| 86 return(NULL); | |
| 87 } |
