* selector is a simple command line utility for selection of strings
* with a dynamic pattern-matching.
*
- * Copyright (c) 2009, 2010, 2011 Francois Fleuret
+ * Copyright (c) 2009, 2010, 2011, 2012 Francois Fleuret
* Written by Francois Fleuret <francois@fleuret.org>
*
* This file is part of selector.
#include <getopt.h>
#include <limits.h>
-#define VERSION "1.1.5"
+#define VERSION "1.1.6"
#define BUFFER_SIZE 4096
};
/* Routine to add an interval to a sorted list of intervals
- extermities. Returns the number of extremities. This is an effing
- nightmare */
+ extremities. Returns the resulting number of extremities.
+
+ This routine is an effing nightmare */
int add_interval(int n, int *switches, int start, int end) {
int f, g, k;
*nb_switches = add_interval(*nb_switches, switches,
(int) (where - string),
(int) (where - string) + strlen(matcher->patterns[n]));
-#warning CHECK THE INTERVALS
- {
- /* int i; */
- /* FILE *out = fopen("/tmp/intervals", "w"); */
- /* for(k = 0; k < (*nb_switches)/2; k++) { */
- /* i = 0; */
- /* for(; i < switches[2 * k]; i++) fprintf(out, "-"); */
- /* for(; i < switches[2 * k + 1]; i++) fprintf(out, "%c", string[i]); */
- /* for(; i < strlen(string); i++) fprintf(out, "-"); */
- /* fprintf(out, "\n"); */
- /* } */
- /* fclose(out); */
- int k;
- for(k = 0; k < *nb_switches - 1; k++) {
- if(switches[k] > switches[k+1]) {
- abort();
- }
- }
- }
}
}
}
initialize_matcher(&matcher, use_regexp, case_sensitive, pattern);
- if(show_hits && matcher.nb_patterns >= 0) {
- switches = safe_malloc(sizeof(int) * matcher.nb_patterns * 2);
+ if(show_hits) {
+ if(matcher.nb_patterns >= 0) {
+ switches = safe_malloc(sizeof(int) * matcher.nb_patterns * 2);
+ } else {
+ switches = safe_malloc(sizeof(int) * 2);
+ }
} else {
- switches = safe_malloc(sizeof(int) * 2);
+ switches = 0;
}
console_width = getmaxx(stdscr);