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(__SORT_FILE_H__)
33 #define __SORT_FILE_H__
38 #define SORT_DEFAULT 0
40 #define SORT_MERGESORT 2
41 #define SORT_HEAPSORT 3
42 #define SORT_RADIXSORT 4
44 #define DEFAULT_SORT_ALGORITHM SORT_HEAPSORT
45 #define DEFAULT_SORT_FUNC heapsort
48 * List of data to be sorted.
52 struct sort_list_item **list;
53 unsigned long long memsize;
65 * List of files to be sorted
79 extern unsigned long long free_memory;
80 extern unsigned long long available_free_memory;
82 /* Are we using mmap ? */
85 /* temporary file dir */
87 extern const char *tmpdir;
90 * Max number of simultaneously open files (including the output file).
92 extern size_t max_open_files;
97 extern const char* compress_program;
101 struct file_reader *file_reader_init(const char *fsrc);
102 struct bwstring *file_reader_readline(struct file_reader *fr);
103 void file_reader_free(struct file_reader *fr);
105 void init_tmp_files(void);
106 void clear_tmp_files(void);
107 char *new_tmp_file_name(void);
108 void tmp_file_atexit(const char *tmp_file);
110 void file_list_init(struct file_list *fl, bool tmp);
111 void file_list_add(struct file_list *fl, const char *fn, bool allocate);
112 void file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate);
113 void file_list_clean(struct file_list *fl);
115 int check(const char *);
116 void merge_files(struct file_list *fl, const char *fn_out);
117 FILE *openfile(const char *, const char *);
118 void closefile(FILE *, const char *);
119 int procfile(const char *fn, struct sort_list *list, struct file_list *fl);
121 void sort_list_init(struct sort_list *l);
122 void sort_list_add(struct sort_list *l, struct bwstring *str);
123 void sort_list_clean(struct sort_list *l);
124 void sort_list_dump(struct sort_list *l, const char *fn);
126 void sort_list_to_file(struct sort_list *list, const char *outfile);
128 #endif /* __SORT_FILE_H__ */