Man 帮助文件转化成为window 下面的文本[1]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 vingo888 的 blog

                    使用unix或者是linux 的人经常使用的命令就是man 来查找一些命令或者是函数的使用方法。前几天,我down了一个cgywin ,想学学在linux环境下面的开发,在cgywin 使用man 来查看帮助总是感觉没有在window下面使用一些文本编辑器例如ultraedit 看得爽,感觉不怎么直接(相信这种感觉只是对于那些刚刚接触*nix 的人才有),于是,我边把帮助文件重定向输出到一个文件中,在window 下面使用ultraedit 来看帮助文件,可是,我发现,重定向输出的文件中包含了man 的一些控制字符(下划线、颜色),在window下面根本就很难直接阅读。于是,我便写了一个小程序,把重定向输出的帮助文件内容,转化成为window 下面的文本文件。

                  程序比较简单,主要是找出控制字符,并且对其进行转换。程序代码如下: 

 int main(int argc, char* argv[])
{
    char *pname = argv[0];
    pname += strlen(argv[0]);
    while(pname > argv[0] && pname[-1] != '\\'){
        pname --;
    }
    if(argc != 2)
    {
        printf("usage : %s filename \r\n   eg.: %s vingo.txt\r\n",pname,pname);
        return 0;
    }
    handle hfile = createfile(argv[1],
        generic_read, file_share_read ,
        0,
       open_existing,file_attribute_normal, null);
    if(hfile == invalid_handle_value)
    {
        printf("can not open file : %s\r\n",argv[1]);
        dword dwerror = getlasterror();
        return 0;
    }
    char sznewfilename[max_path];
    sprintf(sznewfilename,"%s.vingo.txt",argv[1]);
    handle hfilenew = createfile(sznewfilename, generic_write, file_share_read,
        null,create_always, file_attribute_normal,  null);
    if(hfilenew == invalid_handle_value)
    {
        closehandle(hfile);
        printf("can not create file \r\n");
        return 0;
    }
    char chtemp ;
    dword cbread ;
    dword cbwrite;
    while(readfile(hfile,&chtemp,sizeof(char), &cbread, null))
    {
        if(cbread == 0)
        {
            break;
        }
        //printf("[%.2x]",chtemp);
        if(chtemp == 0x08){
            readfile(hfile,&chtemp,sizeof(char), &cbread, null);
            continue;
        }
        if(chtemp == 0x5f){
            readfile(hfile,&chtemp,sizeof(char), &cbread, null);
            if(chtemp == 0x08){
                continue ;
            }
            else{
                if(chtemp == 0x5f){
                    setfilepointer(hfile,-1,0,file_current);
                }
            }
        }
        if(chtemp == 0x0a){
            writefile(hfilenew,"\r\n" ,2,&cbwrite, null);
        }
        if( (chtemp <= 0x7e) && (chtemp >= 0x20) ){
            writefile(hfilenew,&chtemp,sizeof(char),&cbwrite, null);
            if(cbwrite != sizeof(char) )
            {

本文关键:Man 帮助文件转化成为window 下面的文本
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top