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

Function process_line

src/numfmt.c:1478–1529  ·  view source on GitHub ↗

Convert number in a given line of text. NEWLINE specifies whether to output a '\n' for this "line". */

Source from the content-addressed store, hash-verified

1476/* Convert number in a given line of text.
1477 NEWLINE specifies whether to output a '\n' for this "line". */
1478static int
1479process_line (char *line, bool newline)
1480{
1481 char *next;
1482 uintmax_t field = 0;
1483 bool valid_number = true;
1484
1485 while (true) {
1486 ++field;
1487 next = next_field (&line);
1488
1489 if (*line != '\0')
1490 {
1491 /* NUL terminate the current field string and process */
1492 char end_field = *line;
1493 *line = '\0';
1494
1495 if (! process_field (next, field))
1496 valid_number = false;
1497
1498 if (delimiter != NULL)
1499 fputs (delimiter, stdout);
1500 else
1501 fputc (' ', stdout);
1502
1503 if (delimiter)
1504 line += MAX (strlen (delimiter), 1);
1505 else
1506 {
1507 *line = end_field;
1508 mcel_t g = mcel_scanz (line);
1509 line += g.len;
1510 }
1511 }
1512 else
1513 {
1514 /* end of the line, process the last field and finish */
1515 if (! process_field (next, field))
1516 valid_number = false;
1517
1518 break;
1519 }
1520 }
1521
1522 if (newline)
1523 putchar (line_delim);
1524
1525 if (ferror (stdout))
1526 write_error ();
1527
1528 return valid_number;
1529}
1530
1531int
1532main (int argc, char **argv)

Callers 1

mainFunction · 0.85

Calls 3

next_fieldFunction · 0.85
process_fieldFunction · 0.85
write_errorFunction · 0.85

Tested by

no test coverage detected