Back to index

im-sdk  12.3.91
zhuyin_standard.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-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 #include <stdio.h>
00044 #include "zhuyin_standard.h"
00045 
00046 static char *ZhuyinSymbol[NUM_OF_ZHUYIN_SYMBOL + 1] = {
00047   NULL, 
00048   "ㄅ", "ㄆ", "ㄇ", "ㄈ", "ㄉ", "ㄊ", "ㄋ", "ㄌ", "ㄍ", "ㄎ",
00049   "ㄏ", "ㄐ", "ㄑ", "ㄒ", "ㄓ", "ㄔ", "ㄕ", "ㄖ", "ㄗ", "ㄘ",
00050   "ㄙ",  /* 21 */             /* 1-21 */
00051   "ㄧ", "ㄨ", "ㄩ", /* 24 */   /* 1-3  */
00052   "ㄚ", "ㄛ", "ㄜ", "ㄝ", "ㄞ", "ㄟ", "ㄠ", "ㄡ", "ㄢ", "ㄣ",
00053   "ㄤ", "ㄥ", "ㄦ", /* 37 */   /* 1-13 */
00054   "ˉ", "ˊ", "ˇ", "ˋ", "˙", /* 1-5  */
00055 };
00056 
00057 static char StandardKeyMap[NUM_OF_ZHUYIN_SYMBOL + 1] = {
00058   0,
00059   '1', 'q', 'a', 'z', '2', 'w', 's', 'x', 'e', 'd',
00060   'c', 'r', 'f', 'v', '5', 't', 'g', 'b', 'y', 'h',
00061   'n', 'u', 'j', 'm', '8', 'i', 'k', ',', '9', 'o',
00062   'l', '.', '0', 'p', ';', '/', '-', ' ', '6', '3',
00063   '4', '7',
00064 };
00065 
00066 /*
00067  * return the Zhuyin symbol represents the Zhuyin number
00068  */
00069 unsigned char *ZhuyinIndexToZhuyinSymbol(int idx)
00070 {
00071        if (idx <= 0 || idx > NUM_OF_ZHUYIN_SYMBOL) {
00072               return(NULL);
00073        }
00074        return((unsigned char *)ZhuyinSymbol[idx]);
00075 }
00076 
00077 /*
00078  * return the Zhuyin key represents the Zhuyin symbol
00079  */
00080 char ZhuyinIndexToStandardKey(int idx)
00081 {
00082        if (idx <= 0 || idx > NUM_OF_ZHUYIN_SYMBOL) {
00083               return(0);
00084        }
00085        return(StandardKeyMap[idx]);
00086 }
00087 
00088 /*
00089  * return type of the Zhuyin index
00090  */
00091 int ZhuyinIndexToZhuyinType(int idx)
00092 {
00093        if (idx <= 0 || idx > NUM_OF_ZHUYIN_SYMBOL) {
00094               return(ZHUYIN_TYPE_ERROR);
00095        }
00096 
00097        if (idx >= 1 && idx <= 21) {
00098               return(ZHUYIN_TYPE_CONSONANT);
00099        } else if (idx >= 22 && idx <= 24) {
00100               return(ZHUYIN_TYPE_VOWEL1);
00101        } else if (idx >= 25 && idx <= 37) {
00102               return(ZHUYIN_TYPE_VOWEL2);
00103        } else if (idx >= 38 && idx <= 42) {
00104               return(ZHUYIN_TYPE_TONE);
00105        }
00106 
00107        return(ZHUYIN_TYPE_ERROR);
00108 }
00109 
00110 /*
00111  * return index of the Zhuyin symbol
00112  */
00113 int ZhuyinSymbolToZhuyinIndex(unsigned char *sym)
00114 {
00115        int idx;
00116 
00117        if (sym == NULL) return(0);
00118 
00119        for (idx = 1; idx <= NUM_OF_ZHUYIN_SYMBOL; idx++) {
00120               if (!strncmp((char *)sym, (char *)ZhuyinSymbol[idx], strlen(ZhuyinSymbol[idx]))) {
00121                      return(idx);
00122               }
00123        }
00124        return(0);
00125 }
00126 
00127 /*
00128  * return type of the Zhuyin symbol
00129  */
00130 int ZhuyinSymbolToZhuyinType(unsigned char *sym)
00131 {
00132        int idx = ZhuyinSymbolToZhuyinIndex(sym);
00133 
00134        return(ZhuyinIndexToZhuyinType(idx));
00135 }
00136 
00137 /*
00138  * return key of the Zhuyin symbol
00139  */
00140 char ZhuyinSymbolToStandardKey(unsigned char *sym)
00141 {
00142        int idx = ZhuyinSymbolToZhuyinIndex(sym);
00143 
00144        return(ZhuyinIndexToStandardKey(idx));
00145 }
00146 
00147 /*
00148  * return index of the Zhuyin Key
00149  */
00150 int ZhuyinKeyToZhuyinIndex(char key)
00151 {
00152        int idx;
00153 
00154        for (idx = 1; idx <= NUM_OF_ZHUYIN_SYMBOL; idx++) {
00155               if (key == StandardKeyMap[idx]) {
00156                      return(idx);
00157               }
00158        }
00159        return(0);
00160 }
00161 
00162 /*
00163  * return the Zhuyin symbol represents the Zhuyin key
00164  */
00165 unsigned char *ZhuyinKeyToZhuyinSymbol(char key)
00166 {
00167        int idx = ZhuyinKeyToZhuyinIndex(key);
00168        return((unsigned char *)ZhuyinSymbol[idx]);
00169 }
00170 
00171 /*
00172  * return the Zhuyin type represents the Zhuyin key
00173  */
00174 int ZhuyinKeyToZhuyinType(char key)
00175 {
00176        int idx = ZhuyinKeyToZhuyinIndex(key);
00177        return(ZhuyinIndexToZhuyinType(idx));
00178 }
00179 
00180 int ZhuyinSymbolSequenceToStandardKeySequence(unsigned char *sym_sequence, char *key_sequence, int *sym_len)
00181 {
00182        int i, idx;
00183        unsigned char *sym_ptr = sym_sequence;
00184        char *key_ptr = key_sequence;
00185 
00186        i = 0;
00187        while (i++ < 4) {
00188               idx = ZhuyinSymbolToZhuyinIndex(sym_ptr);
00189               if (idx == 0) break;
00190 
00191               *key_ptr++ = StandardKeyMap[idx];
00192               sym_ptr += strlen((char *)ZhuyinSymbol[idx]);
00193        }
00194 
00195        *key_ptr = '\0';
00196        *sym_len = (sym_ptr - sym_sequence);
00197 
00198        return(0);
00199 }