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 if (ka->key[i].k && ka->key[i].k != s)
110 bwsfree(ka->key[i].k);
111 memset(ka, 0, keys_array_size());
116 * Set value of a key in the keys set
119 set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind)
122 if (ka && keys_num > ind) {
123 struct key_value *kv;
125 kv = &(ka->key[ind]);
127 if (kv->k && kv->k != s)
134 * Initialize a sort list item
136 struct sort_list_item *
137 sort_list_item_alloc(void)
139 struct sort_list_item *si;
142 sz = sizeof(struct sort_list_item) + keys_array_size();
143 si = sort_malloc(sz);
150 sort_list_item_size(struct sort_list_item *si)
155 ret = sizeof(struct sort_list_item) + keys_array_size();
157 ret += bws_memsize(si->str);
158 for (size_t i = 0; i < keys_num; ++i) {
159 struct key_value *kv;
161 kv = &(si->ka.key[i]);
163 if (kv->k != si->str)
164 ret += bws_memsize(kv->k);
171 * Calculate key for a sort list item
174 sort_list_item_make_key(struct sort_list_item *si)
177 preproc(si->str, &(si->ka));
181 * Set value of a sort list item.
182 * Return combined string and keys memory size.
185 sort_list_item_set(struct sort_list_item *si, struct bwstring *str)
189 clean_keys_array(si->str, &(si->ka));
191 if (si->str == str) {
192 /* we are trying to reset the same string */
200 sort_list_item_make_key(si);
205 * De-allocate a sort list item object memory
208 sort_list_item_clean(struct sort_list_item *si)
212 clean_keys_array(si->str, &(si->ka));
221 * Skip columns according to specs
224 skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start,
225 bool skip_blanks, bool *empty_key)
228 return (BWSLEN(s) + 1);
231 while (start < BWSLEN(s) && iswblank(BWS_GET(s,start)))
234 while (start < BWSLEN(s) && cols > 1) {
239 if (start >= BWSLEN(s))
246 * Skip fields according to specs
249 skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
256 } else if (!(sort_opts_vals.tflag)) {
260 while (cpos < BWSLEN(s)) {
263 isblank = iswblank(BWS_GET(s, cpos));
265 if (isblank && !pb) {
279 while (cpos < BWSLEN(s)) {
280 if (BWS_GET(s,cpos) == (wchar_t)sort_opts_vals.field_sep) {
297 find_field_start(const struct bwstring *s, struct key_specs *ks,
298 size_t *field_start, size_t *key_start, bool *empty_field, bool *empty_key)
301 *field_start = skip_fields_to_start(s, ks->f1, empty_field);
303 *key_start = skip_cols_to_start(s, ks->c1, *field_start,
304 ks->pos1b, empty_key);
310 * Find end key position
313 find_field_end(const struct bwstring *s, struct key_specs *ks)
315 size_t f2, next_field_start, pos_end;
316 bool empty_field, empty_key;
319 next_field_start = 0;
325 return (BWSLEN(s) + 1);
328 next_field_start = skip_fields_to_start(s, f2 + 1,
330 if ((next_field_start > 0) && sort_opts_vals.tflag &&
331 ((wchar_t)sort_opts_vals.field_sep == BWS_GET(s,
332 next_field_start - 1)))
335 next_field_start = skip_fields_to_start(s, f2,
339 if (empty_field || (next_field_start >= BWSLEN(s)))
340 return (BWSLEN(s) + 1);
343 pos_end = skip_cols_to_start(s, ks->c2, next_field_start,
344 ks->pos2b, &empty_key);
345 if (pos_end < BWSLEN(s))
348 pos_end = next_field_start;
354 * Cut a field according to the key specs
356 static struct bwstring *
357 cut_field(const struct bwstring *s, struct key_specs *ks)
359 struct bwstring *ret = NULL;
362 size_t field_start, key_end, key_start, sz;
363 bool empty_field, empty_key;
370 find_field_start(s, ks, &field_start, &key_start,
371 &empty_field, &empty_key);
376 key_end = find_field_end(s, ks);
377 sz = (key_end < key_start) ? 0 : (key_end - key_start);
382 bwsnocpy(ret, s, key_start, sz);
390 * Preprocesses a line applying the necessary transformations
391 * specified by command line options and returns the preprocessed
392 * string, which can be used to compare.
395 preproc(struct bwstring *s, struct keys_array *ka)
398 if (sort_opts_vals.kflag)
399 for (size_t i = 0; i < keys_num; i++) {
400 struct bwstring *key;
401 struct key_specs *kspecs;
402 struct sort_mods *sm;
405 key = cut_field(s, kspecs);
409 key = dictionary_order(key);
411 key = ignore_nonprinting(key);
412 if (sm->fflag || sm->Mflag)
413 key = ignore_case(key);
415 set_key_on_keys_array(ka, key, i);
418 struct bwstring *ret = NULL;
419 struct sort_mods *sm = default_sort_mods;
424 ret = ignore_leading_blanks(ret);
429 ret = dictionary_order(ret);
430 } else if (sm->iflag) {
433 ret = ignore_nonprinting(ret);
435 if (sm->fflag || sm->Mflag) {
438 ret = ignore_case(ret);
441 set_key_on_keys_array(ka, s, 0);
443 set_key_on_keys_array(ka, ret, 0);
450 get_sort_func(struct sort_mods *sm)
464 return (versioncoll);
470 * Compares the given strings. Returns a positive number if
471 * the first precedes the second, a negative number if the second is
472 * the preceding one, and zero if they are equal. This function calls
473 * the underlying collate functions, which done the actual comparison.
476 key_coll(struct keys_array *ps1, struct keys_array *ps2, size_t offset)
478 struct sort_mods *sm;
481 for (size_t i = 0; i < keys_num; ++i) {
485 res = sm->func(&(ps2->key[i]), &(ps1->key[i]), offset);
487 res = sm->func(&(ps1->key[i]), &(ps2->key[i]), offset);
492 /* offset applies to only the first key */
499 * Compare two strings.
500 * Plain symbol-by-symbol comparison.
503 top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2)
506 if (default_sort_mods->rflag) {
507 const struct bwstring *tmp;
514 return (bwscoll(s1, s2, 0));
518 * Compare a string and a sort list item, according to the sort specs.
521 str_list_coll(struct bwstring *str1, struct sort_list_item **ss2)
523 struct keys_array *ka1;
526 ka1 = keys_array_alloc();
530 sort_list_item_make_key(*ss2);
533 bwsprintf(stdout, str1, "; s1=<", ">");
534 bwsprintf(stdout, (*ss2)->str, ", s2=<", ">");
537 ret = key_coll(ka1, &((*ss2)->ka), 0);
540 printf("; cmp1=%d", ret);
542 clean_keys_array(str1, ka1);
545 if ((ret == 0) && !(sort_opts_vals.sflag) && sort_opts_vals.complex_sort) {
546 ret = top_level_str_coll(str1, ((*ss2)->str));
548 printf("; cmp2=%d", ret);
558 * Compare two sort list items, according to the sort specs.
561 list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2,
566 ret = key_coll(&((*ss1)->ka), &((*ss2)->ka), offset);
570 printf("; offset=%d", (int) offset);
571 bwsprintf(stdout, ((*ss1)->str), "; s1=<", ">");
572 bwsprintf(stdout, ((*ss2)->str), ", s2=<", ">");
573 printf("; cmp1=%d\n", ret);
579 if (!(sort_opts_vals.sflag) && sort_opts_vals.complex_sort) {
580 ret = top_level_str_coll(((*ss1)->str), ((*ss2)->str));
582 printf("; cmp2=%d\n", ret);
589 * Compare two sort list items, according to the sort specs.
592 list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2)
595 return (list_coll_offset(ss1, ss2, 0));
600 list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2) \
603 return (list_coll_offset(ss1, ss2, N)); \
628 get_list_call_func(size_t offset)
630 static const listcoll_t lsarray[] = { list_coll, list_coll_1,
631 list_coll_2, list_coll_3, list_coll_4, list_coll_5,
632 list_coll_6, list_coll_7, list_coll_8, list_coll_9,
633 list_coll_10, list_coll_11, list_coll_12, list_coll_13,
634 list_coll_14, list_coll_15, list_coll_16, list_coll_17,
635 list_coll_18, list_coll_19, list_coll_20 };
638 return (lsarray[offset]);
644 * Compare two sort list items, only by their original string.
647 list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2)
650 return (top_level_str_coll(((*ss1)->str), ((*ss2)->str)));
654 * Maximum size of a number in the string (before or after decimal point)
656 #define MAX_NUM_SIZE (128)
661 static void setsuffix(wchar_t c, unsigned char *si)
695 * Read string s and parse the string into a fixed-decimal-point number.
696 * sign equals -1 if the number is negative (explicit plus is not allowed,
697 * according to GNU sort's "info sort".
698 * The number part before decimal point is in the smain, after the decimal
699 * point is in sfrac, tail is the pointer to the remainder of the string.
702 read_number(struct bwstring *s0, int *sign, wchar_t *smain, size_t *main_len, wchar_t *sfrac, size_t *frac_len, unsigned char *si)
708 /* always end the fraction with zero, even if we have no fraction */
711 while (iswblank(bws_get_iter_value(s)))
712 s = bws_iterator_inc(s, 1);
714 if (bws_get_iter_value(s) == (wchar_t)symbol_negative_sign) {
716 s = bws_iterator_inc(s, 1);
719 // This is '0', not '\0', do not change this
720 while (iswdigit(bws_get_iter_value(s)) &&
721 (bws_get_iter_value(s) == L'0'))
722 s = bws_iterator_inc(s, 1);
724 while (bws_get_iter_value(s) && *main_len < MAX_NUM_SIZE) {
725 if (iswdigit(bws_get_iter_value(s))) {
726 smain[*main_len] = bws_get_iter_value(s);
727 s = bws_iterator_inc(s, 1);
729 } else if (symbol_thousands_sep &&
730 (bws_get_iter_value(s) == (wchar_t)symbol_thousands_sep))
731 s = bws_iterator_inc(s, 1);
736 smain[*main_len] = 0;
738 if (bws_get_iter_value(s) == (wchar_t)symbol_decimal_point) {
739 s = bws_iterator_inc(s, 1);
740 while (iswdigit(bws_get_iter_value(s)) &&
741 *frac_len < MAX_NUM_SIZE) {
742 sfrac[*frac_len] = bws_get_iter_value(s);
743 s = bws_iterator_inc(s, 1);
746 sfrac[*frac_len] = 0;
748 while (*frac_len > 0 && sfrac[*frac_len - 1] == L'0') {
750 sfrac[*frac_len] = L'\0';
754 setsuffix(bws_get_iter_value(s),si);
756 if ((*main_len + *frac_len) == 0)
763 * Implements string sort.
766 wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
771 printf("; offset=%d\n", (int) offset);
772 bwsprintf(stdout, kv1->k, "; k1=<", ">");
773 printf("(%zu)", BWSLEN(kv1->k));
774 bwsprintf(stdout, kv2->k, ", k2=<", ">");
775 printf("(%zu)", BWSLEN(kv2->k));
778 return (bwscoll(kv1->k, kv2->k, offset));
782 * Compare two suffixes
785 cmpsuffix(unsigned char si1, unsigned char si2)
788 return ((char)si1 - (char)si2);
792 * Implements numeric sort for -n and -h.
795 numcoll_impl(struct key_value *kv1, struct key_value *kv2,
796 size_t offset __unused, bool use_suffix)
798 struct bwstring *s1, *s2;
799 wchar_t sfrac1[MAX_NUM_SIZE + 1], sfrac2[MAX_NUM_SIZE + 1];
800 wchar_t smain1[MAX_NUM_SIZE + 1], smain2[MAX_NUM_SIZE + 1];
801 int cmp_res, sign1, sign2;
802 size_t frac1, frac2, main1, main2;
803 unsigned char SI1, SI2;
804 bool e1, e2, key1_read, key2_read;
813 key1_read = key2_read = false;
816 bwsprintf(stdout, s1, "; k1=<", ">");
817 bwsprintf(stdout, s2, ", k2=<", ">");
823 if (kv1->hint->status == HS_UNINITIALIZED) {
824 /* read the number from the string */
825 read_number(s1, &sign1, smain1, &main1, sfrac1, &frac1, &SI1);
827 kv1->hint->v.nh.n1 = wcstoull(smain1, NULL, 10);
828 if(main1 < 1 && frac1 < 1)
829 kv1->hint->v.nh.empty=true;
830 kv1->hint->v.nh.si = SI1;
831 kv1->hint->status = (kv1->hint->v.nh.n1 != ULLONG_MAX) ?
832 HS_INITIALIZED : HS_ERROR;
833 kv1->hint->v.nh.neg = (sign1 < 0) ? true : false;
836 if (kv2->hint->status == HS_UNINITIALIZED) {
837 /* read the number from the string */
838 read_number(s2, &sign2, smain2, &main2, sfrac2, &frac2,&SI2);
840 kv2->hint->v.nh.n1 = wcstoull(smain2, NULL, 10);
841 if(main2 < 1 && frac2 < 1)
842 kv2->hint->v.nh.empty=true;
843 kv2->hint->v.nh.si = SI2;
844 kv2->hint->status = (kv2->hint->v.nh.n1 != ULLONG_MAX) ?
845 HS_INITIALIZED : HS_ERROR;
846 kv2->hint->v.nh.neg = (sign2 < 0) ? true : false;
849 if (kv1->hint->status == HS_INITIALIZED && kv2->hint->status ==
851 unsigned long long n1, n2;
854 e1 = kv1->hint->v.nh.empty;
855 e2 = kv2->hint->v.nh.empty;
860 neg1 = kv1->hint->v.nh.neg;
861 neg2 = kv2->hint->v.nh.neg;
869 return (neg2 ? +1 : -1);
871 return (neg1 ? -1 : +1);
875 cmp_res = cmpsuffix(kv1->hint->v.nh.si, kv2->hint->v.nh.si);
877 return (neg1 ? -cmp_res : cmp_res);
880 n1 = kv1->hint->v.nh.n1;
881 n2 = kv2->hint->v.nh.n1;
883 return (neg1 ? +1 : -1);
885 return (neg1 ? -1 : +1);
888 /* read the numbers from the strings */
890 read_number(s1, &sign1, smain1, &main1, sfrac1, &frac1, &SI1);
892 read_number(s2, &sign2, smain2, &main2, sfrac2, &frac2, &SI2);
894 e1 = ((main1 + frac1) == 0);
895 e2 = ((main2 + frac2) == 0);
900 /* we know the result if the signs are different */
901 if (sign1 < 0 && sign2 >= 0)
903 if (sign1 >= 0 && sign2 < 0)
907 return ((sign2 < 0) ? +1 : -1);
909 return ((sign1 < 0) ? -1 : +1);
912 cmp_res = cmpsuffix(SI1, SI2);
914 return ((sign1 < 0) ? -cmp_res : cmp_res);
917 /* if both numbers are empty assume that the strings are equal */
918 if (main1 < 1 && main2 < 1 && frac1 < 1 && frac2 < 1)
922 * if the main part is of different size, we know the result
923 * (because the leading zeros are removed)
927 else if (main1 > main2)
929 /* if the sizes are equal then simple non-collate string compare gives the correct result */
931 cmp_res = wcscmp(smain1, smain2);
935 cmp_res = wcscmp(sfrac1, sfrac2);
940 /* reverse result if the signs are negative */
941 if (sign1 < 0 && sign2 < 0)
948 * Implements numeric sort (-n).
951 numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
954 return (numcoll_impl(kv1, kv2, offset, false));
958 * Implements 'human' numeric sort (-h).
961 hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
964 return (numcoll_impl(kv1, kv2, offset, true));
968 * Implements random sort (-R).
971 randomcoll(struct key_value *kv1, struct key_value *kv2,
972 size_t offset __unused)
974 struct bwstring *s1, *s2;
982 bwsprintf(stdout, s1, "; k1=<", ">");
983 bwsprintf(stdout, s2, ", k2=<", ">");
989 memcpy(&ctx1,&md5_ctx,sizeof(MD5_CTX));
990 memcpy(&ctx2,&md5_ctx,sizeof(MD5_CTX));
992 MD5Update(&ctx1, bwsrawdata(s1), bwsrawlen(s1));
993 MD5Update(&ctx2, bwsrawdata(s2), bwsrawlen(s2));
994 b1 = MD5End(&ctx1, NULL);
995 b2 = MD5End(&ctx2, NULL);
1003 } else if (b2 == NULL) {
1009 cmp_res = strcmp(b1,b2);
1014 cmp_res = bwscoll(s1, s2, 0);
1021 * Implements version sort (-V).
1024 versioncoll(struct key_value *kv1, struct key_value *kv2,
1025 size_t offset __unused)
1027 struct bwstring *s1, *s2;
1033 bwsprintf(stdout, s1, "; k1=<", ">");
1034 bwsprintf(stdout, s2, ", k2=<", ">");
1040 return (vcmp(s1, s2));
1044 * Check for minus infinity
1047 huge_minus(double d, int err1)
1051 if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL)
1058 * Check for plus infinity
1061 huge_plus(double d, int err1)
1065 if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL)
1072 * Check whether a function is a NAN
1078 return ((d == NAN) || (isnan(d)));
1085 cmp_nans(double d1, double d2)
1096 * Implements general numeric sort (-g).
1099 gnumcoll(struct key_value *kv1, struct key_value *kv2,
1100 size_t offset __unused)
1104 bool empty1, empty2, key1_read, key2_read;
1108 key1_read = key2_read = false;
1111 bwsprintf(stdout, kv1->k, "; k1=<", ">");
1112 bwsprintf(stdout, kv2->k, "; k2=<", ">");
1115 if (kv1->hint->status == HS_UNINITIALIZED) {
1117 d1 = bwstod(kv1->k, &empty1);
1121 kv1->hint->v.gh.notnum = true;
1122 else if (err1 == 0) {
1123 kv1->hint->v.gh.d = d1;
1124 kv1->hint->v.gh.nan = is_nan(d1);
1125 kv1->hint->status = HS_INITIALIZED;
1127 kv1->hint->status = HS_ERROR;
1132 if (kv2->hint->status == HS_UNINITIALIZED) {
1134 d2 = bwstod(kv2->k, &empty2);
1138 kv2->hint->v.gh.notnum = true;
1139 else if (err2 == 0) {
1140 kv2->hint->v.gh.d = d2;
1141 kv2->hint->v.gh.nan = is_nan(d2);
1142 kv2->hint->status = HS_INITIALIZED;
1144 kv2->hint->status = HS_ERROR;
1149 if (kv1->hint->status == HS_INITIALIZED &&
1150 kv2->hint->status == HS_INITIALIZED) {
1151 if (kv1->hint->v.gh.notnum)
1152 return ((kv2->hint->v.gh.notnum) ? 0 : -1);
1153 else if (kv2->hint->v.gh.notnum)
1156 if (kv1->hint->v.gh.nan)
1157 return ((kv2->hint->v.gh.nan) ?
1158 cmp_nans(kv1->hint->v.gh.d, kv2->hint->v.gh.d) :
1160 else if (kv2->hint->v.gh.nan)
1163 d1 = kv1->hint->v.gh.d;
1164 d2 = kv2->hint->v.gh.d;
1176 d1 = bwstod(kv1->k, &empty1);
1182 d2 = bwstod(kv2->k, &empty2);
1186 /* Non-value case: */
1188 return (empty2 ? 0 : -1);
1194 return (is_nan(d2) ? cmp_nans(d1, d2) : -1);
1195 else if (is_nan(d2))
1199 if (err1 == ERANGE || err2 == ERANGE) {
1200 /* Minus infinity case */
1201 if (huge_minus(d1, err1)) {
1202 if (huge_minus(d2, err2)) {
1211 } else if (huge_minus(d2, err2)) {
1212 if (huge_minus(d1, err1)) {
1222 /* Plus infinity case */
1223 if (huge_plus(d1, err1)) {
1224 if (huge_plus(d2, err2)) {
1232 } else if (huge_plus(d2, err2)) {
1233 if (huge_plus(d1, err1)) {
1253 * Implements month sort (-M).
1256 monthcoll(struct key_value *kv1, struct key_value *kv2, size_t offset __unused)
1259 bool key1_read, key2_read;
1262 key1_read = key2_read = false;
1265 bwsprintf(stdout, kv1->k, "; k1=<", ">");
1266 bwsprintf(stdout, kv2->k, "; k2=<", ">");
1269 if (kv1->hint->status == HS_UNINITIALIZED) {
1270 kv1->hint->v.Mh.m = bws_month_score(kv1->k);
1272 kv1->hint->status = HS_INITIALIZED;
1275 if (kv2->hint->status == HS_UNINITIALIZED) {
1276 kv2->hint->v.Mh.m = bws_month_score(kv2->k);
1278 kv2->hint->status = HS_INITIALIZED;
1281 if (kv1->hint->status == HS_INITIALIZED) {
1282 val1 = kv1->hint->v.Mh.m;
1286 if (kv2->hint->status == HS_INITIALIZED) {
1287 val2 = kv2->hint->v.Mh.m;
1292 val1 = bws_month_score(kv1->k);
1294 val2 = bws_month_score(kv2->k);