2 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
3 * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
47 struct key_specs *keys;
50 wint_t symbol_decimal_point = L'.';
51 /* there is no default thousands separator in collate rules: */
52 wint_t symbol_thousands_sep = 0;
53 wint_t symbol_negative_sign = L'-';
54 wint_t symbol_positive_sign = L'+';
56 static int wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset);
57 static int gnumcoll(struct key_value*, struct key_value *, size_t offset);
58 static int monthcoll(struct key_value*, struct key_value *, size_t offset);
59 static int numcoll(struct key_value*, struct key_value *, size_t offset);
60 static int hnumcoll(struct key_value*, struct key_value *, size_t offset);
61 static int randomcoll(struct key_value*, struct key_value *, size_t offset);
62 static int versioncoll(struct key_value*, struct key_value *, size_t offset);
68 keys_array_alloc(void)
70 struct keys_array *ka;
73 sz = keys_array_size();
81 * Calculate whether we need key hint space
87 return (need_hint ? sizeof(struct key_hint) : 0);
91 * Calculate keys array size
97 return (keys_num * (sizeof(struct key_value) + key_hint_size()));
101 * Clean data of keys array
104 clean_keys_array(const struct bwstring *s, struct keys_array *ka)
108 for (size_t i = 0; i < keys_num; ++i) {
109 const struct key_value *kv;
111 kv = get_key_from_keys_array(ka, i);
112 if (kv->k && kv->k != s)
115 memset(ka, 0, keys_array_size());
120 * Get pointer to a key value in the keys set
123 get_key_from_keys_array(struct keys_array *ka, size_t ind)
126 return ((struct key_value *)((caddr_t)ka->key +
127 ind * (sizeof(struct key_value) + key_hint_size())));
131 * Set value of a key in the keys set
134 set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind)
137 if (ka && keys_num > ind) {
138 struct key_value *kv;
140 kv = get_key_from_keys_array(ka, ind);
142 if (kv->k && kv->k != s)
149 * Initialize a sort list item
151 struct sort_list_item *
152 sort_list_item_alloc(void)
154 struct sort_list_item *si;
157 sz = sizeof(struct sort_list_item) + keys_array_size();
158 si = sort_malloc(sz);
165 sort_list_item_size(struct sort_list_item *si)
170 ret = sizeof(struct sort_list_item) + keys_array_size();
172 ret += bws_memsize(si->str);
173 for (size_t i = 0; i < keys_num; ++i) {
174 const struct key_value *kv;
176 kv = get_key_from_keys_array(&si->ka, i);
178 if (kv->k != si->str)
179 ret += bws_memsize(kv->k);
186 * Calculate key for a sort list item
189 sort_list_item_make_key(struct sort_list_item *si)
192 preproc(si->str, &(si->ka));
196 * Set value of a sort list item.
197 * Return combined string and keys memory size.
200 sort_list_item_set(struct sort_list_item *si, struct bwstring *str)
204 clean_keys_array(si->str, &(si->ka));
206 if (si->str == str) {
207 /* we are trying to reset the same string */
215 sort_list_item_make_key(si);
220 * De-allocate a sort list item object memory
223 sort_list_item_clean(struct sort_list_item *si)
227 clean_keys_array(si->str, &(si->ka));
236 * Skip columns according to specs
239 skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start,
240 bool skip_blanks, bool *empty_key)
243 return (BWSLEN(s) + 1);
246 while (start < BWSLEN(s) && iswblank(BWS_GET(s,start)))
249 while (start < BWSLEN(s) && cols > 1) {
254 if (start >= BWSLEN(s))
261 * Skip fields according to specs
264 skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
271 } else if (!(sort_opts_vals.tflag)) {
275 while (cpos < BWSLEN(s)) {
278 isblank = iswblank(BWS_GET(s, cpos));
280 if (isblank && !pb) {
294 while (cpos < BWSLEN(s)) {
295 if (BWS_GET(s,cpos) == (wchar_t)sort_opts_vals.field_sep) {
312 find_field_start(const struct bwstring *s, struct key_specs *ks,
313 size_t *field_start, size_t *key_start, bool *empty_field, bool *empty_key)
316 *field_start = skip_fields_to_start(s, ks->f1, empty_field);
318 *key_start = skip_cols_to_start(s, ks->c1, *field_start,
319 ks->pos1b, empty_key);
325 * Find end key position
328 find_field_end(const struct bwstring *s, struct key_specs *ks)
330 size_t f2, next_field_start, pos_end;
331 bool empty_field, empty_key;
338 return (BWSLEN(s) + 1);
341 next_field_start = skip_fields_to_start(s, f2 + 1,
343 if ((next_field_start > 0) && sort_opts_vals.tflag &&
344 ((wchar_t)sort_opts_vals.field_sep == BWS_GET(s,
345 next_field_start - 1)))
348 next_field_start = skip_fields_to_start(s, f2,
352 if (empty_field || (next_field_start >= BWSLEN(s)))
353 return (BWSLEN(s) + 1);
356 pos_end = skip_cols_to_start(s, ks->c2, next_field_start,
357 ks->pos2b, &empty_key);
358 if (pos_end < BWSLEN(s))
361 pos_end = next_field_start;
367 * Cut a field according to the key specs
369 static struct bwstring *
370 cut_field(const struct bwstring *s, struct key_specs *ks)
372 struct bwstring *ret = NULL;
375 size_t field_start, key_end, key_start, sz;
376 bool empty_field, empty_key;
383 find_field_start(s, ks, &field_start, &key_start,
384 &empty_field, &empty_key);
389 key_end = find_field_end(s, ks);
390 sz = (key_end < key_start) ? 0 : (key_end - key_start);
395 bwsnocpy(ret, s, key_start, sz);
403 * Preprocesses a line applying the necessary transformations
404 * specified by command line options and returns the preprocessed
405 * string, which can be used to compare.
408 preproc(struct bwstring *s, struct keys_array *ka)
411 if (sort_opts_vals.kflag)
412 for (size_t i = 0; i < keys_num; i++) {
413 struct bwstring *key;
414 struct key_specs *kspecs;
415 struct sort_mods *sm;
418 key = cut_field(s, kspecs);
422 key = dictionary_order(key);
424 key = ignore_nonprinting(key);
425 if (sm->fflag || sm->Mflag)
426 key = ignore_case(key);
428 set_key_on_keys_array(ka, key, i);
431 struct bwstring *ret = NULL;
432 struct sort_mods *sm = default_sort_mods;
437 ret = ignore_leading_blanks(ret);
442 ret = dictionary_order(ret);
443 } else if (sm->iflag) {
446 ret = ignore_nonprinting(ret);
448 if (sm->fflag || sm->Mflag) {
451 ret = ignore_case(ret);
454 set_key_on_keys_array(ka, s, 0);
456 set_key_on_keys_array(ka, ret, 0);
463 get_sort_func(struct sort_mods *sm)
477 return (versioncoll);
483 * Compares the given strings. Returns a positive number if
484 * the first precedes the second, a negative number if the second is
485 * the preceding one, and zero if they are equal. This function calls
486 * the underlying collate functions, which done the actual comparison.
489 key_coll(struct keys_array *ps1, struct keys_array *ps2, size_t offset)
491 struct key_value *kv1, *kv2;
492 struct sort_mods *sm;
495 for (size_t i = 0; i < keys_num; ++i) {
496 kv1 = get_key_from_keys_array(ps1, i);
497 kv2 = get_key_from_keys_array(ps2, i);
501 res = sm->func(kv2, kv1, offset);
503 res = sm->func(kv1, kv2, offset);
508 /* offset applies to only the first key */
515 * Compare two strings.
516 * Plain symbol-by-symbol comparison.
519 top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2)
522 if (default_sort_mods->rflag) {
523 const struct bwstring *tmp;
530 return (bwscoll(s1, s2, 0));
534 * Compare a string and a sort list item, according to the sort specs.
537 str_list_coll(struct bwstring *str1, struct sort_list_item **ss2)
539 struct keys_array *ka1;
542 ka1 = keys_array_alloc();
546 sort_list_item_make_key(*ss2);
549 bwsprintf(stdout, str1, "; s1=<", ">");
550 bwsprintf(stdout, (*ss2)->str, ", s2=<", ">");
553 ret = key_coll(ka1, &((*ss2)->ka), 0);
556 printf("; cmp1=%d", ret);
558 clean_keys_array(str1, ka1);
561 if ((ret == 0) && !(sort_opts_vals.sflag) && sort_opts_vals.complex_sort) {
562 ret = top_level_str_coll(str1, ((*ss2)->str));
564 printf("; cmp2=%d", ret);
574 * Compare two sort list items, according to the sort specs.
577 list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2,
582 ret = key_coll(&((*ss1)->ka), &((*ss2)->ka), offset);
586 printf("; offset=%d", (int) offset);
587 bwsprintf(stdout, ((*ss1)->str), "; s1=<", ">");
588 bwsprintf(stdout, ((*ss2)->str), ", s2=<", ">");
589 printf("; cmp1=%d\n", ret);
595 if (!(sort_opts_vals.sflag) && sort_opts_vals.complex_sort) {
596 ret = top_level_str_coll(((*ss1)->str), ((*ss2)->str));
598 printf("; cmp2=%d\n", ret);
605 * Compare two sort list items, according to the sort specs.
608 list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2)
611 return (list_coll_offset(ss1, ss2, 0));
616 list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \
619 return (list_coll_offset(ss1, ss2, N)); \
644 get_list_call_func(size_t offset)
646 static const listcoll_t lsarray[] = { list_coll, list_coll_1,
647 list_coll_2, list_coll_3, list_coll_4, list_coll_5,
648 list_coll_6, list_coll_7, list_coll_8, list_coll_9,
649 list_coll_10, list_coll_11, list_coll_12, list_coll_13,
650 list_coll_14, list_coll_15, list_coll_16, list_coll_17,
651 list_coll_18, list_coll_19, list_coll_20 };
654 return (lsarray[offset]);
660 * Compare two sort list items, only by their original string.
663 list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2)
666 return (top_level_str_coll(((*ss1)->str), ((*ss2)->str)));
670 * Maximum size of a number in the string (before or after decimal point)
672 #define MAX_NUM_SIZE (128)
677 static void setsuffix(wchar_t c, unsigned char *si)
711 * Read string s and parse the string into a fixed-decimal-point number.
712 * sign equals -1 if the number is negative (explicit plus is not allowed,
713 * according to GNU sort's "info sort".
714 * The number part before decimal point is in the smain, after the decimal
715 * point is in sfrac, tail is the pointer to the remainder of the string.
718 read_number(struct bwstring *s0, int *sign, wchar_t *smain, size_t *main_len, wchar_t *sfrac, size_t *frac_len, unsigned char *si)
724 /* always end the fraction with zero, even if we have no fraction */
727 while (iswblank(bws_get_iter_value(s)))
728 s = bws_iterator_inc(s, 1);
730 if (bws_get_iter_value(s) == (wchar_t)symbol_negative_sign) {
732 s = bws_iterator_inc(s, 1);
735 // This is '0', not '\0', do not change this
736 while (iswdigit(bws_get_iter_value(s)) &&
737 (bws_get_iter_value(s) == L'0'))
738 s = bws_iterator_inc(s, 1);
740 while (bws_get_iter_value(s) && *main_len < MAX_NUM_SIZE) {
741 if (iswdigit(bws_get_iter_value(s))) {
742 smain[*main_len] = bws_get_iter_value(s);
743 s = bws_iterator_inc(s, 1);
745 } else if (symbol_thousands_sep &&
746 (bws_get_iter_value(s) == (wchar_t)symbol_thousands_sep))
747 s = bws_iterator_inc(s, 1);
752 smain[*main_len] = 0;
754 if (bws_get_iter_value(s) == (wchar_t)symbol_decimal_point) {
755 s = bws_iterator_inc(s, 1);
756 while (iswdigit(bws_get_iter_value(s)) &&
757 *frac_len < MAX_NUM_SIZE) {
758 sfrac[*frac_len] = bws_get_iter_value(s);
759 s = bws_iterator_inc(s, 1);
762 sfrac[*frac_len] = 0;
764 while (*frac_len > 0 && sfrac[*frac_len - 1] == L'0') {
766 sfrac[*frac_len] = L'\0';
770 setsuffix(bws_get_iter_value(s),si);
772 if ((*main_len + *frac_len) == 0)
779 * Implements string sort.
782 wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
787 printf("; offset=%d\n", (int) offset);
788 bwsprintf(stdout, kv1->k, "; k1=<", ">");
789 printf("(%zu)", BWSLEN(kv1->k));
790 bwsprintf(stdout, kv2->k, ", k2=<", ">");
791 printf("(%zu)", BWSLEN(kv2->k));
794 return (bwscoll(kv1->k, kv2->k, offset));
798 * Compare two suffixes
801 cmpsuffix(unsigned char si1, unsigned char si2)
804 return ((char)si1 - (char)si2);
808 * Implements numeric sort for -n and -h.
811 numcoll_impl(struct key_value *kv1, struct key_value *kv2,
812 size_t offset __unused, bool use_suffix)
814 struct bwstring *s1, *s2;
815 wchar_t sfrac1[MAX_NUM_SIZE + 1], sfrac2[MAX_NUM_SIZE + 1];
816 wchar_t smain1[MAX_NUM_SIZE + 1], smain2[MAX_NUM_SIZE + 1];
817 int cmp_res, sign1, sign2;
818 size_t frac1, frac2, main1, main2;
819 unsigned char SI1, SI2;
820 bool e1, e2, key1_read, key2_read;
828 key1_read = key2_read = false;
831 bwsprintf(stdout, s1, "; k1=<", ">");
832 bwsprintf(stdout, s2, ", k2=<", ">");
838 if (kv1->hint->status == HS_UNINITIALIZED) {
839 /* read the number from the string */
840 read_number(s1, &sign1, smain1, &main1, sfrac1, &frac1, &SI1);
842 kv1->hint->v.nh.n1 = wcstoull(smain1, NULL, 10);
843 if(main1 < 1 && frac1 < 1)
844 kv1->hint->v.nh.empty=true;
845 kv1->hint->v.nh.si = SI1;
846 kv1->hint->status = (kv1->hint->v.nh.n1 != ULLONG_MAX) ?
847 HS_INITIALIZED : HS_ERROR;
848 kv1->hint->v.nh.neg = (sign1 < 0) ? true : false;
851 if (kv2->hint->status == HS_UNINITIALIZED) {
852 /* read the number from the string */
853 read_number(s2, &sign2, smain2, &main2, sfrac2, &frac2,&SI2);
855 kv2->hint->v.nh.n1 = wcstoull(smain2, NULL, 10);
856 if(main2 < 1 && frac2 < 1)
857 kv2->hint->v.nh.empty=true;
858 kv2->hint->v.nh.si = SI2;
859 kv2->hint->status = (kv2->hint->v.nh.n1 != ULLONG_MAX) ?
860 HS_INITIALIZED : HS_ERROR;
861 kv2->hint->v.nh.neg = (sign2 < 0) ? true : false;
864 if (kv1->hint->status == HS_INITIALIZED && kv2->hint->status ==
866 unsigned long long n1, n2;
869 e1 = kv1->hint->v.nh.empty;
870 e2 = kv2->hint->v.nh.empty;
875 neg1 = kv1->hint->v.nh.neg;
876 neg2 = kv2->hint->v.nh.neg;
884 return (neg2 ? +1 : -1);
886 return (neg1 ? -1 : +1);
890 cmp_res = cmpsuffix(kv1->hint->v.nh.si, kv2->hint->v.nh.si);
892 return (neg1 ? -cmp_res : cmp_res);
895 n1 = kv1->hint->v.nh.n1;
896 n2 = kv2->hint->v.nh.n1;
898 return (neg1 ? +1 : -1);
900 return (neg1 ? -1 : +1);
903 /* read the numbers from the strings */
905 read_number(s1, &sign1, smain1, &main1, sfrac1, &frac1, &SI1);
907 read_number(s2, &sign2, smain2, &main2, sfrac2, &frac2, &SI2);
909 e1 = ((main1 + frac1) == 0);
910 e2 = ((main2 + frac2) == 0);
915 /* we know the result if the signs are different */
916 if (sign1 < 0 && sign2 >= 0)
918 if (sign1 >= 0 && sign2 < 0)
922 return ((sign2 < 0) ? +1 : -1);
924 return ((sign1 < 0) ? -1 : +1);
927 cmp_res = cmpsuffix(SI1, SI2);
929 return ((sign1 < 0) ? -cmp_res : cmp_res);
932 /* if both numbers are empty assume that the strings are equal */
933 if (main1 < 1 && main2 < 1 && frac1 < 1 && frac2 < 1)
937 * if the main part is of different size, we know the result
938 * (because the leading zeros are removed)
942 else if (main1 > main2)
944 /* if the sizes are equal then simple non-collate string compare gives the correct result */
946 cmp_res = wcscmp(smain1, smain2);
950 cmp_res = wcscmp(sfrac1, sfrac2);
955 /* reverse result if the signs are negative */
956 if (sign1 < 0 && sign2 < 0)
963 * Implements numeric sort (-n).
966 numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
969 return (numcoll_impl(kv1, kv2, offset, false));
973 * Implements 'human' numeric sort (-h).
976 hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
979 return (numcoll_impl(kv1, kv2, offset, true));
983 * Implements random sort (-R).
986 randomcoll(struct key_value *kv1, struct key_value *kv2,
987 size_t offset __unused)
989 struct bwstring *s1, *s2;
997 bwsprintf(stdout, s1, "; k1=<", ">");
998 bwsprintf(stdout, s2, ", k2=<", ">");
1004 memcpy(&ctx1,&md5_ctx,sizeof(MD5_CTX));
1005 memcpy(&ctx2,&md5_ctx,sizeof(MD5_CTX));
1007 MD5Update(&ctx1, bwsrawdata(s1), bwsrawlen(s1));
1008 MD5Update(&ctx2, bwsrawdata(s2), bwsrawlen(s2));
1009 b1 = MD5End(&ctx1, NULL);
1010 b2 = MD5End(&ctx2, NULL);
1018 } else if (b2 == NULL) {
1024 cmp_res = strcmp(b1,b2);
1029 cmp_res = bwscoll(s1, s2, 0);
1036 * Implements version sort (-V).
1039 versioncoll(struct key_value *kv1, struct key_value *kv2,
1040 size_t offset __unused)
1042 struct bwstring *s1, *s2;
1048 bwsprintf(stdout, s1, "; k1=<", ">");
1049 bwsprintf(stdout, s2, ", k2=<", ">");
1055 return (vcmp(s1, s2));
1059 * Check for minus infinity
1062 huge_minus(double d, int err1)
1066 if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL)
1073 * Check for plus infinity
1076 huge_plus(double d, int err1)
1080 if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL)
1087 * Check whether a function is a NAN
1093 return ((d == NAN) || (isnan(d)));
1100 cmp_nans(double d1, double d2)
1111 * Implements general numeric sort (-g).
1114 gnumcoll(struct key_value *kv1, struct key_value *kv2,
1115 size_t offset __unused)
1119 bool empty1, empty2, key1_read, key2_read;
1123 key1_read = key2_read = false;
1126 bwsprintf(stdout, kv1->k, "; k1=<", ">");
1127 bwsprintf(stdout, kv2->k, "; k2=<", ">");
1130 if (kv1->hint->status == HS_UNINITIALIZED) {
1132 d1 = bwstod(kv1->k, &empty1);
1136 kv1->hint->v.gh.notnum = true;
1137 else if (err1 == 0) {
1138 kv1->hint->v.gh.d = d1;
1139 kv1->hint->v.gh.nan = is_nan(d1);
1140 kv1->hint->status = HS_INITIALIZED;
1142 kv1->hint->status = HS_ERROR;
1147 if (kv2->hint->status == HS_UNINITIALIZED) {
1149 d2 = bwstod(kv2->k, &empty2);
1153 kv2->hint->v.gh.notnum = true;
1154 else if (err2 == 0) {
1155 kv2->hint->v.gh.d = d2;
1156 kv2->hint->v.gh.nan = is_nan(d2);
1157 kv2->hint->status = HS_INITIALIZED;
1159 kv2->hint->status = HS_ERROR;
1164 if (kv1->hint->status == HS_INITIALIZED &&
1165 kv2->hint->status == HS_INITIALIZED) {
1166 if (kv1->hint->v.gh.notnum)
1167 return ((kv2->hint->v.gh.notnum) ? 0 : -1);
1168 else if (kv2->hint->v.gh.notnum)
1171 if (kv1->hint->v.gh.nan)
1172 return ((kv2->hint->v.gh.nan) ?
1173 cmp_nans(kv1->hint->v.gh.d, kv2->hint->v.gh.d) :
1175 else if (kv2->hint->v.gh.nan)
1178 d1 = kv1->hint->v.gh.d;
1179 d2 = kv2->hint->v.gh.d;
1191 d1 = bwstod(kv1->k, &empty1);
1197 d2 = bwstod(kv2->k, &empty2);
1201 /* Non-value case: */
1203 return (empty2 ? 0 : -1);
1209 return (is_nan(d2) ? cmp_nans(d1, d2) : -1);
1210 else if (is_nan(d2))
1214 if (err1 == ERANGE || err2 == ERANGE) {
1215 /* Minus infinity case */
1216 if (huge_minus(d1, err1)) {
1217 if (huge_minus(d2, err2)) {
1226 } else if (huge_minus(d2, err2)) {
1227 if (huge_minus(d1, err1)) {
1237 /* Plus infinity case */
1238 if (huge_plus(d1, err1)) {
1239 if (huge_plus(d2, err2)) {
1247 } else if (huge_plus(d2, err2)) {
1248 if (huge_plus(d1, err1)) {
1268 * Implements month sort (-M).
1271 monthcoll(struct key_value *kv1, struct key_value *kv2, size_t offset __unused)
1274 bool key1_read, key2_read;
1277 key1_read = key2_read = false;
1280 bwsprintf(stdout, kv1->k, "; k1=<", ">");
1281 bwsprintf(stdout, kv2->k, "; k2=<", ">");
1284 if (kv1->hint->status == HS_UNINITIALIZED) {
1285 kv1->hint->v.Mh.m = bws_month_score(kv1->k);
1287 kv1->hint->status = HS_INITIALIZED;
1290 if (kv2->hint->status == HS_UNINITIALIZED) {
1291 kv2->hint->v.Mh.m = bws_month_score(kv2->k);
1293 kv2->hint->status = HS_INITIALIZED;
1296 if (kv1->hint->status == HS_INITIALIZED) {
1297 val1 = kv1->hint->v.Mh.m;
1301 if (kv2->hint->status == HS_INITIALIZED) {
1302 val2 = kv2->hint->v.Mh.m;
1307 val1 = bws_month_score(kv1->k);
1309 val2 = bws_month_score(kv2->k);