From 2532ac7cab732526a3a9fcc8428244d2ef2d9c19 Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 6 Sep 2006 08:16:30 +0000 Subject: [PATCH] *** empty log message *** --- gdkdraw.c | 32 ++++--- run-im.c | 283 +++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 211 insertions(+), 104 deletions(-) diff --git a/gdkdraw.c b/gdkdraw.c index e66b710..e1408bc 100644 --- a/gdkdraw.c +++ b/gdkdraw.c @@ -32,7 +32,8 @@ main (int argc, char **argv) gdImagePtr image; int bg_color; unsigned char *title; - int allocated, len; + int title_len; + int allocated; MSymbol utf8; char *family_names = NULL; @@ -58,19 +59,19 @@ main (int argc, char **argv) utf8 = msymbol ("utf-8"); allocated = nchars * 4; /* Usually this is enough. */ title = malloc (allocated); - len = mconv_encode_buffer (utf8, mt, title, allocated); - while (len < 0 && merror_code == MCONVERSION_RESULT_INSUFFICIENT_DST) + title_len = mconv_encode_buffer (utf8, mt, title, allocated); + while (title_len < 0 && merror_code == MCONVERSION_RESULT_INSUFFICIENT_DST) { allocated += allocated; title = realloc (title, allocated); - len = mconv_encode_buffer (utf8, mt, title, allocated); + title_len = mconv_encode_buffer (utf8, mt, title, allocated); } - if (len < 0) + if (title_len < 0) { fprintf (stderr, "Encoding of native language name failed."); exit (1); } - title[len] = '\0'; + title[title_len] = '\0'; { MPlist *param = mplist (); @@ -84,6 +85,7 @@ main (int argc, char **argv) mplist_add (param, Mdevice, msymbol ("gd")); mplist_add (param, Mface, face); frame = mframe (param); + m17n_object_unref (fontset); m17n_object_unref (face); m17n_object_unref (param); @@ -173,18 +175,22 @@ main (int argc, char **argv) guchar *pixels, *p; int x, y; PangoAttrList *attr_list; - PangoAttribute *attr_size, *attr_family; + PangoAttribute *attr_size; gtk_init (&argc, &argv); attr_list = pango_attr_list_new (); attr_size = pango_attr_size_new (FONT_PT_SIZE * PANGO_SCALE); - attr_family = family_names ? pango_attr_family_new (family_names) : NULL; -#if 0 - if (attr_family) - pango_attr_list_change (attr_list, attr_family); -#endif - pango_attr_list_change (attr_list, attr_size); + attr_size->start_index = 0, attr_size->end_index = title_len; + pango_attr_list_insert (attr_list, attr_size); + if (family_names) + { + PangoAttribute *attr_family; + + attr_family = pango_attr_family_new (family_names); + attr_family->start_index = 0, attr_family->end_index = title_len; + pango_attr_list_insert (attr_list, attr_family); + } pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, metric.width, metric.height); diff --git a/run-im.c b/run-im.c index eb03914..230c1bb 100644 --- a/run-im.c +++ b/run-im.c @@ -7,35 +7,17 @@ MPlist *error_invalid_format; MPlist *error_unknown_command; MPlist *error_invalid_arg; +MPlist *error_command_fail; +MPlist *error_lock_fail; -MSymbol Merror; -MSymbol Mset, Mopen, Mclose; -MSymbol Mget_command, Mconfig_command, Mget_variable, Mconfig_variable; +MSymbol Merror, Mvalue; +MSymbol Meval_function; -void -init (void) -{ - Merror = msymbol ("error"); - Mset = msymbol ("set"); - Mopen = msymbol ("open"); - Mclose = msymbol ("close"); - Mget_command = msymbol ("get-command"); - Mconfig_command = msymbol ("config-command"); - Mget_variable = msymbol ("get-variable"); - Mconfig_variable = msymbol ("config-variable"); - - error_invalid_format = mplist (); - mplist_add (error_invalid_format, Msymbol, Merror); - mplist_add (error_invalid_format, Msymbol, msymbol ("invalid-format")); - - error_unknown_command = mplist (); - mplist_add (error_unknown_command, Msymbol, Merror); - mplist_add (error_unknown_command, Msymbol, msymbol ("unknwon-command")); - - error_invalid_arg = mplist (); - mplist_add (error_invalid_arg, Msymbol, Merror); - mplist_add (error_invalid_arg, Msymbol, msymbol ("invalid-argument")); -} +#define ERROR(msg) \ + do { \ + m17n_object_ref (msg); \ + return msg; \ + } while (0) MPlist *eval (MPlist *); @@ -49,22 +31,19 @@ MPlist * eval_set (MPlist *arg) { MSymbol var; - MPlist *plist; if (! SYMBOLP (arg)) - return error_invalid_arg; + ERROR (error_invalid_arg); var = mplist_value (arg); arg = mplist_next (arg); if (TAILP (arg)) - msymbol_put (var, Mplist, NULL); + msymbol_put (var, Mvalue, NULL); else if (PLISTP (arg)) - { - arg = eval (mplist_value (arg)); - msymbol_put (var, Mplist, arg); - } + msymbol_put (var, Mvalue, eval (mplist_value (arg))); else { - msymbol_put (var, Mplist, arg); + m17n_object_ref (arg); + msymbol_put (var, Mvalue, arg); } return NULL; } @@ -72,118 +51,235 @@ eval_set (MPlist *arg) MPlist * eval_open (MPlist *arg) { - MPlist *plist; MSymbol lang, name; MInputMethod *im;; if (! SYMBOLP (arg)) - return error_invalid_arg; + ERROR (error_invalid_arg); lang = mplist_value (arg); - plist = mplist_next (arg); - if (! SYMBOLP (plist)) - return error_invalid_arg; - name = mplist_value (plist); + arg = mplist_next (arg); + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + name = mplist_value (arg); im = minput_open_im (lang, name, Mnil); - plist = mplist (); - mplist_add (plist, Mt, im); - return plist; + arg = mplist (); + mplist_add (arg, Mt, im); + return arg; } MPlist * eval_close (MPlist *arg) { - MPlist *plist; + MPlist *value; if (! SYMBOLP (arg)) - return error_invalid_arg; - plist = mplist_get (vars, mplist_value (arg)); - if (! plist) - return error_invalid_arg; - minput_close_im (mplist_value (plist)); + ERROR (error_invalid_arg); + value = msymbol_get (mplist_value (arg), Mvalue); + if (! value) + ERROR (error_invalid_arg); + minput_close_im (mplist_value (value)); return NULL; } MPlist * eval_get_command (MPlist *arg) { - MPlist *plist; MSymbol lang, name, command; if (! SYMBOLP (arg)) - return error_invalid_arg; + ERROR (error_invalid_arg); lang = mplist_value (arg); - plist = mplist_next (arg); - if (! SYMBOLP (plist)) - return error_invalid_arg; - name = mplist_value (plist); - plist = mplist_next (arg); + arg = mplist_next (arg); + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + name = mplist_value (arg); + arg = mplist_next (arg); if (SYMBOLP (arg)) command = mplist_value (arg); else if (TAILP (arg)) command = Mnil; else - return error_invalid_arg; - return minput_get_command (lang, name, command); + ERROR (error_invalid_arg); + arg = minput_get_command (lang, name, command); + if (arg) + m17n_object_ref (arg); + return arg; } MPlist * eval_config_command (MPlist *arg) { + MSymbol lang, name, command; + MPlist *keyseq; + + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + lang = mplist_value (arg); + arg = mplist_next (arg); + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + name = mplist_value (arg); + arg = mplist_next (arg); + if (SYMBOLP (arg)) + { + command = mplist_value (arg); + arg = mplist_next (arg); + } + else if (TAILP (arg)) + command = Mnil; + else + ERROR (error_invalid_arg); + if (PLISTP (arg)) + keyseq = arg; + else + keyseq = NULL; + if (minput_config_command (lang, name, command, keyseq) < 0) + ERROR (error_command_fail); return NULL; } MPlist * eval_get_variable (MPlist *arg) { - MPlist *plist; MSymbol lang, name, variable; if (! SYMBOLP (arg)) - return error_invalid_arg; + ERROR (error_invalid_arg); lang = mplist_value (arg); - plist = mplist_next (arg); - if (! SYMBOLP (plist)) - return error_invalid_arg; - name = mplist_value (plist); - plist = mplist_next (arg); + arg = mplist_next (arg); + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + name = mplist_value (arg); + arg = mplist_next (arg); if (SYMBOLP (arg)) variable = mplist_value (arg); else if (TAILP (arg)) variable = Mnil; else - return error_invalid_arg; - return minput_get_variable (lang, name, variable); + ERROR (error_invalid_arg); + arg = minput_get_variable (lang, name, variable); + if (arg) + m17n_object_ref (arg); + return arg; } MPlist * eval_config_variable (MPlist *arg) { + MSymbol lang, name, variable; + + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + lang = mplist_value (arg); + arg = mplist_next (arg); + if (! SYMBOLP (arg)) + ERROR (error_invalid_arg); + name = mplist_value (arg); + arg = mplist_next (arg); + if (SYMBOLP (arg)) + { + variable = mplist_value (arg); + arg = mplist_next (arg); + } + else if (TAILP (arg)) + variable = Mnil; + else + ERROR (error_invalid_arg); + if (TAILP (arg)) + arg = NULL; + if (minput_config_variable (lang, name, variable, arg) < 0) + ERROR (error_command_fail); return NULL; } MPlist * +eval_save_config (MPlist *arg) +{ + int ret = minput_save_config (); + + if (ret < 0) + ERROR (error_command_fail); + if (ret == 0) + ERROR (error_lock_fail); + return NULL; +} + +struct EvalFunc { + MPlist *(*eval_func) (MPlist *arg); +} eval_functions[] = + { {eval_set}, {eval_open}, {eval_close}, {eval_get_command}, + {eval_config_command}, {eval_get_variable}, {eval_config_variable}, + {eval_save_config} }; + +MPlist * eval (MPlist *plist) { MSymbol cmd; + struct EvalFunc *eval_func; if (! SYMBOLP (plist)) - return error_invalid_format; + ERROR (error_invalid_format); cmd = mplist_value (plist); - if (cmd == Mset) - return eval_set (mplist_next (plist)); - if (cmd == Mopen) - return eval_open (mplist_next (plist)); - if (cmd == Mclose) - return eval_close (mplist_next (plist)); - if (cmd == Mget_command) - return eval_get_command (mplist_next (plist)); - if (cmd == Mget_variable) - return eval_get_variable (mplist_next (plist)); - if (cmd == Mconfig_command) - return eval_config_command (mplist_next (plist)); - if (cmd == Mconfig_variable) - return eval_config_variable (mplist_next (plist)); - return error_unknown_command; + eval_func = msymbol_get (cmd, Meval_function); + if (! eval_func) + { + if (mplist_key (mplist_next (plist)) == Mnil) + { + MPlist *value = msymbol_get (cmd, Mvalue); + + if (value) + return value; + } + ERROR (error_unknown_command); + } + + return eval_func->eval_func (mplist_next (plist)); +} + +void +init (void) +{ + 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); + + error_invalid_format = mplist (); + mplist_add (error_invalid_format, Msymbol, Merror); + mplist_add (error_invalid_format, Msymbol, msymbol ("invalid-format")); + + error_unknown_command = mplist (); + mplist_add (error_unknown_command, Msymbol, Merror); + mplist_add (error_unknown_command, Msymbol, msymbol ("unknwon-command")); + + error_invalid_arg = mplist (); + mplist_add (error_invalid_arg, Msymbol, Merror); + mplist_add (error_invalid_arg, Msymbol, msymbol ("invalid-argument")); + + error_command_fail = mplist (); + mplist_add (error_command_fail, Msymbol, Merror); + mplist_add (error_command_fail, Msymbol, msymbol ("command-fail")); + + error_lock_fail = mplist (); + mplist_add (error_lock_fail, Msymbol, Merror); + mplist_add (error_lock_fail, Msymbol, msymbol ("lock-fail")); +} + +void +fini (void) +{ + m17n_object_unref (error_invalid_format); + m17n_object_unref (error_unknown_command); + m17n_object_unref (error_invalid_arg); + m17n_object_unref (error_command_fail); } int @@ -194,24 +290,29 @@ main () M17N_INIT (); init (); - while (fgets (line, 256, stdin) != NULL) + while (printf ("> ") && fgets (line, 256, stdin) != NULL) { - MText *mt = mtext_from_data (line, strlen (line), MTEXT_FORMAT_US_ASCII); - MPlist *plist = mplist_deserialize (mt); - MPlist *val = eval (plist); + MText *mt; + MPlist *plist, *val; + + if (line[strlen (line) - 1] == '\n') + line[strlen (line) - 1] = '\0'; + mt = mtext_from_data (line, strlen (line), MTEXT_FORMAT_US_ASCII); + plist = mplist_deserialize (mt); + val = eval (plist); if (val) { mdebug_dump_plist (val, 0); - fputc ('\n', stderr); + putc ('\n', stderr); fflush (stderr); + m17n_object_unref (val); } m17n_object_unref (plist); m17n_object_unref (mt); } + fini (); M17N_FINI (); exit (0); } - - -- 1.7.10.4