Back to index

im-sdk  12.3.91
codepoint_im.c
Go to the documentation of this file.
00001 /*
00002   Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004   Permission is hereby granted, free of charge, to any person obtaining a
00005   copy of this software and associated documentation files (the
00006   "Software"), to deal in the Software without restriction, including
00007   without limitation the rights to use, copy, modify, merge, publish,
00008   distribute, sublicense, and/or sell copies of the Software, and to
00009   permit persons to whom the Software is furnished to do so, subject to
00010   the following conditions: The above copyright notice and this
00011   permission notice shall be included in all copies or substantial
00012   portions of the Software.
00013 
00014 
00015   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018   IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020   CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021   THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022   ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025   Except as contained in this notice, the names of The Open Group and/or
00026   Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027   promote the sale, use or other dealings in this Software without prior
00028   written authorization from The Open Group and/or Sun Microsystems,
00029   Inc., as applicable.
00030 
00031 
00032   X Window System is a trademark of The Open Group
00033 
00034   OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035   logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036   Group. All other trademarks and registered trademarks mentioned herein
00037   are the property of their respective owners. No right, title or
00038   interest in or to any trademark, service mark, logo or trade name of
00039   Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include <stdio.h>
00043 #include <sys/types.h>
00044 #include <dlfcn.h>
00045 #include <strings.h>
00046 #include <stdlib.h>
00047 #include <string.h>
00048 
00049 #include "unit_input.h"
00050 #include "codepoint_im.h"
00051 #include "codepoint_filter.h"
00052 #include "codepoint_table.h"
00053 #include "logf.h"
00054 
00055 int  codepoint_SetOptions(IMECore, char *);
00056 int  codepoint_SetValues(IMECore, IMEArgList, int);
00057 int  codepoint_Init(IMECore);
00058 int  codepoint_Open(IMECore, IMEBuffer, void *handler);
00059 int  codepoint_Filter(IMECore, IMEKey, IMEArgList, IMEBuffer);
00060 void codepoint_Close(IMECore);
00061 
00062 #ifdef WIN32
00063 #define EXPORT extern __declspec(dllexport)
00064 EXPORT
00065 #endif
00066 
00067 /* IF Method */
00068 IMEMethodsRec ime_methods = {
00069   codepoint_SetOptions,
00070   codepoint_SetValues,
00071   codepoint_Init,
00072   codepoint_Open,
00073   codepoint_Filter,
00074   codepoint_Close
00075 };
00076 
00077 /* Set options for codetable input method. */
00078 int codepoint_SetOptions(IMECore core, char *options) {
00079   char data_path[256];
00080 
00081   /* Change path : /usr/lib/im/locale/UNIT/<options>/codepoint.cfg */
00082   sprintf(data_path, "%s/%s/%s/%s", DEFAULT_ENGINE_PATH, core->envinfo.lang_name, options, CODEPOINT_CONFIG_NAME);
00083 
00084   core->envinfo.data_path = (char *)strdup(data_path);
00085   log_f("codepoint_im: data_path :%s\n", core->envinfo.data_path);
00086 
00087   return (0);
00088 }
00089 
00090 int codepoint_SetValues(IMECore core, IMEArgList arglist, int option_value) {
00091   log_f("codepoint_im: codepoint_SetValues === \n");
00092   
00093   if (arglist == NULL) return(-1);
00094 
00095   arglist->args_num = 0;
00096   return(0);
00097 }
00098 
00099 /* return the name and encode status and status of codetable IME */
00100 
00101 int codepoint_Init(IMECore core) {
00102   int  ret;
00103   char *file_name;
00104   TableStruct tHeader;
00105 
00106   log_f("codepoint_im: codepoint_Init ====\n");
00107 
00108   /* read table from file to memory buffer  */
00109   file_name = core->envinfo.data_path;
00110   log_f("codepoint_im: file name :%s\n",file_name);
00111   
00112   ret = LoadTableHeader(file_name, &tHeader); 
00113   if (ret == -1) 
00114     return (-1);
00115 
00116   /* Return Information that needed by Input Method Manager */
00117   /* Such as Encode, Cname, Status, InputType */
00118   
00119   core->baseinfo.status = ENGINE_NOT_INITIATED;
00120   log_f("Lname:%s\n",tHeader.Lname);
00121   core->baseinfo.lname = (char *)strdup(tHeader.Lname);
00122   log_f("Cname:%s\n",tHeader.Cname);
00123   core->baseinfo.cname = (char *)strdup(tHeader.Cname);
00124   log_f("encode_id:%d\n",tHeader.Encode);
00125   core->baseinfo.encode_id = tHeader.Encode;
00126   log_f("Engine_id:%d\n",core->baseinfo.engine_id);
00127 
00128   log_f("UsedCodes:%s\n",tHeader.UsedCodes);
00129   log_f("InputType:%s\n",tHeader.InputType);
00130   log_f("Default Input Len:%d\n",tHeader.Default_Input);
00131   log_f("Max Input Len:%d\n",tHeader.Max_Input);
00132 
00133   return(0);
00134 }
00135 
00136 int codepoint_Open(IMECore core, IMEBuffer ime_buffer, void *handler) {
00137   char *file_name;
00138   int ret;
00139   TableStruct *tHeader;
00140 
00141   log_f("codepoint_im: codepoint_Open ==== \n");
00142 
00143   ime_buffer->encode = 0;
00144   ime_buffer->return_status = 0;
00145   /*
00146     ime_buffer->preedit_len = 0;
00147     ime_buffer->inputkey_len = 0;
00148   */
00149   ime_buffer->commit_len  = 0;
00150   ime_buffer->lookup_num  = 0;
00151   ime_buffer->cur_lookup_pos = 0;
00152 
00153 
00154   if (core->baseinfo.status == ENGINE_NOT_INSTALLED){
00155     log_f("codepoint_Open: ENGINE_NOT_INSTALLED \n");
00156     return(-1);
00157   }
00158 
00159   if (core->baseinfo.status == ENGINE_INITIATED) {
00160     return 0;
00161   }
00162 
00163   core->baseinfo.status = ENGINE_NOT_INSTALLED;
00164                                                                                 
00165   /* read table from file to memory buffer  */
00166   file_name = core->envinfo.data_path;
00167   log_f("file name :%s\n",file_name);
00168                                                                                 
00169   tHeader = (TableStruct *)calloc(1, sizeof(TableStruct));
00170   if (tHeader == NULL) {
00171     fprintf(stderr, "no memory for CodeTable Input method: %s\n",core->baseinfo.ename);
00172     return(-1);
00173   }
00174                                                                                 
00175   ret = LoadTableHeader(file_name, tHeader);
00176   if (ret == -1) {
00177     free((char *)tHeader);
00178     return(-1);
00179   }
00180 
00181   core->baseinfo.status = ENGINE_INITIATED;
00182   core->envinfo.data_ptr = (char *)tHeader;
00183 
00184   return(0);
00185 }
00186 
00187 /* close IME, and free codetable pointers */
00188 void codepoint_Close(IMECore core) {
00189   log_f("codepoint_im: codepoint_Close ==== \n");
00190 
00191   if (core->baseinfo.lname)
00192     free((char *)core->baseinfo.lname);
00193   if (core->baseinfo.cname)
00194     free((char *)core->baseinfo.cname);
00195   if (core->envinfo.data_path)
00196     free((char *)core->envinfo.data_path);
00197 }
00198 
00199 /* process key input event                                             */
00200 /* return value:  IME_NOT_USED_KEY:  if IME not use this key, return   */
00201 /*                                   this key to systerm directly      */
00202 /*                IME_USED_KEY:      if IME has used this key          */
00203 
00204 int  codepoint_Filter(core, key_event, ime_args, ime_buffer)
00205      IMECore core;
00206      IMEKey  key_event;
00207      IMEArgList ime_args;
00208      IMEBuffer ime_buffer;
00209 {
00210   int ret;
00211   TableStruct *tHeader;
00212 
00213   log_f("codepoint_im: codepoint_Filter ==== \n");
00214 
00215   if (core->baseinfo.status != ENGINE_INITIATED){
00216     log_f("codepoint_Filter: ENGINE_NOT_INITIATED \n");
00217     return(IME_NOT_USED_KEY);
00218   }
00219 
00220   /* tHeader's argument setting are always coveried by user defined data */
00221   tHeader = (TableStruct *)(core->envinfo.data_ptr);
00222   tHeader->Output_Encode = core->envinfo.output_encode_id;
00223 
00224   ret = codepoint_filter(tHeader, key_event, ime_buffer);
00225   log_f("codepoint_im: codepoint_filter : return: %d\n", ret);
00226   return(ret);
00227 }
00228