MCPcopy Create free account
hub / github.com/coreutils/coreutils / extract_regexp

Function extract_regexp

src/csplit.c:1078–1115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1076 Unless IGNORE is true, mark these lines for output. */
1077
1078static struct control *
1079extract_regexp (int argnum, bool ignore, char const *str)
1080{
1081 idx_t len; /* Number of bytes in this regexp. */
1082 char delim = *str;
1083 char const *closing_delim;
1084 struct control *p;
1085 char const *err;
1086
1087 closing_delim = strrchr (str + 1, delim);
1088 if (closing_delim == NULL)
1089 error (EXIT_FAILURE, 0,
1090 _("%s: closing delimiter '%c' missing"), str, delim);
1091
1092 len = closing_delim - str - 1;
1093 p = new_control_record ();
1094 p->argnum = argnum;
1095 p->ignore = ignore;
1096
1097 p->regexpr = true;
1098 p->re_compiled.buffer = NULL;
1099 p->re_compiled.allocated = 0;
1100 p->re_compiled.fastmap = xmalloc (UCHAR_MAX + 1);
1101 p->re_compiled.translate = NULL;
1102 re_syntax_options =
1103 RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
1104 err = re_compile_pattern (str + 1, len, &p->re_compiled);
1105 if (err)
1106 {
1107 error (0, 0, _("%s: invalid regular expression: %s"), quote (str), err);
1108 cleanup_fatal ();
1109 }
1110
1111 if (closing_delim[1])
1112 check_for_offset (p, str, closing_delim + 1);
1113
1114 return p;
1115}
1116
1117/* Extract the break patterns from args START through ARGC - 1 of ARGV.
1118 After each pattern, check if the next argument is a repeat count. */

Callers 1

parse_patternsFunction · 0.85

Calls 3

new_control_recordFunction · 0.85
cleanup_fatalFunction · 0.85
check_for_offsetFunction · 0.85

Tested by

no test coverage detected