inp.c, sharedspice.c, enable adding scripts by 'circbyline'

This commit is contained in:
h_vogt 2016-08-07 19:27:27 +02:00 committed by rlar
parent fb49317c8f
commit ac0c79a591
2 changed files with 23 additions and 2 deletions

View File

@ -1510,19 +1510,39 @@ cktislinear(CKTcircuit *ckt, struct line *deck)
char **circarray;
/* called by int ngSpice_Circ(): copy line by line to circarray, if line == NULL
(sent after last entry), then finish.
called by com_circbyline(): lines are entered manually. If a circuit is entered,
the first line is a title line. The entry will be finished by entering .end.
Circuit parsing is then started automatically.
If a script is to be generated, start with *ng_script, followed by .control
and finished by .endc */
void
create_circbyline(char *line)
{
static int linec = 0;
static int memlen = 256;
static bool is_script = FALSE;
FILE *fp = NULL;
if (line && (linec == 0))
is_script = ciprefix("*ng_script", line);
if (!circarray)
circarray = TMALLOC(char*, memlen);
circarray[linec++] = line;
if (line == NULL) {
inp_spsource(fp, is_script, "", TRUE);
is_script = FALSE;
linec = 0;
return;
}
if (linec < memlen) {
if (ciprefix(".end", line) && (line[4] == '\0' || isspace_c(line[4]))) {
if ((is_script && ciprefix(".endc", line)) ||
(ciprefix(".end", line) && (line[4] == '\0' || isspace_c(line[4])))) {
circarray[linec] = NULL;
inp_spsource(fp, FALSE, "", TRUE);
inp_spsource(fp, is_script, "", TRUE);
is_script = FALSE;
linec = 0;
}
}

View File

@ -774,6 +774,7 @@ int ngSpice_Circ(char** circa){
newline = copy(circa[i]);
create_circbyline(newline);
}
create_circbyline(NULL);
return 0;
}
/* upon error */