Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 2448) +++ trunk/scconfig/plugins.h (revision 2449) @@ -23,6 +23,7 @@ plugin_header("\nImport plugins:\n") plugin_def("import_sch", "import sch", sbuildin) plugin_def("import_edif", "import edif", sbuildin) +plugin_def("import_netlist", "import netlist", sbuildin) plugin_header("\nExport plugins:\n") plugin_def("export_gcode", "gcode exporter", sbuildin) Index: trunk/src/stub_edif.c =================================================================== --- trunk/src/stub_edif.c (revision 2448) +++ trunk/src/stub_edif.c (nonexistent) @@ -1,35 +0,0 @@ -/* - * COPYRIGHT - * - * PCB, interactive printed circuit board design - * Copyright (C) 2016 Tibor 'Igor2' Palinkas - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include "config.h" -#include "global.h" -#include "error.h" -#include "stub_edif.h" - -static int ReadEdifNetlist_dummy(char *filename) -{ - Message(_("Can not importing edif netlist %s: the edif plugin/buildin is not present.\n"), filename); - return 0; -} - -int (*stub_ReadEdifNetlist)(char *filename) = ReadEdifNetlist_dummy; - Index: trunk/src/stub_edif.h =================================================================== --- trunk/src/stub_edif.h (revision 2448) +++ trunk/src/stub_edif.h (nonexistent) @@ -1,23 +0,0 @@ -/* - * COPYRIGHT - * - * PCB, interactive printed circuit board design - * Copyright (C) 2016 Tibor 'Igor2' Palinkas - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -extern int (*stub_ReadEdifNetlist)(char *filename); Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 2448) +++ trunk/src/Makefile.dep (revision 2449) @@ -1073,8 +1073,40 @@ list_arc.h list_text.h list_poly.h list_pad.h list_pin.h list_rat.h \ vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ - global_element.h list_element.h data.h global.h error.h plugins.h \ - stub_edif.h + global_element.h list_element.h data.h global.h error.h plugins.h +../src_plugins/import_edif/import_edif.o: \ + ../src_plugins/import_edif/import_edif.c ../config.h ../config.auto.h \ + global.h const.h macro.h global_typedefs.h unit.h global_objs.h \ + ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ + list_line.h ../src_3rd/genlist/gentdlist_impl.h \ + ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ + list_arc.h list_text.h list_poly.h list_pad.h list_pin.h list_rat.h \ + vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ + ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ + global_element.h list_element.h plugins.h plug_import.h global.h conf.h \ + pcb-printf.h ../src_3rd/genvector/gds_char.h \ + ../src_3rd/liblihata/lihata.h ../src_3rd/liblihata/dom.h \ + ../src_3rd/liblihata/lihata.h ../src_3rd/liblihata/parser.h \ + ../src_3rd/liblihata/genht/htsp.h ../src_3rd/liblihata/genht/ht.h \ + ../src_3rd/liblihata/genht/ht_inlines.h ../src_3rd/genvector/vtp0.h \ + list_conf.h +../src_plugins/import_netlist/import_netlist.o: \ + ../src_plugins/import_netlist/import_netlist.c ../config.h \ + ../config.auto.h global.h const.h macro.h global_typedefs.h unit.h \ + global_objs.h ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h \ + list_common.h list_line.h ../src_3rd/genlist/gentdlist_impl.h \ + ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ + list_arc.h list_text.h list_poly.h list_pad.h list_pin.h list_rat.h \ + vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ + ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ + global_element.h list_element.h plugins.h plug_io.h global.h conf.h \ + pcb-printf.h ../src_3rd/genvector/gds_char.h \ + ../src_3rd/liblihata/lihata.h ../src_3rd/liblihata/dom.h \ + ../src_3rd/liblihata/lihata.h ../src_3rd/liblihata/parser.h \ + ../src_3rd/liblihata/genht/htsp.h ../src_3rd/liblihata/genht/ht.h \ + ../src_3rd/liblihata/genht/ht_inlines.h ../src_3rd/genvector/vtp0.h \ + list_conf.h plug_import.h conf_core.h error.h misc.h mymem.h data.h \ + rats_patch.h ../src_plugins/import_sch/import_sch.o: \ ../src_plugins/import_sch/import_sch.c ../config.h ../config.auto.h \ conf_core.h conf.h global.h const.h macro.h global_typedefs.h unit.h \ @@ -1158,8 +1190,8 @@ create.h crosshair.h data.h error.h ../src_plugins/io_pcb/file.h \ plug_io.h hid.h misc.h mymem.h move.h mymem.h \ ../src_plugins/io_pcb/parse_l.h pcb-printf.h polygon.h rtree.h rats.h \ - remove.h set.h strflags.h compat_fs.h paths.h rats_patch.h stub_edif.h \ - hid_actions.h hid_flags.h ../src_plugins/io_pcb/flags.h \ + remove.h set.h strflags.h compat_fs.h paths.h rats_patch.h hid_actions.h \ + hid_flags.h ../src_plugins/io_pcb/flags.h \ ../src_plugins/io_pcb/attribs.h route_style.h ../src_plugins/io_pcb/flags.o: ../src_plugins/io_pcb/flags.c strflags.h \ global_objs.h ../src_3rd/genlist/gendlist.h ../config.h ../config.auto.h \ @@ -1761,8 +1793,9 @@ ../src_3rd/liblihata/parser.h ../src_3rd/liblihata/genht/htsp.h \ ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ ../src_3rd/genvector/vtp0.h list_conf.h data.h action_helper.h error.h \ - crosshair.h set.h plug_io.h buffer.h misc.h mymem.h remove.h create.h \ - draw.h find.h search.h misc_util.h hid_actions.h hid_attrib.h + crosshair.h set.h plug_io.h plug_import.h buffer.h misc.h mymem.h \ + remove.h create.h draw.h find.h search.h misc_util.h hid_actions.h \ + hid_attrib.h find.o: find.c ../config.h ../config.auto.h conf_core.h conf.h global.h \ const.h macro.h global_typedefs.h unit.h global_objs.h \ ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ @@ -2239,6 +2272,20 @@ vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ global_element.h list_element.h plug_footprint.h vtlibrary.h +plug_import.o: plug_import.c ../config.h ../config.auto.h conf_core.h \ + conf.h global.h const.h macro.h global_typedefs.h unit.h global_objs.h \ + ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ + list_line.h ../src_3rd/genlist/gentdlist_impl.h \ + ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ + list_arc.h list_text.h list_poly.h list_pad.h list_pin.h list_rat.h \ + vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ + ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ + global_element.h list_element.h pcb-printf.h \ + ../src_3rd/genvector/gds_char.h ../src_3rd/liblihata/lihata.h \ + ../src_3rd/liblihata/dom.h ../src_3rd/liblihata/lihata.h \ + ../src_3rd/liblihata/parser.h ../src_3rd/liblihata/genht/htsp.h \ + ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ + ../src_3rd/genvector/vtp0.h list_conf.h plugins.h plug_import.h error.h plug_io.o: plug_io.c ../config.h ../config.auto.h conf_core.h conf.h \ global.h const.h macro.h global_typedefs.h unit.h global_objs.h \ ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ @@ -2254,7 +2301,7 @@ ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ ../src_3rd/genvector/vtp0.h list_conf.h buffer.h change.h create.h \ data.h error.h plug_io.h misc.h mymem.h remove.h set.h paths.h \ - rats_patch.h stub_edif.h hid_actions.h hid_flags.h plugins.h event.h + rats_patch.h hid_actions.h hid_flags.h plugins.h event.h plugins.o: plugins.c plugins.h global.h ../config.h ../config.auto.h \ const.h macro.h global_typedefs.h unit.h global_objs.h \ ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ @@ -2491,15 +2538,6 @@ vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ global_element.h list_element.h strflags.h -stub_edif.o: stub_edif.c ../config.h ../config.auto.h global.h const.h \ - macro.h global_typedefs.h unit.h global_objs.h \ - ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ - list_line.h ../src_3rd/genlist/gentdlist_impl.h \ - ../src_3rd/genlist/gendlist.h ../src_3rd/genlist/gentdlist_undef.h \ - list_arc.h list_text.h list_poly.h list_pad.h list_pin.h list_rat.h \ - vtonpoint.h ../src_3rd/genvector/genvector_impl.h \ - ../src_3rd/genvector/genvector_undef.h hid.h vtroutestyle.h \ - global_element.h list_element.h error.h stub_edif.h stub_mincut.o: stub_mincut.c ../config.h ../config.auto.h global.h \ const.h macro.h global_typedefs.h unit.h global_objs.h \ ../src_3rd/genlist/gendlist.h globalconst.h polyarea.h list_common.h \ Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 2448) +++ trunk/src/Makefile.in (revision 2449) @@ -77,6 +77,7 @@ paths.o pcb-printf.o plugins.o + plug_import.o plug_io.o plug_footprint.o plug_footprint_act.o @@ -97,7 +98,6 @@ select_act.o set.o strflags.o - stub_edif.o stub_mincut.o stub_stroke.o stub_vendor.o Index: trunk/src/file_act.c =================================================================== --- trunk/src/file_act.c (revision 2448) +++ trunk/src/file_act.c (revision 2449) @@ -33,6 +33,7 @@ #include "crosshair.h" #include "set.h" #include "plug_io.h" +#include "plug_import.h" #include "buffer.h" #include "misc.h" #include "remove.h" Index: trunk/src/plug_import.c =================================================================== --- trunk/src/plug_import.c (nonexistent) +++ trunk/src/plug_import.c (revision 2449) @@ -0,0 +1,121 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 1994,1995,1996,1997,1998,2005,2006 Thomas Nau + * Copyright (C) 2015,2016 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Contact addresses for paper mail and Email: + * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany + * Thomas.Nau@rz.uni-ulm.de + * + */ + +/* This used to be file.c; it's a hook based plugin API now */ + +#include "config.h" +#include "conf_core.h" + +#include + +#include "global.h" + +#include + +#include +#include +#include + +#include "plugins.h" +#include "plug_import.h" +#include "error.h" + + +plug_import_t *plug_import_chain = NULL; + +typedef struct { + plug_import_t *plug; + int prio; +} find_t; + +/* Find the plugin that offers the highest write prio for the format */ +static plug_import_t *find_importer(unsigned int aspects, FILE *f, const char *filename) +{ + find_t available[32]; /* wish we had more than 32 import plugins... */ + int n, len = 0, best = 0, bestidx = -1; + +#define cb_append(pl, pr) \ + do { \ + rewind(f); \ + if (pr > 0) { \ + assert(len < sizeof(available)/sizeof(available[0])); \ + available[len].plug = pl; \ + available[len++].prio = pr; \ + } \ + } while(0) + + HOOK_CALL_ALL(plug_import_t, plug_import_chain, fmt_support_prio, cb_append, aspects, f, filename); + if (len == 0) + return NULL; + + for(n = 0; n < len; n++) { + if (available[n].prio > best) { + bestidx = n; + best = available[n].prio; + } + } + + if (best == 0) + return NULL; + + return available[bestidx].plug; +#undef cb_append +} + + +int pcb_import(char *filename, unsigned int aspect) +{ + plug_import_t *plug; + FILE *fp; + + if (!filename) { + Message("Error: need a file name for ImportNetlist()\n"); + return (1); /* nothing to do */ + } + fp = fopen(filename, "r"); + + plug = find_importer(aspect, fp, filename); + if (plug == NULL) { + if (fp != NULL) { + Message("Error: can't find a suitable netlist parser for %s\n", filename); + fclose(fp); + } + else + Message("Error: can't find a suitable netlist parser for %s - might be related: can't open %s for reading\n", filename, filename); + return 1; + } + + if (fp != NULL) + fclose(fp); + + return plug->import(plug, aspect, filename); +} + +int ImportNetlist(char *filename) +{ + return pcb_import(filename, IMPORT_ASPECT_NETLIST); +} Index: trunk/src/plug_import.h =================================================================== --- trunk/src/plug_import.h (nonexistent) +++ trunk/src/plug_import.h (revision 2449) @@ -0,0 +1,62 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 1994,1995,1996,1997,1998,2005,2006 Thomas Nau + * Copyright (C) 2016 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Contact addresses for paper mail and Email: + * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany + * Thomas.Nau@rz.uni-ulm.de + * + */ + +#ifndef PCB_PLUG_IMPORT_H +#define PCB_PLUG_IMPORT_H + +#include "global.h" +#include "conf.h" + +/**************************** API definition *********************************/ + +typedef enum plug_import_aspect_e { /* bitfield of aspects that can be imported */ + IMPORT_ASPECT_NETLIST = 1 +} plug_import_aspect_t; + +typedef struct plug_import_s plug_import_t; +struct plug_import_s { + plug_import_t *next; + void *plugin_data; + + /* Check if the plugin supports format fmt. Return 0 if not supported or + an integer priority if supported. The higher the prio is the more likely + the plugin gets the next operation on the file. Base prio should be 100 + for native formats. Return non-0 only if all aspects are supported. */ + int (*fmt_support_prio)(plug_import_t *ctx, unsigned int aspects, FILE *f, const char *filename); + + /* Perform the import; return 0 on success */ + int (*import)(plug_import_t *ctx, unsigned int aspects, const char *fn); +}; + +extern plug_import_t *plug_import_chain; + +/********** hook wrappers **********/ +int pcb_import(char *filename, unsigned int aspect); +int ImportNetlist(char *); + + +#endif Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (revision 2448) +++ trunk/src/plug_io.c (revision 2449) @@ -94,7 +94,6 @@ #include "set.h" #include "paths.h" #include "rats_patch.h" -#include "stub_edif.h" #include "hid_actions.h" #include "hid_flags.h" #include "plugins.h" @@ -828,146 +827,3 @@ return (fclose(fp) ? STATUS_ERROR : result); } - - -#define BLANK(x) ((x) == ' ' || (x) == '\t' || (x) == '\n' \ - || (x) == '\0') - -/* --------------------------------------------------------------------------- - * Read in a netlist and store it in the netlist menu - */ -#warning TODO: convert this into a HOOK_* based plugin from stubs (vs. edif down there) -int ReadNetlist(char *filename) -{ - char *command = NULL; - char inputline[MAX_NETLIST_LINE_LENGTH + 1]; - char temp[MAX_NETLIST_LINE_LENGTH + 1]; - FILE *fp; - LibraryMenuTypePtr menu = NULL; - LibraryEntryTypePtr entry; - int i, j, lines, kind; - bool continued; - int used_popen = 0; - - if (!filename) - return (1); /* nothing to do */ - - Message(_("Importing PCB netlist %s\n"), filename); - - if (EMPTY_STRING_P(conf_core.rc.rat_command)) { - fp = fopen(filename, "r"); - if (!fp) { - Message("Cannot open %s for reading", filename); - return 1; - } - } - else { - used_popen = 1; - command = EvaluateFilename(conf_core.rc.rat_command, conf_core.rc.rat_path, filename, NULL); - - /* open pipe to stdout of command */ - if (*command == '\0' || (fp = popen(command, "r")) == NULL) { - PopenErrorMessage(command); - free(command); - return (1); - } - free(command); - } - lines = 0; - /* kind = 0 is net name - * kind = 1 is route style name - * kind = 2 is connection - */ - kind = 0; - while (fgets(inputline, MAX_NETLIST_LINE_LENGTH, fp)) { - size_t len = strlen(inputline); - /* check for maximum length line */ - if (len) { - if (inputline[--len] != '\n') - Message(_("Line length (%i) exceeded in netlist file.\n" - "additional characters will be ignored.\n"), MAX_NETLIST_LINE_LENGTH); - else - inputline[len] = '\0'; - } - continued = (inputline[len - 1] == '\\') ? true : false; - if (continued) - inputline[len - 1] = '\0'; - lines++; - i = 0; - while (inputline[i] != '\0') { - j = 0; - /* skip leading blanks */ - while (inputline[i] != '\0' && BLANK(inputline[i])) - i++; - if (kind == 0) { - /* add two spaces for included/unincluded */ - temp[j++] = ' '; - temp[j++] = ' '; - } - while (!BLANK(inputline[i])) - temp[j++] = inputline[i++]; - temp[j] = '\0'; - while (inputline[i] != '\0' && BLANK(inputline[i])) - i++; - if (kind == 0) { - menu = GetLibraryMenuMemory(&PCB->NetlistLib[NETLIST_INPUT], NULL); - menu->Name = strdup(temp); - menu->flag = 1; - kind++; - } - else { - if (kind == 1 && strchr(temp, '-') == NULL) { - kind++; - menu->Style = strdup(temp); - } - else { - entry = GetLibraryEntryMemory(menu); - entry->ListEntry = strdup(temp); - entry->ListEntry_dontfree = 0; - } - } - } - if (!continued) - kind = 0; - } - if (!lines) { - Message(_("Empty netlist file!\n")); - pclose(fp); - return (1); - } - if (used_popen) - pclose(fp); - else - fclose(fp); - sort_netlist(); - rats_patch_make_edited(PCB); - return (0); -} - -int ImportNetlist(char *filename) -{ - FILE *fp; - char buf[16]; - int i; - char *p; - - - if (!filename) - return (1); /* nothing to do */ - fp = fopen(filename, "r"); - if (!fp) - return (1); /* bad filename */ - i = fread(buf, 1, sizeof(buf) - 1, fp); - fclose(fp); - buf[i] = '\0'; - p = buf; - while (*p) { - *p = tolower((int) *p); - p++; - } - p = strstr(buf, "edif"); - if (!p) - return ReadNetlist(filename); - else - return stub_ReadEdifNetlist(filename); -} Index: trunk/src/plug_io.h =================================================================== --- trunk/src/plug_io.h (revision 2448) +++ trunk/src/plug_io.h (revision 2449) @@ -88,7 +88,6 @@ void EmergencySave(void); void DisableEmergencySave(void); int RevertPCB(void); -int ImportNetlist(char *); int SaveBufferElements(char *, const char *fmt); void sort_netlist(void); void PrintQuotedString(FILE *, const char *); Index: trunk/src_plugins/import_edif/Makefile =================================================================== --- trunk/src_plugins/import_edif/Makefile (revision 2448) +++ trunk/src_plugins/import_edif/Makefile (revision 2449) @@ -1,5 +1,5 @@ all: - cd ../../src && make mod_edif + cd ../../src && make mod_import_edif clean: rm *.o *.so 2>/dev/null ; true Index: trunk/src_plugins/import_edif/Plug.tmpasm =================================================================== --- trunk/src_plugins/import_edif/Plug.tmpasm (revision 2448) +++ trunk/src_plugins/import_edif/Plug.tmpasm (revision 2449) @@ -1,5 +1,5 @@ -put /local/pcb/mod {edif} -append /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_edif/edif.o @] +put /local/pcb/mod {import_edif} +append /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_edif/edif.o $(PLUGDIR)/import_edif/import_edif.o @] append /local/pcb/mod/YACC {$(PLUGDIR)/import_edif/edif} switch /local/pcb/import_edif/controls Index: trunk/src_plugins/import_edif/README =================================================================== --- trunk/src_plugins/import_edif/README (revision 2448) +++ trunk/src_plugins/import_edif/README (revision 2449) @@ -1,4 +1,4 @@ -Import code for netlists in the EDIF format. +Import plugin for netlists in the EDIF format. #state: works #default: buildin Index: trunk/src_plugins/import_edif/edif.c =================================================================== --- trunk/src_plugins/import_edif/edif.c (revision 2448) +++ trunk/src_plugins/import_edif/edif.c (revision 2449) @@ -6239,10 +6239,3 @@ return 0; } - -#include "stub_edif.h" -pcb_uninit_t hid_edif_init(void) -{ - stub_ReadEdifNetlist = ReadEdifNetlist; - return NULL; -} Index: trunk/src_plugins/import_edif/edif.y =================================================================== --- trunk/src_plugins/import_edif/edif.y (revision 2448) +++ trunk/src_plugins/import_edif/edif.y (revision 2449) @@ -4451,10 +4451,3 @@ return 0; } - -#include "stub_edif.h" -pcb_uninit_t hid_edif_init(void) -{ - stub_ReadEdifNetlist = ReadEdifNetlist; - return NULL; -} Index: trunk/src_plugins/import_netlist/Makefile =================================================================== --- trunk/src_plugins/import_netlist/Makefile (nonexistent) +++ trunk/src_plugins/import_netlist/Makefile (revision 2449) @@ -0,0 +1,6 @@ +all: + cd ../../src && make mod_import_netlist + +clean: + rm *.o *.so 2>/dev/null ; true + Index: trunk/src_plugins/import_netlist/Plug.tmpasm =================================================================== --- trunk/src_plugins/import_netlist/Plug.tmpasm (nonexistent) +++ trunk/src_plugins/import_netlist/Plug.tmpasm (revision 2449) @@ -0,0 +1,9 @@ +put /local/pcb/mod {import_netlist} +append /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_netlist/import_netlist.o @] +append /local/pcb/mod/YACC {$(PLUGDIR)/import_netlist/netlist} + +switch /local/pcb/import_netlist/controls + case {buildin} include /local/pcb/tmpasm/buildin; end; + case {plugin} include /local/pcb/tmpasm/plugin; end; + case {disable} include /local/pcb/tmpasm/disable; end; +end Index: trunk/src_plugins/import_netlist/README =================================================================== --- trunk/src_plugins/import_netlist/README (nonexistent) +++ trunk/src_plugins/import_netlist/README (revision 2449) @@ -0,0 +1,5 @@ +Import plugin for netlists in the classic pcb netlist format. + +#state: works +#default: buildin +#implements: import Index: trunk/src_plugins/import_netlist/import_netlist.c =================================================================== --- trunk/src_plugins/import_netlist/import_netlist.c (nonexistent) +++ trunk/src_plugins/import_netlist/import_netlist.c (revision 2449) @@ -0,0 +1,184 @@ +/* + * COPYRIGHT + * + * PCB, interactive printed circuit board design + * Copyright (C) 1994,1995,1996,1997,1998,2005,2006 Thomas Nau + * Copyright (C) 2015,2016 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "config.h" +#include "global.h" +#include "plugins.h" +#include "plug_io.h" +#include "plug_import.h" +#include "conf_core.h" +#include "error.h" +#include "misc.h" +#include "data.h" +#include "rats_patch.h" + + +static plug_import_t import_netlist; + + +#define BLANK(x) ((x) == ' ' || (x) == '\t' || (x) == '\n' \ + || (x) == '\0') + +/* --------------------------------------------------------------------------- + * Read in a netlist and store it in the netlist menu + */ +static int ReadNetlist(const char *filename) +{ + char *command = NULL; + char inputline[MAX_NETLIST_LINE_LENGTH + 1]; + char temp[MAX_NETLIST_LINE_LENGTH + 1]; + FILE *fp; + LibraryMenuTypePtr menu = NULL; + LibraryEntryTypePtr entry; + int i, j, lines, kind; + bool continued; + int used_popen = 0; + + if (!filename) + return (1); /* nothing to do */ + + Message(_("Importing PCB netlist %s\n"), filename); + + if (EMPTY_STRING_P(conf_core.rc.rat_command)) { + fp = fopen(filename, "r"); + if (!fp) { + Message("Cannot open %s for reading", filename); + return 1; + } + } + else { + used_popen = 1; + command = EvaluateFilename(conf_core.rc.rat_command, conf_core.rc.rat_path, filename, NULL); + + /* open pipe to stdout of command */ + if (*command == '\0' || (fp = popen(command, "r")) == NULL) { + PopenErrorMessage(command); + free(command); + return (1); + } + free(command); + } + lines = 0; + /* kind = 0 is net name + * kind = 1 is route style name + * kind = 2 is connection + */ + kind = 0; + while (fgets(inputline, MAX_NETLIST_LINE_LENGTH, fp)) { + size_t len = strlen(inputline); + /* check for maximum length line */ + if (len) { + if (inputline[--len] != '\n') + Message(_("Line length (%i) exceeded in netlist file.\n" + "additional characters will be ignored.\n"), MAX_NETLIST_LINE_LENGTH); + else + inputline[len] = '\0'; + } + continued = (inputline[len - 1] == '\\') ? true : false; + if (continued) + inputline[len - 1] = '\0'; + lines++; + i = 0; + while (inputline[i] != '\0') { + j = 0; + /* skip leading blanks */ + while (inputline[i] != '\0' && BLANK(inputline[i])) + i++; + if (kind == 0) { + /* add two spaces for included/unincluded */ + temp[j++] = ' '; + temp[j++] = ' '; + } + while (!BLANK(inputline[i])) + temp[j++] = inputline[i++]; + temp[j] = '\0'; + while (inputline[i] != '\0' && BLANK(inputline[i])) + i++; + if (kind == 0) { + menu = GetLibraryMenuMemory(&PCB->NetlistLib[NETLIST_INPUT], NULL); + menu->Name = strdup(temp); + menu->flag = 1; + kind++; + } + else { + if (kind == 1 && strchr(temp, '-') == NULL) { + kind++; + menu->Style = strdup(temp); + } + else { + entry = GetLibraryEntryMemory(menu); + entry->ListEntry = strdup(temp); + entry->ListEntry_dontfree = 0; + } + } + } + if (!continued) + kind = 0; + } + if (!lines) { + Message(_("Empty netlist file!\n")); + pclose(fp); + return (1); + } + if (used_popen) + pclose(fp); + else + fclose(fp); + sort_netlist(); + rats_patch_make_edited(PCB); + return (0); +} + +int netlist_support_prio(plug_import_t *ctx, unsigned int aspects, FILE *fp, const char *filename) +{ + if (aspects != IMPORT_ASPECT_NETLIST) + return 0; /* only pure netlist import is supported */ + + /* we are sort of a low prio fallback without any chance to check the file format in advance */ + return 10; +} + + +static int netlist_import(plug_import_t *ctx, unsigned int aspects, const char *fn) +{ + return ReadNetlist(fn); +} + +static void hid_import_netlist_uninit(void) +{ +} + +pcb_uninit_t hid_import_netlist_init(void) +{ + + /* register the IO hook */ + import_netlist.plugin_data = NULL; + + import_netlist.fmt_support_prio = netlist_support_prio; + import_netlist.import = netlist_import; + + HOOK_REGISTER(plug_import_t, plug_import_chain, &import_netlist); + + return hid_import_netlist_uninit; +} + Index: trunk/src_plugins/io_pcb/file.c =================================================================== --- trunk/src_plugins/io_pcb/file.c (revision 2448) +++ trunk/src_plugins/io_pcb/file.c (revision 2449) @@ -98,7 +98,6 @@ #include "compat_fs.h" #include "paths.h" #include "rats_patch.h" -#include "stub_edif.h" #include "hid_actions.h" #include "hid_flags.h" #include "flags.h" Index: trunk/src_plugins/plugins_io.tmpasm =================================================================== --- trunk/src_plugins/plugins_io.tmpasm (revision 2448) +++ trunk/src_plugins/plugins_io.tmpasm (revision 2449) @@ -1,6 +1,7 @@ # I/O plugins: import, export, UI include {../src_plugins/import_edif/Plug.tmpasm} +include {../src_plugins/import_netlist/Plug.tmpasm} include {../src_plugins/import_sch/Plug.tmpasm} include {../src_plugins/export_ps/Plug.tmpasm} include {../src_plugins/export_lpr/Plug.tmpasm}