diff options
author | John Ankarström <john@ankarstrom.se> | 2021-09-17 22:34:52 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-09-17 22:34:52 +0200 |
commit | 56509ab16c8d2225182eb0400e5c6a4900870391 (patch) | |
tree | e3c3bcc760ecc187a3f4ee8c6616855d15e86d83 /mktpl/mktpl.lex | |
parent | 3e400c3df5572524b7ba08b030f45eb3ba6b7734 (diff) | |
download | cforum-56509ab16c8d2225182eb0400e5c6a4900870391.tar.gz |
Fix mktpl bug
Diffstat (limited to 'mktpl/mktpl.lex')
-rw-r--r-- | mktpl/mktpl.lex | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/mktpl/mktpl.lex b/mktpl/mktpl.lex index e530e45..56ce93f 100644 --- a/mktpl/mktpl.lex +++ b/mktpl/mktpl.lex @@ -20,10 +20,10 @@ \<%= text(); BEGIN(PRNT); \<%[^=] text(); BEGIN(EVAL); -<PRNT>. apnd(); +<PRNT>(.|\n) apnd(); <PRNT>%\> prnt(); BEGIN(0); -<EVAL>(.|\n) apnd(); +<EVAL>(.|\n) apnd(); <EVAL>%\> eval(); BEGIN(0); <PRNT><<EOF>> prnt(); yyterminate(); @@ -52,27 +52,26 @@ apnd() } buf[len++] = *yytext; - buf[len+1] = 0; } void eval() { - printf("%s\n", buf); + printf("%.*s\n", len, buf); len = 0; } void text() { - char *t; + int i; printf("printf(\""); - for(t = buf; *t; t++){ - if(*t == '\\') printf("\\\\"); - else if(*t == '"') printf("\\\""); - else if(*t == '\n') printf("\\n"); - else printf("%c", *t); + for(i = 0; i < len; i++){ + if(buf[i] == '\\') printf("\\\\"); + else if(buf[i] == '"') printf("\\\""); + else if(buf[i] == '\n') printf("\\n"); + else printf("%c", buf[i]); } printf("\");\n"); len = 0; @@ -81,6 +80,6 @@ text() void prnt() { - printf("printf(\"%%s\", %s);\n", buf); + printf("printf(\"%%s\", %.*s);\n", len, buf); len = 0; }
\ No newline at end of file |