Month Name Sort Order
Order records by month name.
- Define month ordering field
-
Field declaration
- Segment Source
-
118: int month; /* Flag for comparison by month name. */
- Define month name mapping
-
Array definition
Segment Element
Structure declaration
- 123: struct month
124: {
125: char *name;
126: int val;
127: };
128:
Segment Element
Array definition
-
144: /* Table mapping 3-letter month names to integers.
145: Alphabetic order allows binary search. */
146: static struct month const monthtab[] =
147: {
148: {"APR", 4},
149: {"AUG", 8},
150: {"DEC", 12},
151: {"FEB", 2},
152: {"JAN", 1},
153: {"JUL", 7},
154: {"JUN", 6},
155: {"MAR", 3},
156: {"MAY", 5},
157: {"NOV", 11},
158: {"OCT", 10},
159: {"SEP", 9}
160: };
161:
- Insert user message text
-
Text insertion
- Segment Source
-
229: -M compare (unknown) < `JAN' < ... < `DEC', imply -b\n\
- Define getmonth()
-
Function definition
- Segment Source
-
955: /* Return an integer <= 12 associated with month name S with length LEN,
956: 0 if the name in S is not recognized. */
957:
958: static int
959: getmonth (const char *s, int len)
960: {
961: char month[4];
962: register int i, lo = 0, hi = 12;
963:
964: while (len > 0 && blanks[UCHAR(*s)])
965: ++s, --len;
966:
967: if (len < 3)
968: return 0;
969:
970: for (i = 0; i < 3; ++i)
971: month[i] = fold_toupper[UCHAR (s[i])];
972: month[3] = '\0';
973:
974: while (hi - lo > 1)
975: if (strcmp (month, monthtab[(lo + hi) / 2].name) < 0)
976: hi = (lo + hi) / 2;
977: else
978: lo = (lo + hi) / 2;
979: if (!strcmp (month, monthtab[lo].name))
980: return monthtab[lo].val;
981: return 0;
982: }
983:
- Dispatch month compare
-
Code insertion
- Segment Source
-
1083: else if (key->month)
1084: {
1085: diff = getmonth (texta, lena) - getmonth (textb, lenb);
1086: if (diff)
1087: return key->reverse ? -diff : diff;
1088: continue;
1089: }
- Parse MonOrder option (-M)
-
Code insertion
- Segment Source
-
1691: case 'M':
1692: key->month = 1;
1693: break;
- Establish global sort options
-
Code insertion
- Segment Source
-
1773: gkey.numeric = gkey.general_numeric = gkey.month = gkey.reverse = 0;
- Propogate global sort options
-
Code insertion
Segment Element
Code modification
-
2032: && !key->skipeblanks && !key->month && !key->numeric
Segment Element
Code insertion
-
2039: key->month = gkey.month;
Segment Element
Code modification
-
2046: || gkey.skipeblanks || gkey.month || gkey.numeric