[uim-commit] r918 - in trunk: scm uim

tkng at freedesktop.org tkng at freedesktop.org
Sat Jul 2 18:16:23 PDT 2005


Author: tkng
Date: 2005-07-02 18:16:20 -0700 (Sat, 02 Jul 2005)
New Revision: 918

Added:
   trunk/scm/uim-module-manager.scm
   trunk/uim/uim-module-manager.c
Modified:
   trunk/scm/Makefile.am
   trunk/uim/Makefile.am
Log:
* uim/uim-module-manager.c: New file.
* scm/uim-module-manager.scm: New file.

  New progaram uim-module-manager consists of these files. This is a
  program to register/unregister modules.


Modified: trunk/scm/Makefile.am
===================================================================
--- trunk/scm/Makefile.am	2005-07-02 17:24:34 UTC (rev 917)
+++ trunk/scm/Makefile.am	2005-07-03 01:16:20 UTC (rev 918)
@@ -27,7 +27,8 @@
  m17nlib.scm \
  spellcheck.scm spellcheck-custom.scm \
  zaurus.scm \
- scim.scm
+ scim.scm \
+ uim-module-manager.scm
 
 if COMPAT_TABLE
 SCM_FILES += hk.scm

Added: trunk/scm/uim-module-manager.scm
===================================================================
(Binary files differ)


Property changes on: trunk/scm/uim-module-manager.scm
___________________________________________________________________
Name: svn:mime-type
   + Lisp/Scheme program text

Modified: trunk/uim/Makefile.am
===================================================================
--- trunk/uim/Makefile.am	2005-07-02 17:24:34 UTC (rev 917)
+++ trunk/uim/Makefile.am	2005-07-03 01:16:20 UTC (rev 918)
@@ -105,7 +105,7 @@
 libuim_custom_enabler_la_CPPFLAGS = -I$(top_srcdir)
 
 
-bin_PROGRAMS = uim-helper-server uim-sh
+bin_PROGRAMS = uim-helper-server uim-sh uim-module-manager
 
 uim_helper_server_LIBS =  
 uim_helper_server_CPPFLAGS = $(uim_defs) -I$(top_srcdir)
@@ -118,6 +118,12 @@
 uim_sh_LDADD = libuim.la
 uim_sh_SOURCES = uim-sh.c
 
+uim_module_manager_LIBS =
+uim_module_manager_CPPFLAGS = $(uim_defs) -I$(top_srcdir) -DUIM_DATADIR=\""$(datadir)/uim"\"
+uim_module_manager_CFLAGS =
+uim_module_manager_LDADD = libuim.la
+uim_module_manager_SOURCES = uim-module-manager.c
+
 noinst_PROGRAMS = uim-agent
 
 uim_agent_SOURCES = agent.c

Added: trunk/uim/uim-module-manager.c
===================================================================
--- trunk/uim/uim-module-manager.c	2005-07-02 17:24:34 UTC (rev 917)
+++ trunk/uim/uim-module-manager.c	2005-07-03 01:16:20 UTC (rev 918)
@@ -0,0 +1,158 @@
+/*
+  uim-module-manager.c: source file for uim-module-manager.
+
+  Copyright (c) 2005 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "config.h"
+
+#include "uim.h"
+#include "uim-scm.h"
+#include "uim-compat-scm.h"
+
+#define MODULE_LIST_FILENAME UIM_DATADIR"/modules"
+
+static void
+print_usage(void)
+{
+  printf("FIXME: write usage\n");
+}
+
+static uim_lisp
+read_module_list(void)
+{
+  FILE *fp = fopen(MODULE_LIST_FILENAME, "r");
+  char buf[1024];
+  uim_lisp module_list = uim_scm_null_list();
+  
+  if(!fp) {
+    perror("Failed to read module list");
+    return uim_scm_f();
+  }
+  while (fgets (buf, sizeof(buf), fp) != NULL) {
+    if(buf[0] == '#' || buf[0] == '\n') {
+      continue; /* comment line or blank line */
+    }
+    else if(buf[strlen(buf)-1] == '\n') {
+      buf[strlen(buf)-1] = '\0'; /* Clear \n. */
+    }
+    module_list = uim_scm_cons(uim_scm_intern_c_str(buf), module_list);
+  }
+  fclose(fp);
+  return module_list;
+}
+
+static uim_lisp
+write_module_list(uim_lisp new_module, uim_lisp module_list)
+{
+  FILE *fp = fopen(MODULE_LIST_FILENAME, "w");
+
+  if(!fp) {
+    perror("Failed to write module list");
+    return uim_scm_f();
+  }
+
+  fputs("# This is an automatically generated file. DO NOT EDIT.\n\n", fp);
+
+  if(uim_scm_stringp(new_module) == UIM_TRUE) {
+    fputs(uim_scm_refer_c_str(new_module), fp);
+    fputs("\n",fp);
+  }
+
+  if(uim_scm_consp(module_list) == UIM_TRUE) {
+    
+    while(1) {
+      uim_lisp module_name = uim_scm_car(module_list);
+      fputs(uim_scm_refer_c_str(module_name), fp);
+      fputs("\n",fp);
+      module_list = uim_scm_cdr(module_list);
+      if(module_list == uim_scm_null_list()) {
+	break;
+      }
+    }
+
+  }
+  
+  fclose(fp);
+  return uim_scm_t();
+}
+
+int
+main(int argc, char *argv[]) {
+  int registerp;
+  uim_lisp form;
+
+  if(argc <= 2) {
+    print_usage();
+    exit(EXIT_FAILURE); /* FIXME: investigave correct return value. */
+  }
+
+  if(strcmp(argv[1], "--register") == 0) {
+    registerp = 1;
+  } else if(strcmp(argv[1], "--unregister") == 0) {
+    registerp = 2;
+  } else {
+    print_usage();
+    exit(1); /* FIXME: investigave correct return value. */
+  }
+
+  if(!argv[2]) {
+    print_usage();
+    exit(1); /* FIXME: investigave correct return value. */
+  }
+
+  uim_init();
+
+  uim_scm_set_verbose_level(1);
+
+  uim_scm_init_subr_0("read-module-list", read_module_list);
+  uim_scm_init_subr_2("write-module-list", write_module_list);
+  uim_scm_require_file("uim-module-manager.scm");
+
+  if(registerp == 1) {
+    form = uim_scm_list2(uim_scm_intern_c_str("register-module"),
+			 uim_scm_qintern_c_str(argv[2]));
+  }
+  if(registerp == 2) {
+    form = uim_scm_list2(uim_scm_intern_c_str("unregister-module"),
+			 uim_scm_qintern_c_str(argv[2]));
+  }
+
+  uim_scm_eval(form);
+
+  uim_quit();
+
+  return 0;
+}



More information about the uim-commit mailing list