4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
7 * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #if !defined(__COLL_H__)
39 * Sort hint data for -n
43 unsigned long long n1;
50 * Sort hint data for -g
60 * Sort hint data for -M
68 * Status of a sort hint object
72 HS_ERROR = -1, HS_UNINITIALIZED = 0, HS_INITIALIZED = 1
94 struct bwstring *k; /* key string */
95 struct key_hint hint[0]; /* key sort hint */
99 * Set of keys container object.
103 struct key_value key[0];
107 * Parsed -k option data
121 * Single entry in sort list.
123 struct sort_list_item
125 struct bwstring *str;
126 struct keys_array ka;
130 * Function type, used to compare two list objects
132 typedef int (*listcoll_t)(struct sort_list_item **ss1, struct sort_list_item **ss2);
134 extern struct key_specs *keys;
135 extern size_t keys_num;
138 * Main localised symbols. These must be wint_t as they may hold WEOF.
140 extern wint_t symbol_decimal_point;
141 extern wint_t symbol_thousands_sep;
142 extern wint_t symbol_negative_sign;
143 extern wint_t symbol_positive_sign;
147 cmpcoll_t get_sort_func(struct sort_mods *sm);
149 struct keys_array *keys_array_alloc(void);
150 size_t keys_array_size(void);
151 struct key_value *get_key_from_keys_array(struct keys_array *ka, size_t ind);
152 void set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind);
153 void clean_keys_array(const struct bwstring *s, struct keys_array *ka);
155 struct sort_list_item *sort_list_item_alloc(void);
156 void sort_list_item_set(struct sort_list_item *si, struct bwstring *str);
157 void sort_list_item_clean(struct sort_list_item *si);
158 size_t sort_list_item_size(struct sort_list_item *si);
160 int preproc(struct bwstring *s, struct keys_array *ka);
161 int top_level_str_coll(const struct bwstring *, const struct bwstring *);
162 int key_coll(struct keys_array *ks1, struct keys_array *ks2, size_t offset);
163 int str_list_coll(struct bwstring *str1, struct sort_list_item **ss2);
164 int list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2);
165 int list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2);
166 int list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2, size_t offset);
168 listcoll_t get_list_call_func(size_t offset);
170 #endif /* __COLL_H__ */