Chinaunix首页 | 论坛 | 博客
  • 博客访问: 323109
  • 博文数量: 83
  • 博客积分: 3193
  • 博客等级: 中校
  • 技术积分: 1679
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-03 12:04
文章分类

全部博文(83)

文章存档

2013年(2)

2012年(6)

2011年(72)

2010年(2)

2009年(1)

分类: C/C++

2011-08-28 12:52:44

     Yesterday, I wrote a wiki page about "How to create a man shell script to view function usage on ipad2/iphone".Today I tried to write the same  functional man program based on C. As for shell script, please refer to:
http://blog.chinaunix.net/space.php?uid=20282925&do=blog&id=2419947

My C code is here:
##############
# mman.c
#################
#include
#include
#include
#include
#include
#include
 

void usage(char *par)
{      
         printf("Usage:%s [1-8] function_name\n", par);
}

int show_man_html(char *man_path, char *man_dir, char *name)
{
    strcat(man_path,man_dir);
    strcat(man_path,"/");
    strcat(man_path,name);
    int s_ret;
    s_ret = access(man_path,0);
    if(s_ret != 0)
        return -1;
    else
//        return    printf("%s\n",man_path);
        return execl("/usr/bin/lynx", "lynx", man_path, (char *)0);
}
int main(int argc, char **argv)
{      
    char man_dir[10]="man";
    char function_name[20];
    char man_path[50]="/usr/share/man/";
    char *path="/usr/share/man";
    int ret = 0;

         if(argc<2)
         {      
                 usage(argv[0]);
                 exit(0);
         }

     if(!isdigit(argv[1][0]))
     {
         man_dir[3]='1';
         man_dir[4]='\0';
//         printf("%s\n",man_dir);
          strcpy(function_name,argv[1]);
         strcat(function_name,".1.html");
     }
     else
     {
         if(atoi(argv[1])>8 || atoi(argv[1])<1)
             {
             usage(argv[0]);
             exit(0);
             }
         strcat(man_dir,argv[1]);
          strcpy(function_name,argv[2]);
         strcat(function_name,".");
         strcat(function_name,argv[1]);
         strcat(function_name,".html");
//         printf("%s\n",man_dir);
     }
    if(show_man_html(man_path,man_dir,function_name) == -1)
         fprintf(stderr,"man error:%s\n",strerror(errno));
        return 0;
}

You can scp this source code onto your ipad2/iphone , and then execute the command like "gcc -o mman mman.c"   to  compile it:
#scp mman.c root@myipad2:~
#gcc -o mman mman.c
#ln -s mman /usr/bin/man

This one can be used instead of myman.sh. Then, you can enjoy you own man viewer on your E-toy!

P.S.  Sorry, my chinese input was broken on my laptop this morning, so I have to write this wike page in English instead of Chinese.
阅读(885) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~