diff options
author | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
commit | 1f457376b478257b88d4a857f5ec1b6155442dd7 (patch) | |
tree | 2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk-sort.c | |
parent | ac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff) |
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk-sort.c')
-rw-r--r-- | support/dktools/dk-sort.c | 218 |
1 files changed, 111 insertions, 107 deletions
diff --git a/support/dktools/dk-sort.c b/support/dktools/dk-sort.c index 87a55cda5c..dbad5f1806 100644 --- a/support/dktools/dk-sort.c +++ b/support/dktools/dk-sort.c @@ -1,36 +1,14 @@ /* - WARNING: This file was generated by dkct. - Changes you make here will be lost if dkct is run again! - You should modify the original source and run dkct on it. - Original source: dk-sort.ctr +Copyright (C) 2015-2020, Dirk Krause +SPDX-License-Identifier: BSD-3-Clause */ /* -Copyright (C) 2015-2017, Dirk Krause - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above opyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -* Neither the name of the author nor the names of contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + WARNING: This file was generated by the dkct program (see + http://dktools.sourceforge.net/ for details). + Changes you make here will be lost if dkct is run again! + You should modify the original source and run dkct on it. + Original source: dk-sort.ctr */ /** @file dk-sort.c The dk-sort module. @@ -95,12 +73,16 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "dk4fopda.h" #include "dk4pathd.h" #include "dk4filed.h" +#include "dk4unused.h" +#ifndef DK4WMAIN_H_INCLUDED +#include "dk4wmain.h" +#endif -#line 69 "dk-sort.ctr" +#line 73 "dk-sort.ctr" @@ -149,12 +131,12 @@ dkT("--manual\t\t\t\t\t*** SHOW FULL MANUAL. ***"), dkT("--version\t\t\t\t\tShow version information."), dkT("--license\t\t\t\t\tShow license information."), dkT(""), -dkT("http://dktools.sourceforge.net"), +dkT("http://sourceforge.net/p/dktools/wiki/dk-sort/"), dkT(""), NULL -#line 121 "dk-sort.ctr" +#line 125 "dk-sort.ctr" }; @@ -166,7 +148,8 @@ dkT("This software uses code from the following projects, either directly or as" dkT("a library:"), dkT(""), dkT("dktools\t\tDirk Krause's tools and libraries."), -dkT("\t\tSee http://dktools.sourceforge.net/ for more information."), +dkT("\t\tSee http://sourceforge.net/p/dktools/wiki/Home/"), +dkT("\t\tfor more information."), #if DK4_HAVE_ZLIB_H dkT(""), dkT("zlib\t\tData compression library."), @@ -193,27 +176,27 @@ dkT(""), dkT("Redistribution and use in source and binary forms, with or without"), dkT("modification, are permitted provided that the following conditions are met:"), dkT(""), -dkT("* Redistributions of source code must retain the above copyright notice,"), -dkT(" this list of conditions and the following disclaimer."), -dkT("* Redistributions in binary form must reproduce the above copyright"), -dkT(" notice, this list of conditions and the following disclaimer in the"), -dkT(" documentation and/or other materials provided with the distribution."), -dkT("* Neither the name of the Dirk Krause nor the names of contributors may be"), -dkT(" used to endorse or promote products derived from this software without"), -dkT(" specific prior written permission."), +dkT("1. Redistributions of source code must retain the above copyright notice,"), +dkT(" this list of conditions and the following disclaimer."), +dkT("2. Redistributions in binary form must reproduce the above copyright"), +dkT(" notice, this list of conditions and the following disclaimer in the"), +dkT(" documentation and/or other materials provided with the distribution."), +dkT("3. Neither the name of the copyright holder nor the names of its"), +dkT(" contributors may be used to endorse or promote products derived from"), +dkT(" this software without specific prior written permission."), dkT(""), -dkT("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\""), -dkT("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE"), -dkT("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE"), -dkT("ARE DISCLAIMED."), -dkT(""), -dkT("IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,"), -dkT("INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,"), -dkT("BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,"), -dkT("DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY"), -dkT("OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"), -dkT("NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,"), -dkT("EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."), +dkT("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"), +dkT("``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT"), +dkT("LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR"), +dkT("A PARTICULAR PURPOSE ARE DISCLAIMED."), +dkT("IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY"), +dkT("DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES"), +dkT("(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR"), +dkT("SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER"), +dkT("CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT"), +dkT("LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY"), +dkT("OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF"), +dkT("SUCH DAMAGE."), #if DK4_HAVE_ZLIB_H dkT(""), dkT(""), @@ -287,7 +270,7 @@ dkT(""), NULL -#line 252 "dk-sort.ctr" +#line 257 "dk-sort.ctr" }; @@ -349,7 +332,7 @@ dkT("line.size"), NULL -#line 319 "dk-sort.ctr" +#line 324 "dk-sort.ctr" }; @@ -405,7 +388,7 @@ dkT("Failed to initialize text stream processing!"), NULL -#line 364 "dk-sort.ctr" +#line 369 "dk-sort.ctr" }; @@ -528,7 +511,13 @@ static int suppress_empty = 0; /** Expected input encoding. */ -static int input_encoding = DK4_FILE_ENCODING_ASCII; +static int input_encoding = +#if DK4_ON_WINDOWS + DK4_FILE_ENCODING_WIN1252 +#else + DK4_FILE_ENCODING_PLAIN +#endif +; @@ -601,8 +590,9 @@ sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr) */ static void -sig_handler_pipe(int signo) +sig_handler_pipe(int DK4_ARG_UNUSED(signo)) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_pipe) = 1; } #endif @@ -612,8 +602,9 @@ sig_handler_pipe(int signo) */ static void -sig_handler_int(int signo) +sig_handler_int(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_int) = 1; } @@ -622,8 +613,9 @@ sig_handler_int(int signo) */ static void -sig_handler_term(int signo) +sig_handler_term(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_term) = 1; } @@ -647,10 +639,18 @@ sig_read_atomic(DK4_VOLATILE dk4_sig_atomic_t *ap) */ static int -sig_can_continue(int check_pipe) +sig_can_continue( +#ifdef SIGPIPE + int check_pipe +#else + int DK4_ARG_UNUSED(check_pipe) +#endif +) { int back = 1; -#ifdef SIGPIPE +#ifndef SIGPIPE + DK4_UNUSED_ARG(check_pipe) +#else if (0 != check_pipe) { if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; } } @@ -687,14 +687,14 @@ dk_sort_delete_node(dk_sort_line_t *ptr) { -#line 644 "dk-sort.ctr" +#line 666 "dk-sort.ctr" if (NULL != ptr) { dk4mem_release(ptr->line); dk4mem_free(ptr); } -#line 649 "dk-sort.ctr" +#line 671 "dk-sort.ctr" } @@ -715,7 +715,7 @@ dk_sort_new_node(dkChar *line) dk4_im_t i; /* Evaluation integer */ -#line 668 "dk-sort.ctr" +#line 690 "dk-sort.ctr" /* Normalize or remove leading and trailing whitespace if required. */ if (NULL != line) { @@ -804,7 +804,7 @@ dk_sort_new_node(dkChar *line) } -#line 755 "dk-sort.ctr" +#line 777 "dk-sort.ctr" return back; } @@ -819,7 +819,7 @@ dk_sort_is_dot_file(const dkChar *fn) int back = 0; -#line 768 "dk-sort.ctr" +#line 790 "dk-sort.ctr" ptr = fn; while (dkT('\0') != *ptr) { #if DK4_HAVE_BACKSLASH_AS_SEP @@ -833,7 +833,7 @@ dk_sort_is_dot_file(const dkChar *fn) else { fns++; } -#line 780 "dk-sort.ctr" +#line 802 "dk-sort.ctr" if (dkT('.') == *fns) { back = 1; } @@ -844,7 +844,7 @@ dk_sort_is_dot_file(const dkChar *fn) #endif -#line 789 "dk-sort.ctr" +#line 811 "dk-sort.ctr" return back; } @@ -858,7 +858,7 @@ dk_sort_is_dot_file(const dkChar *fn) */ static int -dk_sort_compare_nodes(const void *l, const void *r, int cr) +dk_sort_compare_nodes(const void *l, const void *r, int DK4_ARG_UNUSED(cr) ) { int back = 0; dk_sort_line_t *pl; @@ -867,7 +867,8 @@ dk_sort_compare_nodes(const void *l, const void *r, int cr) const dkChar *fnright; -#line 810 "dk-sort.ctr" +#line 832 "dk-sort.ctr" + DK4_UNUSED_ARG(cr) if (NULL != l) { if (NULL != r) { pl = (dk_sort_line_t *)l; @@ -880,10 +881,10 @@ dk_sort_compare_nodes(const void *l, const void *r, int cr) fnright = dk4str_skip(pr->line, skip_words); if (NULL != fnleft) { -#line 821 "dk-sort.ctr" +#line 844 "dk-sort.ctr" if (NULL != fnright) { -#line 822 "dk-sort.ctr" +#line 845 "dk-sort.ctr" if (0 != dk4file_is_directory(fnleft, NULL)) { if (0 == dk4file_is_directory(fnright, NULL)) { back = -1; @@ -1003,7 +1004,7 @@ dk_sort_compare_nodes(const void *l, const void *r, int cr) } } -#line 940 "dk-sort.ctr" +#line 963 "dk-sort.ctr" return back; } @@ -1012,17 +1013,20 @@ dk_sort_compare_nodes(const void *l, const void *r, int cr) static int dk_sort_line_handler( - void *obj, + void * DK4_ARG_UNUSED(obj), dkChar *line, - dk4_um_t lineno, - dk4_er_t *erp + dk4_um_t DK4_ARG_UNUSED(lineno), + dk4_er_t * DK4_ARG_UNUSED(erp) ) { dk_sort_line_t *nptr; int back = DK4_TSP_RES_OK; -#line 957 "dk-sort.ctr" +#line 980 "dk-sort.ctr" + DK4_UNUSED_ARG(obj) + DK4_UNUSED_ARG(lineno) + DK4_UNUSED_ARG(erp) nptr = dk_sort_new_node(line); if (NULL != nptr) { if (0 == dk4sto_add(lsto, nptr, NULL)) { @@ -1033,7 +1037,7 @@ dk_sort_line_handler( } } -#line 966 "dk-sort.ctr" +#line 992 "dk-sort.ctr" return back; } @@ -1106,7 +1110,7 @@ dk_sort_report_errors( { -#line 1037 "dk-sort.ctr" +#line 1063 "dk-sort.ctr" if (NULL != er_en) { switch (er_en->ec) { case DK4_E_DECODING_FAILED : { @@ -1154,7 +1158,7 @@ dk_sort_report_errors( } -#line 1083 "dk-sort.ctr" +#line 1109 "dk-sort.ctr" } @@ -1177,7 +1181,7 @@ dk_sort_process_file(FILE *fipo, const dkChar *filename) unsigned char ub; -#line 1104 "dk-sort.ctr" +#line 1130 "dk-sort.ctr" dk4error_init(&er_en); dk4error_init(&er_pr); dk4error_init(&er); @@ -1236,7 +1240,7 @@ dk_sort_process_file(FILE *fipo, const dkChar *filename) } -#line 1161 "dk-sort.ctr" +#line 1187 "dk-sort.ctr" } @@ -1252,7 +1256,7 @@ dk_sort_process_stdin(void) #endif -#line 1175 "dk-sort.ctr" +#line 1201 "dk-sort.ctr" #if DK4_ON_WINDOWS oldmode = _setmode(_fileno(stdin), _O_BINARY); #endif @@ -1262,7 +1266,7 @@ dk_sort_process_stdin(void) #endif -#line 1183 "dk-sort.ctr" +#line 1209 "dk-sort.ctr" } @@ -1275,7 +1279,7 @@ dk_sort_process_one_file_name(const dkChar *fn) int tests = DK4_FOPEN_SC_IS_REGULAR; -#line 1194 "dk-sort.ctr" +#line 1220 "dk-sort.ctr" fipo = dk4fopen_app(fn, dk_sort_kwnl[4], tests, app); if (NULL != fipo) { dk_sort_process_file(fipo, fn); @@ -1286,7 +1290,7 @@ dk_sort_process_one_file_name(const dkChar *fn) } -#line 1203 "dk-sort.ctr" +#line 1229 "dk-sort.ctr" } @@ -1304,7 +1308,7 @@ dk_sort_expand_one_file_name(const dkChar *pattern) int can_continue; -#line 1219 "dk-sort.ctr" +#line 1245 "dk-sort.ctr" fne = dk4app_fne_open(pattern, app); if (NULL != fne) { can_continue = 1; @@ -1352,7 +1356,7 @@ dk_sort_expand_one_file_name(const dkChar *pattern) } -#line 1265 "dk-sort.ctr" +#line 1291 "dk-sort.ctr" } #endif @@ -1370,7 +1374,7 @@ dk_sort_process_files(void) int i; /* Current file index */ -#line 1281 "dk-sort.ctr" +#line 1307 "dk-sort.ctr" xargc = dk4app_get_argc(app); if (0 < xargc) { for ( @@ -1397,7 +1401,7 @@ dk_sort_process_files(void) } -#line 1306 "dk-sort.ctr" +#line 1332 "dk-sort.ctr" } @@ -1413,7 +1417,7 @@ dk_sort_write_output(void) int printthis; -#line 1320 "dk-sort.ctr" +#line 1346 "dk-sort.ctr" if ((0 != dk_sort_can_continue()) && (EXIT_SUCCESS == exval)) { dk4sto_it_reset(lsti); prevtext = NULL; @@ -1448,7 +1452,7 @@ dk_sort_write_output(void) } -#line 1353 "dk-sort.ctr" +#line 1379 "dk-sort.ctr" } @@ -1468,7 +1472,7 @@ dk_sort_normal_run(void) int res = 0; /* Operations result */ -#line 1371 "dk-sort.ctr" +#line 1397 "dk-sort.ctr" /* Process command line options */ if (0 != dk4app_opt_is_set_short(app, dkT('c'), NULL)) { @@ -1590,7 +1594,7 @@ dk_sort_normal_run(void) } -#line 1491 "dk-sort.ctr" +#line 1517 "dk-sort.ctr" } @@ -1615,7 +1619,7 @@ dk_sort_run_with_signal_handlers(void) int success = 0; -#line 1514 "dk-sort.ctr" +#line 1540 "dk-sort.ctr" #ifdef SIGPIPE /* Set up signal handling for SIGPIPE. */ @@ -1718,7 +1722,7 @@ dk_sort_run_with_signal_handlers(void) if (0 == success) { exval = EXIT_FAILURE; } -#line 1615 "dk-sort.ctr" +#line 1641 "dk-sort.ctr" } #else #if DK4_HAVE_SIGSET @@ -1735,7 +1739,7 @@ dk_sort_run_with_signal_handlers(void) dk4_sig_handler_t *oldterm = NULL; -#line 1630 "dk-sort.ctr" +#line 1656 "dk-sort.ctr" #ifdef SIGPIPE oldpipe = sigset(SIGPIPE, sig_handler_pipe); #endif @@ -1749,7 +1753,7 @@ dk_sort_run_with_signal_handlers(void) #endif -#line 1642 "dk-sort.ctr" +#line 1668 "dk-sort.ctr" } #else #if DK4_HAVE_SIGNAL @@ -1766,7 +1770,7 @@ dk_sort_run_with_signal_handlers(void) dk4_sig_handler_t *oldterm = NULL; -#line 1657 "dk-sort.ctr" +#line 1683 "dk-sort.ctr" #ifdef SIGPIPE oldpipe = signal(SIGPIPE, sig_handler_pipe); #endif @@ -1780,7 +1784,7 @@ dk_sort_run_with_signal_handlers(void) #endif -#line 1669 "dk-sort.ctr" +#line 1695 "dk-sort.ctr" } #else /** Set signal handlers and run. @@ -1810,10 +1814,10 @@ int main(int argc, char *argv[]) { -#line 1697 "dk-sort.ctr" +#line 1723 "dk-sort.ctr" -#line 1698 "dk-sort.ctr" +#line 1724 "dk-sort.ctr" dk4fput_initialize_stdout(); dk4fput_initialize_stderr(); app = dk4app_open_cmd( @@ -1827,12 +1831,12 @@ int main(int argc, char *argv[]) if (0 != dk4app_can_run_normally(app)) { -#line 1710 "dk-sort.ctr" +#line 1736 "dk-sort.ctr" dk_sort_run_with_signal_handlers(); } else { -#line 1713 "dk-sort.ctr" +#line 1739 "dk-sort.ctr" if (0 != dk4app_help_version_license(app)) { exval = EXIT_SUCCESS; } @@ -1846,10 +1850,10 @@ int main(int argc, char *argv[]) dk4fput_cleanup_stdout(); -#line 1725 "dk-sort.ctr" +#line 1751 "dk-sort.ctr" -#line 1726 "dk-sort.ctr" +#line 1752 "dk-sort.ctr" return exval; } |