X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.c;h=5054f6b6a0050490b4e19d59b208e5ad4eceec0b;hb=31d6b34af7e6587c8eecabeb44da4de86ec93f3d;hp=5c9d85fc51af38c898784d7faebc141b56f54c9a;hpb=e48ddf80392916dcc33514594410d84f34940f71;p=selector.git diff --git a/selector.c b/selector.c index 5c9d85f..5054f6b 100644 --- a/selector.c +++ b/selector.c @@ -42,6 +42,7 @@ #include #include #include +#include #define VERSION "1.0.1" @@ -116,8 +117,9 @@ int string_to_positive_integer(char *string) { int result = 0; char *s; + printf("string_to_positive_integer string=\"%s\"\n", string); if(*string) { - for(s = string; *s; s++) { + for(s = string; *s && *s != ','; s++) { if(*s >= '0' && *s <= '9') { result = result * 10 + (int) (*s - '0'); } else error = 1; @@ -775,11 +777,35 @@ void read_file(struct hash_table_t *hash_table, /*********************************************************************/ +static struct option long_options[] = { + { "output-file", 1, 0, 'o' }, + { "separator-patterns", 1, 0, 's' }, + { "separator-display", 1, 0, 'x' }, + { "inject-in-tty", no_argument, 0, 'v' }, + { "add-control-qs", no_argument, 0, 'w' }, + { "monochrome", no_argument, 0, 'm' }, + { "no-beep", no_argument, 0, 'q' }, + { "input-file", 1, 0, 'f' }, + { "revert-order", no_argument, 0, 'i' }, + { "remove-bash-prefix", no_argument, 0, 'b' }, + { "remove-zsh-prefix", no_argument, 0, 'z' }, + { "remove-duplicates", no_argument, 0, 'd' }, + { "regexp", no_argument, 0, 'e' }, + { "case-sensitive", no_argument, 0, 'a' }, + { "title", 1, 0, 't' }, + { "number-of-lines", 1, 0, 'l' }, + { "colors", 1, 0, 'c' }, + { "rest-are-files", no_argument, 0, '-' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } +}; + int main(int argc, char **argv) { char input_filename[BUFFER_SIZE], output_filename[BUFFER_SIZE]; + char c, *s; char pattern[BUFFER_SIZE]; - int i, k, l, n; + int k, l, n; int cursor_position; int error = 0, show_help = 0; int rest_are_files = 0; @@ -808,123 +834,100 @@ int main(int argc, char **argv) { strcpy(input_filename, ""); strcpy(output_filename, ""); - i = 1; + while (!rest_are_files && + (c = getopt_long(argc, argv, "o:s:x:vwmqf:ibzdeat:l:c:-h", + long_options, NULL)) != -1) { - while(!error && !show_help && - i < argc && - argv[i][0] == '-' && !rest_are_files) { + switch(c) { - if(strcmp(argv[i], "-o") == 0) { - check_opt(argc, argv, i, 1, ""); - strncpy(output_filename, argv[i+1], BUFFER_SIZE); - i += 2; - } + case 'o': + strncpy(output_filename, optarg, BUFFER_SIZE); + break; - else if(strcmp(argv[i], "-s") == 0) { - check_opt(argc, argv, i, 1, ""); - pattern_separator = argv[i+1][0]; - i += 2; - } + case 's': + pattern_separator = optarg[0]; + break; - else if(strcmp(argv[i], "-x") == 0) { - check_opt(argc, argv, i, 1, "