int inverse_order = 0;
int remove_duplicates = 0;
int use_regexp = 0;
+int case_sensitive = 0;
//////////////////////////////////////////////////////////////////////
regex_t preg;
int regexp_error;
int nb_patterns;
+ int case_sensitive;
char *splitted_patterns, **patterns;
};
int match(char *string, matcher_t *matcher) {
if(matcher->nb_patterns >= 0) {
- for(int n = 0; n < matcher->nb_patterns; n++) {
- if(strstr(string, matcher->patterns[n]) == 0) return 0;
+ if(matcher->case_sensitive) {
+ for(int n = 0; n < matcher->nb_patterns; n++) {
+ if(strstr(string, matcher->patterns[n]) == 0) return 0;
+ }
+ } else {
+ for(int n = 0; n < matcher->nb_patterns; n++) {
+ if(strcasestr(string, matcher->patterns[n]) == 0) return 0;
+ }
}
return 1;
} else {
}
}
-void initialize_matcher(int use_regexp, matcher_t *matcher, const char *pattern) {
+void initialize_matcher(int use_regexp, int case_sensitive, matcher_t *matcher, const char *pattern) {
if(use_regexp) {
matcher->nb_patterns = -1;
- matcher->regexp_error = regcomp(&matcher->preg, pattern, REG_ICASE);
+ matcher->regexp_error = regcomp(&matcher->preg, pattern, case_sensitive ? 0 : REG_ICASE);
} else {
matcher->regexp_error = 0;
matcher->nb_patterns = 1;
+ matcher->case_sensitive = case_sensitive;
for(const char *s = pattern; *s; s++) {
if(*s == pattern_separator) {
char buffer[buffer_size];
matcher_t matcher;
- initialize_matcher(use_regexp, &matcher, pattern);
+ initialize_matcher(use_regexp, case_sensitive, &matcher, pattern);
// We now take care of printing the lines per se
if(matcher.regexp_error) {
addstr("[regexp error]");
- } else {
-
+ } else if(nb_lines > 0) {
int new_line;
if(match(lines[*current_line], &matcher)) {
new_line = *current_line;
if(nb_printed_lines == 0) {
addnstr("[no selection]\n", console_width);
}
+ } else {
+ addnstr("[empty choice]\n", console_width);
}
// Draw the modeline
i++;
}
+ else if(strcmp(argv[i], "-a") == 0) {
+ case_sensitive = 1;
+ i++;
+ }
+
else if(strcmp(argv[i], "-l") == 0) {
check_opt(argc, argv, i, 1, "<maximum number of lines>");
nb_lines_max = atoi(argv[i+1]);
<< " -z remove the zsh history line prefix" << endl
<< " -i invert the order of lines" << endl
<< " -e start in regexp mode" << endl
+ << " -a case sensitive" << endl
<< " -m monochrome mode" << endl
<< " -c <fg modeline> <bg modeline> <fg highlight> <bg highlight>" << endl
<< " set the display colors" << endl
file.getline(raw_line, buffer_size);
- if(file.fail()) {
- cerr << "Line too long." << endl;
- cerr << raw_line << endl;
- exit(1);
- }
-
if(raw_line[0]) {
+ if(file.fail()) {
+ cerr << "Line too long:" << endl;
+ cerr << raw_line << endl;
+ exit(1);
+ }
+
char *s, *t;
const char *u;