X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.c;h=11265c673b3efc3713383839ee87fe454a66fb0c;hb=007ead4b6f3d770c9adf6502abac7eb825e16d83;hp=e6b49aa103d2068bdb66c9debb81d28c8637d60a;hpb=5ca5782212c0371f36f1ebbb397208e5eee2110a;p=selector.git diff --git a/selector.c b/selector.c index e6b49aa..11265c6 100644 --- a/selector.c +++ b/selector.c @@ -3,7 +3,7 @@ * selector is a simple command line utility for selection of strings * with a dynamic pattern-matching. * - * Copyright (c) 2009 Francois Fleuret + * Copyright (c) 2009, 2010 Francois Fleuret * Written by Francois Fleuret * * This file is part of selector. @@ -42,8 +42,9 @@ #include #include #include +#include -#define VERSION "1.0" +#define VERSION "1.1" #define BUFFER_SIZE 4096 @@ -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; @@ -144,7 +146,7 @@ void error_feedback() { void print_help(FILE *out) { - fprintf(out, "Selector version %s-R%s (%s)\n", VERSION, REVISION_NUMBER, UNAME); + fprintf(out, "Selector version %s (%s)\n", VERSION, UNAME); fprintf(out, "Written by Francois Fleuret .\n"); fprintf(out, "\n"); fprintf(out, "Usage: selector [options] [ [ ...]]\n"); @@ -775,11 +777,35 @@ void read_file(struct hash_table_t *hash_table, /*********************************************************************/ +static struct option long_options[] = { + { "output-file", 1, 0, 'o' }, + { "pattern-separator", 1, 0, 's' }, + { "label-separator", 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 *s; char pattern[BUFFER_SIZE]; - int i, k, l, n; + int c, 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, "