#define FLAG_TA (1<<0)
#define FLAG_TC (1<<1)
#define FLAG_REMAIN (1<<2)
#define FLAG_LINK (1<<4)
#define FLAG_TERM (1<<8)
#define FLAG_HELP (1<<16)
struct opt {
unsigned int flags;
uint64_t termsign;
};
struct opt opt;
int parse_cmd_line(int argc, char *const argv[])
{
int option;
const char *optstring = "acrlht:?";
struct option longopts[] = {
{"ta", no_argument, NULL, 'a'},
{"tc", no_argument, NULL, 'c'},
{"remain", no_argument, NULL, 'r'},
{"link", no_argument, NULL, 'l'},
{"term", required_argument, NULL, 't'},
{0, 0, 0, 0}
};
while ((option =
getopt_long(argc, argv, optstring, longopts, NULL)) != -1)
switch (option) {
case 'a':
opt.flags |= FLAG_TA;
break;
case 'c':
opt.flags |= FLAG_TC;
break;
case 'r':
opt.flags |= FLAG_REMAIN;
break;
break;
case 'l':
opt.flags |= FLAG_LINK;
break;
case 't':
opt.flags |= FLAG_TERM;
printf("termsign %s \n",optarg);
sscanf(optarg,"%llu",&opt.termsign);
// opt.termsign =(uint64_t)_atoi64( optarg);
printf("termsign %llu \n",opt.termsign);
break;
case '?':
opt.flags |= FLAG_HELP;
return -1;
}
if ((opt.flags & FLAG_TERM) && (!opt.termsign )) {
return -1;
}
return 0;
}
void print_help(void)
{
static const char *help =
"Usage: getopt_long [OPTIONS]\n"
"Options are:\n"
" -a, --ta optional ta \n"
" -c, --tc optional tc \n"
" -r, --remain optional remain \n"
" -l, --link optional link \n"
" -t, --termsign must input termsign \n"
" -h, --help Display this help text and exit\n";
printf("%s", help);
}
int main(int argc, char **argv)
{
indexpeek ci;
uint64_t termsign;
opt.termsign=0;
if(ci.init("./ciconf.ini") != 0)
{
return -1;
}
char par[128] = "";
if (argc < 2)
{
print_help();
exit(0);
}
opt.flags = 0;
if (parse_cmd_line(argc, argv) < 0)
{
// parse command line.
exit(-1);
}
if (opt.flags & FLAG_HELP)
{
// get 'help' .
print_help();
exit(0);
}
if (opt.flags & FLAG_TERM)
{
termsign=opt.termsign;
}
else
{
print_help();
exit(0);
}
if (opt.flags & FLAG_TA)
{
ci.peekTA(termsign );
printf("ta peek over\n");
}
if (opt.flags & FLAG_TC)
{
ci.peekTC(termsign );
printf("tc peek over\n");
}
if (opt.flags & FLAG_LINK)
{
ci.peekLINK(termsign );
printf("link peek over\n");
}
if (opt.flags & FLAG_REMAIN)
{
ci.peekREMAIN(termsign );
printf("remain peek over\n");
}
printf("all succeed\n");
return 0;
}