Skip to content

Commit

Permalink
Fix up vmops generated code for c89 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dgryski committed Apr 20, 2023
1 parent 81b6052 commit 16226c2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/libfsm/print/vmops.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ fsm_print_vmops(FILE *f, const struct fsm *fsm, enum vmops_dialect dialect)

case VMOPS_MAIN:
fprintf(f, "#include <stdio.h>\n");
fprintf(f, "#include <string.h>\n");
fprintf(f, "#include <stdlib.h>\n\n");
fprintf(f, "#ifndef %sLIBFSM_VMOPS_H\n", prefix);
fprintf(f, "#include \"%svmops.h\"\n", prefix);
Expand Down Expand Up @@ -353,9 +354,7 @@ fsm_print_vmops(FILE *f, const struct fsm *fsm, enum vmops_dialect dialect)
fprintf(f, "\n");
fprintf(f, "int main(void)\n");
fprintf(f, "{\n");
fprintf(f, "\tchar *buf;\n");
fprintf(f, "\tsize_t linecap = %sBUFFER_SIZE;\n", prefix);
fprintf(f, "\tssize_t linelen;\n");
fprintf(f, "\tchar *buf, *p;\n");
fprintf(f, "\tint r;\n");
fprintf(f, "\n");
fprintf(f, "\tbuf = malloc(%sBUFFER_SIZE);\n", prefix);
Expand All @@ -364,17 +363,17 @@ fsm_print_vmops(FILE *f, const struct fsm *fsm, enum vmops_dialect dialect)
fprintf(f, "\t\texit(1);\n");
fprintf(f, "\t}\n\n");
fprintf(f, "\tfor (;;) {\n");
fprintf(f, "\t\tlinelen = getline(&buf, &linecap, stdin);\n");
fprintf(f, "\t\tif (linelen <= 0) {\n");
fprintf(f, "\t\tp = fgets(buf, %sBUFFER_SIZE, stdin);\n", prefix);
fprintf(f, "\t\tif (!p) {\n");
fprintf(f, "\t\t\tbreak;\n");
fprintf(f, "\t\t}\n");

switch (fsm->opt->io) {
case FSM_IO_PAIR:
fprintf(f, "\t\tr = %smatch(buf, buf + linelen);\n", prefix);
fprintf(f, "\t\tr = %smatch(p, p + strlen(p));\n", prefix);
break;
case FSM_IO_STR:
fprintf(f, "\t\tr = %smatch(buf);\n", prefix);
fprintf(f, "\t\tr = %smatch(p);\n", prefix);
break;
case FSM_IO_GETC:
fprintf(stderr, "unsupported IO API\n");
Expand Down

0 comments on commit 16226c2

Please sign in to comment.