Back to index

im-sdk  12.3.91
codepoint_table.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 
00043 #ifdef HAVE_CONFIG_H
00044 #include <config.h>
00045 #endif
00046 
00047 #include <stdio.h>
00048 
00049 #ifdef HAVE_LOCALE_H
00050 #include <locale.h>
00051 #endif
00052 
00053 #include <ctype.h>
00054 
00055 #ifdef HAVE_STRING_H
00056 #include <string.h>
00057 #endif
00058 #ifdef HAVE_STDLIB_H
00059 #include <stdlib.h>
00060 #endif
00061 
00062 #include "encode.h"
00063 #include "codepoint_im.h"
00064 #include "logf.h"
00065 
00066 #define MAX_LINE_LEN  256
00067 
00068 int lineno = 0;
00069 
00070 char *skip_space(char *s)
00071 {
00072   while (*s && (*s==' ' || *s=='\t')) s++;
00073   return s;
00074 }
00075 
00076 int LoadTableHeader (file_name, unit_table)
00077      char *file_name;
00078      TableStruct *unit_table;
00079 {
00080   FILE *ifile;
00081   char line_buf[256], line[MAX_LINE_LEN] = { 0 };
00082   char *key, *value_str;
00083   register char *ptr;
00084   int len, line_index;
00085   int flag_section = DEFAULT_SECTION;
00086 
00087   log_f("codepoint_table: ==== LoadTableHeader ====\n");
00088 
00089   /* read table from file to memory buffer  */
00090   ifile = fopen (file_name, "r");
00091   if (! ifile) {
00092     fprintf(stderr, "Unable to open the input table file \"%s\"\n",file_name);
00093     return(-1);
00094   }
00095 
00096   while(fgets(line_buf, 255, ifile) != NULL) {
00097     lineno++;
00098 
00099     if((line_buf[0] == '#') && (line_buf[1] == '#')){
00100       log_f("COMMENTS \n");
00101       continue;
00102     }
00103 
00104     value_str = line_buf;
00105     ptr = skip_space(value_str);
00106 
00107     if (*ptr == '\0') break;
00108 
00109     /* if is space line, get new line 
00110        if (flag_section != COMMENT_SECTION) {
00111        if (*ptr == '\n')
00112        continue;
00113        }
00114     */
00115 
00116     line_index = 0;
00117     while(*ptr != '\n' && *ptr != '\0' && line_index < MAX_LINE_LEN) 
00118       line[line_index++] = *ptr++;
00119 
00120     /* trim right space */
00121     while (line_index > 0 && isspace(line[line_index-1])) line_index--;
00122     line[line_index] = '\0';
00123 
00124     key = line;
00125     len = strlen(line);
00126     log_f("len:%d, %s\n", strlen(line), line);
00127 
00128     if (line[0] == '[' && line[len-1] == ']') {
00129       /* get section name of the item */
00130       ptr = line + 1;
00131       while(isspace(*ptr)) ptr++;
00132       key = ptr;
00133 
00134       ptr = line + len - 2;
00135       while(isspace(*ptr)) ptr--;
00136       *(ptr+1) = '\0';
00137 
00138       if (!*key) continue;
00139 
00140       if (!(strncasecmp(key, DESCRIPTION_STR, strlen(DESCRIPTION_STR)))) {
00141        flag_section = DESCRIPTION_SECTION;
00142        continue;
00143       } 
00144     }
00145 
00146     switch (flag_section) {
00147     case DEFAULT_SECTION:
00148       break;
00149 
00150     case DESCRIPTION_SECTION:
00151       if(!(strncasecmp(key, LOCALE_STR, strlen(LOCALE_STR)))) {
00152        value_str = skip_space(key+strlen(LOCALE_STR));
00153        if ((*value_str == '\0') || (*value_str == '\n'))
00154          continue;
00155        strcpy(unit_table->Lname, value_str);
00156        break;
00157       }
00158 
00159       if (!(strncasecmp(key, NAME_STR, strlen(NAME_STR)))) {
00160        value_str = skip_space(key+strlen(NAME_STR));
00161        if ((*value_str == '\0') || (*value_str == '\n'))
00162          continue;
00163 
00164        strcpy(unit_table->Cname, value_str);
00165        break;
00166       }
00167 
00168       if (!(strncasecmp(key, INPUT_TYPE_STR, strlen(INPUT_TYPE_STR)))) {
00169        value_str = skip_space(key+strlen(INPUT_TYPE_STR));
00170        if ((*value_str == '\0') || (*value_str == '\n'))
00171          continue;
00172 
00173        strcpy(unit_table->InputType, value_str);
00174        break;
00175       }
00176 
00177       if (!(strncasecmp(key, DEFAULT_INPUT_STR, strlen(DEFAULT_INPUT_STR)))) {
00178        value_str = skip_space(key+strlen(DEFAULT_INPUT_STR));
00179        if ((*value_str == '\0') || (*value_str == '\n'))
00180          continue;
00181 
00182         unit_table->Default_Input = atoi(value_str) & 0xff;
00183        break;
00184       }
00185 
00186       if (!(strncasecmp(key, MAX_INPUT_STR, strlen(MAX_INPUT_STR)))) {
00187        value_str = skip_space(key+strlen(MAX_INPUT_STR));
00188        if ((*value_str == '\0') || (*value_str == '\n'))
00189          continue;
00190 
00191         unit_table->Max_Input = atoi(value_str) & 0xff;
00192        break;
00193       }
00194 
00195       if (!(strncasecmp(key, ENCODE_STR, strlen(ENCODE_STR)))) {
00196        value_str = skip_space(key+strlen(ENCODE_STR));
00197        if ((*value_str == '\0') || (*value_str == '\n'))
00198          continue;
00199 
00200        unit_table->Encode = get_encodeid_from_name(value_str);
00201        unit_table->Output_Encode = unit_table->Encode;
00202        break;
00203       }
00204 
00205       if (!(strncasecmp(key, USEDCODES_STR, strlen(USEDCODES_STR)))) {
00206        value_str = skip_space(key+strlen(USEDCODES_STR));
00207        if ((*value_str == '\0') || (*value_str == '\n'))
00208          continue;
00209 
00210        strncpy(unit_table->UsedCodes, value_str, MAX_USEDCODES_NUM);
00211        break;
00212       }
00213     }
00214   } 
00215   fclose (ifile);
00216   return(0);
00217 }