Add another test: don't concatenate .param line, but replace '+' by '.param'

There is however, no significant change in parsing speed.
This commit is contained in:
Holger Vogt 2023-04-18 15:35:29 +02:00
parent 065e9289f3
commit e1076a3979
1 changed files with 93 additions and 0 deletions

View File

@ -625,6 +625,94 @@ static char *cat2strings(char *s1, char *s2, bool spa)
} }
#endif #endif
/* .param line1param
+ line2param
---->
.param line1param
.param line2param
*/
static void inp_stitch_continuation_lines_param(struct card* working)
{
struct card* prev = NULL;
char* oldline;
while (working) {
char* s, c;
for (s = working->line; (c = *s) != '\0' && c <= ' '; s++)
;
#ifdef TRACE
/* SDB debug statement */
printf("In inp_read, processing linked list element line = %d, s = "
"%s . . . \n",
working->linenum, s);
#endif
switch (c) {
case '#':
case '$':
case '*':
case '\0':
/* skip these cards, and keep prev as the last regular card */
working = working->nextcard; /* for these chars, go to next
card */
break;
case '+': /* handle continuation of .param lines only */
if (!prev) {
working->error =
copy("Illegal continuation line: ignored.");
working = working->nextcard;
break;
}
/* only handle .param continuation lines */
if(!ciprefix(".param", prev->line)) {
working = working->nextcard;
break;
}
/* comment out lines containing only .param */
if(cieq(prev->line, ".param")) {
prev->line[0] = '*';
}
/* We now may have lept over some comment lines, which are
located among the continuation lines. We have to delete them
here to prevent a memory leak */
while (prev->nextcard != working) {
struct card* tmpl = prev->nextcard->nextcard;
line_free_x(prev->nextcard, FALSE);
prev->nextcard = tmpl;
}
oldline = working->line;
#if defined (_MSC_VER)
/* vsnprintf (used by tprintf) in Windows is efficient, VS2019 arb. referencevalue 7,
cat2strings() yields ref. speed value 12 only, CYGWIN is 12 in both cases,
MINGW is 36. */
working->line = tprintf(".param %s", s + 1);
#else
/* vsnprintf in Linux is very inefficient, ref. value 24
cat2strings() is efficient with ref. speed value 6,
MINGW is 12 */
working->line = cat2strings(".param", s + 1, TRUE);
#endif
tfree(oldline);
break;
default: /* regular one-line card */
prev = working;
working = working->nextcard;
break;
}
}
}
#if 1 #if 1
/* line1 /* line1
+ line2 + line2
@ -685,8 +773,10 @@ static void inp_stitch_continuation_lines(struct card* working)
firsttime = FALSE; firsttime = FALSE;
} }
else { else {
/* replace '+' by space */
*s = ' '; *s = ' ';
sadd(&newline, s); sadd(&newline, s);
/* mark for later removal */
*s = '*'; *s = '*';
} }
@ -698,6 +788,7 @@ static void inp_stitch_continuation_lines(struct card* working)
prev->line = copy(ds_get_buf(&newline)); prev->line = copy(ds_get_buf(&newline));
ds_clear(&newline); ds_clear(&newline);
firsttime = TRUE; firsttime = TRUE;
/* remove final used '+' line, if regular line is following */
struct card* tmpl = prev->nextcard->nextcard; struct card* tmpl = prev->nextcard->nextcard;
line_free_x(prev->nextcard, FALSE); line_free_x(prev->nextcard, FALSE);
prev->nextcard = tmpl; prev->nextcard = tmpl;
@ -707,6 +798,7 @@ static void inp_stitch_continuation_lines(struct card* working)
break; break;
} }
} }
/* remove final used '+' line when no regular line is following */
if (!firsttime) { if (!firsttime) {
tfree(prev->line); tfree(prev->line);
prev->line = copy(ds_get_buf(&newline)); prev->line = copy(ds_get_buf(&newline));
@ -1779,6 +1871,7 @@ struct inp_read_t inp_read( FILE *fp, int call_depth, const char *dir_name,
inp_stripcomments_deck(cc->nextcard, comfile || is_control); inp_stripcomments_deck(cc->nextcard, comfile || is_control);
// tprint(cc); // tprint(cc);
// inp_stitch_continuation_lines_param(cc->nextcard);
inp_stitch_continuation_lines(cc->nextcard); inp_stitch_continuation_lines(cc->nextcard);
// tprint(cc); // tprint(cc);