1235267Sgabor/* $FreeBSD$ */ 2235267Sgabor 3235267Sgabor/*- 4235267Sgabor * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 5251245Sgabor * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com> 6235267Sgabor * All rights reserved. 7235267Sgabor * 8235267Sgabor * Redistribution and use in source and binary forms, with or without 9235267Sgabor * modification, are permitted provided that the following conditions 10235267Sgabor * are met: 11235267Sgabor * 1. Redistributions of source code must retain the above copyright 12235267Sgabor * notice, this list of conditions and the following disclaimer. 13235267Sgabor * 2. Redistributions in binary form must reproduce the above copyright 14235267Sgabor * notice, this list of conditions and the following disclaimer in the 15235267Sgabor * documentation and/or other materials provided with the distribution. 16235267Sgabor * 17235267Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18235267Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19235267Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20235267Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21235267Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22235267Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23235267Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24235267Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25235267Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26235267Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27235267Sgabor * SUCH DAMAGE. 28235267Sgabor */ 29235267Sgabor 30235267Sgabor#if !defined(__BSD_SORT_H__) 31265160Spfg#define __BSD_SORT_H__ 32235267Sgabor 33235267Sgabor#include <errno.h> 34235267Sgabor#include <stdbool.h> 35235267Sgabor#include <stdio.h> 36235267Sgabor#include <sysexits.h> 37235267Sgabor#include <wchar.h> 38235267Sgabor 39235267Sgabor#include <sys/types.h> 40235267Sgabor#include <md5.h> 41235267Sgabor 42235267Sgabor#define VERSION "2.3-FreeBSD" 43235267Sgabor 44235267Sgabor#ifdef WITHOUT_NLS 45235267Sgabor#define getstr(n) nlsstr[n] 46235267Sgabor#else 47235267Sgabor#include <nl_types.h> 48235267Sgabor 49235267Sgaborextern nl_catd catalog; 50235267Sgabor#define getstr(n) catgets(catalog, 1, n, nlsstr[n]) 51235267Sgabor#endif 52235267Sgabor 53235267Sgaborextern const char *nlsstr[]; 54235267Sgabor 55235267Sgabor#if defined(SORT_THREADS) 56265160Spfg#define MT_SORT_THRESHOLD (10000) 57244346Sgaborextern unsigned int ncpu; 58235267Sgaborextern size_t nthreads; 59235267Sgabor#endif 60235267Sgabor 61235267Sgabor/* 62235267Sgabor * If true, we output some debug information. 63235267Sgabor */ 64235267Sgaborextern bool debug_sort; 65235267Sgabor 66235267Sgabor/* 67235267Sgabor * MD5 context for random hash function 68235267Sgabor */ 69235267Sgaborextern MD5_CTX md5_ctx; 70235267Sgabor 71235267Sgabor/* 72235267Sgabor * sort.c 73235267Sgabor */ 74235267Sgabor 75235267Sgabor/* 76235267Sgabor * This structure holds main sort options which are NOT affecting the sort ordering. 77235267Sgabor */ 78235267Sgaborstruct sort_opts 79235267Sgabor{ 80242430Sgabor wint_t field_sep; 81235267Sgabor int sort_method; 82235267Sgabor bool cflag; 83235267Sgabor bool csilentflag; 84235267Sgabor bool kflag; 85235267Sgabor bool mflag; 86235267Sgabor bool sflag; 87235267Sgabor bool uflag; 88235267Sgabor bool zflag; 89235267Sgabor bool tflag; 90235267Sgabor bool complex_sort; 91235267Sgabor}; 92235267Sgabor 93235267Sgabor/* 94235267Sgabor * Key value structure forward declaration 95235267Sgabor */ 96235267Sgaborstruct key_value; 97235267Sgabor 98235267Sgabor/* 99235267Sgabor * Cmp function 100235267Sgabor */ 101235267Sgabortypedef int (*cmpcoll_t)(struct key_value *kv1, struct key_value *kv2, size_t offset); 102235267Sgabor 103235267Sgabor/* 104235267Sgabor * This structure holds "sort modifiers" - options which are affecting the sort ordering. 105235267Sgabor */ 106235267Sgaborstruct sort_mods 107235267Sgabor{ 108235267Sgabor cmpcoll_t func; 109235267Sgabor bool bflag; 110235267Sgabor bool dflag; 111235267Sgabor bool fflag; 112235267Sgabor bool gflag; 113235267Sgabor bool iflag; 114235267Sgabor bool Mflag; 115235267Sgabor bool nflag; 116235267Sgabor bool rflag; 117235267Sgabor bool Rflag; 118235267Sgabor bool Vflag; 119235267Sgabor bool hflag; 120235267Sgabor}; 121235267Sgabor 122235267Sgaborextern bool need_hint; 123235267Sgabor 124235267Sgaborextern struct sort_opts sort_opts_vals; 125235267Sgabor 126235267Sgaborextern struct sort_mods * const default_sort_mods; 127235267Sgabor 128235267Sgabor#endif /* __BSD_SORT_H__ */ 129