diff options
| author | Michael Matz <matz@suse.de> | 2016-08-08 22:26:11 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2016-12-15 17:47:10 +0100 |
| commit | d0d25ec7df636deaf650d31ae3b50e60659f54dd (patch) | |
| tree | 4eae48c91ac5298b4475e4fc8ed26592f503e658 /tccpp.c | |
| parent | 0381387640fecfc1d8bd9e79d972a2b58c508069 (diff) | |
| download | tinycc-d0d25ec7df636deaf650d31ae3b50e60659f54dd.tar.gz tinycc-d0d25ec7df636deaf650d31ae3b50e60659f54dd.tar.bz2 | |
tccpp: Allow computed include like 42.h
The include directive needs to be parsed as pp-tokens, not
as token (i.e. no conversion to TOK_STR or TOK_NUM). Also fix
parsing computed includes using quoted strings.
Diffstat (limited to 'tccpp.c')
| -rw-r--r-- | tccpp.c | 45 |
1 files changed, 19 insertions, 26 deletions
@@ -1737,34 +1737,27 @@ ST_FUNC void preprocess(int is_bof) inp(); #endif } else { - /* computed #include : either we have only strings or - we have anything enclosed in '<>' */ + int len; + /* computed #include : concatenate everything up to linefeed, + the result must be one of the two accepted forms. + Don't convert pp-tokens to tokens here. */ + parse_flags = (PARSE_FLAG_PREPROCESS + | PARSE_FLAG_LINEFEED + | (parse_flags & PARSE_FLAG_ASM_FILE)); next(); buf[0] = '\0'; - if (tok == TOK_STR) { - while (tok != TOK_LINEFEED) { - if (tok != TOK_STR) { - include_syntax: - tcc_error("'#include' expects \"FILENAME\" or <FILENAME>"); - } - pstrcat(buf, sizeof(buf), (char *)tokc.str.data); - next(); - } - c = '\"'; - } else { - int len; - while (tok != TOK_LINEFEED) { - pstrcat(buf, sizeof(buf), get_tok_str(tok, &tokc)); - next(); - } - len = strlen(buf); - /* check syntax and remove '<>' */ - if (len < 2 || buf[0] != '<' || buf[len - 1] != '>') - goto include_syntax; - memmove(buf, buf + 1, len - 2); - buf[len - 2] = '\0'; - c = '>'; - } + while (tok != TOK_LINEFEED) { + pstrcat(buf, sizeof(buf), get_tok_str(tok, &tokc)); + next(); + } + len = strlen(buf); + /* check syntax and remove '<>|""' */ + if ((len < 2 || ((buf[0] != '"' || buf[len-1] != '"') && + (buf[0] != '<' || buf[len-1] != '>')))) + tcc_error("'#include' expects \"FILENAME\" or <FILENAME>"); + c = buf[len-1]; + memmove(buf, buf + 1, len - 2); + buf[len - 2] = '\0'; } if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE) |
