Record Order
Define the order between two records.
- Declare compare()
-
Function definition
- Segment Source
-
1164: /* Compare two lines A and B, returning negative, zero, or positive
1165: depending on whether A compares less than, equal to, or greater than B. */
1166:
1167: static int
1168: compare (register const struct line *a, register const struct line *b)
1169: {
1170: int diff, tmpa, tmpb, mini;
1171:
1172: /* First try to compare on the specified keys (if any).
1173: The only two cases with no key at all are unadorned sort,
1174: and unadorned sort -r. */
1175: if (keyhead.next)
1176: {
1177: diff = keycompare (a, b);
1178: if (diff != 0)
1179: return diff;
1180: if (unique || stable)
1181: return 0;
1182: }
1183:
1184: /* If the keys all compare equal (or no keys were specified)
1185: fall through to the default byte-by-byte comparison. */
1186: tmpa = a->length, tmpb = b->length;
1187: mini = min (tmpa, tmpb);
1188: if (mini == 0)
1189: diff = tmpa - tmpb;
1190: else
1191: {
1192: char *ap = a->text, *bp = b->text;
1193:
1194: diff = UCHAR (*ap) - UCHAR (*bp);
1195: if (diff == 0)
1196: {
1197: diff = memcmp (ap, bp, mini);
1198: if (diff == 0)
1199: diff = tmpa - tmpb;
1200: }
1201: }
1202:
1203: return reverse ? -diff : diff;
1204: }
1205: