Chinaunix首页 | 论坛 | 博客
  • 博客访问: 358114
  • 博文数量: 78
  • 博客积分: 3380
  • 博客等级: 中校
  • 技术积分: 857
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-16 19:39
文章分类

全部博文(78)

文章存档

2011年(31)

2010年(47)

分类: LINUX

2010-08-22 17:40:19

#include
#include
#include
#include "getopt.h"
void print_usage(const char *program_name)
{
 printf("==>%s 1.0.0(2010-06-13)\n",program_name);
 printf("Usage:%s -f -o [-c ] [-k ]\n", program_name);
 printf("-f--file the CDR file to be decoded\n");
 printf("-o --output the output file in plain text format\n");
 printf("-c --config the description file of the CDR file, if not given,use default configuration\n");
 printf("-k --keyword the keyword to search,if not given,all records will be written into output file\n");
}
int main(int argc,char*argv[])
{
  char *file_name=NULL;
  char *output_name=NULL;
  char *config_name=NULL;
  char *keyword=NULL;
  
  const char *short_opts="hf:o:c:k:";//short options
 //long options 
  const struct option long_opts[]={
      {"help",no_argument,NULL,'h'},
      {"file",required_argument,NULL,'f'},
      {"output",required_argument,NULL,'o'},
      {"config",required_argument,NULL,'c'},
      {"keyword",required_argument,NULL,'k'},
      {0,0,0,0}
      };
  int c;
  while((c=getopt_long(argc,argv,short_opts,long_opts,NULL))!=-1)
  {
   switch(c)
    {
     case 'h':
      print_usage(argv[0]);
      break;
     case'f':
      file_name=optarg;
      break;
     case 'o':
      output_name=optarg;
      break;
     case 'c':
      config_name=optarg;
      break;
     case 'k':
      keyword=optarg;
      break;
     case '?':
      if(optopt=='f'||optopt=='o'||optopt=='c'||optopt=='k')
       printf("Error:option-%c requires an argument\n",optopt);
      else
       return 1;
     default:
       abort();
    }
   } 
  return 0;
}
阅读(869) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~