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

Function keycompare

src/sort.c:2788–2978  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2786 are no more keys or a difference is found. */
2787
2788static int
2789keycompare (struct line const *a, struct line const *b)
2790{
2791 struct keyfield *key = keylist;
2792
2793 /* For the first iteration only, the key positions have been
2794 precomputed for us. */
2795 char *texta = a->keybeg;
2796 char *textb = b->keybeg;
2797 char *lima = a->keylim;
2798 char *limb = b->keylim;
2799
2800 int diff;
2801
2802 while (true)
2803 {
2804 char const *translate = key->translate;
2805 bool const *ignore = key->ignore;
2806
2807 /* Treat field ends before field starts as empty fields. */
2808 lima = MAX (texta, lima);
2809 limb = MAX (textb, limb);
2810
2811 /* Find the lengths. */
2812 size_t lena = lima - texta;
2813 size_t lenb = limb - textb;
2814
2815 if (hard_LC_COLLATE || key_numeric (key)
2816 || key->month || key->random || key->version)
2817 {
2818 /* Ordinarily use the keys in-place, temporarily null-terminated. */
2819 char *ta = texta;
2820 char *tb = textb;
2821 size_t tlena = lena;
2822 size_t tlenb = lenb;
2823 char enda = ta[tlena];
2824 char endb = tb[tlenb];
2825
2826 void *allocated = NULL;
2827 char stackbuf[4000];
2828
2829 if (ignore || translate)
2830 {
2831 /* Compute with copies of the keys, which are the result of
2832 translating or ignoring characters, and which need their
2833 own storage. */
2834
2835 size_t i;
2836
2837 /* Allocate space for copies. */
2838 size_t size = lena + 1 + lenb + 1;
2839 if (size <= sizeof stackbuf)
2840 ta = stackbuf;
2841 else
2842 ta = allocated = xmalloc (size);
2843 tb = ta + lena + 1;
2844
2845 /* Put into each copy a version of the key in which the

Callers 1

compareFunction · 0.85

Calls 10

key_numericFunction · 0.85
to_ucharFunction · 0.85
numcompareFunction · 0.85
general_numcompareFunction · 0.85
human_numcompareFunction · 0.85
getmonthFunction · 0.85
compare_randomFunction · 0.85
limfieldFunction · 0.85
begfieldFunction · 0.85
diff_reversedFunction · 0.85

Tested by

no test coverage detected