[uim-commit] r130 - trunk/uim

yamaken@freedesktop.org yamaken@freedesktop.org
Wed Jan 5 09:44:52 PST 2005


Author: yamaken
Date: 2005-01-05 09:44:47 -0800 (Wed, 05 Jan 2005)
New Revision: 130

Modified:
   trunk/uim/uim-compat-scm.c
   trunk/uim/uim-compat-scm.h
   trunk/uim/uim-custom.c
Log:
* This commit exposes preliminary Scheme->C list representation
  conversion functions. These interfaces are not yet stable and may be
  altered in near future. Be careful to use.

* uim/uim-custom.c
  - (uim_scm_c_list_conv_func, uim_scm_c_list_free_func): Move to
    uim-compat-scm.[hc]
  - (uim_scm_c_list, uim_scm_c_str_failsafe, uim_scm_c_str_list,
    uim_scm_c_list_free): Move to uim-compat-scm.[hc]
* uim/uim-compat-scm.h
  - (uim_scm_c_list_conv_func, uim_scm_c_list_free_func): Moved from
    uim-custom.c
  - (uim_scm_c_list, uim_scm_c_str_failsafe, uim_scm_c_str_list,
    uim_scm_c_list_free): Moved from uim-custom.c
* uim/uim-compat-scm.c
  - (return_val): New variable
  - (uim_init_compat_scm_subrs): Add initialization of return_val
  - (uim_scm_c_list_conv_func, uim_scm_c_list_free_func): Moved from
    uim-custom.c
  - (uim_scm_c_list, uim_scm_c_str_failsafe, uim_scm_c_str_list,
    uim_scm_c_list_free): Moved from uim-custom.c


Modified: trunk/uim/uim-compat-scm.c
===================================================================
--- trunk/uim/uim-compat-scm.c	2005-01-05 16:22:36 UTC (rev 129)
+++ trunk/uim/uim-compat-scm.c	2005-01-05 17:44:47 UTC (rev 130)
@@ -41,6 +41,7 @@
 #include "context.h"
 
 
+static uim_lisp return_val;
 static uim_lisp quote_sym;
 
 
@@ -239,9 +240,76 @@
   init_fsubr(name, (LISP (*)(LISP, LISP))fcn);
 }
 
+/*
+  - list_repl must always returns same list for each evaluation
+  - returns NULL terminated array. NULL will not appeared except terminator
+  - non-string element such as #f is converted to ""
+ */
+void **
+uim_scm_c_list(const char *list_repl, const char *mapper_proc,
+	       uim_scm_c_list_conv_func conv_func)
+{
+  int list_len, i;
+  void **result;
+
+  UIM_EVAL_FSTRING1(NULL, "(length %s)", list_repl);
+  return_val = uim_scm_return_value();
+  list_len = uim_scm_c_int(return_val);
+
+  result = (void **)malloc(sizeof(void *) * (list_len + 1));
+  if (!result)
+    return NULL;
+
+  result[list_len] = NULL;
+  for (i = 0; i < list_len; i++) {
+    UIM_EVAL_FSTRING3(NULL, "(%s (nth %d %s))", mapper_proc, i, list_repl);
+    return_val = uim_scm_return_value();
+    result[i] = (*conv_func)(return_val);
+  }
+
+  return result;
+}
+
+char *
+uim_scm_c_str_failsafe(uim_lisp str)
+{
+  char *c_str;
+  c_str = uim_scm_c_str(str);
+  return (c_str) ? c_str : strdup("");
+}
+
+char **
+uim_scm_c_str_list(const char *list_repl, const char *mapper_proc)
+{
+  void **list;
+  
+  list = uim_scm_c_list(list_repl, mapper_proc,
+			(uim_scm_c_list_conv_func)uim_scm_c_str_failsafe);
+
+  return (char **)list;
+}
+
 void
+uim_scm_c_list_free(void **list, uim_scm_c_list_free_func free_func)
+{
+  void *elem;
+  void **p;
+
+  if (!list)
+    return;
+
+  for (p = list; elem = *p; p++) {
+    free_func(elem);
+  }
+  free(list);
+}
+
+void
 uim_init_compat_scm_subrs(void)
 {
+  return_val = uim_scm_f();
   quote_sym = uim_scm_intern_c_str("quote");
+
+  uim_scm_gc_protect(&return_val);
   uim_scm_gc_protect(&quote_sym);
 }

