{
if (token->type != SCAN_SKIP)
{
+ printf ("error\n");
/* XXX report error */
}
}
return true;
}
+static const char *
+unquote_string_in_place (const char *s, struct string *tmp)
+{
+ ds_init_empty (tmp);
+ return unquote_string (s, tmp) ? ds_cstr (tmp) : s;
+}
+
static bool
parse_integer (const char *s, int *np)
{
else if (parse_macro_function (ctx, &args, ss_cstr ("!head"), 1, 1,
input_consumed))
{
- struct string content = DS_EMPTY_INITIALIZER;
- const char *s = (unquote_string (args.strings[0], &content)
- ? ds_cstr (&content) : args.strings[0]);
+ struct string tmp;
+ const char *s = unquote_string_in_place (args.strings[0], &tmp);
struct macro_tokens mts = { .n = 0 };
macro_tokens_from_string (&mts, ss_cstr (s), SEG_MODE_INTERACTIVE /* XXX */);
if (mts.n > 0)
ds_put_substring (output, mts.mts[0].representation);
macro_tokens_uninit (&mts);
- ds_destroy (&content);
+ ds_destroy (&tmp);
}
else if (parse_macro_function (ctx, &args, ss_cstr ("!index"), 2, 2,
input_consumed))
else if (parse_macro_function (ctx, &args, ss_cstr ("!tail"), 1, 1,
input_consumed))
{
- struct string content = DS_EMPTY_INITIALIZER;
- const char *s = (unquote_string (args.strings[0], &content)
- ? ds_cstr (&content) : args.strings[0]);
+ struct string tmp;
+ const char *s = unquote_string_in_place (args.strings[0], &tmp);
struct macro_tokens mts = { .n = 0 };
macro_tokens_from_string (&mts, ss_cstr (s), SEG_MODE_INTERACTIVE /* XXX */);
macro_tokens_to_representation (&tail, output);
}
macro_tokens_uninit (&mts);
- ds_destroy (&content);
+ ds_destroy (&tmp);
}
else if (parse_macro_function (ctx, &args, ss_cstr ("!unquote"), 1, 1,
input_consumed))
if (!unquote_string (args.strings[0], output))
ds_put_cstr (output, args.strings[0]);
}
+ else if (parse_macro_function (ctx, &args, ss_cstr ("!upcase"), 1, 1,
+ input_consumed))
+ {
+ struct string tmp;
+ const char *s = unquote_string_in_place (args.strings[0], &tmp);
+ char *upper = utf8_to_upper (s);
+ ds_put_cstr (output, upper);
+ free (upper);
+ ds_destroy (&tmp);
+ }
+ else if (parse_macro_function (ctx, &args, ss_cstr ("!eval"), 1, 1,
+ input_consumed))
+ {
+ struct macro_tokens mts = { .n = 0 };
+ macro_tokens_from_string (&mts, ss_cstr (args.strings[0]),
+ SEG_MODE_INTERACTIVE /* XXX */);
+ struct macro_tokens exp = { .n = 0 };
+ macro_expand (&mts, ctx->nesting_countdown - 1, ctx->macros,
+ ctx->me, ctx->expand, &exp);
+ macro_tokens_to_representation (&exp, output);
+ macro_tokens_uninit (&exp);
+ macro_tokens_uninit (&mts);
+ }
else if (ctx->n_input > 0
&& ctx->input[0].token.type == T_MACRO_ID
&& ss_equals_case (ctx->input[0].token.string, ss_cstr ("!null")))
const struct macro_expander *me, bool *expand,
struct macro_tokens *exp)
{
- /* Macro expansion:
-
- - Macro names in macro bodies are not expanded by default. !EVAL()
- expands them.
-
- - Macro names in arguments to macro invocations (outside of macro bodies)
- are expanded by default, unless !NOEXPAND. */
if (nesting_countdown <= 0)
{
printf ("maximum nesting level exceeded\n");