Index: util/Makefile.in =================================================================== --- util/Makefile.in (revision 312) +++ util/Makefile.in (revision 313) @@ -4,12 +4,18 @@ LDFLAGS=@libs/sul/glib/ldflags@ EXE=@sys/ext_exe@ -gsch2pcb$(EXE): gsch2pcb.o ../src/libpcb_fp.o - $(CC) gsch2pcb.o -o gsch2pcb$(EXE) $(LDFLAGS) +gsch2pcb$(EXE): gsch2pcb.o ../src/libpcb_fp.o ../src/portability.o ../src/ds.o + $(CC) gsch2pcb.o ../src/libpcb_fp.o ../src/portability.o ../src/ds.o -o gsch2pcb$(EXE) $(LDFLAGS) gsch2pcb.o: gsch2pcb.c ../src/libpcb_fp.h ../config.h ../config.manual.h ../config.auto.h $(CC) -c $(CFLAGS) gsch2pcb.c -o gsch2pcb.o +../src/portability.o: + cd ../src && make portability.o + +../src/ds.o: + cd ../src && make ds.o + ../src/libpcb_fp.o: cd ../src && make libpcb_fp.o Index: util/gsch2pcb.c =================================================================== --- util/gsch2pcb.c (revision 312) +++ util/gsch2pcb.c (revision 313) @@ -83,7 +83,30 @@ quiet_mode = FALSE, preserve, fix_elements, bak_done, need_PKG_purge; +static char *element_search_path = PCB_LIBRARY_SEARCH_PATHS; +static char *libshell = PCB_LIBRARY_SHELL; +void ChdirErrorMessage (char *DirName) +{ + fprintf(stderr, "gsch2pcb-rnd: warning: can't cd to %s\n", DirName); +} + +void OpendirErrorMessage (char *DirName) +{ + fprintf(stderr, "gsch2pcb-rnd: warning: can't opendir %s\n", DirName); +} + +void PopenErrorMessage (char *cmd) +{ + fprintf(stderr, "gsch2pcb-rnd: warning: can't popen %s\n", cmd); +} + +void Message (char *err) +{ + fprintf(stderr, "gsch2pcb-rnd: %s\n", err); +} + + /** * Build and run a command. No redirection or error handling is * done. Format string is split on whitespace. Specifiers %l and %s @@ -514,38 +537,17 @@ } static gboolean -insert_element (FILE * f_out, gchar * element_file, +insert_element (FILE * f_out, FILE *f_elem, gchar * footprint, gchar * refdes, gchar * value) { - FILE *f_in; PcbElement *el; gchar *fmt, *s, buf[1024]; gboolean retval = FALSE; - if ((f_in = fopen (element_file, "r")) == NULL) { - s = g_strdup_printf ("insert_element() can't open %s", element_file); - perror (s); - g_free (s); - return FALSE; - } - /* Scan the file to detect whether it's actually a PCB - * layout. Assumes that a PCB layout will have a "PCB" line. */ - while ((fgets (buf, sizeof (buf), f_in)) != NULL) { - for (s = buf; *s == ' ' || *s == '\t'; ++s); - s[3] = 0; /* Truncate line */ - if (strncmp ("PCB", s, sizeof (buf)) == 0) { - printf ("Warning: %s appears to be a PCB layout file. Skipping.\n", - element_file); - fclose (f_in); - return FALSE; - } - } - rewind (f_in); - /* Copy the file element lines. Substitute new parameters into the * Element() or Element[] line and strip comments. */ - while ((fgets (buf, sizeof (buf), f_in)) != NULL) { + while ((fgets (buf, sizeof (buf), f_elem)) != NULL) { for (s = buf; *s == ' ' || *s == '\t'; ++s); if ((el = pcb_element_line_parse (s)) != NULL) { simple_translate (el); @@ -561,7 +563,6 @@ fputs (buf, f_out); pcb_element_free (el); } - fclose (f_in); return retval; } @@ -669,11 +670,12 @@ static gint add_elements (gchar * pcb_file) { - FILE *f_in, *f_out; + FILE *f_in, *f_out, *fp; PcbElement *el = NULL; - gchar *command, *p, *tmp_file, *s, buf[1024]; + gchar *command, *tmp_file, *s, buf[1024]; gint total, paren_level = 0; gboolean skipping = FALSE; + int st; if ((f_in = fopen (pcb_file, "r")) == NULL) return 0; @@ -705,21 +707,21 @@ continue; } -/* TODO */ { if (verbose) printf ("%s: need new element for footprint %s (value=%s)\n", el->refdes, el->description, el->value); - p = search_element (el); - if (!p && verbose) + fp = pcb_fp_fopen(libshell, element_search_path, el->description, &st); + + if (fp == NULL && verbose) printf ("\tNo file element found.\n"); - if (p && insert_element (f_out, p, + if ((fp != NULL) && insert_element (f_out, fp, el->description, el->refdes, el->value)) { ++n_added_ef; if (verbose) - printf ("%s: added new file element for footprint %s (value=%s)\n", + printf ("%s: added new element for footprint %s (value=%s)\n", el->refdes, el->description, el->value); } else { fprintf (stderr, @@ -734,7 +736,8 @@ fputs (buf, f_out); /* Copy PKG_ line */ } } - g_free (p); + if (fp != NULL) + pcb_fp_fclose(fp, &st); } pcb_element_free (el);