Annotation of src/usr.bin/sort/coll.h, Revision 1.1
1.1 ! millert 1: /* $OpenBSD$ */
! 2:
! 3: /*-
! 4: * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org>
! 5: * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com>
! 6: * All rights reserved.
! 7: *
! 8: * Redistribution and use in source and binary forms, with or without
! 9: * modification, are permitted provided that the following conditions
! 10: * are met:
! 11: * 1. Redistributions of source code must retain the above copyright
! 12: * notice, this list of conditions and the following disclaimer.
! 13: * 2. Redistributions in binary form must reproduce the above copyright
! 14: * notice, this list of conditions and the following disclaimer in the
! 15: * documentation and/or other materials provided with the distribution.
! 16: *
! 17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
! 18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
! 21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 27: * SUCH DAMAGE.
! 28: */
! 29:
! 30: #if !defined(__COLL_H__)
! 31: #define __COLL_H__
! 32:
! 33: #include "bwstring.h"
! 34: #include "sort.h"
! 35:
! 36: /*
! 37: * Sort hint data for -n
! 38: */
! 39: struct n_hint {
! 40: unsigned long long n1;
! 41: unsigned char si;
! 42: bool empty;
! 43: bool neg;
! 44: };
! 45:
! 46: /*
! 47: * Sort hint data for -g
! 48: */
! 49: struct g_hint {
! 50: double d;
! 51: bool nan;
! 52: bool notnum;
! 53: };
! 54:
! 55: /*
! 56: * Sort hint data for -M
! 57: */
! 58: struct M_hint {
! 59: int m;
! 60: };
! 61:
! 62: /*
! 63: * Status of a sort hint object
! 64: */
! 65: typedef enum {
! 66: HS_ERROR = -1, HS_UNINITIALIZED = 0, HS_INITIALIZED = 1
! 67: } hint_status;
! 68:
! 69: /*
! 70: * Sort hint object
! 71: */
! 72: struct key_hint {
! 73: hint_status status;
! 74: union
! 75: {
! 76: struct n_hint nh;
! 77: struct g_hint gh;
! 78: struct M_hint Mh;
! 79: } v;
! 80: };
! 81:
! 82: /*
! 83: * Key value
! 84: */
! 85: struct key_value {
! 86: struct bwstring *k; /* key string */
! 87: struct key_hint hint[0]; /* key sort hint */
! 88: };
! 89:
! 90: /*
! 91: * Set of keys container object.
! 92: */
! 93: struct keys_array {
! 94: struct key_value key[0];
! 95: };
! 96:
! 97: /*
! 98: * Parsed -k option data
! 99: */
! 100: struct key_specs {
! 101: struct sort_mods sm;
! 102: size_t c1;
! 103: size_t c2;
! 104: size_t f1;
! 105: size_t f2;
! 106: bool pos1b;
! 107: bool pos2b;
! 108: };
! 109:
! 110: /*
! 111: * Single entry in sort list.
! 112: */
! 113: struct sort_list_item {
! 114: struct bwstring *str;
! 115: struct keys_array ka;
! 116: };
! 117:
! 118: /*
! 119: * Function type, used to compare two list objects
! 120: */
! 121: typedef int (*listcoll_t)(struct sort_list_item **ss1, struct sort_list_item **ss2);
! 122:
! 123: extern struct key_specs *keys;
! 124: extern size_t keys_num;
! 125:
! 126: /*
! 127: * Main localised symbols. These must be wint_t as they may hold WEOF.
! 128: */
! 129: extern wint_t symbol_decimal_point;
! 130: extern wint_t symbol_thousands_sep;
! 131: extern wint_t symbol_negative_sign;
! 132: extern wint_t symbol_positive_sign;
! 133:
! 134: /* funcs */
! 135:
! 136: cmpcoll_t get_sort_func(struct sort_mods *sm);
! 137:
! 138: struct keys_array *keys_array_alloc(void);
! 139: size_t keys_array_size(void);
! 140: void set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind);
! 141: void clean_keys_array(const struct bwstring *s, struct keys_array *ka);
! 142:
! 143: struct sort_list_item *sort_list_item_alloc(void);
! 144: void sort_list_item_set(struct sort_list_item *si, struct bwstring *str);
! 145: void sort_list_item_clean(struct sort_list_item *si);
! 146: size_t sort_list_item_size(struct sort_list_item *si);
! 147:
! 148: int preproc(struct bwstring *s, struct keys_array *ka);
! 149: int top_level_str_coll(const struct bwstring *, const struct bwstring *);
! 150: int key_coll(struct keys_array *ks1, struct keys_array *ks2, size_t offset);
! 151: int str_list_coll(struct bwstring *str1, struct sort_list_item **ss2);
! 152: int list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2);
! 153: int list_coll(const void *ss1, const void *ss2);
! 154: int list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2, size_t offset);
! 155:
! 156: listcoll_t get_list_call_func(size_t offset);
! 157:
! 158: #endif /* __COLL_H__ */