|
wnidows默认的码表与linux不一样
于是写了个转换工具
供各位转换WINDOWS下的码表(当然是公开版权的 违反版权的本人不负责)
使用方法 把windows码表文件转换成txt
我记得是有那个转换工具的 以前还把WB的转换出来背
然后取出中间的输入法码表部分
然后转换 这里提供源码
[PHP]
/****************************************************************************
*
* input method convert tool,convert windows input code to linux's input code
* Author:wushuang 2003/10/06 for www.loveunix.net 's birth
* input:windows style input code page
* suchas:
* 工a aaa aaaa
* 式a
* output:linux style input code page,such
* a 工
* aa 式
* aaa 工
* aaaa 工
*
* success run in cygwin
****************************************************************************/
#include <list>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;
/****************************************************************************
*
* define struct
*
****************************************************************************/
#define INPUT_CODE_MAX_LEN 20
#define CHIESE_VALUE_MAX_LEN 50
struct element_struct{
char code[INPUT_CODE_MAX_LEN + 1]; //input code
char value[CHIESE_VALUE_MAX_LEN + 1]; //chinese string
};
// use in sort,the sort order is like this
// a 工
// aa 式
// aaa 工
// aaaa 工
//
inline bool operator <(const element_struct& e1,const element_struct& e2)
{
return stricmp(e1.code,e2.code)<0;
}
// load windows' chinese input table into list
// windows chinese input table lik this:
// 工a aaa aaaa
static bool load(const char *filename,list<element_struct>& element_list)
{
FILE* fp = fopen(filename,"r");
element_list.clear();
if(!fp)
return false;
unsigned char linebuf[100];
while(!feof(fp)){
if(fgets((char*)linebuf,99,fp)<=0)
break;
unsigned char *pstart = NULL;
unsigned char *pstop = linebuf;
element_struct element;
int len;
// get the chinese string
while(*pstop>0x80)pstop+=2;
len = pstop - linebuf;
if( !len || len >CHIESE_VALUE_MAX_LEN)
continue;
memset(&element,0,sizeof(element));
memcpy(element.value,linebuf,len);
// get input code string and put into list
while( *pstop ){
pstart = pstop;
while(isalnum(*pstop)) pstop++;
len = pstop - pstart;
if(!len || len > INPUT_CODE_MAX_LEN ) break;
memcpy(element.code,pstart,len);
element.code[len] = 0;
element_list.push_back(element);
while (isspace(*pstop)) pstop ++;
}
}
return true;
}
static bool save(const char*filename,const list<element_struct>& element_list)
{
FILE* fp = fopen(filename,"wb");
if(fp){
for(list<element_struct>::const_iterator iter = element_list.begin();
iter != element_list.end();iter ++)
fprintf(fp,"%s\t%s\n",iter->code,iter->value);
fclose(fp);
}
return fp!= NULL;
}
int main(int argc,char** argv)
{
if(argv != 3){
printf("tabconv inputfile outputfile\n");
return -1;
}
list<element_struct> element_list;
if(load(argv[1],element_list)){
element_list.sort();
save(argv[2],element_list);
printf("convert success\n");
}
return 0;
}
[/PHP] |
|