- * selector is a simple shell command for selection of strings with a
- * dynamic pattern-matching.
+ * selector is a simple command line utility for selection of strings
+ * with a dynamic pattern-matching.
+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;
+}
+
+void error_feedback() {
+ if(error_flash) {
+ flash();
+ } else {
+ beep();
+ }
+}
+
//////////////////////////////////////////////////////////////////////
// A quick and dirty hash table
//////////////////////////////////////////////////////////////////////
// A quick and dirty hash table
int first_line = new_line, last_line = new_line, nb_match = 1;
// We find the first and last line to show, so that the total of
int first_line = new_line, last_line = new_line, nb_match = 1;
// We find the first and last line to show, so that the total of
- if(bash_history && (*s == ' ' || (*s >= '0' && *s <= '9'))) {
- while(*s == ' ' || (*s >= '0' && *s <= '9')) s++;
+ // Copy the string while transforming the ctrl characters into
+ // printable characters
+
+ s = buffer;
+
+ while(*t) {
+ u = unctrl(*t++);
+ while(*u) { *s++ = *u++; }
- dup = test_and_add(s, *nb_lines, lines, hash_table, hash_table_size);
+ dup = test_and_add(buffer, *nb_lines, lines, hash_table, hash_table_size);
- lines[*nb_lines] = new char[strlen(s) + 1];
- strcpy(lines[*nb_lines], s);
+ lines[*nb_lines] = new char[strlen(buffer) + 1];
+ strcpy(lines[*nb_lines], buffer);
} else {
// The string was already in there, so we do not allocate a
// new string but use the pointer to the first occurence of it
} else {
// The string was already in there, so we do not allocate a
// new string but use the pointer to the first occurence of it
else if(strcmp(argv[i], "-f") == 0) {
check_opt(argc, argv, i, 1, "<input filename>");
strncpy(input_filename, argv[i+1], buffer_size);
else if(strcmp(argv[i], "-f") == 0) {
check_opt(argc, argv, i, 1, "<input filename>");
strncpy(input_filename, argv[i+1], buffer_size);
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>");
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]);
<< " -e start in regexp mode" << endl
<< " -a case sensitive" << endl
<< " -m monochrome mode" << endl
<< " -e start in regexp mode" << endl
<< " -a case sensitive" << endl
<< " -m monochrome mode" << endl
if(input_filename[0]) {
read_file(input_filename,
nb_lines_max, &nb_lines, lines,
if(input_filename[0]) {
read_file(input_filename,
nb_lines_max, &nb_lines, lines,
if(color_fg_modeline < 0 || color_fg_modeline >= COLORS ||
color_bg_modeline < 0 || color_bg_modeline >= COLORS ||
color_fg_highlight < 0 || color_bg_highlight >= COLORS ||
color_bg_highlight < 0 || color_bg_highlight >= COLORS) {
echo();
if(color_fg_modeline < 0 || color_fg_modeline >= COLORS ||
color_bg_modeline < 0 || color_bg_modeline >= COLORS ||
color_fg_highlight < 0 || color_bg_highlight >= COLORS ||
color_bg_highlight < 0 || color_bg_highlight >= COLORS) {
echo();
- init_pair(1, color_fg_modeline, color_bg_modeline);
- init_pair(2, color_fg_highlight, color_bg_highlight);
- init_pair(3, color_bg_modeline, color_fg_modeline);
+
+ init_pair(COLOR_MODELINE, color_fg_modeline, color_bg_modeline);
+ init_pair(COLOR_HIGHLIGHTED_LINE, color_fg_highlight, color_bg_highlight);
+
else if(key == '\025') { // ^U
kill_before_cursor(pattern, &cursor_position);
}
else if(key == '\025') { // ^U
kill_before_cursor(pattern, &cursor_position);
}