1c66bbc91SGabor Kovesdan 2c66bbc91SGabor Kovesdan /*- 3*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 41de7b4b8SPedro F. Giffuni * 5c66bbc91SGabor Kovesdan * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 6c859c6ddSGabor Kovesdan * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com> 7c66bbc91SGabor Kovesdan * All rights reserved. 8c66bbc91SGabor Kovesdan * 9c66bbc91SGabor Kovesdan * Redistribution and use in source and binary forms, with or without 10c66bbc91SGabor Kovesdan * modification, are permitted provided that the following conditions 11c66bbc91SGabor Kovesdan * are met: 12c66bbc91SGabor Kovesdan * 1. Redistributions of source code must retain the above copyright 13c66bbc91SGabor Kovesdan * notice, this list of conditions and the following disclaimer. 14c66bbc91SGabor Kovesdan * 2. Redistributions in binary form must reproduce the above copyright 15c66bbc91SGabor Kovesdan * notice, this list of conditions and the following disclaimer in the 16c66bbc91SGabor Kovesdan * documentation and/or other materials provided with the distribution. 17c66bbc91SGabor Kovesdan * 18c66bbc91SGabor Kovesdan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19c66bbc91SGabor Kovesdan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20c66bbc91SGabor Kovesdan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21c66bbc91SGabor Kovesdan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22c66bbc91SGabor Kovesdan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23c66bbc91SGabor Kovesdan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24c66bbc91SGabor Kovesdan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25c66bbc91SGabor Kovesdan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26c66bbc91SGabor Kovesdan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27c66bbc91SGabor Kovesdan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28c66bbc91SGabor Kovesdan * SUCH DAMAGE. 29c66bbc91SGabor Kovesdan */ 30c66bbc91SGabor Kovesdan 31c66bbc91SGabor Kovesdan #if !defined(__BSD_SORT_H__) 32c66bbc91SGabor Kovesdan #define __BSD_SORT_H__ 33c66bbc91SGabor Kovesdan 34c66bbc91SGabor Kovesdan #include <errno.h> 35c66bbc91SGabor Kovesdan #include <stdbool.h> 36c66bbc91SGabor Kovesdan #include <stdio.h> 37c66bbc91SGabor Kovesdan #include <sysexits.h> 38c66bbc91SGabor Kovesdan #include <wchar.h> 39c66bbc91SGabor Kovesdan 40c66bbc91SGabor Kovesdan #include <sys/types.h> 41c66bbc91SGabor Kovesdan #include <md5.h> 42c66bbc91SGabor Kovesdan 43c66bbc91SGabor Kovesdan #define VERSION "2.3-FreeBSD" 44c66bbc91SGabor Kovesdan 45c66bbc91SGabor Kovesdan #define getstr(n) nlsstr[n] 46c66bbc91SGabor Kovesdan 47c66bbc91SGabor Kovesdan extern const char *nlsstr[]; 48c66bbc91SGabor Kovesdan 49c66bbc91SGabor Kovesdan #if defined(SORT_THREADS) 505ca724dcSGabor Kovesdan #define MT_SORT_THRESHOLD (10000) 51ab28d4d3SGabor Kovesdan extern unsigned int ncpu; 52c66bbc91SGabor Kovesdan extern size_t nthreads; 53c66bbc91SGabor Kovesdan #endif 54c66bbc91SGabor Kovesdan 55c66bbc91SGabor Kovesdan /* 56c66bbc91SGabor Kovesdan * If true, we output some debug information. 57c66bbc91SGabor Kovesdan */ 58c66bbc91SGabor Kovesdan extern bool debug_sort; 59c66bbc91SGabor Kovesdan 60c66bbc91SGabor Kovesdan /* 61c66bbc91SGabor Kovesdan * MD5 context for random hash function 62c66bbc91SGabor Kovesdan */ 63c66bbc91SGabor Kovesdan extern MD5_CTX md5_ctx; 64c66bbc91SGabor Kovesdan 65c66bbc91SGabor Kovesdan /* 66c66bbc91SGabor Kovesdan * sort.c 67c66bbc91SGabor Kovesdan */ 68c66bbc91SGabor Kovesdan 69c66bbc91SGabor Kovesdan /* 70c66bbc91SGabor Kovesdan * This structure holds main sort options which are NOT affecting the sort ordering. 71c66bbc91SGabor Kovesdan */ 72c66bbc91SGabor Kovesdan struct sort_opts 73c66bbc91SGabor Kovesdan { 74e8da8c74SGabor Kovesdan wint_t field_sep; 75c66bbc91SGabor Kovesdan int sort_method; 76c66bbc91SGabor Kovesdan bool cflag; 77c66bbc91SGabor Kovesdan bool csilentflag; 78c66bbc91SGabor Kovesdan bool kflag; 79c66bbc91SGabor Kovesdan bool mflag; 80c66bbc91SGabor Kovesdan bool sflag; 81c66bbc91SGabor Kovesdan bool uflag; 82c66bbc91SGabor Kovesdan bool zflag; 83c66bbc91SGabor Kovesdan bool tflag; 84c66bbc91SGabor Kovesdan bool complex_sort; 85c66bbc91SGabor Kovesdan }; 86c66bbc91SGabor Kovesdan 87c66bbc91SGabor Kovesdan /* 88c66bbc91SGabor Kovesdan * Key value structure forward declaration 89c66bbc91SGabor Kovesdan */ 90c66bbc91SGabor Kovesdan struct key_value; 91c66bbc91SGabor Kovesdan 92c66bbc91SGabor Kovesdan /* 93c66bbc91SGabor Kovesdan * Cmp function 94c66bbc91SGabor Kovesdan */ 95c66bbc91SGabor Kovesdan typedef int (*cmpcoll_t)(struct key_value *kv1, struct key_value *kv2, size_t offset); 96c66bbc91SGabor Kovesdan 97c66bbc91SGabor Kovesdan /* 98c66bbc91SGabor Kovesdan * This structure holds "sort modifiers" - options which are affecting the sort ordering. 99c66bbc91SGabor Kovesdan */ 100c66bbc91SGabor Kovesdan struct sort_mods 101c66bbc91SGabor Kovesdan { 102c66bbc91SGabor Kovesdan cmpcoll_t func; 103c66bbc91SGabor Kovesdan bool bflag; 104c66bbc91SGabor Kovesdan bool dflag; 105c66bbc91SGabor Kovesdan bool fflag; 106c66bbc91SGabor Kovesdan bool gflag; 107c66bbc91SGabor Kovesdan bool iflag; 108c66bbc91SGabor Kovesdan bool Mflag; 109c66bbc91SGabor Kovesdan bool nflag; 110c66bbc91SGabor Kovesdan bool rflag; 111c66bbc91SGabor Kovesdan bool Rflag; 112c66bbc91SGabor Kovesdan bool Vflag; 113c66bbc91SGabor Kovesdan bool hflag; 114c66bbc91SGabor Kovesdan }; 115c66bbc91SGabor Kovesdan 116c66bbc91SGabor Kovesdan extern bool need_hint; 117c66bbc91SGabor Kovesdan 118c66bbc91SGabor Kovesdan extern struct sort_opts sort_opts_vals; 119c66bbc91SGabor Kovesdan 120c66bbc91SGabor Kovesdan extern struct sort_mods * const default_sort_mods; 121c66bbc91SGabor Kovesdan 12271ec05a2SCyril Zhang /* 12371ec05a2SCyril Zhang * Cached value of MB_CUR_MAX. Because MB_CUR_MAX is used often throughout the program, 12471ec05a2SCyril Zhang * this avoids frequent calls to __mb_cur_max. 12571ec05a2SCyril Zhang */ 12671ec05a2SCyril Zhang extern size_t mb_cur_max; 12771ec05a2SCyril Zhang 128c66bbc91SGabor Kovesdan #endif /* __BSD_SORT_H__ */ 129