Skip to content

Instantly share code, notes, and snippets.

@ucasfl
Last active July 28, 2021 07:32
Show Gist options
  • Save ucasfl/3a6e0a474b10c3a44aef12a1ad90e0fd to your computer and use it in GitHub Desktop.
Save ucasfl/3a6e0a474b10c3a44aef12a1ad90e0fd to your computer and use it in GitHub Desktop.
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
extern int optind, opterr, optopt;
extern char * optarg;
static struct option long_options[]
{
{"log", no_argument, NULL, 'l'},
{"file", required_argument, NULL, 'f'},
{"insert", required_argument, NULL, 'i'},
{"update", required_argument, NULL, 'u'},
{"delete", required_argument, NULL, 'd'},
{"get", required_argument, NULL, 'g'}
};
int insert_num = 0;
int update_num = 0;
int delete_num = 0;
int get_num = 0;
int thread_num = 1;
bool has_log_option = false;
bool has_file_option = false;
char file_name[1024];
int main(int argc, char * argv[])
{
int index = 0;
int c = 0;
while (EOF != (c = getopt_long(argc, argv, "iudglft:", long_options, &index)))
{
switch (c)
{
case 'i':
insert_num = atoi(optarg);
break;
case 'u':
update_num = atoi(optarg);
break;
case 'd':
delete_num = atoi(optarg);
break;
case 'g':
get_num = atoi(optarg);
break;
case 'l':
has_log_option = true;
break;
case 'f':
has_file_option = true;
sprintf(file_name, "%s", optarg);
break;
case 't':
thread_num = atoi(optarg);
break;
default:
printf("Unknown option: %c\n", optopt);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment