📄 inpcom.c
字号:
} /* open file specified by .include statement */ if (!(newfp = inp_pathopen(s, "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 */ } inp_readall(newfp, &newcard); /* 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 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++; end->li_next = newcard; /* 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 */ /* Fix the buffer up a bit. */ (void) strncpy(buffer + 1, "end of:", 7); } /* end of .include handling */ /* 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 */ } /* 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++; } if (!end) { /* No stuff here */ *data = NULL; return; } /* end while ((buffer = readline(fp))) */ /* This should be freed because we are done with it. */ /* tfree(buffer); */ /* 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. */ /* sjb - strip or convert end-of-line comments. This must be cone before stitching continuation lines. 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 stripped in the following code. */ inp_stripcomments_deck(working); while (working) { for (s = working->li_line; (c = *s) && c <= ' '; s++) ;#ifdef TRACE /* SDB debug statement */ printf("In inp_readall, processing linked list element line = %d, s = %s . . . \n", working->li_linenum,s); #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; } } *data = cc; return;}/*-------------------------------------------------------------------------* * * *-------------------------------------------------------------------------*/voidinp_casefix(char *string){#ifdef HAVE_CTYPE_H if (string) while (*string) { /* Let's make this really idiot-proof. */#ifdef HAS_ASCII *string = strip(*string);#endif if (*string == '"') { *string++ = ' '; while (*string && *string != '"') string++; if (*string == '"') *string = ' '; } if (!isspace(*string) && !isprint(*string)) *string = '_'; if (isupper(*string)) *string = tolower(*string); string++; } return;#endif}/* Strip all end-of-line comments from a deck */static voidinp_stripcomments_deck(struct line *deck){ struct line *c=deck; while( c!=NULL) { inp_stripcomments_line(c->li_line); c= c->li_next; }}/* Strip end of line comment from a string and remove trailing white space supports comments that begin with single characters ';' or double characters '$ ' or '//' or '--' If there is only white space before the end-of-line comment the the whole line is converted to a normal comment line (i.e. one that begins with a '*'). BUG: comment characters in side of string literals are not ignored. */ static voidinp_stripcomments_line(char * s){ char c = ' '; /* anything other than a comment character */ char * d = s; if(*s=='\0') return; /* empty line */ /* look for comments */ while((c=*d)!='\0') { d++; if (*d==';') { break; } else if ((c=='$') && (*d==' ')) { *d--; /* move d back to first comment character */ break; } else if( (*d==c) && ((c=='/') || (c=='-'))) { *d--; /* move d back to first comment character */ break; } } /* d now points to the first comment character of the null at the string end */ /* check for special case of comment at start of line */ if(d==s) { *s = '*'; /* turn into normal comment */ return; } if(d>s) { d--; /* d now points to character just before comment */ /* eat white space at end of line */ while(d>=s) { if( (*d!=' ') && (*d!='\t' ) ) break; d--; } d++; /* d now points to the first white space character before the end-of-line or end-of-line comment, or it points to the first end-of-line comment character, or to the begining of the line */ } /* Check for special case of comment at start of line with or without preceeding white space */ if(d<=s) { *s = '*'; /* turn the whole line into normal comment */ return; } *d='\0'; /* terminate line in new location */ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -