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

Function key_warnings

src/sort.c:2593–2774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2591/* Output data independent key warnings to stderr. */
2592
2593static void
2594key_warnings (struct keyfield const *gkey, bool gkey_only)
2595{
2596 struct keyfield ugkey = *gkey;
2597 unsigned long keynum = 1;
2598 bool basic_numeric_field = false;
2599 bool general_numeric_field = false;
2600 bool basic_numeric_field_span = false;
2601 bool general_numeric_field_span = false;
2602
2603 for (struct keyfield *key = keylist; key; key = key->next, keynum++)
2604 {
2605 if (key_numeric (key))
2606 {
2607 if (key->general_numeric)
2608 general_numeric_field = true;
2609 else
2610 basic_numeric_field = true;
2611 }
2612
2613 if (key->traditional_used)
2614 {
2615 size_t sword = key->sword;
2616 size_t eword = key->eword;
2617 char tmp[INT_BUFSIZE_BOUND (uintmax_t)];
2618 /* obsolescent syntax +A.x -B.y is equivalent to:
2619 -k A+1.x+1,B.y (when y = 0)
2620 -k A+1.x+1,B+1.y (when y > 0) */
2621 char obuf[INT_BUFSIZE_BOUND (sword) * 2 + 4]; /* +# -# */
2622 char nbuf[INT_BUFSIZE_BOUND (sword) * 2 + 5]; /* -k #,# */
2623 char *po = obuf;
2624 char *pn = nbuf;
2625
2626 if (sword == SIZE_MAX)
2627 sword++;
2628
2629 po = stpcpy (stpcpy (po, "+"), umaxtostr (sword, tmp));
2630 pn = stpcpy (stpcpy (pn, "-k "), umaxtostr (sword + 1, tmp));
2631 if (key->eword != SIZE_MAX)
2632 {
2633 stpcpy (stpcpy (po, " -"), umaxtostr (eword + 1, tmp));
2634 stpcpy (stpcpy (pn, ","),
2635 umaxtostr (eword + 1
2636 + (key->echar == SIZE_MAX), tmp));
2637 }
2638 error (0, 0, _("obsolescent key %s used; consider %s instead"),
2639 quote_n (0, obuf), quote_n (1, nbuf));
2640 }
2641
2642 /* Warn about field specs that will never match. */
2643 bool zero_width = key->sword != SIZE_MAX && key->eword < key->sword;
2644 if (zero_width)
2645 error (0, 0, _("key %lu has zero width and will be ignored"), keynum);
2646
2647 /* Warn about significant leading blanks. */
2648 bool implicit_skip = key_numeric (key) || key->month;
2649 bool line_offset = key->eword == 0 && key->echar != 0; /* -k1.x,1.y */
2650 if (!zero_width && !gkey_only && tab == TAB_DEFAULT && !line_offset

Callers 1

mainFunction · 0.85

Calls 5

key_numericFunction · 0.85
to_ucharFunction · 0.85
default_key_compareFunction · 0.85
key_to_optsFunction · 0.85
select_pluralFunction · 0.85

Tested by

no test coverage detected