FreeCalypso > hg > ueda-linux
view ueda/libueda/filesearch.c @ 139:bf188727e606
donl-rename-parts reader: no tEDAx-style escapes
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Sep 2020 04:25:11 +0000 |
parents | c91e7a30fab3 |
children |
line wrap: on
line source
/* * These routines implement searching for symbol and pinout files. */ #include <sys/param.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> extern char *copystr(); #define MAXDIRS 15 static char *dirlist[MAXDIRS+1]; static int ndirs; /* This var is global so that interested parties can grab and copy it */ char sought_libfile_fullpath[MAXPATHLEN]; add_symfile_dir(dir) char *dir; { if (ndirs >= MAXDIRS) { fprintf(stderr, "Too many symbol file search directories specified\n"); exit(1); } dirlist[ndirs++] = dir; } set_default_sympath() { register FILE *f; char line[MAXPATHLEN]; register char *cp, *np; int lineno; if (ndirs) return; f = fopen("sympath", "r"); if (!f) return; for (lineno = 1; fgets(line, sizeof line, f); lineno++) { for (cp = line; isspace(*cp); cp++) ; if (*cp == '\0' || *cp == '#') continue; if (!isgraph(*cp)) { inv: fprintf(stderr, "sympath: line %d: invalid syntax (one directory per line expected)\n", lineno); exit(1); } for (np = cp; isgraph(*cp); cp++) ; if (isspace(*cp)) *cp++ = '\0'; while (isspace(*cp)) cp++; if (*cp) goto inv; if (ndirs >= MAXDIRS) { fprintf(stderr, "sympath: too many symbol file search directories specified\n"); exit(1); } dirlist[ndirs++] = copystr(np); } fclose(f); } FILE * find_symlib_file(basename, suffix) char *basename, *suffix; { register int i; register FILE *f; for (i = 0; dirlist[i]; i++) { sprintf(sought_libfile_fullpath, "%s/%s", dirlist[i], basename); if (suffix) strcat(sought_libfile_fullpath, suffix); f = fopen(sought_libfile_fullpath, "r"); if (f) return(f); } return(NULL); }