diff options
author | Thomas Adam <thomas@xteddy.org> | 2019-06-14 15:51:09 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2019-06-14 15:51:09 +0100 |
commit | 5e9757b30b8de13028149caa2683a7d76f231790 (patch) | |
tree | 5df34efc0213aa839e5ba6ddefa1193309cff383 /cmd-parse.y | |
parent | 4bbf941436765201825c8d675f45b0cb70eb19d3 (diff) | |
parent | d1d3bbb458b50ec455d65774d5c6669546b3b4ca (diff) | |
download | rtmux-5e9757b30b8de13028149caa2683a7d76f231790.tar.gz rtmux-5e9757b30b8de13028149caa2683a7d76f231790.tar.bz2 rtmux-5e9757b30b8de13028149caa2683a7d76f231790.zip |
Merge branch 'obsd-master'
Diffstat (limited to 'cmd-parse.y')
-rw-r--r-- | cmd-parse.y | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/cmd-parse.y b/cmd-parse.y index a7c12f62..1dbc27a7 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -59,6 +59,7 @@ struct cmd_parse_state { size_t len; size_t off; + int condition; int eol; int eof; struct cmd_parse_input *input; @@ -104,7 +105,7 @@ static void cmd_parse_print_commands(struct cmd_parse_input *, u_int, %token ENDIF %token <token> FORMAT TOKEN EQUALS -%type <token> argument expanded +%type <token> argument expanded format %type <arguments> arguments %type <flag> if_open if_elif %type <elif> elif elif1 @@ -160,7 +161,16 @@ statement : condition } } -expanded : FORMAT +format : FORMAT + { + $$ = $1; + } + | TOKEN + { + $$ = $1; + } + +expanded : format { struct cmd_parse_state *ps = &parse_state; struct cmd_parse_input *pi = ps->input; @@ -507,7 +517,10 @@ cmd_parse_print_commands(struct cmd_parse_input *pi, u_int line, if (pi->item != NULL && (pi->flags & CMD_PARSE_VERBOSE)) { s = cmd_list_print(cmdlist, 0); - cmdq_print(pi->item, "%u: %s", line, s); + if (pi->file != NULL) + cmdq_print(pi->item, "%s:%u: %s", pi->file, line, s); + else + cmdq_print(pi->item, "%u: %s", line, s); free(s); } } @@ -967,12 +980,15 @@ yylex(void) { struct cmd_parse_state *ps = &parse_state; char *token, *cp; - int ch, next; + int ch, next, condition; if (ps->eol) ps->input->line++; ps->eol = 0; + condition = ps->condition; + ps->condition = 0; + for (;;) { ch = yylex_getc(); @@ -1012,11 +1028,11 @@ yylex(void) if (ch == '#') { /* - * #{ opens a format; anything else is a comment, - * ignore up to the end of the line. + * #{ after a condition opens a format; anything else + * is a comment, ignore up to the end of the line. */ next = yylex_getc(); - if (next == '{') { + if (condition && next == '{') { yylval.token = yylex_format(); if (yylval.token == NULL) return (ERROR); @@ -1043,6 +1059,7 @@ yylex(void) } if (*cp == '\0') return (TOKEN); + ps->condition = 1; if (strcmp(yylval.token, "%if") == 0) { free(yylval.token); return (IF); |