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-t2l.ctr | |
parent | ac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff) |
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk-t2l.ctr')
-rw-r--r-- | support/dktools/dk-t2l.ctr | 231 |
1 files changed, 159 insertions, 72 deletions
diff --git a/support/dktools/dk-t2l.ctr b/support/dktools/dk-t2l.ctr index 8a1bcbeb9b..e240ba59ab 100644 --- a/support/dktools/dk-t2l.ctr +++ b/support/dktools/dk-t2l.ctr @@ -2,7 +2,7 @@ copyright owner = Dirk Krause copyright year = 2015-xxxx -license = bsd +SPDX-License-Identifier: BSD-3-Clause %% module @@ -82,6 +82,7 @@ license = bsd #include "dk4vers.h" #include "dk4tsp32.h" #include "dk4uc2l.h" +#include "dk4uc2la.h" #include "dk4maidhdu.h" #include "dk4maidddu.h" #include "dk4maodh.h" @@ -89,6 +90,11 @@ license = bsd #include "dk4mpl.h" #include "dk4strd.h" #include "dk4pathd.h" +#include "dk4strm.h" +#include "dk4strmf.h" +#include "dk4strmo32.h" + + #if DK4_CHAR_SIZE > 1 #if DK4_CHAR_SIZE == 2 @@ -98,7 +104,11 @@ license = bsd #include "dk4ansi.h" #include "dk4utf8.h" #endif +#include "dk4unused.h" +#ifndef DK4WMAIN_H_INCLUDED +#include "dk4wmain.h" +#endif $!trace-include @@ -126,13 +136,14 @@ Options: -t --tabulator Write LaTeX sequence for tabulators --verbose Show error message on SIGPIPE. + --check Syntax check for all data files. --help Show this short help text. --manual *** SHOW FULL MANUAL. *** --version Show version information. --license Show license information. -http://dktools.sourceforge.net +http://sourceforge.net/p/dktools/wiki/dk-t2l/ $!end }; @@ -148,7 +159,8 @@ This software uses code from the following projects, either directly or as a library: dktools Dirk Krause's tools and libraries. - See http://dktools.sourceforge.net/ for more information. + See http://sourceforge.net/p/dktools/wiki/Home/ + for more information. #if DK4_HAVE_ZLIB_H zlib Data compression library. @@ -175,27 +187,27 @@ All rights reserved. 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 copyright - 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 Dirk Krause 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. +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its + 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 HOLDER 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. #if DK4_HAVE_ZLIB_H @@ -321,6 +333,10 @@ stdin # 6 Long option for verbose mode # verbose +# +# 7 Long option for syntax check +# +check $!end }; @@ -424,7 +440,7 @@ static const dk4_option_specification_t dk_t2l_options[] = { /* Command line arguments are hexadecimal character numbers. */ - { dkT('x'), dkT("hex"), DK4_OPT_ARG_NONE }, + { dkT('h'), dkT("hex"), DK4_OPT_ARG_NONE }, /* Write recommendations about font encodings and packages. */ @@ -440,7 +456,11 @@ static const dk4_option_specification_t dk_t2l_options[] = { /* Verbose output. */ - { dkT('\0'), dkT("verbose"), DK4_OPT_ARG_NONE } + { dkT('\0'), dkT("verbose"), DK4_OPT_ARG_NONE }, + + /* Immediately load all data files for syntax check. + */ + { dkT('\0'), dkT("check"), DK4_OPT_ARG_NONE } }; @@ -517,13 +537,25 @@ static int dk_t2l_numeric = 0; /** Input encoding expected when processing stdin. */ -static int dk_t2l_i_std = DK4_FILE_ENCODING_ASCII; +static int dk_t2l_i_std = +#if DK4_ON_WINDOWS + DK4_FILE_ENCODING_WIN1252 +#else + DK4_FILE_ENCODING_PLAIN +#endif +; /** Input encoding expected when processing files. */ -static int dk_t2l_i_file = DK4_FILE_ENCODING_ASCII; +static int dk_t2l_i_file = +#if DK4_ON_WINDOWS + DK4_FILE_ENCODING_WIN1252 +#else + DK4_FILE_ENCODING_PLAIN +#endif +; @@ -580,6 +612,11 @@ static int dk_t2l_tabs = 0; static int dk_t2l_linef = 0; +/** Flag: Syntax check on all data files. +*/ +static int dk_t2l_synchk = 0; + + #ifdef SIGPIPE /** Indicator: SIGPIPE signal received. @@ -626,8 +663,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 @@ -637,8 +675,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; } @@ -647,8 +686,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; } @@ -672,10 +712,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; } } @@ -745,11 +793,14 @@ dk_t2l_process_options(void) dk_t2l_echo = 1; dk_t2l_numeric = 1; } - if (0 != dk4app_opt_is_set_short(app, dkT('x'), NULL)) { + if (0 != dk4app_opt_is_set_short(app, dkT('h'), NULL)) { dk_t2l_echo = 1; dk_t2l_numeric = 2; } - uc2l = dk4uc2l_open_from_app(app); + if (0 != dk4app_opt_is_set_long(app, dk_t2l_kwnl[7], NULL)) { + dk_t2l_synchk = 1; + } + uc2l = dk4uc2l_open_from_app_ex1(app, dk_t2l_synchk); if (NULL == uc2l) { back = 0; } @@ -853,9 +904,7 @@ dk_t2l_end_math_mode(void) static int dk_t2l_c32_after_cr_nl_check( - dk4_c32_t c, - dk4_text_stream_position_t *pos, - dk4_er_t *erp + dk4_c32_t c ) { dkChar buf[16*sizeof(dk4_um_t)]; @@ -885,12 +934,12 @@ dk_t2l_c32_after_cr_nl_check( dk_t2l_end_math_mode(); if (EOF == fputc(' ', stdout)) { output_error = 1; } } else { - lseq = dk4uc2l_find(uc2l, c, 0, app); + lseq = dk4uc2l_find_app(uc2l, c, 0, app); if (NULL != lseq) { dk_t2l_end_math_mode(); if (EOF == fputs(lseq, stdout)) { output_error = 1; } } else { - lseq = dk4uc2l_find(uc2l, c, 1, app); + lseq = dk4uc2l_find_app(uc2l, c, 1, app); if (NULL != lseq) { dk_t2l_begin_math_mode(); if (EOF == fputs(lseq, stdout)) { output_error = 1; } @@ -926,18 +975,21 @@ dk_t2l_c32_after_cr_nl_check( static int dk_t2l_c32_handler( - void *obj, + void * DK4_ARG_UNUSED(obj), dk4_c32_t c, - dk4_text_stream_position_t *pos, - dk4_er_t *erp + dk4_text_stream_position_t * DK4_ARG_UNUSED(pos), + dk4_er_t * DK4_ARG_UNUSED(erp) ) { int back = DK4_TSP_RES_OK; + DK4_UNUSED_ARG(obj) + DK4_UNUSED_ARG(pos) + DK4_UNUSED_ARG(erp) if (dkC32(0x0A) == c) { /* For a newline clear CR and TXT flag, set NL flag. */ - back = dk_t2l_c32_after_cr_nl_check(c, pos, erp); + back = dk_t2l_c32_after_cr_nl_check(c); dk_t2l_lineno++; if ((dk4_um_t)0UL == dk_t2l_lineno) { /* ERROR: Overflow in line number counting */ @@ -955,7 +1007,7 @@ dk_t2l_c32_handler( Otherwise simply set CR flag. */ if (0 != dk_t2l_last_cr) { - back = dk_t2l_c32_after_cr_nl_check(dkC32(0x0D), pos, erp); + back = dk_t2l_c32_after_cr_nl_check(dkC32(0x0D)); dk_t2l_lhtx = 1; dk_t2l_last_nl = 0; } else { @@ -969,8 +1021,8 @@ dk_t2l_c32_handler( Reset NL and CR flag, set TXT flag. */ if (0 != dk_t2l_last_cr) { - back = dk_t2l_c32_after_cr_nl_check(dkC32(0x0D), pos, erp); - switch (dk_t2l_c32_after_cr_nl_check(c, pos, erp)) { + back = dk_t2l_c32_after_cr_nl_check(dkC32(0x0D)); + switch (dk_t2l_c32_after_cr_nl_check(c)) { case DK4_TSP_RES_FATAL: { back = DK4_TSP_RES_FATAL; } break; @@ -981,7 +1033,7 @@ dk_t2l_c32_handler( } break; } } else { - back = dk_t2l_c32_after_cr_nl_check(c, pos, erp); + back = dk_t2l_c32_after_cr_nl_check(c); } dk_t2l_lhtx = 1; dk_t2l_last_nl = 0; @@ -1114,7 +1166,7 @@ dk_t2l_report_errors(dk4_er_t *er_en, dk4_er_t *er_pr) static void -dk_t2l_echo_hex(const dkChar *txt, int argno) +dk_t2l_echo_hex(const dkChar *txt) { const dkChar *endptr = NULL; dk4_um_t um = (dk4_um_t)0UL; @@ -1129,7 +1181,7 @@ dk_t2l_echo_hex(const dkChar *txt, int argno) ); if (0 != res) { if ((dk4_um_t)0xFFFFFFFFUL >= um) { - (void)dk_t2l_c32_after_cr_nl_check((dk4_c32_t)um, NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check((dk4_c32_t)um); } else { dk4app_log_3(app, dk_t2l_msg, dk_t2l_sz_msg, DK4_LL_ERROR, 28, 29, txt); } @@ -1143,7 +1195,7 @@ dk_t2l_echo_hex(const dkChar *txt, int argno) static void -dk_t2l_echo_numeric(const dkChar *txt, int argno) +dk_t2l_echo_numeric(const dkChar *txt) { const dkChar *endptr = NULL; dk4_um_t um = (dk4_um_t)0UL; @@ -1161,7 +1213,7 @@ dk_t2l_echo_numeric(const dkChar *txt, int argno) ); if (0 != res) { if ((dk4_um_t)0xFFFFFFFFUL >= um) { - (void)dk_t2l_c32_after_cr_nl_check((dk4_c32_t)um, NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check((dk4_c32_t)um); } else { dk4app_log_3(app, dk_t2l_msg, dk_t2l_sz_msg, DK4_LL_ERROR, 28, 29, txt); } @@ -1170,7 +1222,7 @@ dk_t2l_echo_numeric(const dkChar *txt, int argno) dk4app_log_3(app, dk_t2l_msg, dk_t2l_sz_msg, DK4_LL_ERROR, 30, 31, txt); } } else { - dk_t2l_echo_hex(&(txt[2]), argno); + dk_t2l_echo_hex(&(txt[2])); } } @@ -1192,7 +1244,7 @@ dk_t2l_echo_c32(const dkChar *txt, int argno) if (EOF == fputc(' ', stdout)) { output_error = 1; } } isfirst = 0; - (void)dk_t2l_c32_after_cr_nl_check(*(txt++), NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check(*(txt++)); } } @@ -1223,7 +1275,7 @@ dk_t2l_echo_utf16(const dkChar *txt, int argno) if (EOF == fputc(' ', stdout)) { output_error = 1; } } isfirst = 0; - (void)dk_t2l_c32_after_cr_nl_check(dk4utf16_get(&dec), NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check(dk4utf16_get(&dec)); } break; } } else { @@ -1258,7 +1310,7 @@ dk_t2l_echo_ascii(const dkChar *txt, int argno) } isfirst = 0; c32 = dkC32(0xFF) & ((dk4_c32_t)((unsigned char)(*(txt++)))); - (void)dk_t2l_c32_after_cr_nl_check(c32, NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check(c32); } } @@ -1288,7 +1340,7 @@ dk_t2l_echo_utf8(const dkChar *txt, int argno) if (EOF == fputc(' ', stdout)) { output_error = 1; } } isfirst = 0; - (void)dk_t2l_c32_after_cr_nl_check(dk4utf8_get(&dec), NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check(dk4utf8_get(&dec)); } break; } } else { @@ -1321,7 +1373,7 @@ dk_t2l_echo_ansi(const dkChar *txt, int argno) if (EOF == fputc(' ', stdout)) { output_error = 1; } } isfirst = 0; - (void)dk_t2l_c32_after_cr_nl_check(c32, NULL, NULL); + (void)dk_t2l_c32_after_cr_nl_check(c32); } else { /* !!!!! ERROR: Decoding */ exval = EXIT_FAILURE; @@ -1352,7 +1404,7 @@ dk_t2l_echo_text(const dkChar *txt, int argno) case DK4_ENCODING_UTF8 : { dk_t2l_echo_utf8(txt, argno); } break; - case DK4_ENCODING_ANSI : { + case DK4_ENCODING_WIN1252 : { dk_t2l_echo_ansi(txt, argno); } break; default : { @@ -1383,7 +1435,7 @@ dk_t2l_process_cmdline(void) for (i = 0; i < argc; i++) { xargv = dk4app_get_argv(app, i); if (NULL != xargv) { - dk_t2l_echo_hex(xargv, i); + dk_t2l_echo_hex(xargv); } } dk_t2l_end_math_mode(); @@ -1392,7 +1444,7 @@ dk_t2l_process_cmdline(void) for (i = 0; i < argc; i++) { xargv = dk4app_get_argv(app, i); if (NULL != xargv) { - dk_t2l_echo_numeric(xargv, i); + dk_t2l_echo_numeric(xargv); } } dk_t2l_end_math_mode(); @@ -1649,8 +1701,10 @@ static void dk_t2l_normal_run(void) { - int argc; - int i; + dk4_er_t er; + dk4_stream_t *wstrm; + int argc; + int i; if (0 != dk_t2l_process_options()) { exval = EXIT_SUCCESS; dk_t2l_output_start_page(); @@ -1663,12 +1717,27 @@ dk_t2l_normal_run(void) dk_t2l_process_filename(dk4app_get_argv(app, i)); } } else { - dk_t2l_process_stdin(); + if (0 == dk_t2l_synchk) { + dk_t2l_process_stdin(); + } } } dk_t2l_output_finish_page(); if (0 != dk4app_opt_is_set_short(app, dkT('r'), NULL)) { - dk4uc2l_recommendations(uc2l, stdout); + dk4error_init(&er); + wstrm = dk4stream_open_for_file(stdout, DK4_STREAM_WRITE, 0, 0, &er); + if (NULL != wstrm) { + dk4stream_set_output_encoding(wstrm, DK4_FILE_ENCODING_PLAIN); + dk4uc2l_recommendations(uc2l, wstrm, &er); + if (0 == dk4stream_close(wstrm, NULL)) { + /* ERROR: Incomplete output */ + dk4app_log_base1(app, DK4_LL_ERROR, 128); + } + } + else { + /* ERROR: Failed to create stream writer */ + dk4app_log_base1(app, DK4_LL_ERROR, 90); + } } if (0 != dk4uc2l_retrieve_errors(uc2l)) { $? "! ERROR" /* ERROR: Probably incorrect output due to problems */ @@ -1882,15 +1951,31 @@ int wmain(int argc, wchar_t *argv[]) int main(int argc, char *argv[]) #endif { + int silent = 0; int shp; $!trace-init dk-t2l.deb $? "+ main" +#if DK4_CHAR_SIZE > 1 + if (NULL != getenv("VIM")) { silent = 1; } + if (NULL != getenv("VIMRUNTIME")) { silent = 1; } +#endif +#if 0 dk4fput_initialize_stderr(); - app = dk4app_open_cmd( - argc, argv, dk_t2l_options, dk_t2l_sz_options, - dk_t2l_kwnl[0], DKT_VERSION_DK, - dk_t2l_kwnl[1], dk_t2l_help_text, dk_t2l_license_text - ); +#endif + if (0 != silent) { + app = dk4app_open_silent( + argc, argv, dk_t2l_options, dk_t2l_sz_options, + dk_t2l_kwnl[0], DKT_VERSION_DK, + dk_t2l_kwnl[1], dk_t2l_help_text, dk_t2l_license_text + ); + } + else { + app = dk4app_open_cmd( + argc, argv, dk_t2l_options, dk_t2l_sz_options, + dk_t2l_kwnl[0], DKT_VERSION_DK, + dk_t2l_kwnl[1], dk_t2l_help_text, dk_t2l_license_text + ); + } if (NULL != app) { dk_t2l_i_std = dk4app_get_stdin_encoding(app); dk_t2l_i_file = dk4app_get_file_in_encoding(app); @@ -1945,8 +2030,10 @@ int main(int argc, char *argv[]) if (0 != sig_read_atomic(&sig_had_pipe)) { exval = EXIT_FAILURE; } #endif if (0 != output_error) { exval = EXIT_FAILURE; } - fflush(stderr); - dk4fput_cleanup_stderr(); + if (0 == silent) { + fflush(stderr); + dk4fput_cleanup_stderr(); + } $? "- main %d", exval $!trace-end exit(exval); return exval; |