/* * * UNICON - The Console Chinese & I18N * Copyright (c) 1999-2002 * * This file is part of UNICON, a console Chinese & I18N * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * See the file COPYING directory of this archive * Author: see CREDITS */ #include #include #include #include #include #include "xl_hzinput.h" #include "xl_sysphrase.h" #include "xl_phrase.h" FILE *fr, *fw; int lineno; void print_error(char *fmt,...) { va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); fprintf(stderr,"\n"); exit(-1); } char *skip_space(char *s) { while ((*s==' ' || *s=='\t') && *s) s++; return s; } char *to_space(char *s) { while (*s!=' ' && *s!='\t' && *s) s++; return s; } void del_nl_space(char *s) { char *t; int len = strlen (s); if (!*s) return; t = s + len - 1; while ((*t=='\n' || *t==' ' || *t=='\t') && s] -c \ [-d 63) print_error("Error, at most 64 key can be defined!\n"); InpTable.KeyName[TotalKeyNum] = arg[0]; } InpTable.KeyMap[32] = 0; /* SPACE = 32 */ InpTable.KeyName[0] = ' '; TotalKeyNum++; InpTable.TotalKey = TotalKeyNum; /* include space */ /****************** now the character/phrase ***********************/ cmd_arg(tt,&cmd, &arg); index=0; TotalAssociatePhrase = 0; while (!feof(fr)) { int len, k, m, n; u_long key1,key2; cmd_arg(tt,&cmd,&arg); if (!cmd[0] || !arg[0]) break; len = strlen(cmd); if (len > InpTable.MaxPress) InpTable.MaxPress=len; if (len > 10) print_error("%d: only <= 10 keys is allowed",lineno); key1 = key2=0; for (i = 0;i < len; i++) { if (i < 5) { k = InpTable.KeyMap[cmd[i]]; key1 |= k << (24-i*6); } else { k = InpTable.KeyMap[cmd[i]]; key2 |= k<< (24-(i-5)*6); } } memcpy(&InpTable.item[index].key1, &key1, 4); memcpy(&InpTable.item[index].key2, &key2, 4); if (TL_MatchPhrase (pDefaultSysphrase, arg, &freq, &nPhrase) == 0) { nPhrase = TL_AppendPhrase (pDefaultSysphrase, arg); TL_GetPhraseFreq (pDefaultSysphrase, nPhrase, &freq); } InpTable.item[index].nPhrase = nPhrase; // InpTable.item[index].frequency = freq; m = (*arg) * 256 + *(arg+1); if (InpTable.pAssociatePhrase[m].total == 0) { InpTable.pAssociatePhrase[m].pPhrase = (ITEM **) malloc (sizeof (ITEM *) * 5); TotalAssociatePhrase ++; } else if (InpTable.pAssociatePhrase[m].total % 5 == 0) { int total = InpTable.pAssociatePhrase[m].total + 5; ITEM **q = InpTable.pAssociatePhrase[m].pPhrase; q = (ITEM **) realloc (q, sizeof (ITEM *) * total); InpTable.pAssociatePhrase[m].pPhrase = q; } n = InpTable.pAssociatePhrase[m].total; InpTable.pAssociatePhrase[m].pPhrase[n] = &InpTable.item[index]; InpTable.pAssociatePhrase[m].total ++; index++; } fclose(fr); InpTable.TotalChar = index; InpTable.TotalAssociatePhrase = TotalAssociatePhrase; SortPhraseItem (pDefaultSysphrase, &InpTable); /**************** generate 64 index number ***********************/ bzero (CharDef, sizeof(CharDef)); for (i = 0; i < index; i++) { int kk = InpTable.item[i].key1 >> 24 & 0x3f; if (!CharDef[kk]) { InpTable.KeyIndex[kk]= (u_short) i; CharDef[kk]=1; } } InpTable.KeyIndex[TotalKeyNum] = index; for(i=TotalKeyNum-1; i>0; i--) { if (!CharDef[i]) InpTable.KeyIndex[i] = InpTable.KeyIndex[i+1]; } SaveLoadInputMethod (&InpTable, fname_tab); if (build_sysphrase == 1) TL_SaveAllPhrase (pDefaultSysphrase, TL_SYSPHRASE_FILE); return 0; }