Browse Source

line renumbering to end of inp_readall added

pre-master-46
h_vogt 17 years ago
parent
commit
9b2170953c
  1. 5
      ChangeLog
  2. 889
      src/frontend/inpcom.c
  3. 1
      src/include/fteinp.h
  4. 1
      src/include/inpdefs.h

5
ChangeLog

@ -1,3 +1,8 @@
2009-03-21 Holger Vogt
* inpcom.c, fteinp.h, inpdefs.h: line renumbering of input deck added
to the end of fcn inp_readall(). cc->li_line_original now contains
the line numbering of the input file
2009-03-15 Holger Vogt 2009-03-15 Holger Vogt
* cktfinddev.c: some (optical) cleanup * cktfinddev.c: some (optical) cleanup
* numparam.h, xpressn.c, spicenum.c, inpcom.c: dynamic memory * numparam.h, xpressn.c, spicenum.c, inpcom.c: dynamic memory

889
src/frontend/inpcom.c

@ -984,87 +984,87 @@ inp_fix_ternary_operator( struct line *start_card )
void void
inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name)
{ {
struct line *end = NULL, *cc = NULL, *prev = NULL, *working, *newcard, *start_lib, *global_card, *tmp_ptr = NULL, *tmp_ptr2 = NULL;
char *buffer = NULL, *s, *t, *y, *z, c;
/* segfault fix */
struct line *end = NULL, *cc = NULL, *prev = NULL, *working, *newcard, *start_lib, *global_card, *tmp_ptr = NULL, *tmp_ptr2 = NULL;
char *buffer = NULL, *s, *t, *y, *z, c;
/* segfault fix */
#ifdef XSPICE #ifdef XSPICE
char big_buff[5000];
int line_count = 0;
Ipc_Status_t ipc_status;
char ipc_buffer[1025]; /* Had better be big enough */
int ipc_len;
char big_buff[5000];
int line_count = 0;
Ipc_Status_t ipc_status;
char ipc_buffer[1025]; /* Had better be big enough */
int ipc_len;
#endif #endif
char *copys=NULL, big_buff2[5000];
char *global_copy = NULL, keep_char;
int line_number = 1; /* sjb - renamed to avoid confusion with struct line */
FILE *newfp;
char *copys=NULL, big_buff2[5000];
char *global_copy = NULL, keep_char;
int line_number = 1; /* sjb - renamed to avoid confusion with struct line */
int line_number_orig = 0;
FILE *newfp;
#if defined(TRACE) || defined(OUTDECK) #if defined(TRACE) || defined(OUTDECK)
FILE *fdo;
FILE *fdo;
#endif #endif
struct line *tmp_ptr1 = NULL;
struct line *tmp_ptr1 = NULL;
int i, j;
bool found_library, found_lib_name, found_end = FALSE, shell_eol_continuation = FALSE;
bool dir_name_flag = FALSE;
int i, j;
bool found_library, found_lib_name, found_end = FALSE, shell_eol_continuation = FALSE;
bool dir_name_flag = FALSE;
struct variable *v;
char *s_ptr, *s_lower;
struct variable *v;
char *s_ptr, *s_lower;
/* Must set this to NULL or non-tilde includes segfault. -- Tim Molteno */
/* copys = NULL; */ /* This caused a parse error with gcc 2.96. Why??? */
/* Must set this to NULL or non-tilde includes segfault. -- Tim Molteno */
/* copys = NULL; */ /* This caused a parse error with gcc 2.96. Why??? */
if ( call_depth == 0 ) {
if ( call_depth == 0 ) {
num_subckt_w_params = 0; num_subckt_w_params = 0;
num_libraries = 0; num_libraries = 0;
num_functions = 0; num_functions = 0;
global = NULL; global = NULL;
found_end = FALSE; found_end = FALSE;
}
}
/* gtri - modify - 12/12/90 - wbk - read from mailbox if ipc enabled */ /* gtri - modify - 12/12/90 - wbk - read from mailbox if ipc enabled */
#ifdef XSPICE #ifdef XSPICE
/* First read in all lines & put them in the struct cc */
while (1) {
/* If IPC is not enabled, do equivalent of what SPICE did before */
if(! g_ipc.enabled) {
if ( call_depth == 0 && line_count == 0 ) {
line_count++;
if ( fgets( big_buff, 5000, fp ) ) {
buffer = tmalloc( strlen(big_buff) + 1 );
strcpy(buffer, big_buff);
}
}
else {
buffer = readline(fp);
if(! buffer) {
break;
}
}
}
else {
/* else, get the line from the ipc channel. */
/* We assume that newlines are not sent by the client */
/* so we add them here */
ipc_status = ipc_get_line(ipc_buffer, &ipc_len, IPC_WAIT);
if(ipc_status == IPC_STATUS_END_OF_DECK) {
buffer = NULL;
break;
/* First read in all lines & put them in the struct cc */
while (1) {
/* If IPC is not enabled, do equivalent of what SPICE did before */
if(! g_ipc.enabled) {
if ( call_depth == 0 && line_count == 0 ) {
line_count++;
if ( fgets( big_buff, 5000, fp ) ) {
buffer = tmalloc( strlen(big_buff) + 1 );
strcpy(buffer, big_buff);
} }
else if(ipc_status == IPC_STATUS_OK) {
buffer = (void *) tmalloc(strlen(ipc_buffer) + 3);
strcpy(buffer, ipc_buffer);
strcat(buffer, "\n");
}
else { /* No good way to report this so just die */
exit(1);
}
else {
buffer = readline(fp);
if(! buffer) {
break;
} }
}
}
}
else {
/* else, get the line from the ipc channel. */
/* We assume that newlines are not sent by the client */
/* so we add them here */
ipc_status = ipc_get_line(ipc_buffer, &ipc_len, IPC_WAIT);
if(ipc_status == IPC_STATUS_END_OF_DECK) {
buffer = NULL;
break;
}
else if(ipc_status == IPC_STATUS_OK) {
buffer = (void *) tmalloc(strlen(ipc_buffer) + 3);
strcpy(buffer, ipc_buffer);
strcat(buffer, "\n");
}
else { /* No good way to report this so just die */
exit(1);
}
}
/* gtri - end - 12/12/90 */ /* gtri - end - 12/12/90 */
#else #else
while ((buffer = readline(fp))) {
while ((buffer = readline(fp))) {
#endif #endif
#ifdef TRACE #ifdef TRACE
@ -1073,251 +1073,255 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name)
#endif #endif
if ( !buffer ) { if ( !buffer ) {
continue;
continue;
}
/* OK -- now we have loaded the next line into 'buffer'. Process it. */
/* If input line is blank, ignore it & continue looping. */
if ( (strcmp(buffer,"\n") == 0) || (strcmp(buffer,"\r\n") == 0) ) {
if ( call_depth != 0 || (call_depth == 0 && cc != NULL) ) {
continue;
}
} }
/* OK -- now we have loaded the next line into 'buffer'. Process it. */
/* If input line is blank, ignore it & continue looping. */
if ( (strcmp(buffer,"\n") == 0) || (strcmp(buffer,"\r\n") == 0) ) {
if ( call_depth != 0 || (call_depth == 0 && cc != NULL) ) {
continue;
}
}
if (*buffer == '@') {
tfree(buffer); /* was allocated by readline() */
break;
}
if (*buffer == '@') {
tfree(buffer); /* was allocated by readline() */
break;
}
/* now handle .lib statements */
if (ciprefix(".lib", buffer)) {
for ( s = buffer; *s && !isspace(*s); s++ ); /* skip over .lib */
while ( isspace(*s) || isquote(*s) ) s++; /* advance past space chars */
if ( !*s ) { /* if at end of line, error */
fprintf(cp_err, "Error: .lib filename missing\n");
tfree(buffer); /* was allocated by readline() */
continue;
} /* Now s points to first char after .lib */
for ( t = s; *t && !isspace(*t) && !isquote(*t); t++ ); /* skip to end of word */
y = t;
while ( isspace(*y) || isquote(*y) ) y++; /* advance past space chars */
// check if rest of line commented out
if ( *y && *y != '$' ) { /* .lib <file name> <lib name> */
for ( z = y; *z && !isspace(*z) && !isquote(*z); z++ );
c = *t;
*t = '\0';
*z = '\0';
if ( *s == '~' ) {
copys = cp_tildexpand(s); /* allocates memory, but can also return NULL */
if( copys != NULL ) {
s = copys; /* reuse s, but remember, buffer still points to allocated memory */
}
}
/* now handle .lib statements */
if (ciprefix(".lib", buffer)) {
for ( s = buffer; *s && !isspace(*s); s++ ); /* skip over .lib */
while ( isspace(*s) || isquote(*s) ) s++; /* advance past space chars */
if ( !*s ) { /* if at end of line, error */
fprintf(cp_err, "Error: .lib filename missing\n");
tfree(buffer); /* was allocated by readline() */
continue;
} /* Now s points to first char after .lib */
for ( t = s; *t && !isspace(*t) && !isquote(*t); t++ ); /* skip to end of word */
y = t;
while ( isspace(*y) || isquote(*y) ) y++; /* advance past space chars */
// check if rest of line commented out
if ( *y && *y != '$' ) { /* .lib <file name> <lib name> */
for ( z = y; *z && !isspace(*z) && !isquote(*z); z++ );
c = *t;
*t = '\0';
*z = '\0';
if ( *s == '~' ) {
copys = cp_tildexpand(s); /* allocates memory, but can also return NULL */
if( copys != NULL ) {
s = copys; /* reuse s, but remember, buffer still points to allocated memory */
}
}
/* lower case the file name for later string compares */
s_ptr = strdup(s);
s_lower = strdup(s);
for(s_ptr = s_lower; *s_ptr && (*s_ptr != '\n'); s_ptr++) *s_ptr = tolower(*s_ptr);
found_library = FALSE;
for ( i = 0; i < num_libraries; i++ ) {
if ( strcmp( library_file[i], s_lower ) == 0 ) {
found_library = TRUE;
break;
}
}
if ( found_library ) {
if(copys) tfree(copys); /* allocated by the cp_tildexpand() above */
} else {
if ( dir_name != NULL ) sprintf( big_buff2, "%s/%s", dir_name, s );
else sprintf( big_buff2, "./%s", s );
dir_name_flag = FALSE;
if ( !( newfp = inp_pathopen( s, "r" ) ) ) {
dir_name_flag = TRUE;
if ( !( newfp = inp_pathopen( big_buff2, "r" ) ) ) {
perror(s);
if(copys) tfree(copys); /* allocated by the cp_tildexpand() above */
tfree(buffer); /* allocated by readline() above */
continue;
}
}
if(copys) tfree(copys); /* allocated by the cp_tildexpand() above */
library_file[num_libraries++] = strdup(s_lower);
if ( dir_name_flag == FALSE ) {
char *s_dup = strdup(s);
inp_readall(newfp, &libraries[num_libraries-1], call_depth+1, dirname(s_dup));
tfree(s_dup);
}
else
inp_readall(newfp, &libraries[num_libraries-1], call_depth+1, dir_name);
fclose(newfp);
}
*t = c;
tfree(s_lower);
/* lower case the file name for later string compares */
s_ptr = strdup(s);
s_lower = strdup(s);
for(s_ptr = s_lower; *s_ptr && (*s_ptr != '\n'); s_ptr++) *s_ptr = tolower(*s_ptr);
found_library = FALSE;
for ( i = 0; i < num_libraries; i++ ) {
if ( strcmp( library_file[i], s_lower ) == 0 ) {
found_library = TRUE;
break;
}
}
if ( found_library ) {
if(copys) tfree(copys); /* allocated by the cp_tildexpand() above */
} else {
if ( dir_name != NULL ) sprintf( big_buff2, "%s/%s", dir_name, s );
else sprintf( big_buff2, "./%s", s );
dir_name_flag = FALSE;
if ( !( newfp = inp_pathopen( s, "r" ) ) ) {
dir_name_flag = TRUE;
if ( !( newfp = inp_pathopen( big_buff2, "r" ) ) ) {
perror(s);
if(copys) tfree(copys); /* allocated by the cp_tildexpand() above */
tfree(buffer); /* allocated by readline() above */
continue;
}
}
if(copys) tfree(copys); /* allocated by the cp_tildexpand() above */
library_file[num_libraries++] = strdup(s_lower);
if ( dir_name_flag == FALSE ) {
char *s_dup = strdup(s);
inp_readall(newfp, &libraries[num_libraries-1], call_depth+1, dirname(s_dup));
tfree(s_dup);
}
else
inp_readall(newfp, &libraries[num_libraries-1], call_depth+1, dir_name);
fclose(newfp);
}
*t = c;
tfree(s_lower);
/* Make the .lib a comment */
*buffer = '*';
}
} /* end of .lib handling */
/* now handle .include statements */
if (ciprefix(".include", buffer) || ciprefix(".inc", buffer)) {
for (s = buffer; *s && !isspace(*s); s++) /* advance past non-space chars */
;
while (isspace(*s) || isquote(*s)) /* now advance past space chars */
s++;
if (!*s) { /* if at end of line, error */
fprintf(cp_err, "Error: .include filename missing\n");
tfree(buffer); /* was allocated by readline() */
continue;
} /* Now s points to first char after .include */
for (t = s; *t && !isspace(*t) && !isquote(*t); t++) /* now advance past non-space chars */
;
*t = '\0'; /* place \0 and end of file name in buffer */
if (*s == '~') {
copys = cp_tildexpand(s); /* allocates memory, but can also return NULL */
if(copys != NULL) {
s = copys; /* reuse s, but remember, buffer still points to allocated memory */
}
}
/* Make the .lib a comment */
*buffer = '*';
}
} /* end of .lib handling */
/* now handle .include statements */
if (ciprefix(".include", buffer) || ciprefix(".inc", buffer)) {
for (s = buffer; *s && !isspace(*s); s++) /* advance past non-space chars */
;
while (isspace(*s) || isquote(*s)) /* now advance past space chars */
s++;
if (!*s) { /* if at end of line, error */
fprintf(cp_err, "Error: .include filename missing\n");
tfree(buffer); /* was allocated by readline() */
continue;
} /* Now s points to first char after .include */
for (t = s; *t && !isspace(*t) && !isquote(*t); t++) /* now advance past non-space chars */
;
*t = '\0'; /* place \0 and end of file name in buffer */
if (*s == '~') {
copys = cp_tildexpand(s); /* allocates memory, but can also return NULL */
if(copys != NULL) {
s = copys; /* reuse s, but remember, buffer still points to allocated memory */
}
}
/* open file specified by .include statement */
if ( dir_name != NULL ) sprintf( big_buff2, "%s/%s", dir_name, s );
else sprintf( big_buff2, "./%s", s );
dir_name_flag = FALSE;
if (!(newfp = inp_pathopen(s, "r"))) {
dir_name_flag = TRUE;
if ( !( newfp = inp_pathopen( big_buff2, "r" ) ) ) {
perror(s);
if(copys) {
tfree(copys); /* allocated by the cp_tildexpand() above */
}
tfree(buffer); /* allocated by readline() above */
continue;
}
/* open file specified by .include statement */
if ( dir_name != NULL ) sprintf( big_buff2, "%s/%s", dir_name, s );
else sprintf( big_buff2, "./%s", s );
dir_name_flag = FALSE;
if (!(newfp = inp_pathopen(s, "r"))) {
dir_name_flag = TRUE;
if ( !( newfp = inp_pathopen( big_buff2, "r" ) ) ) {
perror(s);
if(copys) {
tfree(copys); /* allocated by the cp_tildexpand() above */
}
tfree(buffer); /* allocated by readline() above */
continue;
} }
}
if(copys) {
tfree(copys); /* allocated by the cp_tildexpand() above */
}
if ( dir_name_flag == FALSE ) {
char *s_dup = strdup(s);
inp_readall(newfp, &newcard, call_depth+1, dirname(s_dup)); /* read stuff in include file into netlist */
tfree(s_dup);
}
else
inp_readall(newfp, &newcard, call_depth+1, dir_name); /* read stuff in include file into netlist */
(void) fclose(newfp);
/* Make the .include a comment */
*buffer = '*';
/* now check if this is the first pass (i.e. end points to null) */
if (end) { /* end already exists */
end->li_next = alloc(struct line); /* create next card */
end = end->li_next; /* make end point to next card */
} else {
end = cc = alloc(struct line); /* create the deck & end. cc will
if(copys) {
tfree(copys); /* allocated by the cp_tildexpand() above */
}
if ( dir_name_flag == FALSE ) {
char *s_dup = strdup(s);
inp_readall(newfp, &newcard, call_depth+1, dirname(s_dup)); /* read stuff in include file into netlist */
tfree(s_dup);
}
else
inp_readall(newfp, &newcard, call_depth+1, dir_name); /* read stuff in include file into netlist */
(void) fclose(newfp);
/* Make the .include a comment */
*buffer = '*';
/* now check if this is the first pass (i.e. end points to null) */
if (end) { /* end already exists */
end->li_next = alloc(struct line); /* create next card */
end = end->li_next; /* make end point to next card */
} else {
end = cc = alloc(struct line); /* create the deck & end. cc will
point to beginning of deck, end to point to beginning of deck, end to
the end */ the end */
}
/* now fill out rest of struct end. */
end->li_next = NULL;
end->li_error = NULL;
end->li_actual = NULL;
end->li_line = copy(buffer);
end->li_linenum = line_number++;
if (newcard) {
end->li_next = newcard;
}
/* now fill out rest of struct end. */
end->li_next = NULL;
end->li_error = NULL;
end->li_actual = NULL;
end->li_line = copy(buffer);
end->li_linenum = end->li_linenum_orig = line_number++;
if (newcard) {
end->li_next = newcard;
/* Renumber the lines */ /* Renumber the lines */
for (end = newcard; end && end->li_next; end = end->li_next)
end->li_linenum = line_number++;
end->li_linenum = line_number++; /* SJB - renumber the last line */
}
line_number_orig = 1;
for (end = newcard; end && end->li_next; end = end->li_next) {
end->li_linenum = line_number_orig++;
end->li_linenum_orig = line_number++;
}
end->li_linenum = line_number++; /* SJB - renumber the last line */
end->li_linenum_orig = line_number_orig++; /* SJB - renumber the last line */
}
/* Fix the buffer up a bit. */
(void) strncpy(buffer + 1, "end of:", 7);
} /* end of .include handling */
/* Fix the buffer up a bit. */
(void) strncpy(buffer + 1, "end of:", 7);
} /* end of .include handling */
/* loop through 'buffer' until end is reached. Then test for
/* loop through 'buffer' until end is reached. Then test for
premature end. If premature end is reached, spew premature end. If premature end is reached, spew
error and zap the line. */ error and zap the line. */
if ( !ciprefix( "write", buffer ) ) { // exclude 'write' command so filename case preserved
for (s = buffer; *s && (*s != '\n') && (*s != '\0'); s++) *s = tolower(*s);
if (!*s) {
//fprintf(cp_err, "Warning: premature EOF\n");
}
*s = '\0'; /* Zap the newline. */
if ( !ciprefix( "write", buffer ) ) { // exclude 'write' command so filename case preserved
for (s = buffer; *s && (*s != '\n') && (*s != '\0'); s++) *s = tolower(*s);
if (!*s) {
//fprintf(cp_err, "Warning: premature EOF\n");
}
*s = '\0'; /* Zap the newline. */
if((s-1) >= buffer && *(s-1) == '\r') /* Zop the carriage return under windows */
*(s-1) = '\0';
}
if (ciprefix(".end", buffer) && strlen(buffer) == 4 ) {
found_end = TRUE;
*buffer = '*';
}
if((s-1) >= buffer && *(s-1) == '\r') /* Zop the carriage return under windows */
*(s-1) = '\0';
}
if ( ciprefix( ".global", buffer ) ) {
for ( s = buffer; *s && !isspace(*s); s++ );
if (ciprefix(".end", buffer) && strlen(buffer) == 4 ) {
found_end = TRUE;
*buffer = '*';
}
if ( global == NULL ) {
global = strdup(buffer);
} else {
global_copy = tmalloc( strlen(global) + strlen(s) + 1 );
sprintf( global_copy, "%s%s", global, s );
tfree(global);
global = global_copy;
}
*buffer = '*';
}
if ( ciprefix( ".global", buffer ) ) {
for ( s = buffer; *s && !isspace(*s); s++ );
if ( global == NULL ) {
global = strdup(buffer);
} else {
global_copy = tmalloc( strlen(global) + strlen(s) + 1 );
sprintf( global_copy, "%s%s", global, s );
tfree(global);
global = global_copy;
}
*buffer = '*';
}
if ( shell_eol_continuation ) {
char *new_buffer = tmalloc( strlen(buffer) + 2);
sprintf( new_buffer, "+%s", buffer );
if ( shell_eol_continuation ) {
char *new_buffer = tmalloc( strlen(buffer) + 2);
sprintf( new_buffer, "+%s", buffer );
tfree(buffer);
buffer = new_buffer;
}
tfree(buffer);
buffer = new_buffer;
}
shell_eol_continuation = chk_for_line_continuation( buffer );
shell_eol_continuation = chk_for_line_continuation( buffer );
/* now check if this is the first pass (i.e. end points to null) */
if (end) { /* end already exists */
end->li_next = alloc(struct line); /* create next card */
end = end->li_next; /* point to next card */
} else { /* End doesn't exist. Create it. */
end = cc = alloc(struct line); /* note that cc points to beginning
/* now check if this is the first pass (i.e. end points to null) */
if (end) { /* end already exists */
end->li_next = alloc(struct line); /* create next card */
end = end->li_next; /* point to next card */
} else { /* End doesn't exist. Create it. */
end = cc = alloc(struct line); /* note that cc points to beginning
of deck, end to the end */ of deck, end to the end */
}
}
/* now put buffer into li */
end->li_next = NULL;
end->li_error = NULL;
end->li_actual = NULL;
end->li_line = buffer;
end->li_linenum = line_number++;
} /* end while ((buffer = readline(fp))) */
if (!end) { /* No stuff here */
*data = NULL;
return;
}
/* now put buffer into li */
end->li_next = NULL;
end->li_error = NULL;
end->li_actual = NULL;
end->li_line = buffer;
end->li_linenum = end->li_linenum_orig = line_number++;
} /* end while ((buffer = readline(fp))) */
if (!end) { /* No stuff here */
*data = NULL;
return;
}
/* This should be freed because we are done with it. */
/* tfree(buffer); */
/* This should be freed because we are done with it. */
/* tfree(buffer); */
if ( call_depth == 0 && found_end == TRUE) {
if ( call_depth == 0 && found_end == TRUE) {
if ( global == NULL ) { if ( global == NULL ) {
global = tmalloc( strlen(".global gnd") + 1 );
sprintf( global, ".global gnd" );
global = tmalloc( strlen(".global gnd") + 1 );
sprintf( global, ".global gnd" );
} }
global_card = alloc(struct line); global_card = alloc(struct line);
global_card->li_error = NULL; global_card->li_error = NULL;
@ -1331,170 +1335,174 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name)
inp_init_lib_data(); inp_init_lib_data();
inp_determine_libraries(cc, NULL); inp_determine_libraries(cc, NULL);
}
}
/*
/*
add libraries add libraries
*/
found_lib_name = FALSE;
if ( call_depth == 0 ) {
*/
found_lib_name = FALSE;
if ( call_depth == 0 ) {
for( i = 0; i < num_libraries; i++ ) { for( i = 0; i < num_libraries; i++ ) {
working = libraries[i];
while ( working ) {
buffer = working->li_line;
if ( found_lib_name && ciprefix(".endl", buffer) ) {
/* Make the .endl a comment */
*buffer = '*';
found_lib_name = FALSE;
/* set pointer and continue to avoid deleting below */
tmp_ptr2 = working->li_next;
working->li_next = tmp_ptr;
working = tmp_ptr2;
/* end = working;
* working = working->li_next;
* end->li_next = NULL; */
continue;
}
if ( ciprefix(".lib", buffer) ) {
if ( found_lib_name == TRUE ) {
fprintf( stderr, "ERROR: .lib is missing .endl!\n" );
exit(-1);
}
for ( s = buffer; *s && !isspace(*s); s++ ); /* skip over .lib */
while ( isspace(*s) || isquote(*s) ) s++; /* advance past space chars */
for ( t = s; *t && !isspace(*t) && !isquote(*t); t++ ); /* skip to end of word */
keep_char = *t;
*t = '\0';
/* see if library we want to copy */
found_lib_name = FALSE;
for( j = 0; j < num_lib_names[i]; j++ ) {
if ( strcmp( library_name[i][j], s ) == 0 ) {
found_lib_name = TRUE;
start_lib = working;
/* make the .lib a comment */
*buffer = '*';
tmp_ptr = library_ll_ptr[i][j]->li_next;
library_ll_ptr[i][j]->li_next = working;
working = libraries[i];
while ( working ) {
buffer = working->li_line;
if ( found_lib_name && ciprefix(".endl", buffer) ) {
/* Make the .endl a comment */
*buffer = '*';
found_lib_name = FALSE;
/* set pointer and continue to avoid deleting below */
tmp_ptr2 = working->li_next;
working->li_next = tmp_ptr;
working = tmp_ptr2;
/* end = working;
* working = working->li_next;
* end->li_next = NULL; */
continue;
} /* for ... */
if ( ciprefix(".lib", buffer) ) {
if ( found_lib_name == TRUE ) {
fprintf( stderr, "ERROR: .lib is missing .endl!\n" );
exit(-1);
}
for ( s = buffer; *s && !isspace(*s); s++ ); /* skip over .lib */
while ( isspace(*s) || isquote(*s) ) s++; /* advance past space chars */
for ( t = s; *t && !isspace(*t) && !isquote(*t); t++ ); /* skip to end of word */
keep_char = *t;
*t = '\0';
/* see if library we want to copy */
found_lib_name = FALSE;
for( j = 0; j < num_lib_names[i]; j++ ) {
if ( strcmp( library_name[i][j], s ) == 0 ) {
found_lib_name = TRUE;
start_lib = working;
/* make the .lib a comment */
*buffer = '*';
tmp_ptr = library_ll_ptr[i][j]->li_next;
library_ll_ptr[i][j]->li_next = working;
/* renumber lines */
line_number_orig = 1;
for ( start_lib = working; !ciprefix(".endl", start_lib->li_line); start_lib = start_lib->li_next ) {
start_lib->li_linenum = line_number++;
start_lib->li_linenum_orig = line_number_orig++;
}
start_lib->li_linenum = line_number++; // renumber endl line
start_lib->li_linenum_orig = line_number_orig++;
break;
}
}
*t = keep_char;
}
prev = working;
working = working->li_next;
/* renumber lines */
for ( start_lib = working; !ciprefix(".endl", start_lib->li_line); start_lib = start_lib->li_next )
start_lib->li_linenum = line_number++;
start_lib->li_linenum = line_number++; // renumber endl line
break;
}
}
*t = keep_char;
}
prev = working;
working = working->li_next;
if ( found_lib_name == FALSE ) {
tfree(prev->li_line);
tfree(prev);
}
} /* end while */
} /* end for */
if ( found_lib_name == FALSE ) {
tfree(prev->li_line);
tfree(prev);
}
} /* end while */
}
if ( found_end == TRUE ) { if ( found_end == TRUE ) {
end->li_next = alloc(struct line); /* create next card */
end = end->li_next; /* point to next card */
buffer = tmalloc( strlen( ".end" ) + 1 );
sprintf( buffer, ".end" );
/* now put buffer into li */
end->li_next = NULL;
end->li_error = NULL;
end->li_actual = NULL;
end->li_line = buffer;
end->li_linenum = line_number++;
end->li_next = alloc(struct line); /* create next card */
end = end->li_next; /* point to next card */
buffer = tmalloc( strlen( ".end" ) + 1 );
sprintf( buffer, ".end" );
/* now put buffer into li */
end->li_next = NULL;
end->li_error = NULL;
end->li_actual = NULL;
end->li_line = buffer;
end->li_linenum = end->li_linenum_orig = line_number++;
} }
}
}
/* Now clean up li: remove comments & stitch together continuation lines. */
working = cc->li_next; /* cc points to head of deck. Start with the
/* Now clean up li: remove comments & stitch together continuation lines. */
working = cc->li_next; /* cc points to head of deck. Start with the
next card. */ next card. */
/* sjb - strip or convert end-of-line comments.
/* sjb - strip or convert end-of-line comments.
This must be cone before stitching continuation lines. This must be cone before stitching continuation lines.
If the line only contains an end-of-line comment then it is converted If the line only contains an end-of-line comment then it is converted
into a normal comment with a '*' at the start. This will then get into a normal comment with a '*' at the start. This will then get
stripped in the following code. */ stripped in the following code. */
inp_stripcomments_deck(working);
inp_stripcomments_deck(working);
while (working) {
for (s = working->li_line; (c = *s) && c <= ' '; s++)
;
while (working) {
for (s = working->li_line; (c = *s) && c <= ' '; s++)
;
#ifdef TRACE #ifdef TRACE
/* SDB debug statement */ /* SDB debug statement */
printf("In inp_readall, processing linked list element line = %d, s = %s . . . \n", working->li_linenum,s); printf("In inp_readall, processing linked list element line = %d, s = %s . . . \n", working->li_linenum,s);
#endif #endif
switch (c) {
case '#':
case '$':
case '*':
case '\0':
/* this used to be commented out. Why? */
/* prev = NULL; */
working = working->li_next; /* for these chars, go to next card */
break;
case '+': /* handle continuation */
if (!prev) {
working->li_error = copy(
"Illegal continuation line: ignored.");
working = working->li_next;
break;
}
/* create buffer and write last and current line into it. */
buffer = tmalloc(strlen(prev->li_line) + strlen(s) + 2);
(void) sprintf(buffer, "%s %s", prev->li_line, s + 1);
s = prev->li_line;
prev->li_line = buffer;
prev->li_next = working->li_next;
working->li_next = NULL;
if (prev->li_actual) {
for (end = prev->li_actual;
end->li_next; end = end->li_next)
;
end->li_next = working;
tfree(s);
} else {
newcard = alloc(struct line);
newcard->li_linenum = prev->li_linenum;
newcard->li_line = s;
newcard->li_next = working;
newcard->li_error = NULL;
newcard->li_actual = NULL;
prev->li_actual = newcard;
}
working = prev->li_next;
break;
default: /* regular one-line card */
prev = working;
working = working->li_next;
break;
}
}
switch (c) {
case '#':
case '$':
case '*':
case '\0':
/* this used to be commented out. Why? */
/* prev = NULL; */
working = working->li_next; /* for these chars, go to next card */
break;
case '+': /* handle continuation */
if (!prev) {
working->li_error = copy(
"Illegal continuation line: ignored.");
working = working->li_next;
break;
}
/* create buffer and write last and current line into it. */
buffer = tmalloc(strlen(prev->li_line) + strlen(s) + 2);
(void) sprintf(buffer, "%s %s", prev->li_line, s + 1);
s = prev->li_line;
prev->li_line = buffer;
prev->li_next = working->li_next;
working->li_next = NULL;
if (prev->li_actual) {
for (end = prev->li_actual; end->li_next; end = end->li_next)
;
end->li_next = working;
tfree(s);
} else {
newcard = alloc(struct line);
newcard->li_linenum = prev->li_linenum;
newcard->li_line = s;
newcard->li_next = working;
newcard->li_error = NULL;
newcard->li_actual = NULL;
prev->li_actual = newcard;
}
working = prev->li_next;
break;
default: /* regular one-line card */
prev = working;
working = working->li_next;
break;
}
}
working = cc->li_next;
working = cc->li_next;
inp_fix_for_numparam(working);
inp_remove_excess_ws(working);
inp_fix_for_numparam(working);
inp_remove_excess_ws(working);
if ( call_depth == 0 ) {
if ( call_depth == 0 ) {
comment_out_unused_subckt_models(working); comment_out_unused_subckt_models(working);
line_number = inp_split_multi_param_lines(working, line_number); line_number = inp_split_multi_param_lines(working, line_number);
@ -1510,37 +1518,40 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name)
// get end card as last card in list; end card pntr does not appear to always // get end card as last card in list; end card pntr does not appear to always
// be correct at this point // be correct at this point
for(newcard = working; newcard != NULL; newcard = newcard->li_next) for(newcard = working; newcard != NULL; newcard = newcard->li_next)
end = newcard;
end = newcard;
inp_reorder_params(working, cc, end); inp_reorder_params(working, cc, end);
inp_fix_inst_calls_for_numparam(working); inp_fix_inst_calls_for_numparam(working);
inp_fix_gnd_name(working); inp_fix_gnd_name(working);
inp_chk_for_multi_in_vcvs(working, &line_number); inp_chk_for_multi_in_vcvs(working, &line_number);
if (cp_getvar("addcontrol", VT_BOOL, (char *) &v))
inp_add_control_section(working, &line_number);
}
*data = cc;
/* get max. line length and number of lines in input deck*/
dynmaxline = 0;
dynLlen = 0;
for(tmp_ptr1 = cc; tmp_ptr1 != NULL; tmp_ptr1 = tmp_ptr1->li_next) {
dynmaxline++;
if (dynLlen < strlen(tmp_ptr1->li_line))
dynLlen = strlen(tmp_ptr1->li_line);
}
if (cp_getvar("addcontrol", VT_BOOL, (char *) &v))
inp_add_control_section(working, &line_number);
}
*data = cc;
/* get max. line length and number of lines in input deck,
* and renumber the lines */
dynmaxline = 0;
dynLlen = 0;
for(tmp_ptr1 = cc; tmp_ptr1 != NULL; tmp_ptr1 = tmp_ptr1->li_next) {
dynmaxline++;
/* renumber the lines of the processed input deck */
tmp_ptr1->li_linenum = dynmaxline;
if (dynLlen < strlen(tmp_ptr1->li_line))
dynLlen = strlen(tmp_ptr1->li_line);
}
#if defined(TRACE) || defined(OUTDECK) #if defined(TRACE) || defined(OUTDECK)
/*debug: print into file*/
fdo = fopen("debug-out.txt", "w");
for(tmp_ptr1 = cc; tmp_ptr1 != NULL; tmp_ptr1 = tmp_ptr1->li_next)
fprintf(fdo, "%s\n", tmp_ptr1->li_line);
;
(void) fclose(fdo);
fprintf(stdout, "lLen %d, maxline %d\n", dynLlen, dynmaxline);
/*debug: print into file*/
fdo = fopen("debug-out.txt", "w");
for(tmp_ptr1 = cc; tmp_ptr1 != NULL; tmp_ptr1 = tmp_ptr1->li_next)
fprintf(fdo, "%d %d %s\n", tmp_ptr1->li_linenum_orig, tmp_ptr1->li_linenum, tmp_ptr1->li_line);
(void) fclose(fdo);
fprintf(stdout, "lLen %d, maxline %d\n", dynLlen, dynmaxline);
#endif #endif
return;
return;
} }
/*-------------------------------------------------------------------------* /*-------------------------------------------------------------------------*

1
src/include/fteinp.h

@ -16,6 +16,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
/* This struct defines a linked list of lines from a SPICE file. */ /* This struct defines a linked list of lines from a SPICE file. */
struct line { struct line {
int li_linenum; int li_linenum;
int li_linenum_orig;
char *li_line; char *li_line;
char *li_error; char *li_error;
struct line *li_next; struct line *li_next;

1
src/include/inpdefs.h

@ -58,6 +58,7 @@ typedef struct sINPtables{
typedef struct card{ typedef struct card{
int linenum; int linenum;
int linenum_orig;
char *line; char *line;
char *error; char *error;
struct card *nextcard; struct card *nextcard;

Loading…
Cancel
Save