diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/libueda/filesearch.c	Mon Jul 20 00:24:37 2015 +0000
@@ -0,0 +1,87 @@
+/*
+ * These routines implement searching for symbol and pinout files.
+ */
+
+#include <sys/param.h>
+#include <ctype.h>
+#include <stdio.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);
+}