Extended the code from the last commit to cover cases in which the

definition covers multiple lines;  this also is a general handler
of the backslash-newline continuation line.
This commit is contained in:
Tim Edwards
2020-07-01 16:00:54 -04:00
parent 07c493c796
commit 18739235a9
+18 -1
View File
@@ -289,6 +289,7 @@ int GetNextLineNoNewline(char *delimiter)
char *newbuf; char *newbuf;
int testc; int testc;
int nested = 0; int nested = 0;
int llen;
if (feof(infile)) return -1; if (feof(infile)) return -1;
@@ -306,12 +307,25 @@ int GetNextLineNoNewline(char *delimiter)
linetok = (char *)MALLOC(linesize + 1); linetok = (char *)MALLOC(linesize + 1);
} }
fgets(line, linesize, infile); fgets(line, linesize, infile);
while (strlen(line) == linesize - 1) { /* Immediately resolve backslash-EOL */
llen = strlen(line);
while ((llen > 1) && (llen < linesize - 1) && *(line + llen - 2) == '\\') {
*(line + llen - 2) = '\n';
fgets(line + llen - 1, linesize - llen + 1, infile);
llen = strlen(line);
}
while (llen == linesize - 1) {
newbuf = (char *)MALLOC(linesize + 501); newbuf = (char *)MALLOC(linesize + 501);
strcpy(newbuf, line); strcpy(newbuf, line);
FREE(line); FREE(line);
line = newbuf; line = newbuf;
fgets(line + linesize - 1, 501, infile); fgets(line + linesize - 1, 501, infile);
llen = strlen(line);
while ((llen > 1) && (llen < linesize - 1) && *(line + llen - 2) == '\\') {
*(line + llen - 2) = '\n';
fgets(line + llen - 1, linesize - llen + 1, infile);
llen = strlen(line);
}
linesize += 500; linesize += 500;
FREE(linetok); FREE(linetok);
linetok = (char *)MALLOC(linesize + 1); linetok = (char *)MALLOC(linesize + 1);
@@ -498,6 +512,9 @@ void GetNextLine(char *delimiter)
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
/* Return a pointer to the line at the position of nexttok */ /* Return a pointer to the line at the position of nexttok */
/* This is used only when returning the entire line, untokenized, and */
/* is only called by the verilog read routine when reading the value of */
/* a `define statement. */
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
char *GetLineAtTok() char *GetLineAtTok()