search: accept toggles for case and regex when searching at startup

Allow the user to specify that the search string should be interpreted
case-sensitively and/or as a regular expression by preceding the search
indicator (/ or ?) with c and/or r.  Or to switch these things off by
using C and/or R.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
master
Brand Huntsman 2019-08-17 15:30:43 -06:00 committed by Benno Schulenberg
parent a9dd73fb16
commit 2326bf695e
1 changed files with 21 additions and 6 deletions

View File

@ -2585,16 +2585,31 @@ int main(int argc, char **argv)
/* If there's a +LINE[,COLUMN] argument here, eat it up. */
if (optind < argc - 1 && argv[optind][0] == '+') {
if (argv[optind][1] == '/' || argv[optind][1] == '?') {
if (argv[optind][2]) {
searchstring = mallocstrcpy(NULL, &argv[optind][2]);
if (argv[optind][1] == '?')
int n = 1;
while (isalpha(argv[optind][n])) {
switch (argv[optind][n++]) {
case 'c': SET(CASE_SENSITIVE); break;
case 'C': UNSET(CASE_SENSITIVE); break;
case 'r': SET(USE_REGEXP); break;
case 'R': UNSET(USE_REGEXP); break;
default:
statusline(ALERT, _("Invalid search modifier '%c'"),
argv[optind][n - 1]);
}
}
if (argv[optind][n] == '/' || argv[optind][n] == '?') {
if (argv[optind][n + 1]) {
searchstring = mallocstrcpy(NULL, &argv[optind][n + 1]);
if (argv[optind][n] == '?')
SET(BACKWARDS_SEARCH);
} else
} else if (n == 1)
statusline(ALERT, _("Empty search string"));
optind++;
} else
if (!parse_line_column(&argv[optind++][1], &givenline, &givencol))
if (!parse_line_column(&argv[optind++][n], &givenline, &givencol))
statusline(ALERT, _("Invalid line or column number"));
}