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

Function term

src/test.c:223–284  ·  view source on GitHub ↗

* term - parse a term and return 1 or 0 depending on whether the term * evaluates to true or false, respectively. * * term ::= * '-'('h'|'d'|'f'|'r'|'s'|'w'|'c'|'b'|'p'|'u'|'g'|'k') filename * '-'('L'|'x') filename * '-t' int * '-'('z'|'n') string * string * string ('!='|'='|>|<) string * '-'(eq|ne|le|lt|ge|gt) * file '-'(nt|ot|ef) file * '(' ')' * int ::= * '-l' s

Source from the content-addressed store, hash-verified

221 * positive and negative integers
222 */
223static bool
224term (void)
225{
226 bool value;
227 bool negated = false;
228 int bop;
229
230 /* Deal with leading 'not's. */
231 while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
232 {
233 advance (true);
234 negated = !negated;
235 }
236
237 if (pos >= argc)
238 beyond ();
239
240 /* A paren-bracketed argument. */
241 if (argv[pos][0] == '(' && argv[pos][1] == '\0')
242 {
243 int nargs;
244
245 advance (true);
246
247 for (nargs = 1;
248 pos + nargs < argc && ! streq (argv[pos + nargs], ")");
249 nargs++)
250 if (nargs == 4)
251 {
252 nargs = argc - pos;
253 break;
254 }
255
256 value = posixtest (nargs);
257 if (!argv[pos])
258 test_syntax_error (_("%s expected"), quote (")"));
259 else
260 if (argv[pos][0] != ')' || argv[pos][1])
261 test_syntax_error (_("%s expected, found %s"),
262 quote_n (0, ")"), quote_n (1, argv[pos]));
263 advance (false);
264 }
265
266 /* Are there enough arguments left that this could be dyadic? */
267 else if (4 <= argc - pos && streq (argv[pos], "-l")
268 && 0 <= (bop = binop (argv[pos + 2])))
269 value = binary_operator (true, bop);
270 else if (3 <= argc - pos
271 && 0 <= (bop = binop (argv[pos + 1])))
272 value = binary_operator (false, bop);
273
274 /* It might be a switch type argument. */
275 else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
276 value = unary_operator ();
277 else
278 {
279 value = (argv[pos][0] != '\0');
280 advance (false);

Callers 1

andFunction · 0.85

Calls 7

advanceFunction · 0.85
beyondFunction · 0.85
posixtestFunction · 0.85
test_syntax_errorFunction · 0.85
binary_operatorFunction · 0.85
unary_operatorFunction · 0.85
binopFunction · 0.70

Tested by

no test coverage detected