Revision: 6812
Author: ek.kato
Date: Thu Nov 11 18:51:32 2010
Log: * src/chewing.c
  - (configure_kbd_type)
  - (configure)
  - (activate_candwin)
  - (deactivate_candwin)
  - (shift_candwin)
  - (pushback_preedit_string)
  - (clear_preedit)
  - (commit_string)
    - Don't use inefficient uim_scm_c_string().
      Use uim_scm_callf() instead.

http://code.google.com/p/uim/source/detail?r=6812

Modified:
 /uim-chewing-trunk/src/chewing.c

=======================================
--- /uim-chewing-trunk/src/chewing.c    Thu Nov 11 04:49:20 2010
+++ /uim-chewing-trunk/src/chewing.c    Thu Nov 11 18:51:32 2010
@@ -136,7 +136,7 @@
 {
   uim_lisp kbd_layout;

-  kbd_layout = uim_scm_eval_c_string("(chewing-get-kbd-layout)");
+  kbd_layout = uim_scm_callf("chewing-get-kbd-layout", "");
   chewing_set_KBType(ucc->cc, uim_scm_c_int(kbd_layout));
 }

@@ -145,26 +145,27 @@
 {
   int i, style;
   int selkey[10];
-  uim_lisp phrase_forward, esc_clean, space_as_selection, sel_style,
-          phrase_choice_rearward, auto_shift_cursor;
+  uim_lisp sel_style;
+  int phrase_forward, esc_clean, space_as_selection,
+      phrase_choice_rearward, auto_shift_cursor;

   chewing_set_candPerPage(ucc->cc, 10);
   chewing_set_maxChiSymbolLen(ucc->cc, 16);

-  phrase_forward = uim_scm_eval_c_string("chewing-phrase-forward?");
-  chewing_set_addPhraseDirection(ucc->cc, !uim_scm_c_bool(phrase_forward));
-
- phrase_choice_rearward = uim_scm_eval_c_string("chewing-phrase-choice-rearward?"); - chewing_set_phraseChoiceRearward(ucc->cc, uim_scm_c_bool(phrase_choice_rearward));
-
-  auto_shift_cursor = uim_scm_eval_c_string("chewing-auto-shift-cursor?");
-  chewing_set_autoShiftCur(ucc->cc, uim_scm_c_bool(auto_shift_cursor));
-
- space_as_selection = uim_scm_eval_c_string("chewing-space-as-selection?"); - chewing_set_spaceAsSelection(ucc->cc, uim_scm_c_bool(space_as_selection));
-
-  esc_clean = uim_scm_eval_c_string("chewing-esc-clean?");
-  chewing_set_escCleanAllBuf(ucc->cc, uim_scm_c_bool(esc_clean));
+  phrase_forward = uim_scm_symbol_value_bool("chewing-phrase-forward?");
+  chewing_set_addPhraseDirection(ucc->cc, !phrase_forward);
+
+ phrase_choice_rearward = uim_scm_symbol_value_bool("chewing-phrase-choice-rearward?");
+  chewing_set_phraseChoiceRearward(ucc->cc, phrase_choice_rearward);
+
+ auto_shift_cursor = uim_scm_symbol_value_bool("chewing-auto-shift-cursor?");
+  chewing_set_autoShiftCur(ucc->cc, auto_shift_cursor);
+
+ space_as_selection = uim_scm_symbol_value_bool("chewing-space-as-selection?");
+  chewing_set_spaceAsSelection(ucc->cc, space_as_selection);
+
+  esc_clean = uim_scm_symbol_value_bool("chewing-esc-clean?");
+  chewing_set_escCleanAllBuf(ucc->cc, esc_clean);

   sel_style =
uim_scm_eval_c_string("(symbol-value chewing-candidate-selection-style)");
@@ -194,84 +195,40 @@
 static void
 activate_candwin(uim_chewing_context *ucc)
 {
-  char *buf;
-  int len;
-
-  len = strlen(ACTIVATE_CMD "(   )") + MAX_LENGTH_OF_INT_AS_STR * 3;
-  buf = malloc(len + 1);
-  snprintf(buf, len + 1, "(" ACTIVATE_CMD " %d %d %d)", ucc->slot_id,
-          chewing_cand_TotalChoice(ucc->cc),
-          chewing_cand_ChoicePerPage(ucc->cc));
-  uim_scm_eval_c_string(buf);
-  free(buf);
+  uim_scm_callf(ACTIVATE_CMD, "iii",
+               ucc->slot_id,
+               chewing_cand_TotalChoice(ucc->cc),
+               chewing_cand_ChoicePerPage(ucc->cc));
 }

 static void
 deactivate_candwin(uim_chewing_context *ucc)
 {
-  char *buf;
-  int len;
-
-  len = strlen(DEACTIVATE_CMD "( )") + MAX_LENGTH_OF_INT_AS_STR;
-  buf = malloc(len + 1);
-  snprintf(buf, len + 1, "(" DEACTIVATE_CMD " %d)", ucc->slot_id);
-  uim_scm_eval_c_string(buf);
-  free(buf);
+  uim_scm_callf(DEACTIVATE_CMD, "i", ucc->slot_id);
 }

 static void
 shift_candwin(uim_chewing_context *ucc, int dir)
 {
-  char *buf;
-  int len;
-
-  len = strlen(SHIFT_CMD "(  )") + MAX_LENGTH_OF_INT_AS_STR + 3;
-  buf = malloc(len + 1);
-  snprintf(buf, len + 1, "(" SHIFT_CMD " %d %s)", ucc->slot_id,
-          dir ? "#t" : "#f");
-  uim_scm_eval_c_string(buf);
-  free(buf);
+  uim_scm_callf(SHIFT_CMD, "ib", ucc->slot_id, dir ? 1 : 0);
 }

 static void
pushback_preedit_string(uim_chewing_context *ucc, const char *str, int attr)
 {
-  char *buf;
-  int len;
-
-  len = strlen(PUSHBACK_CMD "   \"\")") + strlen(str) +
-              MAX_LENGTH_OF_INT_AS_STR + PREEDIT_ATTR_MAX_LEN;
-  buf = malloc(len + 1);
-  snprintf(buf, len + 1, "(" PUSHBACK_CMD " %d %d \"%s\")", ucc->slot_id,
-          attr, str);
-  uim_scm_eval_c_string(buf);
-  free(buf);
+  uim_scm_callf(PUSHBACK_CMD, "iis", ucc->slot_id, attr, str);
 }

 static void
 clear_preedit(uim_chewing_context *ucc)
 {
-  char *buf;
-  int len;
-
-  len = strlen(CLEAR_CMD "( )") + MAX_LENGTH_OF_INT_AS_STR;
-  buf = malloc(len + 1);
-  snprintf(buf, len + 1, "(" CLEAR_CMD " %d)", ucc->slot_id);
-  uim_scm_eval_c_string(buf);
-  free(buf);
+  uim_scm_callf(CLEAR_CMD, "i", ucc->slot_id);
 }

 static void
 commit_string(uim_chewing_context *ucc, const char *str)
 {
-  char *buf;
-  int len;
-
- len = strlen(COMMIT_CMD "( \"\")") + strlen(str) + MAX_LENGTH_OF_INT_AS_STR;
-  buf = malloc(len + 1);
-  snprintf(buf, len + 1, "(" COMMIT_CMD " %d \"%s\")", ucc->slot_id, str);
-  uim_scm_eval_c_string(buf);
-  free(buf);
+  uim_scm_callf(COMMIT_CMD, "is", ucc->slot_id, str);
 }


Reply via email to