#define PLISTP(plist) (mplist_key (plist) == Mplist)
#define TAILP(plist) (mplist_key (plist) == Mnil)
+MPlist *eval_help (MPlist *arg);
+
MPlist *
eval_set (MPlist *arg)
{
struct EvalFunc {
MPlist *(*eval_func) (MPlist *arg);
+ char *form;
} eval_functions[] =
- { {eval_set}, {eval_open}, {eval_close}, {eval_get_command},
- {eval_config_command}, {eval_get_variable}, {eval_config_variable},
- {eval_save_config} };
+ { {eval_help, "help"},
+ {eval_set, "set SYMBOL FORM"},
+ {eval_open, "open LANG NAME"},
+ {eval_close, "close SYMBOL"},
+ {eval_get_command, "get-command LANG NAME [COMMAND]"},
+ {eval_config_command, "config-command LANG NAME [COMMAND [(KEY ...) ...]]"},
+ {eval_get_variable, "get-variable LANG NAME [VARIABLE]"},
+ {eval_config_variable, "config-variable LANG NAME [VARIABLE [VALUE]]"},
+ {eval_save_config, "save-config"} };
+
+MPlist *
+eval_help (MPlist *arg)
+{
+ int i;
+
+ printf ("Valid FORMs are:\n");
+ for (i = 0; i < (sizeof eval_functions) / (sizeof eval_functions[0]); i++)
+ printf (" %s\n", eval_functions[i].form);
+ printf (" SYMBOL -- print the value of SYMBOL\n");
+ return NULL;
+}
MPlist *
eval (MPlist *plist)
void
init (void)
{
+ M17N_INIT ();
+
Merror = msymbol ("error");
Mvalue = msymbol ("value");
Meval_function = msymbol ("eval-function");
- msymbol_put (msymbol ("set"), Meval_function, eval_functions + 0);
- msymbol_put (msymbol ("open"), Meval_function, eval_functions + 1);
- msymbol_put (msymbol ("close"), Meval_function, eval_functions + 2);
- msymbol_put (msymbol ("get-command"), Meval_function, eval_functions + 3);
- msymbol_put (msymbol ("config-command"), Meval_function, eval_functions + 4);
- msymbol_put (msymbol ("get-variable"), Meval_function, eval_functions + 5);
- msymbol_put (msymbol ("config-variable"), Meval_function, eval_functions + 6);
- msymbol_put (msymbol ("save-config"), Meval_function, eval_functions + 7);
+ msymbol_put (msymbol ("help"), Meval_function, eval_functions + 0);
+ msymbol_put (msymbol ("set"), Meval_function, eval_functions + 1);
+ msymbol_put (msymbol ("open"), Meval_function, eval_functions + 2);
+ msymbol_put (msymbol ("close"), Meval_function, eval_functions + 3);
+ msymbol_put (msymbol ("get-command"), Meval_function, eval_functions + 4);
+ msymbol_put (msymbol ("config-command"), Meval_function, eval_functions + 5);
+ msymbol_put (msymbol ("get-variable"), Meval_function, eval_functions + 6);
+ msymbol_put (msymbol ("config-variable"), Meval_function, eval_functions + 7);
+ msymbol_put (msymbol ("save-config"), Meval_function, eval_functions + 8);
error_invalid_format = mplist ();
mplist_add (error_invalid_format, Msymbol, Merror);
m17n_object_unref (error_unknown_command);
m17n_object_unref (error_invalid_arg);
m17n_object_unref (error_command_fail);
+
+ M17N_FINI ();
}
int
{
char line[256];
- M17N_INIT ();
init ();
while (printf ("> ") && fgets (line, 256, stdin) != NULL)
{
MText *mt;
MPlist *plist, *val;
+ int len = strlen (line);
+
+ if (line[len - 1] == '\n')
+ line[--len] = '\0';
+ if (len == 0)
+ continue;
- if (line[strlen (line) - 1] == '\n')
- line[strlen (line) - 1] = '\0';
- mt = mtext_from_data (line, strlen (line), MTEXT_FORMAT_US_ASCII);
+ mt = mtext_from_data (line, len, MTEXT_FORMAT_US_ASCII);
plist = mplist_deserialize (mt);
val = eval (plist);
}
fini ();
- M17N_FINI ();
exit (0);
}