#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;
}
阅读(876) | 评论(0) | 转发(0) |