| 2471 | If KEY is null, underline the whole line. */ |
| 2472 | |
| 2473 | static void |
| 2474 | debug_key (struct line const *line, struct keyfield const *key) |
| 2475 | { |
| 2476 | char *text = line->text; |
| 2477 | char *beg = text; |
| 2478 | char *lim = text + line->length - 1; |
| 2479 | |
| 2480 | if (key) |
| 2481 | { |
| 2482 | if (key->sword != SIZE_MAX) |
| 2483 | beg = begfield (line, key); |
| 2484 | if (key->eword != SIZE_MAX) |
| 2485 | { |
| 2486 | lim = limfield (line, key); |
| 2487 | /* Treat field ends before field starts as empty fields. */ |
| 2488 | lim = MAX (beg, lim); |
| 2489 | } |
| 2490 | |
| 2491 | if ((key->skipsblanks && key->sword == SIZE_MAX) |
| 2492 | || key->month || key_numeric (key)) |
| 2493 | { |
| 2494 | char saved = *lim; |
| 2495 | *lim = '\0'; |
| 2496 | |
| 2497 | while (blanks[to_uchar (*beg)]) |
| 2498 | beg++; |
| 2499 | |
| 2500 | char *tighter_lim = beg; |
| 2501 | |
| 2502 | if (lim < beg) |
| 2503 | tighter_lim = lim; |
| 2504 | else if (key->month) |
| 2505 | getmonth (beg, &tighter_lim); |
| 2506 | else if (key->general_numeric) |
| 2507 | ignore_value (strtold (beg, &tighter_lim)); |
| 2508 | else if (key->numeric || key->human_numeric) |
| 2509 | { |
| 2510 | char const *p = beg + (beg < lim && *beg == '-'); |
| 2511 | char max_digit = traverse_raw_number (&p); |
| 2512 | if ('0' <= max_digit) |
| 2513 | { |
| 2514 | unsigned char ch = *p; |
| 2515 | tighter_lim = (char *) p |
| 2516 | + (key->human_numeric && unit_order[ch]); |
| 2517 | } |
| 2518 | } |
| 2519 | else |
| 2520 | tighter_lim = lim; |
| 2521 | |
| 2522 | *lim = saved; |
| 2523 | lim = tighter_lim; |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | size_t offset = debug_width (text, beg); |
| 2528 | size_t width = debug_width (beg, lim); |
| 2529 | mark_key (offset, width); |
| 2530 | } |
no test coverage detected