/* * Reads a file name of #include directive. If the file name is quoted with <>, * "std" will set to true. If quoted with doublequote, set to false. We use * expand_one() rather than read_cpp_token(), because macros are allowed to be * used in #include. * (C99 6.10.2 Source file inclusion) */ static void read_cpp_header_name(CppContext *ctx, String **name, bool *std) { if (LIST_IS_EMPTY(ctx->ungotten)) { *name = read_header_name(ctx, std); if (name) return; } Token *tok = expand_one(ctx); if (!tok || tok->toktype == TOKTYPE_NEWLINE) error_token(tok, "expected file name, but got '%s'", token_to_string(tok)); if (tok->toktype == TOKTYPE_STRING) { *name = tok->val.str; *std = false; return; } List *tokens = make_list(); if (is_punct(tok, '<')) { for (;;) { Token *tok = expand_one(ctx); if (!tok || tok->toktype == TOKTYPE_NEWLINE) error_token(tok, "premature end of header name"); if (is_punct(tok, '>')) break; list_push(tokens, tok); } *name = join_tokens(tokens, false); *std = true; return; } error_token(tok, "'<' expected, but got '%s'", token_to_string(tok)); }
t_parse *ft_checking_syntax(t_token *tok) { tok = inibitor_handler(tok); return_type_quoted(tok); tok = join_quoted(tok, QUOTES); tok = join_quoted(tok, SINGLE_QUOTES); tok = ft_subshell(tok); tok = check_dollar(tok); tok = ft_tild_expand(tok); ft_edit_useless(tok); if ((tok = ft_token_removal(tok, QUOTES)) == NULL) return (NULL); if ((tok = ft_token_removal(tok, SINGLE_QUOTES)) == NULL) return (NULL); tok = join_tokens(tok); if ((tok = ft_token_removal(tok, WHITESPACE)) == NULL) return (NULL); if (!tok) return (NULL); if (!(ft_command_isvalid(tok))) { free_token_list(tok); return (NULL); } return (parse_build_list(tok)); }
/* * Write a string representation of a given token sequence. Used by * # operator. */ static Token *stringize(Token *tmpl, List *arg) { Token *r = copy_token(tmpl); r->toktype = TOKTYPE_STRING; r->val.str = join_tokens(arg, true); return r; }