Deleted Added
full compact
coll.c (236764) coll.c (242430)
1/*-
2 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
3 * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko@citrix.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

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
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
3 * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko@citrix.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

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
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/usr.bin/sort/coll.c 236764 2012-06-08 19:21:49Z gabor $");
29__FBSDID("$FreeBSD: head/usr.bin/sort/coll.c 242430 2012-11-01 11:38:34Z gabor $");
30
31#include <sys/types.h>
32
33#include <errno.h>
34#include <err.h>
35#include <langinfo.h>
36#include <limits.h>
37#include <math.h>

--- 4 unchanged lines hidden (view full) ---

42#include <wctype.h>
43
44#include "coll.h"
45#include "vsort.h"
46
47struct key_specs *keys;
48size_t keys_num = 0;
49
30
31#include <sys/types.h>
32
33#include <errno.h>
34#include <err.h>
35#include <langinfo.h>
36#include <limits.h>
37#include <math.h>

--- 4 unchanged lines hidden (view full) ---

42#include <wctype.h>
43
44#include "coll.h"
45#include "vsort.h"
46
47struct key_specs *keys;
48size_t keys_num = 0;
49
50wchar_t symbol_decimal_point = L'.';
50wint_t symbol_decimal_point = L'.';
51/* there is no default thousands separator in collate rules: */
51/* there is no default thousands separator in collate rules: */
52wchar_t symbol_thousands_sep = 0;
53wchar_t symbol_negative_sign = L'-';
54wchar_t symbol_positive_sign = L'+';
52wint_t symbol_thousands_sep = 0;
53wint_t symbol_negative_sign = L'-';
54wint_t symbol_positive_sign = L'+';
55
56static int wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset);
57static int gnumcoll(struct key_value*, struct key_value *, size_t offset);
58static int monthcoll(struct key_value*, struct key_value *, size_t offset);
59static int numcoll(struct key_value*, struct key_value *, size_t offset);
60static int hnumcoll(struct key_value*, struct key_value *, size_t offset);
61static int randomcoll(struct key_value*, struct key_value *, size_t offset);
62static int versioncoll(struct key_value*, struct key_value *, size_t offset);

--- 192 unchanged lines hidden (view full) ---

255 return (0);
256 } else if (!(sort_opts_vals.tflag)) {
257 size_t cpos = 0;
258 bool pb = true;
259
260 while (cpos < BWSLEN(s)) {
261 bool isblank;
262
55
56static int wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset);
57static int gnumcoll(struct key_value*, struct key_value *, size_t offset);
58static int monthcoll(struct key_value*, struct key_value *, size_t offset);
59static int numcoll(struct key_value*, struct key_value *, size_t offset);
60static int hnumcoll(struct key_value*, struct key_value *, size_t offset);
61static int randomcoll(struct key_value*, struct key_value *, size_t offset);
62static int versioncoll(struct key_value*, struct key_value *, size_t offset);

--- 192 unchanged lines hidden (view full) ---

255 return (0);
256 } else if (!(sort_opts_vals.tflag)) {
257 size_t cpos = 0;
258 bool pb = true;
259
260 while (cpos < BWSLEN(s)) {
261 bool isblank;
262
263 isblank = iswblank(BWS_GET(s,cpos));
263 isblank = iswblank(BWS_GET(s, cpos));
264
265 if (isblank && !pb) {
266 --fields;
267 if (fields <= 1)
268 return (cpos);
269 }
270 pb = isblank;
271 ++cpos;
272 }
273 if (fields > 1)
274 *empty_field = true;
275 return (cpos);
276 } else {
277 size_t cpos = 0;
278
279 while (cpos < BWSLEN(s)) {
264
265 if (isblank && !pb) {
266 --fields;
267 if (fields <= 1)
268 return (cpos);
269 }
270 pb = isblank;
271 ++cpos;
272 }
273 if (fields > 1)
274 *empty_field = true;
275 return (cpos);
276 } else {
277 size_t cpos = 0;
278
279 while (cpos < BWSLEN(s)) {
280 if (BWS_GET(s,cpos) == sort_opts_vals.field_sep) {
280 if (BWS_GET(s,cpos) == (wchar_t)sort_opts_vals.field_sep) {
281 --fields;
282 if (fields <= 1)
283 return (cpos + 1);
284 }
285 ++cpos;
286 }
287 if (fields > 1)
288 *empty_field = true;

--- 34 unchanged lines hidden (view full) ---

323
324 if (f2 == 0)
325 return (BWSLEN(s) + 1);
326 else {
327 if (ks->c2 == 0) {
328 next_field_start = skip_fields_to_start(s, f2 + 1,
329 &empty_field);
330 if ((next_field_start > 0) && sort_opts_vals.tflag &&
281 --fields;
282 if (fields <= 1)
283 return (cpos + 1);
284 }
285 ++cpos;
286 }
287 if (fields > 1)
288 *empty_field = true;

--- 34 unchanged lines hidden (view full) ---

323
324 if (f2 == 0)
325 return (BWSLEN(s) + 1);
326 else {
327 if (ks->c2 == 0) {
328 next_field_start = skip_fields_to_start(s, f2 + 1,
329 &empty_field);
330 if ((next_field_start > 0) && sort_opts_vals.tflag &&
331 (sort_opts_vals.field_sep == BWS_GET(s,
331 ((wchar_t)sort_opts_vals.field_sep == BWS_GET(s,
332 next_field_start - 1)))
333 --next_field_start;
334 } else
335 next_field_start = skip_fields_to_start(s, f2,
336 &empty_field);
337 }
338
339 if (empty_field || (next_field_start >= BWSLEN(s)))

--- 354 unchanged lines hidden (view full) ---

694/*
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.
700 */
701static int
332 next_field_start - 1)))
333 --next_field_start;
334 } else
335 next_field_start = skip_fields_to_start(s, f2,
336 &empty_field);
337 }
338
339 if (empty_field || (next_field_start >= BWSLEN(s)))

