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

Function parse_patterns

src/csplit.c:1120–1166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1118 After each pattern, check if the next argument is a repeat count. */
1119
1120static void
1121parse_patterns (int argc, int start, char **argv)
1122{
1123 struct control *p; /* New control record created. */
1124 static intmax_t last_val = 0;
1125
1126 for (int i = start; i < argc; i++)
1127 {
1128 if (*argv[i] == '/' || *argv[i] == '%')
1129 {
1130 p = extract_regexp (i, *argv[i] == '%', argv[i]);
1131 }
1132 else
1133 {
1134 p = new_control_record ();
1135 p->argnum = i;
1136
1137 uintmax_t val;
1138 if (xstrtoumax (argv[i], NULL, 10, &val, "") != LONGINT_OK
1139 || INTMAX_MAX < val)
1140 error (EXIT_FAILURE, 0, _("%s: invalid pattern"), quote (argv[i]));
1141 if (val == 0)
1142 error (EXIT_FAILURE, 0,
1143 _("%s: line number must be greater than zero"), argv[i]);
1144 if (val < last_val)
1145 error (EXIT_FAILURE, 0,
1146 _("line number %s is smaller than preceding line number,"
1147 " %jd"), quote (argv[i]), last_val);
1148
1149 if (val == last_val)
1150 error (0, 0,
1151 _("warning: line number %s is the same as preceding line number"),
1152 quote (argv[i]));
1153
1154 last_val = val;
1155
1156 p->lines_required = val;
1157 }
1158
1159 if (i + 1 < argc && *argv[i + 1] == '{')
1160 {
1161 /* We have a repeat count. */
1162 i++;
1163 parse_repeat_count (i, p, argv[i]);
1164 }
1165 }
1166}
1167
1168
1169

Callers 1

mainFunction · 0.85

Calls 3

extract_regexpFunction · 0.85
new_control_recordFunction · 0.85
parse_repeat_countFunction · 0.85

Tested by

no test coverage detected