X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.cc;h=46ff098228a8660c412787aabf56d269b0ce1a4e;hb=e9a5dbfb21e1c625bed5683b9170d1a76ba75a56;hp=ccc615850d5ea07c110fffb96369e049c845ee45;hpb=cda5c93df1c5cfe6f22a41e35bc1719a824d1e63;p=selector.git diff --git a/selector.cc b/selector.cc index ccc6158..46ff098 100644 --- a/selector.cc +++ b/selector.cc @@ -84,6 +84,26 @@ void check_opt(int argc, char **argv, int n_opt, int n, const char *help) { } } +int string_to_positive_integer(char *string) { + int error = 0; + int result = 0; + + if(*string) { + for(char *s = string; *s; s++) { + if(*s >= '0' && *s <= '9') { + result = result * 10 + int(*s - '0'); + } else error = 1; + } + } else error = 1; + + if(error) { + cerr << "Value `" << string << "' is not a positive integer." << endl; + exit(1); + } + + return result; +} + ////////////////////////////////////////////////////////////////////// // A quick and dirty hash table @@ -483,6 +503,10 @@ void update_screen(int *current_line, int *temporary_line, int motion, addstr(" [regexp]"); } + if(case_sensitive) { + addstr(" [case]"); + } + move(0, cursor_x); if(with_colors) { @@ -667,16 +691,16 @@ int main(int argc, char **argv) { else if(strcmp(argv[i], "-l") == 0) { check_opt(argc, argv, i, 1, ""); - nb_lines_max = atoi(argv[i+1]); + nb_lines_max = string_to_positive_integer(argv[i+1]); i += 2; } else if(strcmp(argv[i], "-c") == 0) { check_opt(argc, argv, i, 4, " "); - color_fg_modeline = atoi(argv[i+1]); - color_bg_modeline = atoi(argv[i+2]); - color_fg_highlight = atoi(argv[i+3]); - color_bg_highlight = atoi(argv[i+4]); + color_fg_modeline = string_to_positive_integer(argv[i + 1]); + color_bg_modeline = string_to_positive_integer(argv[i + 2]); + color_fg_highlight = string_to_positive_integer(argv[i + 3]); + color_bg_highlight = string_to_positive_integer(argv[i + 4]); i += 5; } @@ -891,6 +915,10 @@ int main(int argc, char **argv) { use_regexp = !use_regexp; } + else if(key == '\011') { // ^R + case_sensitive = !case_sensitive; + } + else if(key == '\025') { // ^U kill_before_cursor(pattern, &cursor_position); } @@ -933,7 +961,8 @@ int main(int argc, char **argv) { } out.flush(); } - + } else { + cout << "Aborted." << endl; } for(int l = 0; l < nb_lines; l++) {