Modified: trunk/uim/uim-compat-scm.h
===================================================================
--- trunk/uim/uim-compat-scm.h	2005-01-05 16:22:36 UTC (rev 129)
+++ trunk/uim/uim-compat-scm.h	2005-01-05 17:44:47 UTC (rev 130)
@@ -107,7 +107,20 @@
 void
 uim_scm_init_fsubr(char *name, uim_lisp (*fcn)(uim_lisp, uim_lisp));
 
+/*
+  C representation of list: These interfaces are not yet stable and
+  may be altered in near future. Be careful to use.
+    -- YamaKen 2004-01-06
+*/
+typedef void *(*uim_scm_c_list_conv_func)(uim_lisp elem);
+typedef void (*uim_scm_c_list_free_func)(void *elem);
 
+void **uim_scm_c_list(const char *list_repl, const char *mapper_proc,
+		      uim_scm_c_list_conv_func conv_func);
+char *uim_scm_c_str_failsafe(uim_lisp str);
+char **uim_scm_c_str_list(const char *list_repl, const char *mapper_proc);
+void uim_scm_c_list_free(void **list, uim_scm_c_list_free_func free_func);
+
 /* function table for dynamic loading */
 struct uim_api_tbl {
   int       (*uim_init)(void);

Modified: trunk/uim/uim-custom.c
===================================================================
--- trunk/uim/uim-custom.c	2005-01-05 16:22:36 UTC (rev 129)
+++ trunk/uim/uim-custom.c	2005-01-05 17:44:47 UTC (rev 130)
@@ -90,88 +90,9 @@
 static const char custom_subdir[] = "customs";
 static const char custom_msg_tmpl[] = "prop_update_custom\n%s\n%s\n";
 static int helper_fd = -1;
-
-
-#if 1  /* should be reorganized into uim-scm.[hc] */
-typedef void *(*uim_scm_c_list_conv_func)(uim_lisp elem);
-typedef void (*uim_scm_c_list_free_func)(void *elem);
-
-static void **uim_scm_c_list(const char *list_repl, const char *mapper_proc,
-			     uim_scm_c_list_conv_func conv_func);
-static char *uim_scm_c_str_failsafe(uim_lisp str);
-static char **uim_scm_c_str_list(const char *list_repl, const char *mapper_proc);
-static void uim_scm_c_list_free(void **list, uim_scm_c_list_free_func free_func);
-
 static uim_lisp return_val;
 
 
-/*
-  - list_repl must always returns same list for each evaluation
-  - returns NULL terminated array. NULL will not appeared except terminator
-  - non-string element such as #f is converted to ""
- */
-static void **
-uim_scm_c_list(const char *list_repl, const char *mapper_proc,
-	       uim_scm_c_list_conv_func conv_func)
-{
-  int list_len, i;
-  void **result;
-
-  UIM_EVAL_FSTRING1(NULL, "(length %s)", list_repl);
-  return_val = uim_scm_return_value();
-  list_len = uim_scm_c_int(return_val);
-
-  result = (void **)malloc(sizeof(void *) * (list_len + 1));
-  if (!result)
-    return NULL;
-
-  result[list_len] = NULL;
-  for (i = 0; i < list_len; i++) {
-    UIM_EVAL_FSTRING3(NULL, "(%s (nth %d %s))", mapper_proc, i, list_repl);
-    return_val = uim_scm_return_value();
-    result[i] = (*conv_func)(return_val);
-  }
-
-  return result;
-}
-
-static char *
-uim_scm_c_str_failsafe(uim_lisp str)
-{
-  char *c_str;
-  c_str = uim_scm_c_str(str);
-  return (c_str) ? c_str : strdup("");
-}
-
-static char **
-uim_scm_c_str_list(const char *list_repl, const char *mapper_proc)
-{
-  void **list;
-  
-  list = uim_scm_c_list(list_repl, mapper_proc,
-			(uim_scm_c_list_conv_func)uim_scm_c_str_failsafe);
-
-  return (char **)list;
-}
-
-static void
-uim_scm_c_list_free(void **list, uim_scm_c_list_free_func free_func)
-{
-  void *elem;
-  void **p;
-
-  if (!list)
-    return;
-
-  for (p = list; elem = *p; p++) {
-    free_func(elem);
-  }
-  free(list);
-}
-
-#endif  /* should be reorganized into uim-scm.[hc] and others */
-
-
 static int
 uim_custom_type_eq(const char *custom_sym, const char *custom_type)
 {



More information about the Uim-commit mailing list