Index: trunk/src/file.h =================================================================== --- trunk/src/file.h (revision 1766) +++ trunk/src/file.h (nonexistent) @@ -1,2 +0,0 @@ -#warning TODO: this should be gone once io_pcb is really a plugin -#include "../src_plugins/io_pcb/file.h" Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 1766) +++ trunk/src/Makefile.dep (revision 1767) @@ -553,7 +553,7 @@ ../src_plugins/hid_gtk/ghid-route-style-selector.h \ ../src_plugins/hid_gtk/gui-pinout-preview.h \ ../src_plugins/hid_gtk/gtkhid.h conf_hid.h action_helper.h change.h \ - file.h ../src_plugins/io_pcb/file.h error.h draw.h pcb-printf.h set.h \ + ../src_plugins/io_pcb/file.h error.h draw.h pcb-printf.h set.h \ hid_attrib.h conf.h compat_fs.h ../src_plugins/hid_gtk/gui-dialog-print.o: \ ../src_plugins/hid_gtk/gui-dialog-print.c ../config.h ../config.manual.h \ @@ -827,7 +827,7 @@ ../src_plugins/hid_gtk/ghid-coord-entry.h \ ../src_plugins/hid_gtk/ghid-main-menu.h \ ../src_plugins/hid_gtk/gui-pinout-preview.h action_helper.h buffer.h \ - change.h copy.h create.h crosshair.h draw.h error.h file.h \ + change.h copy.h create.h crosshair.h draw.h error.h \ ../src_plugins/io_pcb/file.h find.h insert.h line.h mymem.h move.h \ pcb-printf.h polygon.h rats.h remove.h rotate.h rubberband.h search.h \ select.h set.h undo.h event.h free_atexit.h paths.h \ @@ -1099,7 +1099,7 @@ 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 global_element.h \ - list_element.h create.h global.h data.h draw.h error.h file.h \ + list_element.h create.h global.h data.h draw.h error.h \ ../src_plugins/io_pcb/file.h find.h misc.h \ ../src_3rd/genvector/gds_char.h mymem.h mymem.h polygon.h rats.h \ search.h set.h undo.h plugins.h ../src_plugins/mincut/pcb-mincut/graph.h \ @@ -1184,7 +1184,7 @@ ../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 global.h action_helper.h buffer.h \ - ../src_plugins/shand_cmd/command.h data.h error.h file.h \ + ../src_plugins/shand_cmd/command.h data.h error.h \ ../src_plugins/io_pcb/file.h mymem.h misc.h mymem.h rats.h set.h \ plugins.h hid_actions.h dolists.h ../src_plugins/stroke/stroke.o: ../src_plugins/stroke/stroke.c \ @@ -1349,7 +1349,7 @@ ../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 action_helper.h buffer.h copy.h create.h crosshair.h data.h \ - error.h file.h ../src_plugins/io_pcb/file.h global.h mymem.h mirror.h \ + error.h ../src_plugins/io_pcb/file.h global.h mymem.h mirror.h \ misc.h parse_l.h ../src_plugins/io_pcb/parse_l.h polygon.h rats.h \ rotate.h remove.h rtree.h search.h select.h set.h funchash_core.h \ funchash.h funchash_core_list.h @@ -1514,7 +1514,7 @@ ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ ../src_3rd/genvector/vtp0.h list_conf.h create.h data.h draw.h error.h \ mymem.h misc.h parse_l.h ../src_plugins/io_pcb/parse_l.h global.h \ - polygon.h rtree.h search.h set.h undo.h file.h \ + polygon.h rtree.h search.h set.h undo.h \ ../src_plugins/io_pcb/file.h stub_vendor.h hid_actions.h paths.h crosshair.o: crosshair.c ../config.h ../config.manual.h ../config.auto.h \ global.h const.h ../globalconst.h ../config.h macro.h global_typedefs.h \ @@ -1573,7 +1573,7 @@ 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 global_element.h \ - list_element.h data.h error.h file.h ../src_plugins/io_pcb/file.h \ + list_element.h data.h error.h ../src_plugins/io_pcb/file.h \ global.h misc.h ../src_3rd/genvector/gds_char.h mymem.h event.o: event.c event.h error.h file_act.o: file_act.c ../config.h ../config.manual.h ../config.auto.h \ @@ -1590,7 +1590,7 @@ ../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 change.h error.h undo.h crosshair.h \ - set.h file.h ../src_plugins/io_pcb/file.h global.h buffer.h mymem.h \ + set.h ../src_plugins/io_pcb/file.h global.h buffer.h mymem.h \ misc.h remove.h create.h draw.h find.h search.h hid_actions.h \ hid_attrib.h find.o: find.c ../config.h ../config.manual.h ../config.auto.h global.h \ @@ -1608,7 +1608,7 @@ ../src_3rd/liblihata/genht/ht.h ../src_3rd/liblihata/genht/ht_inlines.h \ ../src_3rd/genvector/vtp0.h list_conf.h crosshair.h data.h draw.h \ error.h find.h mymem.h misc.h rtree.h polygon.h search.h set.h undo.h \ - rats.h file.h ../src_plugins/io_pcb/file.h global.h hid_actions.h + rats.h ../src_plugins/io_pcb/file.h global.h hid_actions.h find_act.o: find_act.c ../config.h ../config.manual.h ../config.auto.h \ conf_core.h ../globalconst.h ../config.h conf.h global.h const.h macro.h \ global_typedefs.h global_objs.h ../src_3rd/genlist/gendlist.h polyarea.h \ @@ -1903,7 +1903,7 @@ ../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 data.h buffer.h create.h crosshair.h draw.h error.h file.h \ + list_conf.h data.h buffer.h create.h crosshair.h draw.h error.h \ ../src_plugins/io_pcb/file.h global.h set.h action_helper.h misc.h \ mymem.h compat_lrealpath.h free_atexit.h polygon.h buildin.h paths.h \ strflags.h plugins.h plug_footprint.h vtlibrary.h event.h funchash.h \ @@ -1933,7 +1933,7 @@ ../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 box.h misc.h mymem.h crosshair.h create.h data.h draw.h \ - file.h ../src_plugins/io_pcb/file.h global.h error.h move.h polygon.h \ + ../src_plugins/io_pcb/file.h global.h error.h move.h polygon.h \ remove.h rtree.h rotate.h rubberband.h search.h set.h undo.h \ action_helper.h compat_fs.h compat_misc.h hid_actions.h hid_init.h move.o: move.c ../config.h ../config.manual.h ../config.auto.h \ @@ -1970,7 +1970,7 @@ 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 global_element.h \ - list_element.h action_helper.h buffer.h data.h error.h file.h \ + list_element.h action_helper.h buffer.h data.h error.h \ ../src_plugins/io_pcb/file.h global.h find.h mymem.h misc.h \ ../src_3rd/genvector/gds_char.h rats.h set.h create.h rats_patch.h \ hid_actions.h @@ -2011,7 +2011,7 @@ 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 global_element.h \ - list_element.h data.h file.h ../src_plugins/io_pcb/file.h global.h \ + list_element.h data.h ../src_plugins/io_pcb/file.h global.h \ mymem.h paths.h plug_footprint.h vtlibrary.h plugins.h \ ../src_3rd/liblihata/genht/htsp.h ../src_3rd/liblihata/genht/ht.h \ ../src_3rd/liblihata/genht/ht_inlines.h \ @@ -2030,7 +2030,7 @@ ../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 data.h file.h ../src_plugins/io_pcb/file.h global.h \ + list_conf.h data.h ../src_plugins/io_pcb/file.h global.h \ plug_footprint.h vtlibrary.h plugins.h error.h plugins.o: plugins.c plugins.h ../config.h ../config.manual.h \ ../config.auto.h global.h const.h ../globalconst.h ../config.h macro.h \ @@ -2091,7 +2091,7 @@ 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 global_element.h \ - list_element.h data.h draw.h drill.h file.h ../src_plugins/io_pcb/file.h \ + list_element.h data.h draw.h drill.h ../src_plugins/io_pcb/file.h \ global.h find.h error.h misc.h ../src_3rd/genvector/gds_char.h mymem.h \ print.h polygon.h rtree.h search.h rats.o: rats.c ../config.h ../config.manual.h ../config.auto.h \ @@ -2107,7 +2107,7 @@ ../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 create.h data.h draw.h error.h file.h \ + list_conf.h create.h data.h draw.h error.h \ ../src_plugins/io_pcb/file.h global.h find.h misc.h mymem.h polygon.h \ rats.h search.h set.h undo.h stub_mincut.h rats_act.o: rats_act.c ../config.h ../config.manual.h ../config.auto.h \ Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 1766) +++ trunk/src/Makefile.in (revision 1767) @@ -73,6 +73,7 @@ paths.o pcb-printf.o plugins.o + plug_io.o plug_footprint.o plug_footprint_host.o polygon.o Index: trunk/src/buffer.c =================================================================== --- trunk/src/buffer.c (revision 1766) +++ trunk/src/buffer.c (revision 1767) @@ -45,11 +45,10 @@ #include "crosshair.h" #include "data.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "mymem.h" #include "mirror.h" #include "misc.h" -#include "parse_l.h" #include "polygon.h" #include "rats.h" #include "rotate.h" Index: trunk/src/create.c =================================================================== --- trunk/src/create.c (revision 1766) +++ trunk/src/create.c (revision 1767) @@ -45,7 +45,6 @@ #include "error.h" #include "mymem.h" #include "misc.h" -#include "parse_l.h" #include "pcb-printf.h" #include "polygon.h" #include "rtree.h" @@ -52,7 +51,7 @@ #include "search.h" #include "set.h" #include "undo.h" -#include "file.h" +#include "plug_io.h" #include "stub_vendor.h" #include "hid_actions.h" #include "paths.h" Index: trunk/src/error.c =================================================================== --- trunk/src/error.c (revision 1766) +++ trunk/src/error.c (revision 1767) @@ -54,7 +54,7 @@ #include "data.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "misc.h" Index: trunk/src/file_act.c =================================================================== --- trunk/src/file_act.c (revision 1766) +++ trunk/src/file_act.c (revision 1767) @@ -35,7 +35,7 @@ #include "crosshair.h" #include "set.h" -#include "file.h" +#include "plug_io.h" #include "buffer.h" #include "mymem.h" #include "misc.h" Index: trunk/src/find.c =================================================================== --- trunk/src/find.c (revision 1766) +++ trunk/src/find.c (revision 1767) @@ -94,7 +94,7 @@ #include "set.h" #include "undo.h" #include "rats.h" -#include "file.h" +#include "plug_io.h" #include "hid_actions.h" #undef DEBUG Index: trunk/src/main.c =================================================================== --- trunk/src/main.c (revision 1766) +++ trunk/src/main.c (revision 1767) @@ -49,7 +49,7 @@ #include "crosshair.h" #include "draw.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "set.h" #include "action_helper.h" #include "misc.h" @@ -429,7 +429,6 @@ uninit_strflags_layerlist(); fp_uninit(); - file_uninit(); funchash_uninit(); #define free0(ptr) \ Index: trunk/src/misc.c =================================================================== --- trunk/src/misc.c (revision 1766) +++ trunk/src/misc.c (revision 1767) @@ -57,7 +57,7 @@ #include "create.h" #include "data.h" #include "draw.h" -#include "file.h" +#include "plug_io.h" #include "error.h" #include "mymem.h" #include "misc.h" Index: trunk/src/netlist.c =================================================================== --- trunk/src/netlist.c (revision 1766) +++ trunk/src/netlist.c (revision 1767) @@ -46,7 +46,7 @@ #include "buffer.h" #include "data.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "find.h" #include "mymem.h" #include "misc.h" Index: trunk/src/plug_footprint.c =================================================================== --- trunk/src/plug_footprint.c (revision 1766) +++ trunk/src/plug_footprint.c (revision 1767) @@ -28,7 +28,7 @@ #include "global.h" #include "data.h" -#include "file.h" +#include "plug_io.h" #include "mymem.h" #include "paths.h" #include "plug_footprint.h" Index: trunk/src/plug_footprint_host.c =================================================================== --- trunk/src/plug_footprint_host.c (revision 1766) +++ trunk/src/plug_footprint_host.c (revision 1767) @@ -36,7 +36,7 @@ #include "global.h" #include "data.h" -#include "file.h" +#include "plug_io.h" #include "plug_footprint.h" #include "plugins.h" #include "error.h" Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (nonexistent) +++ trunk/src/plug_io.c (revision 1767) @@ -0,0 +1,650 @@ +/* $Id$ */ + +/* + * 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; some of the code landed in the io_pcb plugin, + the format-independent parts ended up here. */ + +/* file save, load, merge ... routines + * getpid() needs a cast to (int) to get rid of compiler warnings + * on several architectures + */ + +#include "config.h" +#include "conf_core.h" + +#include + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#include "global.h" + +#include +#ifdef HAVE_PWD_H +#include +#endif +#include + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#include + +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef HAVE_NETDB_H +#include +#endif + +#include + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + + +#include "buffer.h" +#include "change.h" +#include "create.h" +#include "crosshair.h" +#include "data.h" +#include "error.h" +#include "plug_io.h" +#include "hid.h" +#include "misc.h" +#include "move.h" +#include "mymem.h" +#include "pcb-printf.h" +#include "polygon.h" +#include "rats.h" +#include "remove.h" +#include "set.h" +#include "strflags.h" +#include "compat_fs.h" +#include "paths.h" +#include "rats_patch.h" +#include "stub_edif.h" +#include "hid_actions.h" +#include "hid_flags.h" +#include "plug_io.h" + +RCSID("$Id$"); + +#if !defined(HAS_ATEXIT) && !defined(HAS_ON_EXIT) +/* --------------------------------------------------------------------------- + * some local identifiers for OS without an atexit() or on_exit() + * call + */ +static char TMPFilename[80]; +#endif + +/* --------------------------------------------------------------------------- + * Flag helper functions + */ + +#define F2S(OBJ, TYPE) flags_to_string ((OBJ)->Flags, TYPE) + +/* --------------------------------------------------------------------------- */ + +static int string_cmp(const char *a, const char *b) +{ + while (*a && *b) { + if (isdigit((int) *a) && isdigit((int) *b)) { + int ia = atoi(a); + int ib = atoi(b); + if (ia != ib) + return ia - ib; + while (isdigit((int) *a) && *(a + 1)) + a++; + while (isdigit((int) *b) && *(b + 1)) + b++; + } + else if (tolower((int) *a) != tolower((int) *b)) + return tolower((int) *a) - tolower((int) *b); + a++; + b++; + } + if (*a) + return 1; + if (*b) + return -1; + return 0; +} + +static int netlist_sort_offset = 0; + +static int netlist_sort(const void *va, const void *vb) +{ + LibraryMenuType *am = (LibraryMenuType *) va; + LibraryMenuType *bm = (LibraryMenuType *) vb; + char *a = am->Name; + char *b = bm->Name; + if (*a == '~') + a++; + if (*b == '~') + b++; + return string_cmp(a, b); +} + +static int netnode_sort(const void *va, const void *vb) +{ + LibraryEntryType *am = (LibraryEntryType *) va; + LibraryEntryType *bm = (LibraryEntryType *) vb; + char *a = am->ListEntry; + char *b = bm->ListEntry; + return string_cmp(a, b); +} + +void sort_library(LibraryTypePtr lib) +{ + int i; + qsort(lib->Menu, lib->MenuN, sizeof(lib->Menu[0]), netlist_sort); + for (i = 0; i < lib->MenuN; i++) + qsort(lib->Menu[i].Entry, lib->Menu[i].EntryN, sizeof(lib->Menu[i].Entry[0]), netnode_sort); +} + +void sort_netlist() +{ + netlist_sort_offset = 2; + sort_library(&(PCB->NetlistLib[NETLIST_INPUT])); + netlist_sort_offset = 0; +} + +/* --------------------------------------------------------------------------- + * opens a file and check if it exists + */ +FILE *CheckAndOpenFile(char *Filename, bool Confirm, bool AllButton, bool * WasAllButton, bool * WasCancelButton) +{ + FILE *fp = NULL; + struct stat buffer; + char message[MAXPATHLEN + 80]; + int response; + + if (Filename && *Filename) { + if (!stat(Filename, &buffer) && Confirm) { + sprintf(message, _("File '%s' exists, use anyway?"), Filename); + if (WasAllButton) + *WasAllButton = false; + if (WasCancelButton) + *WasCancelButton = false; + if (AllButton) + response = gui->confirm_dialog(message, "Cancel", "Ok", AllButton ? "Sequence OK" : 0); + else + response = gui->confirm_dialog(message, "Cancel", "Ok", "Sequence OK"); + + switch (response) { + case 2: + if (WasAllButton) + *WasAllButton = true; + break; + case 0: + if (WasCancelButton) + *WasCancelButton = true; + } + } + if ((fp = fopen(Filename, "w")) == NULL) + OpenErrorMessage(Filename); + } + return (fp); +} + +/* --------------------------------------------------------------------------- + * opens a file for saving connection data + */ +FILE *OpenConnectionDataFile(void) +{ + char *fname; + FILE *fp; + static char *default_file = NULL; + bool result; /* not used */ + + /* CheckAndOpenFile deals with the case where fname already exists */ + fname = gui->fileselect(_("Save Connection Data As ..."), + _("Choose a file to save all connection data to."), default_file, ".net", "connection_data", 0); + if (fname == NULL) + return NULL; + + if (default_file != NULL) { + free(default_file); + default_file = NULL; + } + + if (fname && *fname) + default_file = strdup(fname); + + fp = CheckAndOpenFile(fname, true, false, &result, NULL); + free(fname); + + return fp; +} + +/* --------------------------------------------------------------------------- + * save elements in the current buffer + */ +int SaveBufferElements(char *Filename) +{ + int result; + + if (SWAP_IDENT) + SwapBuffers(); + result = WritePipe(Filename, false); + if (SWAP_IDENT) + SwapBuffers(); + return (result); +} + +/* --------------------------------------------------------------------------- + * save PCB + */ +int SavePCB(char *file) +{ + int retcode; + + if (gui->notify_save_pcb == NULL) + return WritePipe(file, true); + + gui->notify_save_pcb(file, false); + retcode = WritePipe(file, true); + gui->notify_save_pcb(file, true); + + return retcode; +} + +/* --------------------------------------------------------------------------- + * set the route style to the first one, if the current one doesn't + * happen to match any. This way, "revert" won't change the route + * style. + */ +void set_some_route_style() +{ + if (hid_get_flag("style")) + return; + SetLineSize(PCB->RouteStyle[0].Thick); + SetViaSize(PCB->RouteStyle[0].Diameter, true); + SetViaDrillingHole(PCB->RouteStyle[0].Hole, true); + SetKeepawayWidth(PCB->RouteStyle[0].Keepaway); +} + +/* --------------------------------------------------------------------------- + * Load PCB + */ +int LoadPCB(char *file, bool require_font, bool is_misc) +{ + return real_load_pcb(file, false, require_font, is_misc); +} + +/* --------------------------------------------------------------------------- + * Revert PCB + */ +int RevertPCB(void) +{ + return real_load_pcb(PCB->Filename, true, true, true); +} + +/* --------------------------------------------------------------------------- + * functions for loading elements-as-pcb + */ + +extern PCBTypePtr yyPCB; +extern DataTypePtr yyData; +extern FontTypePtr yyFont; + +void PreLoadElementPCB() +{ + + if (!yyPCB) + return; + + yyFont = &yyPCB->Font; + yyData = yyPCB->Data; + yyData->pcb = yyPCB; + yyData->LayerN = 0; +} + +void PostLoadElementPCB() +{ + PCBTypePtr pcb_save = PCB; + ElementTypePtr e; + + if (!yyPCB) + return; + + CreateNewPCBPost(yyPCB, 0); + ParseGroupString("1,c:2,s", &yyPCB->LayerGroups, yyData->LayerN); + e = elementlist_first(&yyPCB->Data->Element); /* we know there's only one */ + PCB = yyPCB; + MoveElementLowLevel(yyPCB->Data, e, -e->BoundingBox.X1, -e->BoundingBox.Y1); + PCB = pcb_save; + yyPCB->MaxWidth = e->BoundingBox.X2; + yyPCB->MaxHeight = e->BoundingBox.Y2; + yyPCB->is_footprint = 1; +} + +/* --------------------------------------------------------------------------- + * writes the quoted string created by another subroutine + */ +void PrintQuotedString(FILE * FP, const char *S) +{ + const char *start; + + fputc('"', FP); + for(start = S; *S != '\0'; S++) { + if (*S == '"' || *S == '\\') { + if (start != S) + fwrite(start, S-start, 1, FP); + fputc('\\', FP); + fputc(*S, FP); + start = S+1; + } + } + + if (start != S) + fwrite(start, S-start, 1, FP); + + fputc('"', FP); +} + +/* --------------------------------------------------------------------------- + * saves the layout in a temporary file + * this is used for fatal errors and does not call the program specified + * in 'saveCommand' for safety reasons + */ +void SaveInTMP(void) +{ + char filename[80]; + + /* memory might have been released before this function is called */ + if (PCB && PCB->Changed) { + sprintf(filename, EMERGENCY_NAME, (int) getpid()); + Message(_("Trying to save your layout in '%s'\n"), filename); + WritePCBFile(filename); + } +} + +/* --------------------------------------------------------------------------- + * front-end for 'SaveInTMP()' + * just makes sure that the routine is only called once + */ +static bool dont_save_any_more = false; +void EmergencySave(void) +{ + + if (!dont_save_any_more) { + SaveInTMP(); + dont_save_any_more = true; + } +} + +void DisableEmergencySave(void) +{ + dont_save_any_more = true; +} + +/* ---------------------------------------------------------------------- + * Callback for the autosave + */ + +static hidval backup_timer; + +/* + * If the backup interval is > 0 then set another timer. Otherwise + * we do nothing and it is up to the GUI to call EnableAutosave() + * after setting conf_core.rc.backup_interval > 0 again. + */ +static void backup_cb(hidval data) +{ + backup_timer.ptr = NULL; + Backup(); + if (conf_core.rc.backup_interval > 0 && gui->add_timer) + backup_timer = gui->add_timer(backup_cb, 1000 * conf_core.rc.backup_interval, data); +} + +void EnableAutosave(void) +{ + hidval x; + + x.ptr = NULL; + + /* If we already have a timer going, then cancel it out */ + if (backup_timer.ptr != NULL && gui->stop_timer) + gui->stop_timer(backup_timer); + + backup_timer.ptr = NULL; + /* Start up a new timer */ + if (conf_core.rc.backup_interval > 0 && gui->add_timer) + backup_timer = gui->add_timer(backup_cb, 1000 * conf_core.rc.backup_interval, x); +} + +/* --------------------------------------------------------------------------- + * creates backup file. The default is to use the pcb file name with + * a "-" appended (like "foo.pcb-") and if we don't have a pcb file name + * then use the template in BACKUP_NAME + */ +void Backup(void) +{ + char *filename = NULL; + + if (PCB && PCB->Filename) { + filename = (char *) malloc(sizeof(char) * (strlen(PCB->Filename) + 2)); + if (filename == NULL) { + fprintf(stderr, "Backup(): malloc failed\n"); + exit(1); + } + sprintf(filename, "%s-", PCB->Filename); + } + else { + /* BACKUP_NAME has %.8i which will be replaced by the process ID */ + filename = (char *) malloc(sizeof(char) * (strlen(BACKUP_NAME) + 8)); + if (filename == NULL) { + fprintf(stderr, "Backup(): malloc failed\n"); + exit(1); + } + sprintf(filename, BACKUP_NAME, (int) getpid()); + } + + WritePCBFile(filename); + free(filename); +} + +#if !defined(HAS_ATEXIT) && !defined(HAS_ON_EXIT) +/* --------------------------------------------------------------------------- + * makes a temporary copy of the data. This is useful for systems which + * doesn't support calling functions on exit. We use this to save the data + * before LEX and YACC functions are called because they are able to abort + * the program. + */ +void SaveTMPData(void) +{ + sprintf(TMPFilename, EMERGENCY_NAME, (int) getpid()); + WritePCBFile(TMPFilename); +} + +/* --------------------------------------------------------------------------- + * removes the temporary copy of the data file + */ +void RemoveTMPData(void) +{ + unlink(TMPFilename); +} +#endif + +#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 (nonexistent) +++ trunk/src/plug_io.h (revision 1767) @@ -0,0 +1,79 @@ +/* + * 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_IO_H +#define PCB_PLUG_IO_H +/**************************** API definition *********************************/ +typedef struct plug_io_s plug_io_t; +struct plug_io_s { + plug_io_t *next; + void *plugin_data; + + /* Attempt to load a pcb design from Filename to Ptr. Return 0 on success. */ + int (*ParsePCB)(PCBTypePtr Ptr, char *Filename); + + /* Attempt to load an element from Filename to Ptr. Return 0 on success. */ + int (*ParseElement)(DataTypePtr Ptr, const char *name); + + /* Attempt to load fonts from a file. Return 0 on success. */ + int (*ParseFont)(FontTypePtr Ptr, char *Filename); + +}; + +extern plug_io_t *plug_io_chain; + +/********** common function used to be part of file.[ch] and friends **********/ +FILE *CheckAndOpenFile(char *, bool, bool, bool *, bool *); +FILE *OpenConnectionDataFile(void); +int SavePCB(char *); +int LoadPCB(char *, bool, bool); +void EnableAutosave(void); +void Backup(void); +void SaveInTMP(void); +void EmergencySave(void); +void DisableEmergencySave(void); +int RevertPCB(void); +int ImportNetlist(char *); +int SaveBufferElements(char *); +void PreLoadElementPCB(void); +void PostLoadElementPCB(void); +void sort_netlist(void); +void PrintQuotedString(FILE *, const char *); +void sort_library(LibraryTypePtr lib); +void set_some_route_style(); + + +#ifndef HAS_ATEXIT +#ifdef HAS_ON_EXIT +void GlueEmergencySave(int, caddr_t); +#else +void SaveTMPData(void); +void RemoveTMPData(void); +#endif +#endif + +#endif Index: trunk/src/print.c =================================================================== --- trunk/src/print.c (revision 1766) +++ trunk/src/print.c (revision 1767) @@ -49,7 +49,7 @@ #include "data.h" #include "draw.h" #include "drill.h" -#include "file.h" +#include "plug_io.h" #include "find.h" #include "error.h" #include "misc.h" Index: trunk/src/rats.c =================================================================== --- trunk/src/rats.c (revision 1766) +++ trunk/src/rats.c (revision 1767) @@ -47,7 +47,7 @@ #include "data.h" #include "draw.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "find.h" #include "misc.h" #include "mymem.h" Index: trunk/src_plugins/hid_gtk/gui-config.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-config.c (revision 1766) +++ trunk/src_plugins/hid_gtk/gui-config.c (revision 1767) @@ -40,7 +40,7 @@ #include "global.h" #include "action_helper.h" #include "change.h" -#include "file.h" +#include "plug_io.h" #include "error.h" #include "draw.h" #include "misc.h" Index: trunk/src_plugins/hid_gtk/gui-top-window.c =================================================================== --- trunk/src_plugins/hid_gtk/gui-top-window.c (revision 1766) +++ trunk/src_plugins/hid_gtk/gui-top-window.c (revision 1767) @@ -79,7 +79,7 @@ #include "crosshair.h" #include "draw.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "find.h" #include "insert.h" #include "line.h" Index: trunk/src_plugins/io_pcb/file.c =================================================================== --- trunk/src_plugins/io_pcb/file.c (revision 1766) +++ trunk/src_plugins/io_pcb/file.c (revision 1767) @@ -85,6 +85,7 @@ #include "data.h" #include "error.h" #include "file.h" +#include "plug_io.h" #include "hid.h" #include "misc.h" #include "move.h" @@ -124,8 +125,8 @@ static void WriteElementData(FILE *, DataTypePtr); static void WriteLayerData(FILE *, Cardinal, LayerTypePtr); static int WritePCB(FILE *); -static int WritePCBFile(char *); -static int WritePipe(char *, bool); +int WritePCBFile(char *); +int WritePipe(char *, bool); /* --------------------------------------------------------------------------- * Flag helper functions @@ -173,188 +174,7 @@ return PCB_FILE_VERSION_BASELINE; } -/* --------------------------------------------------------------------------- */ - -static int string_cmp(const char *a, const char *b) -{ - while (*a && *b) { - if (isdigit((int) *a) && isdigit((int) *b)) { - int ia = atoi(a); - int ib = atoi(b); - if (ia != ib) - return ia - ib; - while (isdigit((int) *a) && *(a + 1)) - a++; - while (isdigit((int) *b) && *(b + 1)) - b++; - } - else if (tolower((int) *a) != tolower((int) *b)) - return tolower((int) *a) - tolower((int) *b); - a++; - b++; - } - if (*a) - return 1; - if (*b) - return -1; - return 0; -} - -static int netlist_sort_offset = 0; - -static int netlist_sort(const void *va, const void *vb) -{ - LibraryMenuType *am = (LibraryMenuType *) va; - LibraryMenuType *bm = (LibraryMenuType *) vb; - char *a = am->Name; - char *b = bm->Name; - if (*a == '~') - a++; - if (*b == '~') - b++; - return string_cmp(a, b); -} - -static int netnode_sort(const void *va, const void *vb) -{ - LibraryEntryType *am = (LibraryEntryType *) va; - LibraryEntryType *bm = (LibraryEntryType *) vb; - char *a = am->ListEntry; - char *b = bm->ListEntry; - return string_cmp(a, b); -} - -void sort_library(LibraryTypePtr lib) -{ - int i; - qsort(lib->Menu, lib->MenuN, sizeof(lib->Menu[0]), netlist_sort); - for (i = 0; i < lib->MenuN; i++) - qsort(lib->Menu[i].Entry, lib->Menu[i].EntryN, sizeof(lib->Menu[i].Entry[0]), netnode_sort); -} - -void sort_netlist() -{ - netlist_sort_offset = 2; - sort_library(&(PCB->NetlistLib[NETLIST_INPUT])); - netlist_sort_offset = 0; -} - /* --------------------------------------------------------------------------- - * opens a file and check if it exists - */ -FILE *CheckAndOpenFile(char *Filename, bool Confirm, bool AllButton, bool * WasAllButton, bool * WasCancelButton) -{ - FILE *fp = NULL; - struct stat buffer; - char message[MAXPATHLEN + 80]; - int response; - - if (Filename && *Filename) { - if (!stat(Filename, &buffer) && Confirm) { - sprintf(message, _("File '%s' exists, use anyway?"), Filename); - if (WasAllButton) - *WasAllButton = false; - if (WasCancelButton) - *WasCancelButton = false; - if (AllButton) - response = gui->confirm_dialog(message, "Cancel", "Ok", AllButton ? "Sequence OK" : 0); - else - response = gui->confirm_dialog(message, "Cancel", "Ok", "Sequence OK"); - - switch (response) { - case 2: - if (WasAllButton) - *WasAllButton = true; - break; - case 0: - if (WasCancelButton) - *WasCancelButton = true; - } - } - if ((fp = fopen(Filename, "w")) == NULL) - OpenErrorMessage(Filename); - } - return (fp); -} - -/* --------------------------------------------------------------------------- - * opens a file for saving connection data - */ -FILE *OpenConnectionDataFile(void) -{ - char *fname; - FILE *fp; - static char *default_file = NULL; - bool result; /* not used */ - - /* CheckAndOpenFile deals with the case where fname already exists */ - fname = gui->fileselect(_("Save Connection Data As ..."), - _("Choose a file to save all connection data to."), default_file, ".net", "connection_data", 0); - if (fname == NULL) - return NULL; - - if (default_file != NULL) { - free(default_file); - default_file = NULL; - } - - if (fname && *fname) - default_file = strdup(fname); - - fp = CheckAndOpenFile(fname, true, false, &result, NULL); - free(fname); - - return fp; -} - -/* --------------------------------------------------------------------------- - * save elements in the current buffer - */ -int SaveBufferElements(char *Filename) -{ - int result; - - if (SWAP_IDENT) - SwapBuffers(); - result = WritePipe(Filename, false); - if (SWAP_IDENT) - SwapBuffers(); - return (result); -} - -/* --------------------------------------------------------------------------- - * save PCB - */ -int SavePCB(char *file) -{ - int retcode; - - if (gui->notify_save_pcb == NULL) - return WritePipe(file, true); - - gui->notify_save_pcb(file, false); - retcode = WritePipe(file, true); - gui->notify_save_pcb(file, true); - - return retcode; -} - -/* --------------------------------------------------------------------------- - * set the route style to the first one, if the current one doesn't - * happen to match any. This way, "revert" won't change the route - * style. - */ -static void set_some_route_style() -{ - if (hid_get_flag("style")) - return; - SetLineSize(PCB->RouteStyle[0].Thick); - SetViaSize(PCB->RouteStyle[0].Diameter, true); - SetViaDrillingHole(PCB->RouteStyle[0].Hole, true); - SetKeepawayWidth(PCB->RouteStyle[0].Keepaway); -} - -/* --------------------------------------------------------------------------- * load PCB * parse the file with enabled 'PCB mode' (see parser) * if successful, update some other stuff @@ -362,7 +182,7 @@ * If revert is true, we pass "revert" as a parameter * to the HID's PCBChanged action. */ -static int real_load_pcb(char *Filename, bool revert, bool require_font, bool is_misc) +int real_load_pcb(char *Filename, bool revert, bool require_font, bool is_misc) { const char *unit_suffix; char *new_filename; @@ -375,10 +195,12 @@ start = clock(); #endif +#warning these should be moved to the caller { resolve_path(Filename, &new_filename, 0); oldPCB = PCB; PCB = newPCB; +#warning } /* mark the default font invalid to know if the file has one */ newPCB->Font.Valid = false; @@ -441,98 +263,18 @@ return (0); } + +#warning these should be moved to the caller { PCB = oldPCB; hid_action("PCBChanged"); /* release unused memory */ RemovePCB(newPCB); +#warning } return (1); } /* --------------------------------------------------------------------------- - * Load PCB - */ -int LoadPCB(char *file, bool require_font, bool is_misc) -{ - return real_load_pcb(file, false, require_font, is_misc); -} - -/* --------------------------------------------------------------------------- - * Revert PCB - */ -int RevertPCB(void) -{ - return real_load_pcb(PCB->Filename, true, true, true); -} - -/* --------------------------------------------------------------------------- - * functions for loading elements-as-pcb - */ - -extern PCBTypePtr yyPCB; -extern DataTypePtr yyData; -extern FontTypePtr yyFont; - -void PreLoadElementPCB() -{ - - if (!yyPCB) - return; - - yyFont = &yyPCB->Font; - yyData = yyPCB->Data; - yyData->pcb = yyPCB; - yyData->LayerN = 0; -} - -void PostLoadElementPCB() -{ - PCBTypePtr pcb_save = PCB; - ElementTypePtr e; - - if (!yyPCB) - return; - - CreateNewPCBPost(yyPCB, 0); - ParseGroupString("1,c:2,s", &yyPCB->LayerGroups, yyData->LayerN); - e = elementlist_first(&yyPCB->Data->Element); /* we know there's only one */ - PCB = yyPCB; - MoveElementLowLevel(yyPCB->Data, e, -e->BoundingBox.X1, -e->BoundingBox.Y1); - PCB = pcb_save; - yyPCB->MaxWidth = e->BoundingBox.X2; - yyPCB->MaxHeight = e->BoundingBox.Y2; - yyPCB->is_footprint = 1; -} - -/* --------------------------------------------------------------------------- - * writes the quoted string created by another subroutine - */ -void PrintQuotedString(FILE * FP, const char *S) -{ - const char *start; - - fputc('"', FP); - for(start = S; *S != '\0'; S++) { - if (*S == '"' || *S == '\\') { - if (start != S) - fwrite(start, S-start, 1, FP); - fputc('\\', FP); - fputc(*S, FP); - start = S+1; - } - } - - if (start != S) - fwrite(start, S-start, 1, FP); - - fputc('"', FP); -} - -void file_uninit() -{ -} - -/* --------------------------------------------------------------------------- * writes out an attribute list */ static void WriteAttributeList(FILE * FP, AttributeListTypePtr list, char *prefix) @@ -872,7 +614,7 @@ /* --------------------------------------------------------------------------- * writes PCB to file */ -static int WritePCBFile(char *Filename) +int WritePCBFile(char *Filename) { FILE *fp; int result; @@ -890,7 +632,7 @@ * writes to pipe using the command defined by conf_core.rc.save_command * %f are replaced by the passed filename */ -static int WritePipe(char *Filename, bool thePcb) +int WritePipe(char *Filename, bool thePcb) { FILE *fp; int result; @@ -941,269 +683,3 @@ return (pclose(fp) ? STATUS_ERROR : result); return (fclose(fp) ? STATUS_ERROR : result); } - -/* --------------------------------------------------------------------------- - * saves the layout in a temporary file - * this is used for fatal errors and does not call the program specified - * in 'saveCommand' for safety reasons - */ -void SaveInTMP(void) -{ - char filename[80]; - - /* memory might have been released before this function is called */ - if (PCB && PCB->Changed) { - sprintf(filename, EMERGENCY_NAME, (int) getpid()); - Message(_("Trying to save your layout in '%s'\n"), filename); - WritePCBFile(filename); - } -} - -/* --------------------------------------------------------------------------- - * front-end for 'SaveInTMP()' - * just makes sure that the routine is only called once - */ -static bool dont_save_any_more = false; -void EmergencySave(void) -{ - - if (!dont_save_any_more) { - SaveInTMP(); - dont_save_any_more = true; - } -} - -void DisableEmergencySave(void) -{ - dont_save_any_more = true; -} - -/* ---------------------------------------------------------------------- - * Callback for the autosave - */ - -static hidval backup_timer; - -/* - * If the backup interval is > 0 then set another timer. Otherwise - * we do nothing and it is up to the GUI to call EnableAutosave() - * after setting conf_core.rc.backup_interval > 0 again. - */ -static void backup_cb(hidval data) -{ - backup_timer.ptr = NULL; - Backup(); - if (conf_core.rc.backup_interval > 0 && gui->add_timer) - backup_timer = gui->add_timer(backup_cb, 1000 * conf_core.rc.backup_interval, data); -} - -void EnableAutosave(void) -{ - hidval x; - - x.ptr = NULL; - - /* If we already have a timer going, then cancel it out */ - if (backup_timer.ptr != NULL && gui->stop_timer) - gui->stop_timer(backup_timer); - - backup_timer.ptr = NULL; - /* Start up a new timer */ - if (conf_core.rc.backup_interval > 0 && gui->add_timer) - backup_timer = gui->add_timer(backup_cb, 1000 * conf_core.rc.backup_interval, x); -} - -/* --------------------------------------------------------------------------- - * creates backup file. The default is to use the pcb file name with - * a "-" appended (like "foo.pcb-") and if we don't have a pcb file name - * then use the template in BACKUP_NAME - */ -void Backup(void) -{ - char *filename = NULL; - - if (PCB && PCB->Filename) { - filename = (char *) malloc(sizeof(char) * (strlen(PCB->Filename) + 2)); - if (filename == NULL) { - fprintf(stderr, "Backup(): malloc failed\n"); - exit(1); - } - sprintf(filename, "%s-", PCB->Filename); - } - else { - /* BACKUP_NAME has %.8i which will be replaced by the process ID */ - filename = (char *) malloc(sizeof(char) * (strlen(BACKUP_NAME) + 8)); - if (filename == NULL) { - fprintf(stderr, "Backup(): malloc failed\n"); - exit(1); - } - sprintf(filename, BACKUP_NAME, (int) getpid()); - } - - WritePCBFile(filename); - free(filename); -} - -#if !defined(HAS_ATEXIT) && !defined(HAS_ON_EXIT) -/* --------------------------------------------------------------------------- - * makes a temporary copy of the data. This is useful for systems which - * doesn't support calling functions on exit. We use this to save the data - * before LEX and YACC functions are called because they are able to abort - * the program. - */ -void SaveTMPData(void) -{ - sprintf(TMPFilename, EMERGENCY_NAME, (int) getpid()); - WritePCBFile(TMPFilename); -} - -/* --------------------------------------------------------------------------- - * removes the temporary copy of the data file - */ -void RemoveTMPData(void) -{ - unlink(TMPFilename); -} -#endif - -#define BLANK(x) ((x) == ' ' || (x) == '\t' || (x) == '\n' \ - || (x) == '\0') - -/* --------------------------------------------------------------------------- - * Read in a netlist and store it in the netlist menu - */ - -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_plugins/io_pcb/file.h =================================================================== --- trunk/src_plugins/io_pcb/file.h (revision 1766) +++ trunk/src_plugins/io_pcb/file.h (revision 1767) @@ -33,22 +33,9 @@ #include /* needed to define 'FILE *' */ #include "global.h" -FILE *CheckAndOpenFile(char *, bool, bool, bool *, bool *); -FILE *OpenConnectionDataFile(void); -int SavePCB(char *); -int LoadPCB(char *, bool, bool); -int RevertPCB(void); -void EnableAutosave(void); -void Backup(void); -void SaveInTMP(void); -void EmergencySave(void); -void DisableEmergencySave(void); -int ImportNetlist(char *); -int SaveBufferElements(char *); -void PreLoadElementPCB(void); -void PostLoadElementPCB(void); -void sort_netlist(void); +int WritePipe(char *Filename, bool thePcb); + /* * Whenever the pcb file format is modified, this version number * should be updated to the date when the new code is committed. @@ -63,19 +50,4 @@ /* This is the version we support. */ #define PCB_FILE_VERSION 20110603 - -#ifndef HAS_ATEXIT -#ifdef HAS_ON_EXIT -void GlueEmergencySave(int, caddr_t); -#else -void SaveTMPData(void); -void RemoveTMPData(void); #endif -#endif - -void PrintQuotedString(FILE *, const char *); - -void file_uninit(); -void sort_library(LibraryTypePtr lib); - -#endif Index: trunk/src_plugins/mincut/rats_mincut.c =================================================================== --- trunk/src_plugins/mincut/rats_mincut.c (revision 1766) +++ trunk/src_plugins/mincut/rats_mincut.c (revision 1767) @@ -37,7 +37,7 @@ #include "data.h" #include "draw.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "find.h" #include "misc.h" #include "mymem.h" Index: trunk/src_plugins/shand_cmd/command.c =================================================================== --- trunk/src_plugins/shand_cmd/command.c (revision 1766) +++ trunk/src_plugins/shand_cmd/command.c (revision 1767) @@ -44,7 +44,7 @@ #include "command.h" #include "data.h" #include "error.h" -#include "file.h" +#include "plug_io.h" #include "mymem.h" #include "misc.h" #include "rats.h"