From: handa Date: Wed, 6 Sep 2006 13:18:59 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbababcbacc9254652b40da6731408af0ba2b112;p=m17n%2Fm17n-test.git *** empty log message *** --- diff --git a/run-im.c b/run-im.c index 230c1bb..63bbf3e 100644 --- a/run-im.c +++ b/run-im.c @@ -27,6 +27,8 @@ MPlist *eval (MPlist *); #define PLISTP(plist) (mplist_key (plist) == Mplist) #define TAILP(plist) (mplist_key (plist) == Mnil) +MPlist *eval_help (MPlist *arg); + MPlist * eval_set (MPlist *arg) { @@ -206,10 +208,29 @@ eval_save_config (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) @@ -239,18 +260,21 @@ 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); @@ -280,6 +304,8 @@ fini (void) m17n_object_unref (error_unknown_command); m17n_object_unref (error_invalid_arg); m17n_object_unref (error_command_fail); + + M17N_FINI (); } int @@ -287,17 +313,20 @@ main () { 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); @@ -313,6 +342,5 @@ main () } fini (); - M17N_FINI (); exit (0); }