LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 546|回复: 2

码表转换工具 wndows转换成linux

[复制链接]
发表于 2003-10-6 15:51:02 | 显示全部楼层 |阅读模式
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]
发表于 2003-10-6 16:54:42 | 显示全部楼层
码表????
 楼主| 发表于 2003-10-6 19:01:55 | 显示全部楼层
就是输入法

在WINDOWS下可以把IMB转换成文本文件的

然后你再使用这个软件转换成LINUX下输入法
这样就可以方便的使用习惯的输入法了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表