diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 8e692bac9..f2c9361c8 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -2341,7 +2341,8 @@ static char *readline(FILE *fd) /* Replace "gnd" by " 0 " Delimiters of gnd may be ' ' or ',' or '(' or ')', - may be disabled by setting variable no_auto_gnd */ + may be disabled by setting variable no_auto_gnd. + If called by KiCad, replace /gnd and /0 by 0 */ static void inp_fix_gnd_name(struct card *c) { @@ -2349,6 +2350,10 @@ static void inp_fix_gnd_name(struct card *c) for (; c; c = c->nextcard) { char *gnd = c->line; + // if there is a comment, go to next line + if (*gnd == '*') + continue; + // if inside of a subcircuit, and compatmode is ps, don't replace gnd if (newcompat.ps) { if (ciprefix(".subckt", c->line)) @@ -2357,10 +2362,13 @@ static void inp_fix_gnd_name(struct card *c) found_subckt = FALSE; } - // if there is a comment or no gnd, go to next line - if (found_subckt || (*gnd == '*') || !strstr(gnd, "gnd")) + // if there is a subcircuit or no gnd, go to next line + if (found_subckt || (!strstr(gnd, "gnd") && !strstr(gnd, "/0"))) continue; + // a gnd node will not occur in the first token of the line + gnd = nexttok(gnd); + // replace "?gnd?" by "? 0 ?", ? being a ' ' ',' '(' ')'. while ((gnd = strstr(gnd, "gnd")) != NULL) { if ((isspace_c(gnd[-1]) || gnd[-1] == '(' || gnd[-1] == ',') && @@ -2370,6 +2378,32 @@ static void inp_fix_gnd_name(struct card *c) gnd += 3; } + // Special treatment for KiCad: replace local /gnd and /0 by 0 + if (newcompat.ki) { + /* replace local "/gnd" by " 0 " */ + gnd = c->line; + // a gnd node will not occur in the first token of the line + gnd = nexttok(gnd); + while ((gnd = strstr(gnd, "/gnd")) != NULL) { + if ((isspace_c(gnd[-1]) || gnd[-1] == '(' || gnd[-1] == ',') && + (isspace_c(gnd[4]) || gnd[4] == ')' || gnd[4] == ',')) { + memcpy(gnd, " 0 ", 4); + } + gnd += 4; + } + // replace " /0 " by " 0 " + gnd = c->line; + // a gnd node will not occur in the first token of the line + gnd = nexttok(gnd); + while ((gnd = strstr(gnd, "/0")) != NULL) { + if ((isspace_c(gnd[-1]) || gnd[-1] == '(' || gnd[-1] == ',') && + (isspace_c(gnd[2]) || gnd[2] == ')' || gnd[2] == ',')) { + gnd[0] = ' '; + } + gnd += 2; + } + } + // now remove the extra white spaces around 0 c->line = inp_remove_ws(c->line); }