Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 6768) +++ trunk/scconfig/Rev.h (revision 6769) @@ -1 +1 @@ -static const int myrev = 6767; +static const int myrev = 6768; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 6768) +++ trunk/scconfig/Rev.tab (revision 6769) @@ -1,4 +1,4 @@ -6767 configure new import plugins +6768 configure new import plugins 6735 configure gtk splitup 6392 configure draw cross section plugin (gtk and lesstif depend on it) 6365 configure gtk splitup Index: trunk/src/Makefile.in =================================================================== --- trunk/src/Makefile.in (revision 6768) +++ trunk/src/Makefile.in (revision 6769) @@ -161,12 +161,12 @@ ../src_3rd/genregex/regex_sei.o ../src_3rd/genregex/regex_se.o ../src_3rd/genregex/regex.o + ../src_3rd/qparse/qparse.o @] # We do not compile these in the executable but we need rules for these for utils put /local/pcb/OBJS_UTIL [@ ../src_3rd/genvector/vts0.o - ../src_3rd/qparse/qparse.o @] # main: action registrations Index: trunk/src_plugins/import_ltspice/ltspice.c =================================================================== --- trunk/src_plugins/import_ltspice/ltspice.c (revision 6768) +++ trunk/src_plugins/import_ltspice/ltspice.c (revision 6769) @@ -27,6 +27,7 @@ #include #include #include +#include #include "board.h" #include "data.h" @@ -41,12 +42,63 @@ static const char *ltspice_cookie = "ltspice importer"; +static int ltspice_hdr_net(FILE *f) +{ + char s[1024]; + while(fgets(s, sizeof(s), f) != NULL) { + int argc; + char **argv; + + /* split and print fields */ + argc = qparse(s, &argv); + if ((argc > 0) && (pcb_strcasecmp(argv[0], "ExpressPCB Netlist") == 0)) + return 0; + } + return -1; +} + +static int ltspice_load(const char *fname_net, const char *fname_asc) +{ + FILE *fn, *fa; + int ret = 0; + + fn = fopen(fname_net, "r"); + if (fn == NULL) { + pcb_message(PCB_MSG_ERROR, "can't open file '%s' for read\n", fname_net); + return -1; + } + fa = fopen(fname_asc, "r"); + if (fa == NULL) { + pcb_message(PCB_MSG_ERROR, "can't open file '%s' for read\n", fname_asc); + fclose(fn); + return -1; + } + + if (ltspice_hdr_net(fn)) { + pcb_message(PCB_MSG_ERROR, "file '%s' doesn't look like an ExpressPCB netlist\n", fname_net); + goto error; + } +/* if (ltspice_hdr_asc(fn)) goto error;*/ + + + quit:; + fclose(fa); + fclose(fn); + return ret; + + error: + ret = -1; + goto quit; +} + static const char pcb_acts_LoadLtspiceFrom[] = "LoadLtspiceFrom(filename)"; -static const char pcb_acth_LoadLtspiceFrom[] = "Loads the specified ltspice routing file."; +static const char pcb_acth_LoadLtspiceFrom[] = "Loads the specified ltspice .net and .asc file - the netlist must be an ExpressPCB netlist."; int pcb_act_LoadLtspiceFrom(int argc, const char **argv, pcb_coord_t x, pcb_coord_t y) { - const char *fname = NULL; + const char *fname = NULL, *end; + char *fname_asc, *fname_net, *fname_base; static char *default_file = NULL; + int res; fname = argc ? argv[0] : 0; @@ -62,7 +114,26 @@ } } - return 0; + end = strrchr(fname, '.'); + if (strcmp(end, ".net") == 0) + fname_base = pcb_strndup(fname, end - fname); + else if (strcmp(end, ".asc") == 0) + fname_base = pcb_strndup(fname, end - fname); + else { + pcb_message(PCB_MSG_ERROR, "file name '%s' doesn't end in .net or .asc\n", fname); + PCB_ACT_FAIL(LoadLtspiceFrom); + } + + fname_net = pcb_strdup_printf("%s.net", fname_base); + fname_asc = pcb_strdup_printf("%s.asc", fname_base); + free(fname_base); + + res = ltspice_load(fname_net, fname_asc); + + free(fname_asc); + free(fname_net); + + return res; } pcb_hid_action_t ltspice_action_list[] = {