2 bff58270 2022-09-19 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 bff58270 2022-09-19 op * Copyright (c) 2007-2016 Reyk Floeter <reyk@openbsd.org>
4 bff58270 2022-09-19 op * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
5 bff58270 2022-09-19 op * Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
6 bff58270 2022-09-19 op * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
7 bff58270 2022-09-19 op * Copyright (c) 2001 Markus Friedl. All rights reserved.
8 bff58270 2022-09-19 op * Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
9 bff58270 2022-09-19 op * Copyright (c) 2001 Theo de Raadt. All rights reserved.
11 bff58270 2022-09-19 op * Permission to use, copy, modify, and distribute this software for any
12 bff58270 2022-09-19 op * purpose with or without fee is hereby granted, provided that the above
13 bff58270 2022-09-19 op * copyright notice and this permission notice appear in all copies.
15 bff58270 2022-09-19 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 bff58270 2022-09-19 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 bff58270 2022-09-19 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 bff58270 2022-09-19 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 bff58270 2022-09-19 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 bff58270 2022-09-19 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 bff58270 2022-09-19 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 bff58270 2022-09-19 op #include <sys/queue.h>
28 bff58270 2022-09-19 op #include <ctype.h>
29 bff58270 2022-09-19 op #include <err.h>
30 bff58270 2022-09-19 op #include <stdio.h>
31 bff58270 2022-09-19 op #include <stdlib.h>
32 bff58270 2022-09-19 op #include <stdarg.h>
33 bff58270 2022-09-19 op #include <stdint.h>
34 bff58270 2022-09-19 op #include <string.h>
35 bff58270 2022-09-19 op #include <unistd.h>
37 bff58270 2022-09-19 op #ifndef nitems
38 bff58270 2022-09-19 op #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
41 bff58270 2022-09-19 op TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
42 bff58270 2022-09-19 op static struct file {
43 bff58270 2022-09-19 op TAILQ_ENTRY(file) entry;
46 bff58270 2022-09-19 op size_t ungetpos;
47 bff58270 2022-09-19 op size_t ungetsize;
48 8eb6aff8 2022-09-30 op unsigned char *ungetbuf;
49 bff58270 2022-09-19 op int eof_reached;
52 bff58270 2022-09-19 op } *file, *topfile;
53 bff58270 2022-09-19 op int parse(const char *);
54 bff58270 2022-09-19 op struct file *pushfile(const char *, int);
55 bff58270 2022-09-19 op int popfile(void);
56 bff58270 2022-09-19 op int yyparse(void);
57 bff58270 2022-09-19 op int yylex(void);
58 bff58270 2022-09-19 op int yyerror(const char *, ...)
59 bff58270 2022-09-19 op __attribute__((__format__ (printf, 1, 2)))
60 bff58270 2022-09-19 op __attribute__((__nonnull__ (1)));
61 bff58270 2022-09-19 op int kw_cmp(const void *, const void *);
62 bff58270 2022-09-19 op int lookup(char *);
63 bff58270 2022-09-19 op int igetc(void);
64 bff58270 2022-09-19 op int lgetc(int);
65 bff58270 2022-09-19 op void lungetc(int);
66 bff58270 2022-09-19 op int findeol(void);
68 bff58270 2022-09-19 op void dbg(void);
69 bff58270 2022-09-19 op void printq(const char *);
71 bff58270 2022-09-19 op extern int nodebug;
73 bff58270 2022-09-19 op static int block;
74 bff58270 2022-09-19 op static int in_define;
75 bff58270 2022-09-19 op static int errors;
76 9a90a3d1 2022-09-29 op static int lastline = -1;
78 bff58270 2022-09-19 op typedef struct {
87 9c75d045 2022-10-03 op %token DEFINE ELSE END ERROR FINALLY FOR IF INCLUDE PRINTF
88 bff58270 2022-09-19 op %token RENDER TQFOREACH UNSAFE URLESCAPE
89 bff58270 2022-09-19 op %token <v.string> STRING
90 bff58270 2022-09-19 op %type <v.string> string
91 6125bd61 2022-09-29 op %type <v.string> stringy
95 bff58270 2022-09-19 op grammar : /* empty */
96 bff58270 2022-09-19 op | grammar include
97 bff58270 2022-09-19 op | grammar verbatim
98 bff58270 2022-09-19 op | grammar block
99 bff58270 2022-09-19 op | grammar error { file->errors++; }
102 bff58270 2022-09-19 op include : INCLUDE STRING {
103 bff58270 2022-09-19 op struct file *nfile;
105 bff58270 2022-09-19 op if ((nfile = pushfile($2, 0)) == NULL) {
106 bff58270 2022-09-19 op yyerror("failed to include file %s", $2);
112 bff58270 2022-09-19 op file = nfile;
113 bff58270 2022-09-19 op lungetc('\n');
117 bff58270 2022-09-19 op verbatim : '!' verbatim1 '!' {
118 bff58270 2022-09-19 op if (in_define) {
119 bff58270 2022-09-19 op /* TODO: check template status and exit in case */
124 bff58270 2022-09-19 op verbatim1 : /* empty */
125 bff58270 2022-09-19 op | verbatim1 STRING {
126 bff58270 2022-09-19 op if (*$2 != '\0') {
134 bff58270 2022-09-19 op verbatims : /* empty */
135 bff58270 2022-09-19 op | verbatims verbatim
138 bff58270 2022-09-19 op raw : STRING {
140 95448b62 2022-09-29 op printf("if ((tp_ret = tp->tp_puts(tp, ");
142 37b638a4 2022-09-29 op puts(")) == -1) goto err;");
148 bff58270 2022-09-19 op block : define body end {
149 37b638a4 2022-09-29 op puts("err:");
150 95448b62 2022-09-29 op puts("return tp_ret;");
152 bff58270 2022-09-19 op in_define = 0;
154 bff58270 2022-09-19 op | define body finally end {
155 95448b62 2022-09-29 op puts("return tp_ret;");
157 bff58270 2022-09-19 op in_define = 0;
161 bff58270 2022-09-19 op define : '{' DEFINE string '}' {
162 bff58270 2022-09-19 op in_define = 1;
165 bff58270 2022-09-19 op printf("int\n%s\n{\n", $3);
166 95448b62 2022-09-29 op puts("int tp_ret = 0;");
172 bff58270 2022-09-19 op body : /* empty */
173 bff58270 2022-09-19 op | body verbatim
175 bff58270 2022-09-19 op | body special
178 bff58270 2022-09-19 op special : '{' RENDER string '}' {
180 95448b62 2022-09-29 op printf("if ((tp_ret = %s) == -1) goto err;\n", $3);
184 bff58270 2022-09-19 op | if body endif { puts("}"); }
186 bff58270 2022-09-19 op | '{' string '|' UNSAFE '}' {
188 95448b62 2022-09-29 op printf("if ((tp_ret = tp->tp_puts(tp, %s)) == -1)\n",
190 95448b62 2022-09-29 op puts("goto err;");
193 bff58270 2022-09-19 op | '{' string '|' URLESCAPE '}' {
195 95448b62 2022-09-29 op printf("if ((tp_ret = tp_urlescape(tp, %s)) == -1)\n",
197 95448b62 2022-09-29 op puts("goto err;");
200 bff58270 2022-09-19 op | '{' string '}' {
202 95448b62 2022-09-29 op printf("if ((tp_ret = tp->tp_escape(tp, %s)) == -1)\n",
204 95448b62 2022-09-29 op puts("goto err;");
209 83e0f74d 2022-09-29 op printf : '{' PRINTF {
211 83e0f74d 2022-09-29 op printf("if (asprintf(&tp->tp_tmp, ");
212 83e0f74d 2022-09-29 op } printfargs '}' {
213 37b638a4 2022-09-29 op puts(") == -1)");
214 37b638a4 2022-09-29 op puts("goto err;");
215 95448b62 2022-09-29 op puts("if ((tp_ret = tp->tp_escape(tp, tp->tp_tmp)) "
217 83e0f74d 2022-09-29 op puts("goto err;");
218 83e0f74d 2022-09-29 op puts("free(tp->tp_tmp);");
219 83e0f74d 2022-09-29 op puts("tp->tp_tmp = NULL;");
223 83e0f74d 2022-09-29 op printfargs : /* empty */
224 83e0f74d 2022-09-29 op | printfargs STRING {
225 83e0f74d 2022-09-29 op printf(" %s", $2);
230 6125bd61 2022-09-29 op if : '{' IF stringy '}' {
232 bff58270 2022-09-19 op printf("if (%s) {\n", $3);
238 bff58270 2022-09-19 op | else body end
239 bff58270 2022-09-19 op | elsif body endif
242 6125bd61 2022-09-29 op elsif : '{' ELSE IF stringy '}' {
244 bff58270 2022-09-19 op printf("} else if (%s) {\n", $4);
249 bff58270 2022-09-19 op else : '{' ELSE '}' {
251 bff58270 2022-09-19 op puts("} else {");
255 9c75d045 2022-10-03 op loop : '{' FOR stringy '}' {
256 9c75d045 2022-10-03 op printf("for (%s) {\n", $3);
261 9c75d045 2022-10-03 op | '{' TQFOREACH STRING STRING STRING '}' {
262 bff58270 2022-09-19 op printf("TAILQ_FOREACH(%s, %s, %s) {\n",
272 bff58270 2022-09-19 op end : '{' END '}'
275 bff58270 2022-09-19 op finally : '{' FINALLY '}' {
277 83f0f95a 2022-09-29 op puts("err:");
281 bff58270 2022-09-19 op string : STRING string {
282 bff58270 2022-09-19 op if (asprintf(&$$, "%s %s", $1, $2) == -1)
283 bff58270 2022-09-19 op err(1, "asprintf");
290 6125bd61 2022-09-29 op stringy : STRING
291 6125bd61 2022-09-29 op | STRING stringy {
292 6125bd61 2022-09-29 op if (asprintf(&$$, "%s %s", $1, $2) == -1)
293 6125bd61 2022-09-29 op err(1, "asprintf");
297 6125bd61 2022-09-29 op | '|' stringy {
298 6125bd61 2022-09-29 op if (asprintf(&$$, "|%s", $2) == -1)
299 6125bd61 2022-09-29 op err(1, "asprintf");
306 bff58270 2022-09-19 op struct keywords {
307 bff58270 2022-09-19 op const char *k_name;
312 bff58270 2022-09-19 op yyerror(const char *fmt, ...)
317 bff58270 2022-09-19 op file->errors++;
318 bff58270 2022-09-19 op va_start(ap, fmt);
319 bff58270 2022-09-19 op if (vasprintf(&msg, fmt, ap) == -1)
320 bff58270 2022-09-19 op err(1, "yyerror vasprintf");
322 bff58270 2022-09-19 op fprintf(stderr, "%s:%d: %s\n", file->name, yylval.lineno, msg);
328 bff58270 2022-09-19 op kw_cmp(const void *k, const void *e)
330 bff58270 2022-09-19 op return (strcmp(k, ((const struct keywords *)e)->k_name));
334 bff58270 2022-09-19 op lookup(char *s)
336 bff58270 2022-09-19 op /* this has to be sorted always */
337 bff58270 2022-09-19 op static const struct keywords keywords[] = {
338 bff58270 2022-09-19 op { "define", DEFINE },
339 bff58270 2022-09-19 op { "else", ELSE },
340 bff58270 2022-09-19 op { "end", END },
341 bff58270 2022-09-19 op { "finally", FINALLY },
342 9c75d045 2022-10-03 op { "for", FOR },
343 bff58270 2022-09-19 op { "if", IF },
344 bff58270 2022-09-19 op { "include", INCLUDE },
345 83e0f74d 2022-09-29 op { "printf", PRINTF },
346 bff58270 2022-09-19 op { "render", RENDER },
347 bff58270 2022-09-19 op { "tailq-foreach", TQFOREACH },
348 bff58270 2022-09-19 op { "unsafe", UNSAFE },
349 bff58270 2022-09-19 op { "urlescape", URLESCAPE },
351 bff58270 2022-09-19 op const struct keywords *p;
353 bff58270 2022-09-19 op p = bsearch(s, keywords, nitems(keywords), sizeof(keywords[0]),
357 bff58270 2022-09-19 op return (p->k_val);
359 bff58270 2022-09-19 op return (STRING);
362 bff58270 2022-09-19 op #define START_EXPAND 1
363 bff58270 2022-09-19 op #define DONE_EXPAND 2
365 bff58270 2022-09-19 op static int expanding;
373 bff58270 2022-09-19 op if (file->ungetpos > 0)
374 bff58270 2022-09-19 op c = file->ungetbuf[--file->ungetpos];
376 bff58270 2022-09-19 op c = getc(file->stream);
378 bff58270 2022-09-19 op if (c == START_EXPAND)
379 bff58270 2022-09-19 op expanding = 1;
380 bff58270 2022-09-19 op else if (c == DONE_EXPAND)
381 bff58270 2022-09-19 op expanding = 0;
389 bff58270 2022-09-19 op lgetc(int quotec)
393 bff58270 2022-09-19 op if (quotec) {
394 bff58270 2022-09-19 op if ((c = igetc()) == EOF) {
395 bff58270 2022-09-19 op yyerror("reached end of filewhile parsing "
396 bff58270 2022-09-19 op "quoted string");
397 bff58270 2022-09-19 op if (file == topfile || popfile() == EOF)
398 bff58270 2022-09-19 op return (EOF);
399 bff58270 2022-09-19 op return (quotec);
405 bff58270 2022-09-19 op if (c == '\t' || c == ' ') {
406 bff58270 2022-09-19 op /* Compress blanks to a sigle space. */
408 bff58270 2022-09-19 op c = getc(file->stream);
409 bff58270 2022-09-19 op } while (c == '\t' || c == ' ');
410 bff58270 2022-09-19 op ungetc(c, file->stream);
414 bff58270 2022-09-19 op if (c == EOF) {
416 bff58270 2022-09-19 op * Fake EOL when hit EOF for the first time. This gets line
417 bff58270 2022-09-19 op * count rigchtif last line included file is syntactically
418 bff58270 2022-09-19 op * invalid and has no newline.
420 bff58270 2022-09-19 op if (file->eof_reached == 0) {
421 bff58270 2022-09-19 op file->eof_reached = 1;
422 bff58270 2022-09-19 op return ('\n');
424 bff58270 2022-09-19 op while (c == EOF) {
425 bff58270 2022-09-19 op if (file == topfile || popfile() == EOF)
426 bff58270 2022-09-19 op return (EOF);
434 bff58270 2022-09-19 op lungetc(int c)
436 bff58270 2022-09-19 op if (c == EOF)
439 bff58270 2022-09-19 op if (file->ungetpos >= file->ungetsize) {
440 bff58270 2022-09-19 op void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
441 bff58270 2022-09-19 op if (p == NULL)
442 bff58270 2022-09-19 op err(1, "reallocarray");
443 bff58270 2022-09-19 op file->ungetbuf = p;
444 bff58270 2022-09-19 op file->ungetsize *= 2;
446 bff58270 2022-09-19 op file->ungetbuf[file->ungetpos++] = c;
450 bff58270 2022-09-19 op findeol(void)
454 bff58270 2022-09-19 op /* skip to either EOF or the first real EOL */
456 bff58270 2022-09-19 op c = lgetc(0);
457 bff58270 2022-09-19 op if (c == '\n') {
458 bff58270 2022-09-19 op file->lineno++;
461 bff58270 2022-09-19 op if (c == EOF)
464 bff58270 2022-09-19 op return (ERROR);
470 bff58270 2022-09-19 op char buf[8096];
471 bff58270 2022-09-19 op char *p = buf;
474 bff58270 2022-09-19 op int starting = 0;
475 bff58270 2022-09-19 op int ending = 0;
477 bff58270 2022-09-19 op if (!in_define && block == 0) {
478 bff58270 2022-09-19 op while ((c = lgetc(0)) != '{' && c != EOF) {
479 bff58270 2022-09-19 op if (c == '\n')
480 bff58270 2022-09-19 op file->lineno++;
483 bff58270 2022-09-19 op if (c == EOF)
487 bff58270 2022-09-19 op c = lgetc(0);
488 bff58270 2022-09-19 op if (c == '{' || c == '!') {
489 bff58270 2022-09-19 op if (c == '{')
495 bff58270 2022-09-19 op if (c == '\n')
496 bff58270 2022-09-19 op file->lineno++;
499 bff58270 2022-09-19 op while ((c = lgetc(0)) == ' ' || c == '\t' || c == '\n') {
500 bff58270 2022-09-19 op if (c == '\n')
501 bff58270 2022-09-19 op file->lineno++;
504 bff58270 2022-09-19 op if (c == EOF) {
505 bff58270 2022-09-19 op yyerror("unterminated block");
509 bff58270 2022-09-19 op yylval.lineno = file->lineno;
511 bff58270 2022-09-19 op if (block != 0 && c == block) {
512 bff58270 2022-09-19 op if ((c = lgetc(0)) == '}') {
513 bff58270 2022-09-19 op if (block == '!') {
515 bff58270 2022-09-19 op return ('!');
518 bff58270 2022-09-19 op return ('}');
524 bff58270 2022-09-19 op if (in_define && block == 0) {
525 bff58270 2022-09-19 op if (c == '{')
526 bff58270 2022-09-19 op goto newblock;
529 bff58270 2022-09-19 op if (starting) {
530 bff58270 2022-09-19 op if (c == '!' || c == '{') {
532 c063deb1 2022-10-21 op lungetc('{');
535 bff58270 2022-09-19 op starting = 0;
538 bff58270 2022-09-19 op } else if (c == '{') {
539 bff58270 2022-09-19 op starting = 1;
544 bff58270 2022-09-19 op if ((size_t)(p - buf) >= sizeof(buf)) {
545 bff58270 2022-09-19 op yyerror("string too long");
546 bff58270 2022-09-19 op return (findeol());
548 bff58270 2022-09-19 op } while ((c = lgetc(0)) != EOF && c != '\n');
550 bff58270 2022-09-19 op if (c == EOF) {
551 bff58270 2022-09-19 op yyerror("unterminated block");
554 bff58270 2022-09-19 op if (c == '\n')
555 bff58270 2022-09-19 op file->lineno++;
556 bff58270 2022-09-19 op if ((yylval.v.string = strdup(buf)) == NULL)
557 bff58270 2022-09-19 op err(1, "strdup");
558 bff58270 2022-09-19 op return (STRING);
561 bff58270 2022-09-19 op if (block == '!') {
563 bff58270 2022-09-19 op if (ending) {
564 bff58270 2022-09-19 op if (c == '}') {
566 bff58270 2022-09-19 op lungetc(block);
572 bff58270 2022-09-19 op } else if (c == '!') {
578 bff58270 2022-09-19 op if ((size_t)(p - buf) >= sizeof(buf)) {
579 bff58270 2022-09-19 op yyerror("line too long");
580 bff58270 2022-09-19 op return (findeol());
582 bff58270 2022-09-19 op } while ((c = lgetc(0)) != EOF && c != '\n');
585 bff58270 2022-09-19 op if (c == EOF) {
586 bff58270 2022-09-19 op yyerror("unterminated block");
589 bff58270 2022-09-19 op if (c == '\n')
590 bff58270 2022-09-19 op file->lineno++;
592 bff58270 2022-09-19 op if ((yylval.v.string = strdup(buf)) == NULL)
593 bff58270 2022-09-19 op err(1, "strdup");
594 bff58270 2022-09-19 op return (STRING);
597 bff58270 2022-09-19 op if (c == '|')
601 bff58270 2022-09-19 op if (c == '|') {
606 bff58270 2022-09-19 op if (ending) {
607 bff58270 2022-09-19 op if (c == '}') {
609 bff58270 2022-09-19 op lungetc('}');
615 bff58270 2022-09-19 op } else if (c == '}') {
621 bff58270 2022-09-19 op if ((size_t)(p - buf) >= sizeof(buf)) {
622 bff58270 2022-09-19 op yyerror("string too long");
623 bff58270 2022-09-19 op return (findeol());
625 bff58270 2022-09-19 op } while ((c = lgetc(0)) != EOF && !isspace((unsigned char)c));
628 bff58270 2022-09-19 op if (c == EOF) {
629 bff58270 2022-09-19 op yyerror("unterminated block");
632 bff58270 2022-09-19 op if (c == '\n')
633 bff58270 2022-09-19 op file->lineno++;
634 bff58270 2022-09-19 op if ((token = lookup(buf)) == STRING)
635 bff58270 2022-09-19 op if ((yylval.v.string = strdup(buf)) == NULL)
636 bff58270 2022-09-19 op err(1, "strdup");
637 bff58270 2022-09-19 op return (token);
640 bff58270 2022-09-19 op struct file *
641 bff58270 2022-09-19 op pushfile(const char *name, int secret)
643 bff58270 2022-09-19 op struct file *nfile;
645 bff58270 2022-09-19 op if ((nfile = calloc(1, sizeof(*nfile))) == NULL)
646 bff58270 2022-09-19 op err(1, "calloc");
647 bff58270 2022-09-19 op if ((nfile->name = strdup(name)) == NULL)
648 bff58270 2022-09-19 op err(1, "strdup");
649 bff58270 2022-09-19 op if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
650 bff58270 2022-09-19 op warn("can't open %s", nfile->name);
651 bff58270 2022-09-19 op free(nfile->name);
653 bff58270 2022-09-19 op return (NULL);
655 bff58270 2022-09-19 op nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
656 bff58270 2022-09-19 op nfile->ungetsize = 16;
657 bff58270 2022-09-19 op nfile->ungetbuf = malloc(nfile->ungetsize);
658 bff58270 2022-09-19 op if (nfile->ungetbuf == NULL)
659 bff58270 2022-09-19 op err(1, "malloc");
660 bff58270 2022-09-19 op TAILQ_INSERT_TAIL(&files, nfile, entry);
661 bff58270 2022-09-19 op return (nfile);
665 bff58270 2022-09-19 op popfile(void)
667 bff58270 2022-09-19 op struct file *prev;
669 bff58270 2022-09-19 op if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
670 bff58270 2022-09-19 op prev->errors += file->errors;
672 bff58270 2022-09-19 op TAILQ_REMOVE(&files, file, entry);
673 bff58270 2022-09-19 op fclose(file->stream);
674 bff58270 2022-09-19 op free(file->name);
675 bff58270 2022-09-19 op free(file->ungetbuf);
678 bff58270 2022-09-19 op return (file ? 0 : EOF);
682 bff58270 2022-09-19 op parse(const char *filename)
684 bff58270 2022-09-19 op if ((file = pushfile(filename, 0)) == 0)
686 bff58270 2022-09-19 op topfile = file;
689 bff58270 2022-09-19 op errors = file->errors;
692 bff58270 2022-09-19 op return (errors ? -1 : 0);
701 9a90a3d1 2022-09-29 op if (yylval.lineno == lastline + 1) {
702 9a90a3d1 2022-09-29 op lastline = yylval.lineno;
705 9a90a3d1 2022-09-29 op lastline = yylval.lineno;
707 bff58270 2022-09-19 op printf("#line %d ", yylval.lineno);
708 bff58270 2022-09-19 op printq(file->name);
709 bff58270 2022-09-19 op putchar('\n');
713 bff58270 2022-09-19 op printq(const char *str)
715 bff58270 2022-09-19 op putchar('"');
716 bff58270 2022-09-19 op for (; *str; ++str) {
717 bff58270 2022-09-19 op if (*str == '"')
718 bff58270 2022-09-19 op putchar('\\');
719 bff58270 2022-09-19 op putchar(*str);
721 bff58270 2022-09-19 op putchar('"');