Field List Management
Provide a list of sort fields ordered by significance.
Notes
The key list is maintained as a simple null terminated
linked list of key records.
- Declare head of field list (keyhead)
-
Variable declaration
- Segment Source
-
202: /* Lists of key field comparisons to be tried. */
203: static struct keyfield keyhead;
204:
- Compare field sequence
Segment Element
Variable declaration
- 993: struct keyfield *key;
Segment Element
Code insertionIterate field list
-
996: for (key = keyhead.next; key; key = key->next, ++iter)
997: {
998: ignore = key->ignore;
999: translate = (unsigned char *) key->translate;
1000:
1001: /* Find the beginning and limit of each field. */
1002: if (iter || a->keybeg == NULL || b->keybeg == NULL)
1003: {
1004: if (key->eword >= 0)
1005: lima = limfield (a, key), limb = limfield (b, key);
1006: else
1007: lima = a->text + a->length, limb = b->text + b->length;
1008:
1009: if (key->sword >= 0)
1010: texta = begfield (a, key), textb = begfield (b, key);
1011: else
1012: {
1013: texta = a->text, textb = b->text;
1014: if (key->skipsblanks)
1015: {
1016: while (texta < lima && blanks[UCHAR (*texta)])
1017: ++texta;
1018: while (textb < limb && blanks[UCHAR (*textb)])
1019: ++textb;
1020: }
1021: }
1022: }
1023: else
1024: {
1025: /* For the first iteration only, the key positions have
1026: been precomputed for us. */
1027: texta = a->keybeg, lima = a->keylim;
1028: textb = b->keybeg, limb = b->keylim;
1029: }
1030:
Segment Element
Code insertionIterate field list
- 1159: }
1160:
- Define insertkey()
-
Function definition
- Segment Source
-
1622: /* Insert key KEY at the end of the list (`keyhead'). */
1623:
1624: static void
1625: insertkey (struct keyfield *key)
1626: {
1627: struct keyfield *k = &keyhead;
1628:
1629: while (k->next)
1630: k = k->next;
1631: k->next = key;
1632: key->next = NULL;
1633: }
1634:
- Manage field list
Segment Element
Variable definition
-
1718: struct keyfield *key = NULL, gkey;
Segment Element
Code insertion
- 2026: if (key)
2027: insertkey (key);
2028:
Segment Element
Code insertion
-
2029: /* Inheritance of global options to individual keys. */
2030: for (key = keyhead.next; key; key = key->next)
2031: if (!key->ignore && !key->translate && !key->skipsblanks && !key->reverse
2032: && !key->skipeblanks && !key->month && !key->numeric
2033: && !key->general_numeric)
2034: {
2035: key->ignore = gkey.ignore;
2036: key->translate = gkey.translate;
2037: key->skipsblanks = gkey.skipsblanks;
2038: key->skipeblanks = gkey.skipeblanks;
2039: key->month = gkey.month;
2040: key->numeric = gkey.numeric;
2041: key->general_numeric = gkey.general_numeric;
2042: key->reverse = gkey.reverse;
2043: }
2044:
Segment Element
Code insertion
-
2045: if (!keyhead.next && (gkey.ignore || gkey.translate || gkey.skipsblanks
2046: || gkey.skipeblanks || gkey.month || gkey.numeric
2047: || gkey.general_numeric))
2048: insertkey (&gkey);