Added the ^I keystroke to switch the case-sensitivity. Added a check
authorFrancois Fleuret <francois@fleuret.org>
Mon, 13 Apr 2009 12:59:44 +0000 (14:59 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Mon, 13 Apr 2009 13:01:08 +0000 (15:01 +0200)
for the integer valued arguments.

REVISION_NUMBER
selector.1
selector.cc

index dee261d..b4f334f 100644 (file)
@@ -1 +1 @@
-140
+141
index 10cf637..c349ace 100644 (file)
@@ -12,7 +12,8 @@ in real time to show only the lines containing all the said strings,
 or matching the regexp.
 
 The ^R key switches between the standard multi-substring mode and the
 or matching the regexp.
 
 The ^R key switches between the standard multi-substring mode and the
-regexp mode.
+regexp mode, and ^I between the case-sensitive and case-insensitive
+modes.
 
 The main usage of selector is as an efficient search in the shell
 command history. With the correct option, it will inject the selected
 
 The main usage of selector is as an efficient search in the shell
 command history. With the correct option, it will inject the selected
index ccc6158..46ff098 100644 (file)
@@ -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
 
 //////////////////////////////////////////////////////////////////////
 // A quick and dirty hash table
 
@@ -483,6 +503,10 @@ void update_screen(int *current_line, int *temporary_line, int motion,
     addstr(" [regexp]");
   }
 
     addstr(" [regexp]");
   }
 
+  if(case_sensitive) {
+    addstr(" [case]");
+  }
+
   move(0, cursor_x);
 
   if(with_colors) {
   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, "<maximum number of lines>");
 
     else if(strcmp(argv[i], "-l") == 0) {
       check_opt(argc, argv, i, 1, "<maximum number of lines>");
-      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, "<fg modeline> <bg modeline> <fg highlight> <bg highlight>");
       i += 2;
     }
 
     else if(strcmp(argv[i], "-c") == 0) {
       check_opt(argc, argv, i, 4, "<fg modeline> <bg modeline> <fg highlight> <bg highlight>");
-      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;
     }
 
       i += 5;
     }
 
@@ -891,6 +915,10 @@ int main(int argc, char **argv) {
       use_regexp = !use_regexp;
     }
 
       use_regexp = !use_regexp;
     }
 
+    else if(key == '\011') { // ^R
+      case_sensitive = !case_sensitive;
+    }
+
     else if(key == '\025') { // ^U
       kill_before_cursor(pattern, &cursor_position);
     }
     else if(key == '\025') { // ^U
       kill_before_cursor(pattern, &cursor_position);
     }
@@ -933,7 +961,8 @@ int main(int argc, char **argv) {
       }
       out.flush();
     }
       }
       out.flush();
     }
-
+  } else {
+    cout << "Aborted." << endl;
   }
 
   for(int l = 0; l < nb_lines; l++) {
   }
 
   for(int l = 0; l < nb_lines; l++) {