--- 354 unchanged lines hidden (view full) ---

694/*
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.
700 */
701static int
702read_number(struct bwstring *s0, int *sign, wchar_t *smain, int *main_len, wchar_t *sfrac, int *frac_len, unsigned char *si)
702read_number(struct bwstring *s0, int *sign, wchar_t *smain, size_t *main_len, wchar_t *sfrac, size_t *frac_len, unsigned char *si)
703{
704 bwstring_iterator s;
705
706 s = bws_begin(s0);
707
708 /* always end the fraction with zero, even if we have no fraction */
709 sfrac[0] = 0;
710
711 while (iswblank(bws_get_iter_value(s)))
712 s = bws_iterator_inc(s, 1);
713
703{
704 bwstring_iterator s;
705
706 s = bws_begin(s0);
707
708 /* always end the fraction with zero, even if we have no fraction */
709 sfrac[0] = 0;
710
711 while (iswblank(bws_get_iter_value(s)))
712 s = bws_iterator_inc(s, 1);
713
714 if (bws_get_iter_value(s) == symbol_negative_sign) {
714 if (bws_get_iter_value(s) == (wchar_t)symbol_negative_sign) {
715 *sign = -1;
716 s = bws_iterator_inc(s, 1);
717 }
718
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);
723
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);
728 *main_len += 1;
729 } else if (symbol_thousands_sep &&
715 *sign = -1;
716 s = bws_iterator_inc(s, 1);
717 }
718
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);
723
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);
728 *main_len += 1;
729 } else if (symbol_thousands_sep &&
730 (bws_get_iter_value(s) == symbol_thousands_sep))
730 (bws_get_iter_value(s) == (wchar_t)symbol_thousands_sep))
731 s = bws_iterator_inc(s, 1);
732 else
733 break;
734 }
735
736 smain[*main_len] = 0;
737
731 s = bws_iterator_inc(s, 1);
732 else
733 break;
734 }
735
736 smain[*main_len] = 0;
737
738 if (bws_get_iter_value(s) == symbol_decimal_point) {
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);
744 *frac_len += 1;
745 }
746 sfrac[*frac_len] = 0;

--- 46 unchanged lines hidden (view full) ---

793 */
794static int
795numcoll_impl(struct key_value *kv1, struct key_value *kv2,
796 size_t offset __unused, bool use_suffix)
797{
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];
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);
744 *frac_len += 1;
745 }
746 sfrac[*frac_len] = 0;

--- 46 unchanged lines hidden (view full) ---

793 */
794static int
795numcoll_impl(struct key_value *kv1, struct key_value *kv2,
796 size_t offset __unused, bool use_suffix)
797{
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, frac1, frac2, main1, main2, sign1, sign2;
801 int cmp_res, sign1, sign2;
802 size_t frac1, frac2, main1, main2;
802 unsigned char SI1, SI2;
803 bool e1, e2, key1_read, key2_read;
804
805 s1 = kv1->k;
806 s2 = kv2->k;
807 sign1 = sign2 = 0;
808 main1 = main2 = 0;
809 frac1 = frac2 = 0;

--- 492 unchanged lines hidden ---
803 unsigned char SI1, SI2;
804 bool e1, e2, key1_read, key2_read;
805
806 s1 = kv1->k;
807 s2 = kv2->k;
808 sign1 = sign2 = 0;
809 main1 = main2 = 0;
810 frac1 = frac2 = 0;

--- 492 unchanged lines hidden ---