Back to index

im-sdk  12.3.91
configapi.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003 Sun Microsystems Inc.
00003  *
00004  * This is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  *
00019  * Authors: Karl Park <karl.park@sun.com>
00020  */
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <assert.h>
00025 #include <le-options.h>
00026 #include "configapi.h"
00027 #include "kolelog.h"
00028 
00029 static KOLE_config *leoption_make_deletion_option (const char *sdel);
00030 static KOLE_config *leoption_make_charset_option (const char *cset);
00031 static KOLE_config *leoption_make_keyboard_option (const char *kbd);
00032 static KOLE_config *leoption_make_commit_option (const char *scommitby);
00033 KOLE_config *
00034 leoption_make_option (KOLE_option_type type)
00035 {
00036   KOLE_config *leconf;
00037   leconf = (KOLE_config *) malloc (sizeof (KOLE_config));
00038   if (!leconf)
00039     return NULL;
00040 
00041   leconf->type = type;
00042 
00043   return leconf;
00044 }
00045 
00046 KOLE_config *
00047 leoption_make_option_with_string_value (const char *sopt,
00048                                    const char *vstr)
00049 
00050 {
00051   KOLE_config *pconf;
00052   assert (vstr != NULL);
00053 #if 0
00054   fprintf (stderr,"option : %s, value :%s\n", sopt, vstr);
00055 #endif
00056   
00057   if (!vstr){
00058     KOLE_LOG (LOGDEST_STDERR,
00059             "leoption_make_option_with_value: vstr is NULL");
00060     return NULL;
00061   }
00062 
00063   if (!strcmp (sopt, STR_OPTION_CHARSET)){
00064     
00065     pconf =
00066       leoption_make_option_with_value (KOLE_OPTION_TYPE_CHARSET, vstr);
00067     
00068   } else if (!strcmp (sopt, STR_OPTION_DELETION)){
00069     
00070     pconf =
00071       leoption_make_option_with_value (KOLE_OPTION_TYPE_DELETION, vstr);
00072     
00073   } else if (!strcmp (sopt, STR_OPTION_KEYBOARD)){
00074     pconf =
00075       leoption_make_option_with_value (KOLE_OPTION_TYPE_KEYBOARD, vstr);
00076     
00077   } else if (!strcmp (sopt, STR_OPTION_COMMITMODE)){
00078     
00079     pconf =
00080       leoption_make_option_with_value (KOLE_OPTION_TYPE_COUNT, vstr);
00081     
00082   } else {
00083     pconf = NULL;
00084   }
00085   if (!pconf){
00086     KOLE_LOG (LOGDEST_STDERR,
00087             "leoption_make_option_with_string_value error");
00088     return NULL;
00089   }
00090   return pconf;
00091 }
00092 
00093 KOLE_config *
00094 leoption_make_option_with_value (KOLE_option_type type,
00095                              const char *vstr)
00096 
00097 {
00098   KOLE_config *pconf;
00099   assert (vstr != NULL);
00100   
00101   if (!vstr){
00102     KOLE_LOG (LOGDEST_STDERR,
00103             "leoption_make_option_with_value: vstr is NULL");
00104     return NULL;
00105   }
00106   
00107   switch (type){
00108   case KOLE_OPTION_TYPE_KEYBOARD:
00109     pconf = leoption_make_keyboard_option (vstr);
00110     if (!pconf){
00111       KOLE_LOG (LOGDEST_STDERR,
00112               "leoption_make_option_with_value error");
00113       return NULL;
00114     } else
00115       return pconf;
00116     break;
00117     
00118   case  KOLE_OPTION_TYPE_CHARSET:
00119     pconf = leoption_make_charset_option (vstr);
00120     if (!pconf){
00121       KOLE_LOG (LOGDEST_STDERR,
00122               "leoption_make_option_with_value error\n");
00123       return NULL;
00124     } else
00125       return pconf;
00126     break;
00127     
00128   case KOLE_OPTION_TYPE_DELETION:
00129     pconf = leoption_make_deletion_option (vstr);
00130     if (!pconf){
00131       fprintf (stderr,
00132               "leoption_make_deletion_option error\n");
00133       return NULL;
00134     } else
00135       return pconf;
00136     break;
00137   case KOLE_OPTION_TYPE_CHARBASED_COMMIT:
00138     pconf = leoption_make_commit_option (vstr);
00139     if (!pconf){
00140       fprintf (stderr,
00141               "leoption_make_deletion_option error\n");
00142       return NULL;
00143     } else
00144       return pconf;
00145     
00146   default:
00147     fprintf (stderr,
00148             "leoption_make_option_with_value error\n");
00149     return NULL;
00150     break;
00151   }
00152 
00153 }
00154 
00155 KOLE_config *
00156 leoption_copy (KOLE_config *option)
00157 {
00158   KOLE_config *opt;
00159   
00160   assert (option != NULL);
00161   if (!option){
00162     fprintf (stderr, "leoption_copy failed: parameter is NULL\n");
00163     return NULL;
00164   }
00165   
00166   opt = (KOLE_config *) malloc (sizeof (KOLE_config));
00167   
00168   if (!opt){
00169     fprintf (stderr, "leoption_copy failed: memory alloc error\n");
00170     return NULL;
00171   }
00172 
00173   memcpy (opt, option, sizeof (KOLE_config));
00174   return opt;
00175 }
00176 
00177 void
00178 leoption_delete (KOLE_config *option)
00179 {
00180   if (!option)
00181     return;
00182   if (option->vstr)
00183     free (option->vstr);
00184 
00185   free (option);
00186 }
00187 
00188 static KOLE_config *
00189 leoption_make_charset_option (const char *cset)
00190 {
00191   KOLE_config *pconf;
00192   assert (cset != NULL);
00193 
00194   if (!cset)
00195     return NULL;
00196   
00197   pconf = leoption_make_option (KOLE_OPTION_TYPE_CHARSET);
00198   
00199   pconf->vstr = (char *) strdup (cset);
00200   
00201   if (!strcmp (cset, STR_CHARSET_EUC))
00202     {
00203       pconf->v.cset = IN_EUC;
00204     }
00205   else if (!strcmp (cset, STR_CHARSET_UNICODE))
00206     {
00207       pconf->v.cset = IN_UNICODE;
00208     }
00209   else
00210     {
00211       pconf->v.cset = IN_UNICODE;
00212     }
00213   return pconf;
00214 }
00215 
00216 static KOLE_config *
00217 leoption_make_keyboard_option (const char *kbd)
00218 {
00219   KOLE_config *pconf;
00220   assert (kbd != NULL);
00221 
00222   if (!kbd)
00223     return NULL;
00224   
00225   pconf = leoption_make_option (KOLE_OPTION_TYPE_KEYBOARD);
00226   pconf->vstr = (char *) strdup (kbd);
00227   
00228   if (!strcmp (kbd, STR_KEYBOARD_LAYOUT_2PAIR))
00229     {
00230       pconf->v.kbd = LAYOUT_2PART;
00231     }
00232   else if (!strcmp (kbd, STR_KEYBOARD_LAYOUT_3PAIRFINAL))
00233     {
00234       pconf->v.kbd = LAYOUT_3PART_FINAL;
00235     }
00236   else if (!strcmp (kbd, STR_KEYBOARD_LAYOUT_3PAIR390))
00237     {
00238       pconf->v.kbd = LAYOUT_3PART390;
00239     }
00240   else
00241     {
00242       pconf->v.kbd = LAYOUT_2PART;
00243     }
00244   return pconf;
00245   
00246 }
00247 
00248 static KOLE_config *
00249 leoption_make_deletion_option (const char *sdel)
00250 {
00251   KOLE_config *pconf;
00252   
00253   assert (sdel != NULL);
00254   if (!sdel)
00255     return NULL;
00256   
00257   pconf = leoption_make_option (KOLE_OPTION_TYPE_DELETION);
00258   pconf->vstr = (char *) strdup (sdel);
00259   
00260   if (!strcmp (sdel, STR_DELETION_BY_JASO_NO))
00261     {
00262       pconf->v.del = BY_JASO;
00263     }
00264   else if (!strcmp (sdel, STR_DELETION_BY_JASO_YES))
00265     {
00266       pconf->v.del = BY_CHAR;
00267     }
00268   else
00269     {
00270       pconf->v.del = BY_CHAR;
00271     }
00272   return pconf;
00273 }
00274 
00275 static KOLE_config *
00276 leoption_make_commit_option (const char *scommitby)
00277 {
00278   KOLE_config *pconf;
00279   
00280   assert (scommitby != NULL);
00281   if (!scommitby)
00282     return NULL;
00283   pconf = leoption_make_option (KOLE_OPTION_TYPE_CHARBASED_COMMIT);
00284   
00285   pconf->vstr = (char *) strdup (scommitby);
00286   
00287   if (!strcmp (scommitby, STR_COMMITMODE_BY_CHAR))
00288     {
00289       pconf->v.commit_by = COMMIT_BY_CHAR;
00290     }
00291   else if (!strcmp (scommitby, STR_COMMITMODE_BY_HOTKEY))
00292     {
00293       pconf->v.commit_by = COMMIT_BY_HOTKEY;
00294     }
00295   else
00296     {
00297       pconf->v.commit_by = COMMIT_BY_HOTKEY;
00298     }
00299   return pconf;
00300 }
00301 
00302 void
00303 leoption_debug_print (KOLE_config *p)
00304 {
00305   switch (p->type)
00306     {
00307     case KOLE_OPTION_TYPE_KEYBOARD:
00308       KOLE_LOG (LOGDEST_STDOUT,
00309               "%s : %d(%s)",
00310               STR_OPTION_KEYBOARD,
00311               p->v.kbd,
00312               p->v.kbd == LAYOUT_2PART ?  STR_KEYBOARD_LAYOUT_2PAIR :
00313               (p->v.kbd == LAYOUT_3PART390 ? STR_KEYBOARD_LAYOUT_3PAIR390 :
00314                STR_KEYBOARD_LAYOUT_3PAIRFINAL));
00315       break;
00316       
00317     case KOLE_OPTION_TYPE_CHARSET:
00318       KOLE_LOG (LOGDEST_STDOUT,
00319               "%s : %d(%s)",
00320               STR_OPTION_CHARSET,
00321               p->v.cset,
00322               p->v.cset == IN_EUC ?  STR_CHARSET_EUC :  STR_CHARSET_UNICODE);
00323       break;
00324     case KOLE_OPTION_TYPE_DELETION:
00325       KOLE_LOG (LOGDEST_STDOUT,
00326               "%s : %d(%s)",
00327               STR_OPTION_DELETION,
00328               p->v.del,
00329               p->v.del == BY_CHAR ?
00330               STR_DELETION_BY_JASO_YES :  STR_DELETION_BY_JASO_NO
00331               );
00332       break;
00333     case KOLE_OPTION_TYPE_CHARBASED_COMMIT:
00334       KOLE_LOG (LOGDEST_STDOUT,
00335               "%s : %d(%s)",
00336               STR_OPTION_COMMITMODE,
00337               p->v.commit_by,
00338               p->v.commit_by == COMMIT_BY_CHAR ?
00339               STR_COMMITMODE_BY_CHAR :  STR_COMMITMODE_BY_HOTKEY
00340               );      
00341       break;
00342     default:
00343       break;
00344     }
00345 }