static void mp4m_system_execute (MP4H_BUILTIN_ARGS) { const char *type, *s; const builtin *bp; type = predefined_attribute ("type", &argc, argv, FALSE); if (!type) { MP4HERROR ((warning_status, errno, _("Warning:%s:%d: Missing `type' attribute in <%s>"), CURRENT_FILE_LINE, ARG (0))); return; } if (bad_argc (argv[0], argc, 1, 1)) return; s = xstrdup(type); bp = find_builtin_by_name(s); if (!bp) { MP4HERROR ((warning_status, errno, _("Warning:%s:%d: %s: Undefined type in <%s>"), CURRENT_FILE_LINE, type, ARG (0))); return; } (*(bp->func))(MP4H_BUILTIN_RECUR); }
int peek_input (void) { int ch; int (*f)(void); while (1) { if (isp == NULL) return CHAR_EOF; f = isp->funcs->peek_func; if (f != NULL) { if ((ch = (*f)()) != CHAR_RETRY) { return /* (IS_IGNORE(ch)) ? next_char () : */ ch; } } else { MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Input stack botch in peek_input ()")); exit (1); } /* End of input source --- pop one level. */ pop_input (); } }
static int next_char (void) { int ch; int (*f)(void); while (1) { if (isp == NULL) return CHAR_EOF; f = isp->funcs->read_func; if (f != NULL) { while ((ch = (*f)()) != CHAR_RETRY) { /* if (!IS_IGNORE(ch)) */ return ch; } } else { MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Input stack botch in next_char ()")); exit (1); } /* End of input source --- pop one level. */ pop_input (); } }
void read_file_verbatim (struct obstack *obs) { int ch; int (*f)(void); struct obstack *st; if (next != NULL) st = obs; else st = push_string_init (); f = isp->funcs->read_func; if (f != NULL) { while ((ch = (*f)()) != CHAR_RETRY) obstack_1grow (st, ch); } else { MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Input stack botch in read_file_verbatim ()")); exit (1); } push_string_finish (READ_BODY); }
boolean bad_argc (token_data *name, int argc, int min, int max) { boolean isbad = FALSE; if (min > 0 && argc < min) { if (!suppress_warnings) MP4HERROR ((warning_status, 0, _("Warning:%s:%d: Too few arguments to built-in `%s'"), CURRENT_FILE_LINE, TOKEN_DATA_TEXT (name))); isbad = TRUE; } else if (max > 0 && argc > max && !suppress_warnings) { MP4HERROR ((warning_status, 0, _("Warning:%s:%d: Excess arguments to built-in `%s' ignored"), CURRENT_FILE_LINE, TOKEN_DATA_TEXT (name))); } return isbad; }
static void mp4m_intl_bindtextdomain (MP4H_BUILTIN_ARGS) { const char *domain, *path; domain = predefined_attribute ("domain", &argc, argv, FALSE); path = predefined_attribute ("path", &argc, argv, FALSE); if (!domain) { MP4HERROR ((warning_status, 0, _("Warning:%s:%d: In <%s>, required attribute `%s' is not specified"), CURRENT_FILE_LINE, ARG (0), "domain")); return; } if (!path) { MP4HERROR ((warning_status, 0, _("Warning:%s:%d: In <%s>, required attribute `%s' is not specified"), CURRENT_FILE_LINE, ARG (0), "path")); return; } bindtextdomain (domain, path); }
static void mp4m_intl_bind_textdomain_codeset (MP4H_BUILTIN_ARGS) { const char *domain, *codeset; domain = predefined_attribute ("domain", &argc, argv, FALSE); codeset = predefined_attribute ("codeset", &argc, argv, FALSE); if (!domain) { MP4HERROR ((warning_status, 0, _("Warning:%s:%d: In <%s>, required attribute `%s' is not specified"), CURRENT_FILE_LINE, ARG (0), "domain")); return; } if (!codeset) { MP4HERROR ((warning_status, 0, _("Warning:%s:%d: In <%s>, required attribute `%s' is not specified"), CURRENT_FILE_LINE, ARG (0), "codeset")); return; } bind_textdomain_codeset (domain, codeset); }
static void init_macro_token (token_data *td) { if (isp->funcs->read_func != macro_read) { MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Bad call to init_macro_token ()")); exit (1); } TOKEN_DATA_TYPE (td) = TOKEN_FUNC; TOKEN_DATA_FUNC (td) = isp->u.u_m.func; TOKEN_DATA_FUNC_TRACED (td) = isp->u.u_m.traced; }
struct obstack * push_string_init (void) { if (next != NULL) { MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Recursive push_string!")); exit (1); } next = (input_block *) obstack_alloc (current_input, sizeof (struct input_block)); next->funcs = &string_funcs; return current_input; }
boolean numeric_arg (token_data *macro, const char *arg, boolean warn, int *valuep) { char *endp; if (*arg == 0 || (*valuep = strtol (skip_space (arg), &endp, 10), *skip_space (endp) != 0)) { if (warn) MP4HERROR ((warning_status, 0, _("Warning:%s:%d: Argument `%s' non-numeric in the <%s> tag"), CURRENT_FILE_LINE, arg, TOKEN_DATA_TEXT (macro))); return FALSE; } return TRUE; }
token_type next_token (token_data *td, read_type expansion, boolean in_string) { int ch; token_type type = TOKEN_NONE; int quote_level; if (TOKEN_DATA_TYPE (&token_read) != TOKEN_VOID) { type = TOKEN_STRING; obstack_grow (&token_stack, TOKEN_DATA_TEXT (&token_read), strlen (TOKEN_DATA_TEXT (&token_read))); xfree ((voidstar) TOKEN_DATA_TEXT (&token_read)); TOKEN_DATA_TYPE (&token_read) = TOKEN_VOID; } while (type == TOKEN_NONE) { obstack_free (&token_stack, token_bottom); obstack_1grow (&token_stack, '\0'); token_bottom = obstack_finish (&token_stack); ch = peek_input (); if (ch == CHAR_EOF) /* EOF */ { #ifdef DEBUG_INPUT fprintf (stderr, "next_token -> EOF\n"); #endif return TOKEN_EOF; } if (ch == CHAR_MACRO) /* MACRO TOKEN */ { init_macro_token (td); (void) next_char (); #ifdef DEBUG_INPUT print_token("next_token", TOKEN_MACDEF, td); #endif return TOKEN_MACDEF; } (void) next_char (); if (IS_TAG(ch)) /* ESCAPED WORD */ { if (lquote.length > 0 && MATCH (ch, lquote.string)) { if (visible_quotes || expansion == READ_ATTR_VERB || expansion == READ_ATTR_ASIS || expansion == READ_BODY) obstack_grow (&token_stack, lquote.string, lquote.length); while ((ch = next_char ()) != CHAR_EOF) { if (rquote.length > 0 && MATCH (ch, rquote.string)) break; obstack_1grow (&token_stack, ch); } if (visible_quotes || expansion == READ_ATTR_VERB || expansion == READ_ATTR_ASIS || expansion == READ_BODY) { obstack_grow (&token_stack, rquote.string, rquote.length); type = TOKEN_STRING; } else type = TOKEN_QUOTED; } else { obstack_1grow (&token_stack, ch); if ((ch = peek_input ()) != CHAR_EOF) { if (ch == '/') { obstack_1grow (&token_stack, '/'); (void) next_char (); ch = peek_input (); } if (IS_ALPHA(ch)) { ch = next_char (); obstack_1grow (&token_stack, ch); while ((ch = next_char ()) != CHAR_EOF && IS_ALNUM(ch)) { obstack_1grow (&token_stack, ch); } if (ch == '*') { obstack_1grow (&token_stack, ch); ch = peek_input (); } else unget_input(ch); if (IS_SPACE(ch) || IS_CLOSE(ch) || IS_SLASH (ch)) type = TOKEN_WORD; else type = TOKEN_STRING; } else type = TOKEN_STRING; } else type = TOKEN_SIMPLE; /* escape before eof */ } } else if (IS_CLOSE(ch)) { obstack_1grow (&token_stack, ch); type = TOKEN_SIMPLE; } else if (IS_ENTITY(ch)) /* entity */ { obstack_1grow (&token_stack, ch); if ((ch = peek_input ()) != CHAR_EOF) { if (IS_ALPHA(ch)) { ch = next_char (); obstack_1grow (&token_stack, ch); while ((ch = next_char ()) != CHAR_EOF && IS_ALNUM(ch)) { obstack_1grow (&token_stack, ch); } if (ch == ';') { obstack_1grow (&token_stack, ch); type = TOKEN_ENTITY; } else { type = TOKEN_STRING; unget_input(ch); } } else type = TOKEN_STRING; } else type = TOKEN_SIMPLE; /* escape before eof */ } else if (eolcomm.length > 0 && MATCH (ch, eolcomm.string)) skip_line (); else if (expansion == READ_BODY) { if (ch == '"') obstack_1grow (&token_stack, CHAR_QUOTE); else obstack_1grow (&token_stack, ch); while ((ch = next_char ()) != CHAR_EOF && ! IS_TAG(ch) && ! IS_CLOSE (ch)) { if (eolcomm.length > 0 && MATCH (ch, eolcomm.string)) { skip_line (); ch = CHAR_EOF; break; } if (ch == '"') obstack_1grow (&token_stack, CHAR_QUOTE); else obstack_1grow (&token_stack, ch); } unget_input(ch); type = TOKEN_STRING; } /* Below we know that expansion != READ_BODY */ else if (IS_ALPHA(ch)) { obstack_1grow (&token_stack, ch); while ((ch = next_char ()) != CHAR_EOF && (IS_ALNUM(ch))) { obstack_1grow (&token_stack, ch); } if (ch == '*') { obstack_1grow (&token_stack, ch); ch = peek_input (); } else unget_input(ch); type = TOKEN_STRING; } else if (IS_RQUOTE(ch)) { MP4HERROR ((EXIT_FAILURE, 0, "INTERNAL ERROR: CHAR_RQUOTE found.")); } else if (IS_LQUOTE(ch)) /* QUOTED STRING */ { quote_level = 1; while (1) { ch = next_char (); if (ch == CHAR_EOF) MP4HERROR ((EXIT_FAILURE, 0, "INTERNAL ERROR: EOF in string")); if (IS_BGROUP(ch) || IS_EGROUP(ch)) continue; else if (IS_RQUOTE(ch)) { quote_level--; if (quote_level == 0) break; } else if (IS_LQUOTE(ch)) quote_level++; else obstack_1grow (&token_stack, ch); } type = TOKEN_QUOTED; } else if (IS_BGROUP(ch)) /* BEGIN GROUP */ type = TOKEN_BGROUP; else if (IS_EGROUP(ch)) /* END GROUP */ type = TOKEN_EGROUP; else if (ch == '"') /* QUOTED STRING */ { switch (expansion) { case READ_NORMAL: obstack_1grow (&token_stack, CHAR_QUOTE); type = TOKEN_SIMPLE; break; case READ_ATTRIBUTE: case READ_ATTR_VERB: type = TOKEN_QUOTE; break; case READ_ATTR_ASIS: case READ_ATTR_QUOT: obstack_1grow (&token_stack, '"'); type = TOKEN_QUOTE; break; default: MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Unknown expansion type")); exit (1); } } else if (ch == '\\') { switch (expansion) { case READ_NORMAL: obstack_1grow (&token_stack, ch); type = TOKEN_SIMPLE; break; case READ_ATTRIBUTE: case READ_ATTR_QUOT: ch = next_char(); if (ch == 'n') obstack_1grow (&token_stack, '\n'); else if (ch == 't') obstack_1grow (&token_stack, '\t'); else if (ch == 'r') obstack_1grow (&token_stack, '\r'); else if (ch == '\\') obstack_1grow (&token_stack, ch); else if (ch == '"' && in_string) obstack_1grow (&token_stack, CHAR_QUOTE); else { if (!(exp_flags & EXP_STD_BSLASH)) obstack_1grow (&token_stack, '\\'); obstack_1grow (&token_stack, ch); } type = TOKEN_STRING; break; case READ_ATTR_VERB: ch = next_char(); if (ch == '"' && in_string) obstack_1grow (&token_stack, CHAR_QUOTE); else { obstack_1grow (&token_stack, '\\'); obstack_1grow (&token_stack, ch); } type = TOKEN_STRING; break; case READ_ATTR_ASIS: obstack_1grow (&token_stack, ch); ch = next_char(); obstack_1grow (&token_stack, ch); type = TOKEN_STRING; break; default: MP4HERROR ((warning_status, 0, "INTERNAL ERROR: Unknown expansion type")); exit (1); } } else /* EVERYTHING ELSE */ { obstack_1grow (&token_stack, ch); if (IS_OTHER(ch) || IS_NUM(ch)) type = TOKEN_STRING; else if (IS_SPACE(ch)) { while ((ch = next_char ()) != CHAR_EOF && IS_SPACE(ch)) obstack_1grow (&token_stack, ch); unget_input(ch); type = TOKEN_SPACE; } else type = TOKEN_SIMPLE; } } obstack_1grow (&token_stack, '\0'); TOKEN_DATA_TYPE (td) = TOKEN_TEXT; TOKEN_DATA_TEXT (td) = obstack_finish (&token_stack); #ifdef DEBUG_INPUT print_token("next_token", type, td); #endif return type; }
static int print_token (const char *s, token_type t, token_data *td) { fprintf (stderr, "%s: ", s); switch (t) { /* TOKSW */ case TOKEN_SIMPLE: fprintf (stderr, "char\t\"%s\"\n", TOKEN_DATA_TEXT (td)); break; case TOKEN_WORD: fprintf (stderr, "word\t\"%s\"\n", TOKEN_DATA_TEXT (td)); break; case TOKEN_ENTITY: fprintf (stderr, "entity\t\"%s\"\n", TOKEN_DATA_TEXT (td)); break; case TOKEN_STRING: fprintf (stderr, "string\t\"%s\"\n", TOKEN_DATA_TEXT (td)); break; case TOKEN_QUOTED: fprintf (stderr, "quoted\t\"%s\"\n", TOKEN_DATA_TEXT (td)); break; case TOKEN_BGROUP: fprintf (stderr, "bgroup\n"); break; case TOKEN_EGROUP: fprintf (stderr, "egroup\n"); break; case TOKEN_QUOTE: fprintf (stderr, "quote\n"); break; case TOKEN_SPACE: fprintf (stderr, "space\t\"%s\"\n", TOKEN_DATA_TEXT (td)); break; case TOKEN_MACDEF: fprintf (stderr, "macro 0x%x\n", (int)TOKEN_DATA_FUNC (td)); break; case TOKEN_EOF: fprintf (stderr, "eof\n"); break; case TOKEN_NONE: fprintf (stderr, "none\n"); break; default: MP4HERROR ((warning_status, 0, "INTERNAL ERROR: unknown token in print_token")); break; } return 0; }