Using klib

This commit is contained in:
Haoyu Cheng
2019-05-10 16:14:01 -04:00
parent 0b209dd1e9
commit eee68408be
7 changed files with 438 additions and 251 deletions

View File

@@ -1,7 +1,7 @@
#include "CommandLines.h"
#include <stdlib.h>
#include <getopt.h>
#include <stdio.h>
#include "ketopt.h"
char* read_file_name = NULL;
char* output_file_name = NULL;
@@ -17,41 +17,28 @@ void Print_H()
int CommandLine_process (int argc, char *argv[])
{
int o;
int index;
static struct option longOptions[] =
{
{"seq", required_argument, 0, 'q'},
{"threads", required_argument, 0, 't'},
{"threads", required_argument, 0, 'o'},
{0, 0, 0, 0},
static ko_longopt_t longopts[] = {
{ "help", ko_no_argument, 100},
{ "seq", ko_required_argument, 101},
{ "output", ko_required_argument, 102},
{ "thread", ko_required_argument, 103},
{ NULL, 0, 0 }
};
ketopt_t opt = KETOPT_INIT;
while ( (o = getopt_long ( argc, argv, "q:t:o:", longOptions, &index)) != -1 )
{
switch (o)
{
case 'q':
read_file_name = optarg;
break;
case 'o':
output_file_name = optarg;
break;
case 't':
thread_num = atoi(optarg);
break;
case '?':
fprintf(stderr, "Unrecognized option!\n" );
return 0;
break;
default:
Print_H();
return 0;
}
int i, c;
while ((c = ketopt(&opt, argc, argv, 1, "ht:o:q:", longopts)) >= 0) {
if (c == 100 || c == 'h') Print_H();
else if (c == 103 || c == 't') thread_num = atoi(opt.arg);
else if (c == 102 || c == 'o') output_file_name = opt.arg;
else if (c == 101 || c == 'q') read_file_name = opt.arg;
else if (c == '?') printf("unknown opt: -%c\n", opt.opt? opt.opt : ':');
else if (c == ':') printf("missing arg: -%c\n", opt.opt? opt.opt : ':');
}
if (argc == 1)
{
Print_H();