linux界面操作程序

 

 
#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;
  }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值