Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for case insensitive regex matching #487

Open
wants to merge 1 commit into
base: pu
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/calcurse.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ from that session will be lost without warning!
converted and echoed to stdout. Two formats are available: +ical+ and
+pcal+. The default 'format' is +ical+.

*--pattern-case-insensitive*::
Interpret the pattern in *--filter-pattern* as case insensitive.

FILTER OPTIONS
--------------

Expand Down Expand Up @@ -352,7 +355,8 @@ General filters

*--filter-pattern* 'pattern'::
Include items with a description that matches the pattern. The pattern is
interpreted as an extended regular expression.
interpreted as an extended regular expression. By default, this is case
sensitive. To make it case insensitive, use *--pattern-case-insensitive*.

*--filter-hash* 'string'::
Include items with a hash starting with 'string'. The filter can be negated
Expand Down
10 changes: 8 additions & 2 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ enum {
OPT_STATUS,
OPT_DAEMON,
OPT_INPUT_DATEFMT,
OPT_OUTPUT_DATEFMT
OPT_OUTPUT_DATEFMT,
OPT_PATTERN_ICASE
};

/*
Expand Down Expand Up @@ -412,6 +413,7 @@ int parse_args(int argc, char **argv)
time_t from = -1, to = -1;
int range = 0;
int limit = INT_MAX;
int flag_case_insensitive = 0;
/* Filters */
struct item_filter filter = { 0, 0, NULL, NULL, -1, -1, -1, -1, 0, 0, 0 };
/* Format strings */
Expand Down Expand Up @@ -497,6 +499,7 @@ int parse_args(int argc, char **argv)
{"daemon", no_argument, NULL, OPT_DAEMON},
{"input-datefmt", required_argument, NULL, OPT_INPUT_DATEFMT},
{"output-datefmt", required_argument, NULL, OPT_OUTPUT_DATEFMT},
{"pattern-case-insensitive", no_argument, NULL, OPT_PATTERN_ICASE},
{NULL, no_argument, NULL, 0}
};

Expand Down Expand Up @@ -652,11 +655,14 @@ int parse_args(int argc, char **argv)
filter.hash = mem_strdup(optarg);
filter_opt = 1;
break;
case OPT_PATTERN_ICASE:
flag_case_insensitive = REG_ICASE;
break;
case 'S':
case OPT_FILTER_PATTERN:
EXIT_IF(filter.regex,
_("cannot handle more than one regular expression"));
if (regcomp(&reg, optarg, REG_EXTENDED))
if (regcomp(&reg, optarg, REG_EXTENDED | flag_case_insensitive))
EXIT(_("could not compile regular expression: %s"), optarg);
filter.regex = ®
filter_opt = 1;
Expand Down