summaryrefslogtreecommitdiff
path: root/support/dktools/dk-fic.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-10-12 03:04:00 +0000
committerNorbert Preining <norbert@preining.info>2020-10-12 03:04:00 +0000
commit0ce40abb18ec02ec6fd6bcc5f21612c88daa7578 (patch)
tree416289fe1448873fd8ca33051f50ad85bffa8aaa /support/dktools/dk-fic.c
parentfdb18507cd80dc17f5a5256153d34668b4f4e61c (diff)
CTAN sync 202010120303
Diffstat (limited to 'support/dktools/dk-fic.c')
-rw-r--r--support/dktools/dk-fic.c2222
1 files changed, 0 insertions, 2222 deletions
diff --git a/support/dktools/dk-fic.c b/support/dktools/dk-fic.c
deleted file mode 100644
index d4d84225e2..0000000000
--- a/support/dktools/dk-fic.c
+++ /dev/null
@@ -1,2222 +0,0 @@
-/*
-Copyright (C) 2015-2020, Dirk Krause
-SPDX-License-Identifier: BSD-3-Clause
-*/
-
-/*
- 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-fic.ctr
-*/
-
-
-#line 8 "dk-fic.ctr"
-
-/** @file dk-fic.c File integrity checker.
-*/
-
-
-
-#include "dk4conf.h"
-
-#if DK4_ON_WINDOWS
-#ifndef WINDOWS_H_INCLUDED
-#include <windows.h>
-#define WINDOWS_H_INCLUDED
-#endif
-#endif
-
-#if DK4_HAVE_UNISTD_H
-#ifndef UNISTD_H_INCLUDED
-#include <unistd.h>
-#define UNISTD_H_INCLUDED 1
-#endif
-#endif
-
-#if DK4_HAVE_PROCESS_H
-#ifndef PROCESS_H_INCLUDED
-#include <process.h>
-#define PROCESS_H_INCLUDED 1
-#endif
-#endif
-
-#if DK4_HAVE_SIGNAL_H
-#ifndef SIGNAL_H_INCLUDED
-#include <signal.h>
-#define SIGNAL_H_INCLUDED 1
-#endif
-#endif
-
-#if DK4_HAVE_IO_H
-#ifndef IO_H_INCLUDED
-#include <io.h>
-#define IO_H_INCLUDED 1
-#endif
-#endif
-
-#if DK4_HAVE_FCNTL_H
-#ifndef FCNTL_H_INCLUDED
-#include <fcntl.h>
-#define FCNTL_H_INCLUDED 1
-#endif
-#endif
-
-#include "dk4types.h"
-#include "dk4const.h"
-#include "dk4vers.h"
-#include "dk4app.h"
-#include "dk4aopt.h"
-#include "dk4mem.h"
-#include "dk4mema.h"
-#include "dk4fput.h"
-#include "dk4mpl.h"
-#include "dk4enc.h"
-#include "dk4tspdk.h"
-#include "dk4fopda.h"
-#include "dk4pathd.h"
-#include "dk4md.h"
-#include "dk4maodd.h"
-#include "dk4filed.h"
-#include "dk4filei.h"
-#include "dk4fileia.h"
-#include "dk4strd.h"
-#include "dk4numl.h"
-#include "dk4maidddu.h"
-#include "dk4unused.h"
-
-#ifndef DK4WMAIN_H_INCLUDED
-#include "dk4wmain.h"
-#endif
-
-
-
-
-#line 87 "dk-fic.ctr"
-
-
-
-/** Default help text, shown if help text file is not found.
-*/
-static const dkChar * const dk_fic_help_text[] = {
-dkT(""),
-dkT("File integrity checker"),
-dkT(""),
-dkT("Create checksum lists for files or verify files against a checksum list."),
-dkT(""),
-dkT("dk-fic [<options>] [<file(s)>]"),
-dkT(""),
-dkT("Options:"),
-dkT("-c\t\t--check\t\t\tCheck (verify a checksum list)."),
-dkT("-v\t\t--verbose\t\tMessages for succeeded tests."),
-dkT("-q\t\t--quiet\t\t\tNo messages for failed tests."),
-dkT("-l <size>\t--line-size=<size>\tSize for input line buffer."),
-dkT(""),
-dkT("--help\t\t\t\t\tShow this short help text."),
-dkT("--manual\t\t\t\t*** SHOW FULL MANUAL. ***"),
-dkT("--version\t\t\t\tShow version information."),
-dkT("--license\t\t\t\tShow license information."),
-dkT(""),
-dkT("Typical operations:"),
-dkT("find <directory> -type f | dk-fic > checklist.txt\t\tCreate check-"),
-dkT("dk-ls -r -tf -pn <directory> | dk-fic > checklist.txt\t\tsum list."),
-dkT("dk-fic -c < checklist.txt\t\t\t\t\tVerify files."),
-dkT(""),
-dkT("http://sourceforge.net/p/dktools/wiki/dk-fic/"),
-dkT(""),
-NULL
-
-
-#line 120 "dk-fic.ctr"
-};
-
-
-
-/** License conditions.
-*/
-static const dkChar * const dk_fic_license_text[] = {
-dkT(""),
-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://sourceforge.net/p/dktools/wiki/Home/"),
-dkT("\t\tfor more information."),
-#if DK4_HAVE_ZLIB_H
-dkT(""),
-dkT("zlib\t\tData compression library."),
-dkT("\t\tSee http://www.zlib.net/ for more information."),
-#endif
-#if DK4_HAVE_BZLIB_H
-dkT(""),
-dkT("bzip2\t\tData compression program and library."),
-dkT("\t\tSee http://www.bzip.org/ for more information."),
-#endif
-dkT(""),
-dkT("All the licenses below apply to the program."),
-dkT("Licenses for used libraries are shown as found on my Scientific Linux 6.x"),
-dkT("computer in the /usr/share/doc directory on 2015-04-01. Check the project"),
-dkT("homepages of the used libraries for additional information and/or updated"),
-dkT("license terms."),
-dkT(""),
-dkT(""),
-dkT("DK tools and libraries license"),
-dkT("=============================="),
-dkT("Copyright (c) 2015-2016, Dirk Krause"),
-dkT("All rights reserved."),
-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("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"),
-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(""),
-dkT("Zlib license"),
-dkT("============"),
-dkT("(C) 1995-2004 Jean-loup Gailly and Mark Adler"),
-dkT(""),
-dkT("This software is provided 'as-is', without any express or implied"),
-dkT("warranty. In no event will the authors be held liable for any damages"),
-dkT("arising from the use of this software."),
-dkT(""),
-dkT("Permission is granted to anyone to use this software for any purpose,"),
-dkT("including commercial applications, and to alter it and redistribute it"),
-dkT("freely, subject to the following restrictions:"),
-dkT(""),
-dkT("1. The origin of this software must not be misrepresented; you must not"),
-dkT(" claim that you wrote the original software. If you use this software"),
-dkT(" in a product, an acknowledgment in the product documentation would be"),
-dkT(" appreciated but is not required."),
-dkT("2. Altered source versions must be plainly marked as such, and must not be"),
-dkT(" misrepresented as being the original software."),
-dkT("3. This notice may not be removed or altered from any source distribution."),
-dkT(""),
-dkT("Jean-loup Gailly Mark Adler"),
-dkT("jloup@gzip.org madler@alumni.caltech.edu"),
-#endif
-#if DK4_HAVE_BZLIB_H
-dkT(""),
-dkT(""),
-dkT("Bzip2 and libbzip2 library license"),
-dkT("=================================="),
-dkT("This program, \"bzip2\", the associated library \"libbzip2\", and all"),
-dkT("documentation, are copyright (C) 1996-2007 Julian R Seward. All"),
-dkT("rights reserved."),
-dkT(""),
-dkT("Redistribution and use in source and binary forms, with or without"),
-dkT("modification, are permitted provided that the following conditions"),
-dkT("are met:"),
-dkT(""),
-dkT("1. Redistributions of source code must retain the above copyright"),
-dkT(" notice, this list of conditions and the following disclaimer."),
-dkT(""),
-dkT("2. The origin of this software must not be misrepresented; you must "),
-dkT(" not claim that you wrote the original software. If you use this "),
-dkT(" software in a product, an acknowledgment in the product "),
-dkT(" documentation would be appreciated but is not required."),
-dkT(""),
-dkT("3. Altered source versions must be plainly marked as such, and must"),
-dkT(" not be misrepresented as being the original software."),
-dkT(""),
-dkT("4. The name of the author may not be used to endorse or promote "),
-dkT(" products derived from this software without specific prior written "),
-dkT(" permission."),
-dkT(""),
-dkT("THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS"),
-dkT("OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED"),
-dkT("WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE"),
-dkT("ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY"),
-dkT("DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL"),
-dkT("DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE"),
-dkT("GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS"),
-dkT("INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,"),
-dkT("WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"),
-dkT("NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS"),
-dkT("SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."),
-dkT(""),
-dkT("Julian Seward, jseward@bzip.org"),
-dkT("bzip2/libbzip2 version 1.0.5 of 10 December 2007"),
-#endif
-dkT(""),
-NULL
-
-
-#line 253 "dk-fic.ctr"
-};
-
-
-
-/** Keywords used by the program, not localized.
-*/
-static const dkChar * const dk_fic_kwnl[] = {
-/* 0 */
-dkT("dktools"),
-
-/* 1 */
-dkT("dk-fic.txt"),
-
-/* 2 */
-dkT("dk-fic.str"),
-
-/* 3 */
-dkT("line.size"),
-
-/* 4 */
-dkT("stdin"),
-
-/* 5 */
-dkT("rb"),
-
-/* 6 */
-dkT("\\"),
-
-/* 7 */
-dkT("# dk-fic 3\n"),
-
-/* 8 */
-dkT("# dk-fic 4\n"),
-
-/* 9 */
-dkT("dk-fic"),
-
-NULL
-
-
-#line 302 "dk-fic.ctr"
-};
-
-
-
-/** Default keywords, localized.
-*/
-static const dkChar * const dk_fic_kw_def[] = {
-/* 0 */
-dkT("Failed to set up signal handlers!"),
-
-/* 1 */
-dkT("Failed to restore signal handlers!"),
-
-/* 2 */
-dkT("PASSED "),
-
-/* 3 */
-dkT("FAILED "),
-
-/* 4 */
-dkT("Failed to read data from file!"),
-
-/* 5 */
-dkT("Failed to convert file size to text for file:\n\t\""),
-
-/* 6 */
-dkT("\"!"),
-
-/* 7 */
-dkT("Failed to finish at least one message digest for file:\n\t\""),
-
-/* 8 */
-dkT("\"!"),
-
-/* 9 */
-dkT("Failed to add data to message digest for file:\n\t\""),
-
-/* 10 */
-dkT("\"!"),
-
-/* 11 */
-dkT("Failed to initialize at least one message digest for file:\n\t\""),
-
-/* 12 */
-dkT("\"!"),
-
-/* 13 */
-dkT("Not a regular file:\n\t\""),
-
-/* 14 */
-dkT("\"!"),
-
-/* 15 */
-dkT("Failed to obtain file size:\n\t\""),
-
-/* 16 */
-dkT("\"!"),
-
-/* 17 */
-dkT("SHA-512 message digest not supported, SHA-512 checksums ignored."),
-
-/* 18 */
-dkT("Syntax error, first line must be \"# dk-fic 3\" or \"# dk-fic 4\"!"),
-
-/* 19 */
-dkT("Syntax error, expected:\n\tmd5 sha-1 ripemd-160 sha-512 size name"),
-
-/* 20 */
-dkT("Syntax error, expected:\n\tmd5 sha-1 ripemd-160 size name"),
-
-/* 21 */
-dkT("Syntax error, invalid file size: \""),
-
-/* 22 */
-dkT("\"!"),
-
-/* 23 */
-dkT("Failed to set up text line processing!"),
-
-/* 24 */
-dkT("Build problem: At least one required message digest type is not supported!"),
-
-/* 25 */
-dkT("Options -q and -v are mutually exclusive!"),
-
-/* 26 */
-dkT("Encoding not found: \""),
-
-/* 27 */
-dkT("\"!"),
-
-/* 28 */
-dkT("Problems while writing output!"),
-
-/* 29 */
-dkT("Signal SIGPIPE received!"),
-
-/* 30 */
-dkT("Aborted by SIGINT signal!"),
-
-/* 31 */
-dkT("Aborted by SIGTERM signal!"),
-
-/* 32 */
-dkT("Decoding error!"),
-
-/* 33 */
-dkT("Encoding error!"),
-
-/* 34 */
-dkT("Processing error!"),
-
-/* 35 */
-dkT("Decoding error!\n\tByte: "),
-
-/* 36 */
-dkT("Encoding error!\n\tByte: "),
-
-/* 37 */
-dkT("Processing error!\n\tByte: "),
-
-/* 38 */
-dkT(",\n\tCharacter: "),
-
-/* 39 */
-dkT(",\n\tPosition in line: "),
-
-/* 40 */
-dkT("."),
-
-NULL
-
-
-#line 427 "dk-fic.ctr"
-};
-
-/* VARIABLES */
-
-/** Options for the program.
-*/
-static const dk4_option_specification_t dk_fic_options[] = {
-
- /* Check (input is a previously generated checksum list.
- */
- { dkT('c'), dkT("check"), DK4_OPT_ARG_NONE },
-
- /* Input line size.
- */
- { dkT('l'), dkT("line-size"), DK4_OPT_ARG_SIZE },
-
- /* Quite when checking (only set exit status code).
- */
- { dkT('q'), dkT("quiet"), DK4_OPT_ARG_NONE },
-
- /* Verbose (write report line for succeeded test too).
- */
- { dkT('v'), dkT("verbose"), DK4_OPT_ARG_NONE },
-
- /* Expected input encoding.
- */
- { dkT('i'), dkT("input-encoding"), DK4_OPT_ARG_STRING },
-
-};
-
-
-
-/** Data buffer for reading the file.
-*/
-static char data_buf[4096];
-
-
-
-/** Default input line buffer.
-*/
-static dkChar ibuf_def[256 + DK4_MAX_PATH];
-
-
-#if DK4_HAVE_OPENSSL_MD5_H && DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_OPENSSL_RIPEMD_H
-
-static dk4_md_ctx_t ctx_md5;
-
-static dk4_md_ctx_t ctx_sha1;
-
-static dk4_md_ctx_t ctx_ripemd160;
-
-#if DK4_HAVE_SHA512
-
-static dk4_md_ctx_t ctx_sha512;
-
-#endif
-
-#endif
-
-
-/** Allocated input buffer for larger line size.
-*/
-static dkChar *ibuf_all = NULL;
-
-
-
-/** Pointer to real input buffer to use.
-*/
-static dkChar *ibuf_ptr = ibuf_def;
-
-
-
-/** Input line buffer size.
-*/
-static size_t ibuf_sz = DK4_SIZEOF(ibuf_def,dkChar);
-
-
-
-/** Application structure.
-*/
-static dk4_app_t *app = NULL;
-
-
-
-/** Message array, localized messages or default texts.
-*/
-static const dkChar * const *dk_fic_msg = dk_fic_kw_def;
-
-
-
-/** Number of elements in the dk_fic_msg array.
-*/
-static size_t dk_fic_sz_msg =
-sizeof(dk_fic_kw_def)/sizeof(DK4_PCDKCHAR) - 1;
-
-
-/** Number of elements in the dk_fic_options array.
-*/
-static const size_t dk_fic_sz_options =
-sizeof(dk_fic_options)/sizeof(dk4_option_specification_t);
-
-
-
-/** Length of file size to print.
-*/
-static size_t dk_fic_num_len = 2 * sizeof(dk4_um_t);
-
-
-
-/** Number of message digests (3 or 4).
-*/
-static size_t dk_fic_num_mds = 4;
-
-
-
-/** Flag: Write error occured while writing output.
-*/
-static int dk_fic_write_error = 0;
-
-
-
-/** Exit status code.
-*/
-static int exval = EXIT_FAILURE;
-
-
-
-/** Flag: Verify checksums instead of creating them.
-*/
-static int dk_fic_verify = 0;
-
-
-
-/** Verbosity level (0=silent, 1=errors, 2=errors+success).
-*/
-static int dk_fic_verbosity = 1;
-
-
-
-/** Input encoding expected on standard input.
-*/
-static int dk_fic_ie_stdin =
-#if DK4_ON_WINDOWS
- DK4_FILE_ENCODING_WIN1252
-#else
- DK4_FILE_ENCODING_PLAIN
-#endif
-;
-
-
-
-/** Input encoding expected on files.
-*/
-static int dk_fic_ie_file =
-#if DK4_ON_WINDOWS
- DK4_FILE_ENCODING_WIN1252
-#else
- DK4_FILE_ENCODING_PLAIN
-#endif
-;
-
-
-
-/** Flag: Current line to process is first line of data stream.
-*/
-static int dk_fic_first_line = 0;
-
-
-
-/* SIGNAL HANDLING VARIABLES AND HANDLER FUNCTIONS */
-
-
-#ifdef SIGPIPE
-/** Indicator: SIGPIPE signal received.
-*/
-static
-DK4_VOLATILE
-dk4_sig_atomic_t sig_had_pipe = 0;
-#endif
-
-/** Indicator: SIGINT signal received.
-*/
-static
-DK4_VOLATILE
-dk4_sig_atomic_t sig_had_int = 0;
-
-/** Indicator: SIGTERM signal received.
-*/
-static
-DK4_VOLATILE
-dk4_sig_atomic_t sig_had_term = 0;
-
-
-
-/** Pass a volatile pointer to an atomic integer.
- This function is necessary as some compilers mis-optimize
- direct access to volatile variables (at least if you believe
- one of the coding standards).
- @param ptr Address of atomic integer variable.
- @return The unmodified pointer.
-*/
-static
-DK4_VOLATILE
-dk4_sig_atomic_t *
-sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr)
-{
- return ptr;
-}
-
-
-
-#ifdef SIGPIPE
-/** Handler for SIGPIPE signal.
- @param signo Signal number (always SIGPIPE, ignored).
-*/
-static
-void
-sig_handler_pipe(int DK4_ARG_UNUSED(signo) )
-{
- DK4_UNUSED_ARG(signo)
- *sig_pass_pointer(&sig_had_pipe) = 1;
-}
-#endif
-
-/** Handler for SIGINT signal.
- @param signo Signal number (always SIGINT, ignored).
-*/
-static
-void
-sig_handler_int(int DK4_ARG_UNUSED(signo) )
-{
- DK4_UNUSED_ARG(signo)
- *sig_pass_pointer(&sig_had_int) = 1;
-}
-
-/** Handler for SIGTERM signal.
- @param signo Signal number (always SIGTERM, ignored).
-*/
-static
-void
-sig_handler_term(int DK4_ARG_UNUSED(signo) )
-{
- DK4_UNUSED_ARG(signo)
- *sig_pass_pointer(&sig_had_term) = 1;
-}
-
-/** Read value from volatile atomic type.
- This function is necessary as some compilers mis-optimize
- direct access to volatile variables (at least if you believe
- one of the coding standards).
- @param ap Pointer to volatile atomic variable.
- @return Contents of the variable.
-*/
-static
-dk4_sig_atomic_t
-sig_read_atomic(DK4_VOLATILE dk4_sig_atomic_t *ap)
-{
- return (*ap);
-}
-
-/** Check whether we can continue or if a signal was received.
- @param check_pipe Flag: Check for occured SIGPIPE signal too.
- @return 1 if the program can continue, 0 if a signal was received.
-*/
-static
-int
-sig_can_continue(
-#ifdef SIGPIPE
-int check_pipe
-#else
-int DK4_ARG_UNUSED(check_pipe)
-#endif
-)
-{
- int back = 1;
-#ifndef SIGPIPE
- DK4_UNUSED_ARG(check_pipe)
-#else
- if (0 != check_pipe) {
- if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; }
- }
-#endif
- if (0 != sig_read_atomic(&sig_had_int )) { back = 0; }
- if (0 != sig_read_atomic(&sig_had_term)) { back = 0; }
- return back;
-}
-
-
-
-/* FUNCTIONS */
-
-
-static
-int
-dk_fic_can_continue(void)
-{
- int back;
- back = sig_can_continue(1);
- if (0 != back) {
- if (0 != dk_fic_write_error) {
- back = 0;
- }
- }
- return back;
-}
-
-
-#if DK4_HAVE_OPENSSL_MD5_H && DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_OPENSSL_RIPEMD_H
-
-
-
-/** Report an error with position.
- @param i1 Index of first message part in array.
- @param i2 Index of alternative first message part.
- @param bno Current byte number.
- @param lno Current line number.
- @param cno Current character number.
- @param cil Current character number within line.
- @param fn File name processed.
-*/
-static
-void
-dk_fic_report_with_position(
- size_t i1,
- size_t i2,
- dk4_um_t bno,
- dk4_um_t lno,
- dk4_um_t cno,
- dk4_um_t cil,
- const dkChar *fn
-)
-{
- dkChar b1[8*(1+sizeof(dk4_um_t))+16];
- dkChar b2[8*(1+sizeof(dk4_um_t))+16];
- dkChar b3[8*(1+sizeof(dk4_um_t))+16];
- const dkChar *oldlogname = NULL;
- dk4_um_t oldlogline = (dk4_um_t)0UL;
- int allbuffersok = 0;
-
- oldlogname = dk4app_get_log_source_file(app);
- oldlogline = dk4app_get_log_source_line(app);
- dk4app_set_log_source_file(app, fn);
- dk4app_set_log_source_line(app, lno);
- if (0 != dk4ma_write_decimal_unsigned(b3,DK4_SIZEOF(b3,dkChar),cil,0,NULL)) {
- if (0 != dk4ma_write_decimal_unsigned(b2,DK4_SIZEOF(b2,dkChar),cno,0,NULL)) {
- if (0 != dk4ma_write_decimal_unsigned(b1,DK4_SIZEOF(b1,dkChar),bno,0,NULL)) {
- allbuffersok = 1;
- }
- }
- }
- if (0 != allbuffersok) {
- dk4app_log_7(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, i1, 38, 39, 40, b1, b2, b3
- );
- } else {
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, i2);
- }
- dk4app_set_log_source_line(app, oldlogline);
- dk4app_set_log_source_file(app, oldlogname);
-}
-
-
-
-/** Report decoding/encoding and processing errors.
- @param er_en Error report for decoding/encoding errors.
- @param er_pr Error report for processing errors.
- @param fn File name.
-*/
-static
-void
-dk_fic_report_errors(
- dk4_er_t *er_en,
- dk4_er_t *er_pr,
- const dkChar *fn
-)
-{
- static int had_decoding_errors = 0;
- static int had_encoding_errors = 0;
- static int had_processing_errors = 0;
-
- if (NULL != er_en) {
- switch (er_en->ec) {
- case DK4_E_DECODING_FAILED : {
- if (3 > had_decoding_errors) {
- dk_fic_report_with_position(
- 35, 32,
- er_en->dt.fpos.byteno, er_en->dt.fpos.lineno,
- er_en->dt.fpos.charno, er_en->dt.fpos.charinline,
- fn
- );
- }
- if (2 <= had_decoding_errors) { had_decoding_errors++; }
- } break;
- case DK4_E_ENCODING_FAILED : {
- if (3 > had_encoding_errors) {
- dk_fic_report_with_position(
- 36, 33,
- er_en->dt.fpos.byteno, er_en->dt.fpos.lineno,
- er_en->dt.fpos.charno, er_en->dt.fpos.charinline,
- fn
- );
- }
- if (2 <= had_encoding_errors) { had_encoding_errors++; }
- } break;
- }
- }
- if (NULL != er_pr) {
- if (DK4_E_NONE != er_pr->ec) {
- if (3 > had_processing_errors) {
- dk_fic_report_with_position(
- 37, 34,
- er_pr->dt.fpos.byteno, er_pr->dt.fpos.lineno,
- er_pr->dt.fpos.charno, er_pr->dt.fpos.charinline,
- fn
- );
- }
- if (2 <= had_processing_errors) { had_processing_errors++; }
- }
- }
-}
-
-
-
-/** Write one ASCII-Hex encoded message digest to stdout.
- @param digptr Start address of text buffer.
- @param sz Digest size.
-*/
-static
-void
-dk_fic_output_digest(const char *digptr, size_t sz)
-{
- while (0 < sz--) {
- if (0 == dk4fputc((dkChar)(*(digptr++)), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- }
-}
-
-
-
-/** Create checksum line for one file.
- @param filename File name.
- @param filesize File size.
-*/
-static
-void
-dk_fic_checksum_file(const dkChar *filename, dk4_um_t filesize)
-{
- dkChar fszbuf[8*sizeof(dk4_um_t)+16];
- const dkChar *oldsourcename;
- const char *md5ptr;
- const char *sha1ptr;
- const char *ripemd160ptr;
-#if DK4_HAVE_SHA512
- const char *sha512ptr;
-#endif
- FILE *fipo;
- dk4_um_t oldsourceline;
- size_t rdb;
- size_t md5sz;
- size_t sha1sz;
- size_t ripemd160sz;
- size_t sl;
-#if DK4_HAVE_SHA512
- size_t sha512sz;
-#endif
- int tests = DK4_FOPEN_SC_IS_REGULAR;
- int ok = 1;
- int res;
- int cc;
-
- res = dk4md_ctx_init(
- &ctx_md5, DK4_MD_MD5, DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- );
- if (0 == res) { ok = 0; }
- res = dk4md_ctx_init(
- &ctx_sha1, DK4_MD_SHA1, DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- );
- if (0 == res) { ok = 0; }
- res = dk4md_ctx_init(
- &ctx_ripemd160, DK4_MD_RIPEMD_160, DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- );
- if (0 == res) { ok = 0; }
-#if DK4_HAVE_SHA512
- res = dk4md_ctx_init(
- &ctx_sha512, DK4_MD_SHA512, DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- );
- if (0 == res) { ok = 0; }
-#endif
- if (0 != ok) {
- fipo = dk4fopen_app(filename, dk_fic_kwnl[5], tests, app);
- if (NULL != fipo) {
- cc = 1;
- while (1 == cc) {
- if (dk_fic_can_continue()) {
- rdb = fread(data_buf, 1, sizeof(data_buf), fipo);
- if (0 < rdb) {
- res = dk4md_ctx_add(&ctx_md5, data_buf, rdb, NULL);
- if (0 == res) { cc = -1; }
- res = dk4md_ctx_add(&ctx_sha1, data_buf, rdb, NULL);
- if (0 == res) { cc = -1; }
- res = dk4md_ctx_add(&ctx_ripemd160, data_buf, rdb, NULL);
- if (0 == res) { cc = -1; }
-#if DK4_HAVE_SHA512
- res = dk4md_ctx_add(&ctx_sha512, data_buf, rdb, NULL);
- if (0 == res) { cc = -1; }
-#endif
- } else {
- cc = 0;
- if (0 != ferror(fipo)) {
- cc = -1;
- /* ERROR Read attempt failed */
- oldsourcename = dk4app_get_log_source_file(app);
- oldsourceline = dk4app_get_log_source_line(app);
- dk4app_set_log_source_file(app, filename);
- dk4app_set_log_source_line(app, (dk4_um_t)0UL);
- dk4app_log_1(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 4
- );
- dk4app_set_log_source_file(app, oldsourcename);
- dk4app_set_log_source_line(app, oldsourceline);
- exval = EXIT_FAILURE;
- }
- }
- } else {
- cc = -1;
- }
- }
- fclose(fipo);
- if (0 == cc) {
- md5ptr = NULL; sha1ptr = NULL; ripemd160ptr = NULL;
- md5sz = 0; sha1sz = 0; ripemd160sz = 0;
-#if DK4_HAVE_SHA512
- sha512ptr = NULL;
- sha512sz = 0;
-#endif
- res = dk4md_ctx_finish(&md5ptr, &md5sz, &ctx_md5, NULL);
- if (0 == res) { cc = -1; }
- res = dk4md_ctx_finish(&sha1ptr, &sha1sz, &ctx_sha1, NULL);
- if (0 == res) { cc = -1; }
- res = dk4md_ctx_finish(&ripemd160ptr,&ripemd160sz,&ctx_ripemd160,NULL);
- if (0 == res) { cc = -1; }
-#if DK4_HAVE_SHA512
- res = dk4md_ctx_finish(&sha512ptr, &sha512sz, &ctx_sha512, NULL);
- if (0 == res) { cc = -1; }
-#endif
- if (0 == cc) {
- res = dk4ma_write_decimal_unsigned(
- fszbuf, DK4_SIZEOF(fszbuf,dkChar), filesize, 0, NULL
- );
- if (0 != res) {
- dk_fic_output_digest(md5ptr, md5sz);
- if (0 == dk4fputc(dkT(' '), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- dk_fic_output_digest(sha1ptr, sha1sz);
- if (0 == dk4fputc(dkT(' '), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- dk_fic_output_digest(ripemd160ptr, ripemd160sz);
-#if DK4_HAVE_SHA512
- if (0 == dk4fputc(dkT(' '), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- dk_fic_output_digest(sha512ptr, sha512sz);
-#endif
- if (0 == dk4fputc(dkT(' '), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- sl = dk4str_len(fszbuf);
- while (sl++ < dk_fic_num_len) {
- if (0 == dk4fputc(dkT(' '), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- }
- if (0 == dk4fputs(fszbuf, stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- if (0 == dk4fputc(dkT(' '), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- if (0 == dk4fputs(filename, stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- if (0 == dk4fputc(dkT('\n'), stdout, NULL)) {
- dk_fic_write_error = 1;
- }
- } else {
- /* ERROR: Failed to convert file size to text */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 5, 6, filename
- );
- exval = EXIT_FAILURE;
- }
- } else {
- /* ERROR: Failed to finish at least one message digest */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 7, 8, filename
- );
- exval = EXIT_FAILURE;
- }
- } else {
- if (-1 == cc) {
- /* ERROR: Failed to add data to message digest context */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 9, 10, filename
- );
- exval = EXIT_FAILURE;
- }
- }
- } else {
- /* ERROR: Failed to open file, already reported */
- exval = EXIT_FAILURE;
- }
- } else {
- /* ERROR: Failed to initialize at least one ctx */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 11, 12, filename
- );
- exval = EXIT_FAILURE;
- }
-}
-
-
-
-/** Line handler when creating a checksum list.
- @param obj Object to modify.
- @param line Text line to process.
- @param lineno Current line number.
- @param erp Error report, may be NULL.
- @return DK4_TSP_RES_OK, DK4_TSP_RES_ERROR, or DK4_TSP_RES_FATAL.
-*/
-static
-int
-dk_fic_create_line_handler(
- void *DK4_ARG_UNUSED(obj),
- dkChar *line,
- dk4_um_t DK4_ARG_UNUSED(lineno),
- dk4_er_t * DK4_ARG_UNUSED(erp)
-)
-{
- dk4_file_info_t fi;
- dk4_er_t er;
- dk4_um_t filesize;
- int res;
- int back = DK4_TSP_RES_OK;
-
- DK4_UNUSED_ARG(obj)
- DK4_UNUSED_ARG(lineno)
- DK4_UNUSED_ARG(erp)
- dk4str_delnl(line);
- dk4path_correct_sep(line);
- filesize = (dk4_um_t)0UL;
- dk4error_init(&er);
- dk4fileinfo_init(&fi);
- if (0 != dk4fileinfo_app(&fi, line, app)) {
- res = dk4fileinfo_size(
- &filesize, &fi, DK4_FILE_INFO_CONTENTS_DATA_TARGET, &er
- );
- if (0 != res) {
- if (0 != dk4fileinfo_exists_and_is_regular(&fi, &er)) {
- dk_fic_checksum_file(line, filesize);
- } else {
- /* ERROR: Not a regular file */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 13, 14, line
- );
- exval = EXIT_FAILURE;
- }
- } else {
- /* ERROR: Failed to obtain file size */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 15, 16, line
- );
- exval = EXIT_FAILURE;
- }
- } else {
- /* ERROR: Failed to information about file, already reported */
- exval = EXIT_FAILURE;
- }
- return back;
-}
-
-
-
-/** Compare current checksum against checksum from file.
- @param curcs Current checksum.
- @param orics Original checksum from file.
- @param curlen Current checksum length.
- @return 1 if both checksums are equal, 0 otherwise.
-*/
-static
-int
-dk_fic_compare_checksums(
- const char *curcs,
- const dkChar *orics,
- size_t curlen
-)
-{
- int back = 0;
-
-
-#line 1128 "dk-fic.ctr"
- if ((NULL != curcs) && (NULL != orics) && (0 < curlen)) {
- back = 1;
- while ((1 == back) && (0 < curlen--)) {
- if ((dkChar)(*(curcs++)) != *(orics++)) {
- back = 0;
- }
- }
- }
-
-#line 1136 "dk-fic.ctr"
- return back;
-}
-
-
-
-/** Line handler when verifying a checksum list.
- @param obj Object to modify.
- @param line Text line to process.
- @param lineno Current line number.
- @param erp Error report, may be NULL.
- @return DK4_TSP_RES_OK, DK4_TSP_RES_ERROR, or DK4_TSP_RES_FATAL.
-*/
-static
-int
-dk_fic_verify_line_handler(
- void * DK4_ARG_UNUSED(obj),
- dkChar *line,
- dk4_um_t DK4_ARG_UNUSED(lineno),
- dk4_er_t * DK4_ARG_UNUSED(erp)
-)
-{
- dk4_file_info_t fi; /* File information */
- dk4_er_t er; /* Error report */
- FILE *fipo; /* File to read */
- const dkChar *oldsourcename; /* Source file */
- const dkChar *endptr; /* Text after size */
- dkChar *tok[16]; /* Tokens in input line */
- const char *md5ptr; /* Encoded message digest */
- const char *sha1ptr; /* Encoded message digest */
- const char *ripemd160ptr; /* Encoded message digest */
-#if DK4_HAVE_SHA512
- const char *sha512ptr; /* Encoded message digest */
-#endif
- dk4_um_t oldsourceline; /* Source line number */
- dk4_um_t filesize; /* Current file size */
- dk4_um_t um; /* File size from input line */
- size_t ntok; /* Number of tokens in input line */
- size_t i; /* Index to initialize tokens */
- size_t rdb; /* Number of bytes read */
- size_t md5sz; /* Encoded digest length */
- size_t sha1sz; /* Encoded digest length */
- size_t ripemd160sz; /* Encoded digest length */
-#if DK4_HAVE_SHA512
- size_t sha512sz; /* Encoded digest length */
-#endif
- int res; /* Operations result */
- int cc; /* Flag: Can continue */
- int tests = DK4_FOPEN_SC_IS_REGULAR;
- int back = DK4_TSP_RES_ERROR;
- int ok = 0; /* Flag: Check passed */
- dk4str_delnl(line);
-
-
-#line 1188 "dk-fic.ctr"
- DK4_UNUSED_ARG(obj)
- DK4_UNUSED_ARG(lineno)
- DK4_UNUSED_ARG(erp)
- /* dk4path_correct_sep(line); Correct file name only! */
- for (i = 0; i < 16; i++) { tok[i] = NULL; }
- if (0 != dk_fic_first_line) {
-
-#line 1194 "dk-fic.ctr"
- dk_fic_first_line = 0;
- ntok = dk4str_tokenize(tok, 16, line, NULL, NULL);
- if (3 == ntok) {
-
-#line 1197 "dk-fic.ctr"
- if (dkT('#') == *(tok[0])) {
- if (0 == dk4str_cmp(dk_fic_kwnl[9], tok[1])) {
- endptr = NULL;
- if (0 != dk4ma_input_dk_dec_dk4_um_t(&um, tok[2], &endptr, 1, NULL)) {
- if ((dk4_um_t)3UL == um) {
-
-#line 1202 "dk-fic.ctr"
- dk_fic_num_mds = 3;
- back = DK4_TSP_RES_OK;
- } else {
- if ((dk4_um_t)4UL == um) {
-
-#line 1206 "dk-fic.ctr"
- dk_fic_num_mds = 4;
- back = DK4_TSP_RES_OK;
-#if !DK4_HAVE_SHA512
- /* Warning SHA-512 checksum ignored, not supported */
- dk4app_log_1(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_WARNING, 17
- );
-#endif
- } else {
-
-#line 1215 "dk-fic.ctr"
- }
- }
- } else {
-
-#line 1218 "dk-fic.ctr"
- }
- } else {
-
-#line 1220 "dk-fic.ctr"
- }
- } else {
-
-#line 1222 "dk-fic.ctr"
- }
- } else {
-
-#line 1224 "dk-fic.ctr"
- }
- if (DK4_TSP_RES_ERROR == back) {
- /* ERROR: Syntax error */
- dk4app_log_1(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 18
- );
- exval = EXIT_FAILURE;
- }
- } else {
-
-#line 1233 "dk-fic.ctr"
- ntok = dk4str_tokenize(tok, 16, line, NULL, NULL);
-
-
-#line 1235 "dk-fic.ctr"
- if ((5 == ntok) && (3 == dk_fic_num_mds)) {
-
-#line 1236 "dk-fic.ctr"
- back = DK4_TSP_RES_OK;
- } else {
- if ((6 == ntok) && (4 == dk_fic_num_mds)) {
-
-#line 1239 "dk-fic.ctr"
- back = DK4_TSP_RES_OK;
- }
- }
- if (DK4_TSP_RES_OK == back) {
-
-#line 1243 "dk-fic.ctr"
-#if VERSION_BEFORE_20150821
- back = DK4_TSP_RES_ERROR;
-#endif
- dk4path_correct_sep(tok[ntok - 1]);
- dk4error_init(&er);
- dk4fileinfo_init(&fi);
- if (0 != dk4fileinfo_app(&fi, tok[ntok - 1], app)) {
-
-#line 1250 "dk-fic.ctr"
- filesize = (dk4_um_t)0UL;
- res = dk4fileinfo_size(
- &filesize, &fi, DK4_FILE_INFO_CONTENTS_DATA_TARGET, &er
- );
- if (0 != res) {
-
-#line 1255 "dk-fic.ctr"
- res = dk4ma_input_dk_dec_dk4_um_t(&um, tok[ntok-2], &endptr, 1, NULL);
- if (0 != res) {
-
-#line 1257 "dk-fic.ctr"
- if (um == filesize) {
-
-#line 1258 "dk-fic.ctr"
- ok = 1;
- /* Initialize message digest contexts.
- */
- res = dk4md_ctx_init(
- &ctx_md5, DK4_MD_MD5, DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- ); if (0 == res) { ok = 0; }
- res = dk4md_ctx_init(
- &ctx_sha1, DK4_MD_SHA1, DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- ); if (0 == res) { ok = 0; }
- res = dk4md_ctx_init(
- &ctx_ripemd160,DK4_MD_RIPEMD_160,
- DK4_BINARY_TO_TEXT_ENCODING_A85, NULL
- ); if (0 == res) { ok = 0; }
-#if DK4_HAVE_SHA512
- if (6 == ntok) {
-
-#line 1273 "dk-fic.ctr"
- res = dk4md_ctx_init(
- &ctx_sha512,DK4_MD_SHA512,DK4_BINARY_TO_TEXT_ENCODING_A85,NULL
- );
- if (0 == res) {
-
-#line 1277 "dk-fic.ctr"
- ok = 0;
- }
- }
-#endif
- if (0 != ok) {
-
-#line 1282 "dk-fic.ctr"
- ok = 0;
- fipo = dk4fopen_app(tok[ntok-1], dk_fic_kwnl[5], tests, app);
- if (NULL != fipo) {
-
-#line 1285 "dk-fic.ctr"
- ok = 1;
- cc = 1;
- while (1 == cc) {
-
-#line 1288 "dk-fic.ctr"
- if (dk_fic_can_continue()) {
-
-#line 1289 "dk-fic.ctr"
- rdb = fread(data_buf, 1, sizeof(data_buf), fipo);
- if (0 < rdb) {
-
-#line 1291 "dk-fic.ctr"
- /* Add data from file to message digest contexts.
- */
- res = dk4md_ctx_add(&ctx_md5, data_buf, rdb, NULL);
- if (0 == res) { ok = 0; cc = -1; }
- res = dk4md_ctx_add(&ctx_sha1, data_buf, rdb, NULL);
- if (0 == res) { ok = 0; cc = -1; }
- res = dk4md_ctx_add(&ctx_ripemd160,data_buf,rdb,NULL);
- if (0 == res) { ok = 0; cc = -1; }
-#if DK4_HAVE_SHA512
- if (6 == ntok) {
- res = dk4md_ctx_add(&ctx_sha512, data_buf, rdb, NULL);
- if (0 == res) { ok = 0; cc = -1; }
- }
-#endif
- if (0 == ok) {
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR,
- 9, 10, tok[ntok-1]
- );
- }
- } else {
-
-#line 1312 "dk-fic.ctr"
- cc = 0;
- if (0 != ferror(fipo)) {
-
-#line 1314 "dk-fic.ctr"
- cc = -1;
- /* ERROR Read attempt failed */
- oldsourcename = dk4app_get_log_source_file(app);
- oldsourceline = dk4app_get_log_source_line(app);
- dk4app_set_log_source_file(app, tok[ntok-1]);
- dk4app_set_log_source_line(app, (dk4_um_t)0UL);
- dk4app_log_1(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 4
- );
- dk4app_set_log_source_file(app, oldsourcename);
- dk4app_set_log_source_line(app, oldsourceline);
- exval = EXIT_FAILURE;
- }
- }
- } else {
-
-#line 1329 "dk-fic.ctr"
- cc = -1;
- }
- }
- fclose(fipo);
- if (0 == cc) {
-
-#line 1334 "dk-fic.ctr"
- /* Retrieve results from message digest contexts.
- */
- md5ptr = NULL; sha1ptr = NULL; ripemd160ptr = NULL;
- md5sz = 0; sha1sz = 0; ripemd160sz = 0;
-#if DK4_HAVE_SHA512
- sha512ptr = NULL;
-
-#line 1340 "dk-fic.ctr"
- sha512sz = 0;
-#endif
- res = dk4md_ctx_finish(&md5ptr, &md5sz, &ctx_md5, NULL);
- if (0 == res) {
- ok = 0;
-#if VERSION_BEFORE_20150821
- cc = -1;
-#endif
- }
- res = dk4md_ctx_finish(&sha1ptr, &sha1sz, &ctx_sha1, NULL);
- if (0 == res) {
- ok = 0;
-#if VERSION_BEFORE_20150821
- cc = -1;
-#endif
- }
- res = dk4md_ctx_finish(
- &ripemd160ptr,&ripemd160sz,&ctx_ripemd160,NULL
- );
- if (0 == res) {
- ok = 0;
-#if VERSION_BEFORE_20150821
- cc = -1;
-#endif
- }
-#if DK4_HAVE_SHA512
- if (6 == ntok) {
-
-#line 1367 "dk-fic.ctr"
- res = dk4md_ctx_finish(
- &sha512ptr, &sha512sz, &ctx_sha512, NULL
- );
-
-#line 1370 "dk-fic.ctr"
- if (0 == res) {
- ok = 0;
-#if VERSION_BEFORE_20150821
- cc = -1;
-#endif
- }
- }
-#endif
- if (0 == ok) {
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR,
- 7, 8, tok[ntok-1]
- );
- }
- /* Compare current results against input contents.
- */
- if (0 != ok) {
-
-#line 1387 "dk-fic.ctr"
- res = dk_fic_compare_checksums(md5ptr, tok[0], md5sz);
- if (0 == res) {
-
-#line 1389 "dk-fic.ctr"
- ok = 0;
- }
- }
- if (0 != ok) {
-
-#line 1393 "dk-fic.ctr"
- res = dk_fic_compare_checksums(sha1ptr, tok[1], sha1sz);
- if (0 == res) {
-
-#line 1395 "dk-fic.ctr"
- ok = 0;
- }
- }
- if (0 != ok) {
-
-#line 1399 "dk-fic.ctr"
- res = dk_fic_compare_checksums(
- ripemd160ptr, tok[2], ripemd160sz
- );
- if (0 == res) {
-
-#line 1403 "dk-fic.ctr"
- ok = 0;
- }
- }
-
-#if DK4_HAVE_SHA512
- if (6 == ntok) {
-
-#line 1409 "dk-fic.ctr"
- if (0 != ok) {
-
-#line 1410 "dk-fic.ctr"
- res = dk_fic_compare_checksums(
- sha512ptr, tok[3], sha512sz
- );
- if (0 == res) {
-
-#line 1414 "dk-fic.ctr"
- ok = 0;
- }
- }
- }
-#endif
- } else {
-
-#line 1420 "dk-fic.ctr"
- ok = 0;
- }
- } else {
-
-#line 1423 "dk-fic.ctr"
- }
- } else {
-
-#line 1425 "dk-fic.ctr"
- /* ERROR Failed to initialize MD contexts */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 11, 12,
- tok[ntok-1]
- );
- }
- } else {
-
-#line 1432 "dk-fic.ctr"
- }
- if (0 != ok) {
-
-#line 1434 "dk-fic.ctr"
- if (2 <= dk_fic_verbosity) {
- if (0 == dk4fputs(dk_fic_msg[2], stdout, NULL)) {
- exval = EXIT_FAILURE; dk_fic_write_error = 1;
- }
- if (0 == dk4fputs(tok[ntok-1], stdout, NULL)) {
- exval = EXIT_FAILURE; dk_fic_write_error = 1;
- }
- if (0 == dk4fputc(dkT('\n'), stdout, NULL)) {
- exval = EXIT_FAILURE; dk_fic_write_error = 1;
- }
- }
- } else {
-
-#line 1446 "dk-fic.ctr"
- exval = EXIT_FAILURE;
- if (1 <= dk_fic_verbosity) {
- if (0 == dk4fputs(dk_fic_msg[3], stdout, NULL)) {
- exval = EXIT_FAILURE; dk_fic_write_error = 1;
- }
- if (0 == dk4fputs(tok[ntok-1], stdout, NULL)) {
- exval = EXIT_FAILURE; dk_fic_write_error = 1;
- }
- if (0 == dk4fputc(dkT('\n'), stdout, NULL)) {
- exval = EXIT_FAILURE; dk_fic_write_error = 1;
- }
- }
- }
- } else {
-
-#line 1460 "dk-fic.ctr"
- /* Syntax error */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 21, 22, tok[ntok-2]
- );
- exval = EXIT_FAILURE;
- }
- } else {
-
-#line 1467 "dk-fic.ctr"
- /* ERROR: Failed to retrieve file size */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 15, 16, line
- );
- exval = EXIT_FAILURE;
- }
- } else {
-
-#line 1474 "dk-fic.ctr"
- /* ERROR: Failed to information about file, already reported */
- exval = EXIT_FAILURE;
- }
-#if VERSION_BEFORE_20150821
- back = DK4_TSP_RES_OK;
-#endif
- } else {
-
-#line 1481 "dk-fic.ctr"
- /* Syntax error */
- if (3 == dk_fic_num_mds) {
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 20);
- } else {
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 19);
- }
- exval = EXIT_FAILURE;
- }
- }
-
-
-#line 1491 "dk-fic.ctr"
- return back;
-}
-
-
-
-/** Process one file.
- @param fipo Opened file.
- @param fn File name.
- @param ie Expected input encoding.
-*/
-static
-void
-dk_fic_process_file(FILE *fipo, const dkChar *fn, int ie)
-{
- dk4_tspdk_t tsp;
- dk4_er_t er_en;
- dk4_er_t er_pr;
- dk4_er_t er;
- int res;
- int cc;
- int c;
- unsigned char ub;
-
-
-#line 1514 "dk-fic.ctr"
- dk4error_init(&er_en);
- dk4error_init(&er_pr);
- dk4error_init(&er);
- res = dk4tspdk_setup_line(
- &tsp, NULL,
- (
- (0 != dk_fic_verify)
- ? dk_fic_verify_line_handler
- : dk_fic_create_line_handler
- ),
- ibuf_ptr, ibuf_sz,
- dk4app_get_encoding(app), ie,
- &er
- );
- if (0 != res) {
- cc = 1;
- dk_fic_first_line = 1;
- dk_fic_num_mds = 4;
- do {
- if (dk_fic_can_continue()) {
- c = fgetc(fipo);
- if (EOF != c) {
- ub = (unsigned char)c;
- switch (dk4tspdk_add_one_byte(&tsp, ub)) {
- case DK4_TSP_RES_FATAL : {
- cc = -1;
- exval = EXIT_FAILURE;
- dk4tspdk_get_errors(&er_en, &er_pr, &tsp);
- dk_fic_report_errors(&er_en, &er_pr, fn);
- } break;
- case DK4_TSP_RES_ERROR : {
- exval = EXIT_FAILURE;
- dk4tspdk_get_errors(&er_en, &er_pr, &tsp);
- dk_fic_report_errors(&er_en, &er_pr, fn);
- } break;
- }
- } else {
- cc = 0;
- }
- } else {
- cc = -1;
- }
- } while (1 == cc);
- if (0 == cc) {
- switch (dk4tspdk_finish(&tsp)) {
- case DK4_TSP_RES_FATAL : {
-#if VERSION_BEFORE_20150821
- cc = -1;
-#endif
- exval = EXIT_FAILURE;
- dk4tspdk_get_errors(&er_en, &er_pr, &tsp);
- dk_fic_report_errors(&er_en, &er_pr, fn);
- } break;
- case DK4_TSP_RES_ERROR : {
- exval = EXIT_FAILURE;
- dk4tspdk_get_errors(&er_en, &er_pr, &tsp);
- dk_fic_report_errors(&er_en, &er_pr, fn);
- } break;
- }
- }
- } else {
- /* ERROR: Failed to initialize text stream processor */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 23);
- exval = EXIT_FAILURE;
- }
-
-
-#line 1580 "dk-fic.ctr"
-}
-
-
-
-static
-void
-dk_fic_process_filename(const dkChar *filename)
-{
- FILE *fipo;
- int tests = DK4_FOPEN_SC_IS_REGULAR;
- fipo = dk4fopen_app(filename, dk_fic_kwnl[5], tests, app);
- if (NULL != fipo) {
- dk_fic_process_file(fipo, filename, dk_fic_ie_file);
- fclose(fipo);
- } else {
- exval = EXIT_FAILURE;
- }
-}
-
-
-
-#if DK4_ON_WINDOWS
-static
-void
-dk_fic_expand_path_and_file(
- dkChar *bptr,
- size_t bsz,
- const dkChar *pth,
- const dkChar *shf
-)
-{
- if (0 != dk4str_cpy_s(bptr, bsz, pth, NULL)) {
- if (0 != dk4str_cat_s(bptr, bsz, dk_fic_kwnl[6], NULL)) {
- if (0 != dk4str_cat_s(bptr, bsz, shf, NULL)) {
- dk_fic_process_filename(bptr);
- } else {
- /* ERROR: Name too long */
- dk4app_log_base3(app, DK4_LL_ERROR, 98, 99, shf);
- exval = EXIT_FAILURE;
- }
- } else {
- /* ERROR: Name too long */
- dk4app_log_base3(app, DK4_LL_ERROR, 98, 99, pth);
- exval = EXIT_FAILURE;
- }
- } else {
- /* ERROR: Name too long */
- dk4app_log_base3(app, DK4_LL_ERROR, 98, 99, pth);
- exval = EXIT_FAILURE;
- }
-}
-
-
-
-static
-void
-dk_fic_expand_filename(const dkChar *pattern)
-{
- dkChar buf[DK4_MAX_PATH];
- dk4_dir_t *fne;
- const dkChar *shf;
- const dkChar *pth;
- int any_file_found = 0;
- int can_continue;
-
-
-#line 1645 "dk-fic.ctr"
- fne = dk4app_fne_open(pattern, app);
- if (NULL != fne) {
- do {
- shf = dk4dir_next_file(fne);
- if (NULL != shf) {
- any_file_found = 1;
- can_continue = dk_fic_can_continue();
- if (0 != can_continue) {
- pth = dk4dir_get_path(fne);
- if (NULL != pth) {
- dk_fic_expand_path_and_file(buf, DK4_SIZEOF(buf,dkChar), pth, shf);
- } else {
- dk_fic_process_filename(shf);
- }
- }
- } else {
- can_continue = 0;
- }
- } while (1 == can_continue);
- dk4dir_close(fne);
- if (0 == any_file_found) {
- /* ERROR: No matching file found */
- dk4app_log_base3(app, DK4_LL_ERROR, 100, 107, pattern);
- exval = EXIT_FAILURE;
- }
- } else {
- exval = EXIT_FAILURE;
- }
-
-
-#line 1674 "dk-fic.ctr"
-}
-#endif
-
-#endif
-/* if DK4_HAVE_... */
-
-
-
-/** Process the command line arguments.
-*/
-static
-void
-dk_fic_run_for_command_line_args(void)
-{
- const dkChar *filename;
- int xargc;
- int i;
-#if DK4_HAVE_OPENSSL_MD5_H && DK4_HAVE_OPENSSL_SHA_H && DK4_HAVE_OPENSSL_RIPEMD_H
-#if DK4_ON_WINDOWS
- int oldmode;
-#endif
- if (0 == dk_fic_verify) {
-#if DK4_HAVE_SHA512
- dk4fputs(dk_fic_kwnl[8], stdout, NULL);
-#else
- dk4fputs(dk_fic_kwnl[7], stdout, NULL);
-#endif
- }
- xargc = dk4app_get_argc(app);
- if (0 < xargc) {
- for (i = 0; ((0 != dk_fic_can_continue()) && (i < xargc)); i++) {
- filename = dk4app_get_argv(app, i);
- if (NULL != filename) {
-#if DK4_ON_WINDOWS
- if (0 != dk4path_must_expand(filename)) {
- dk_fic_expand_filename(filename);
- } else {
-#endif
- dk_fic_process_filename(filename);
-#if DK4_ON_WINDOWS
- }
-#endif
- } else {
- /* ERROR: Failed to obtain command line argument, bug! */
- exval = EXIT_FAILURE;
- }
- }
- } else {
-#if DK4_ON_WINDOWS
- oldmode = _setmode(_fileno(stdin), _O_BINARY);
-#endif
- dk_fic_process_file(stdin, dk_fic_kwnl[4], dk_fic_ie_stdin);
-#if DK4_ON_WINDOWS
- _setmode(_fileno(stdin), oldmode);
-#endif
- }
-#else
- /* ERROR: At least one unsupported message digest type */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 24);
- exval = EXIT_FAILURE;
-#endif
-}
-
-
-
-/** Process options and preferences.
-*/
-static
-void
-dk_fic_normal_run(void)
-{
- dkChar encbuf[64];
- size_t myll = 0;
- int res;
-
- /* Assume success.
- */
- exval = EXIT_SUCCESS;
-
- /* Process command line options.
- */
- if (0 != dk4app_opt_is_set_short(app, dkT('c'), NULL)) {
- dk_fic_verify = 1;
- }
- if (0 != dk4app_opt_is_set_short(app, dkT('q'), NULL)) {
- dk_fic_verbosity = 0;
- if (0 != dk4app_opt_is_set_short(app, dkT('v'), NULL)) {
- /* ERROR: Options -q an -v are mutually exclusve */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 25);
- exval = EXIT_FAILURE;
- goto finished;
- }
- } else {
- if (0 != dk4app_opt_is_set_short(app, dkT('v'), NULL)) {
- dk_fic_verbosity = 2;
- }
- }
-#if VERSION_BEFORE_20150821
- res = 0;
-#endif
- if (0 != dk4app_opt_is_set_short(app, dkT('i'), NULL)) {
- res = dk4app_opt_get_string_short(
- encbuf, DK4_SIZEOF(encbuf,dkChar), app, dkT('i'), NULL
- );
- if (0 != res) {
- res = dk4enc_find(&dk_fic_ie_stdin, NULL, encbuf, NULL);
- if (0 != res) {
- dk_fic_ie_file = dk_fic_ie_stdin;
- } else {
- /* ERROR: Encoding not found! */
- dk4app_log_3(
- app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 26, 27, encbuf
- );
- exval = EXIT_FAILURE;
- goto finished;
- }
- }
- }
- res = 0;
- if (0 != dk4app_opt_is_set_short(app, dkT('l'), NULL)) {
- res = dk4app_opt_get_size_short(&myll, app, dkT('l'), NULL);
- }
- if ((0 == res) && (0 == dk4app_opt_is_set_short(app, dkT('R'), NULL))) {
- res = dk4app_pref_get_size(&myll, app, dk_fic_kwnl[3], 0);
- }
- if ((0 != res) && (DK4_SIZEOF(ibuf_def,dkChar) < myll)) {
- ibuf_all = dk4mem_new_app(dkChar, myll, app);
- if (NULL != ibuf_all) {
- ibuf_ptr = ibuf_all;
- ibuf_sz = myll;
- } else {
- goto finished;
- }
- }
-
- /* If no errors yet, process input.
- */
- if (EXIT_SUCCESS == exval) {
- dk_fic_run_for_command_line_args();
- }
-
- /* Clean up dynamic buffers, if any.
- */
- finished:
- if (NULL != ibuf_all) {
- dk4mem_release(ibuf_all);
- }
-}
-
-
-
-/* SIGNAL HANDLING */
-
-
-#if DK4_HAVE_SIGACTION
-/** Set signal handlers and run.
-*/
-static
-void
-dk_fic_run_with_signal_handlers(void)
-{
-#ifdef SIGPIPE
- struct sigaction opipe;
-#endif
- struct sigaction oint;
-#ifdef SIGPIPE
- struct sigaction npipe;
-#endif
- struct sigaction nint;
- struct sigaction oterm;
- struct sigaction nterm;
- int success = 0;
-
-#ifdef SIGPIPE
- /* Set up signal handling for SIGPIPE.
- */
- DK4_MEMRES(&npipe, sizeof(npipe));
- npipe.sa_handler = sig_handler_pipe;
- npipe.sa_flags = 0;
- if (0 != sigemptyset(&npipe.sa_mask)) {
- /* ERROR: Failed to set up masked signal set for SIGPIPE */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto finished;
- }
- if (0 != sigaddset(&npipe.sa_mask, SIGPIPE)) {
- /* ERROR: Failed to set up masked signal set for SIGPIPE */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto finished;
- }
- if (0 != sigaction(SIGPIPE, &npipe, &opipe)) {
- /* ERROR: Failed to set up signal handler for SIGPIPE */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto finished;
- }
-#endif
-
- /* Set up signal handling for SIGINT.
- */
- DK4_MEMRES(&nint, sizeof(nint));
- nint.sa_handler = sig_handler_int;
- nint.sa_flags = 0;
- if (0 != sigemptyset(&nint.sa_mask)) {
- /* ERROR: Failed to set up masked signal set for SIGINT */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto restore_old_pipe;
- }
- if (0 != sigaddset(&nint.sa_mask, SIGINT)) {
- /* ERROR: Failed to set up masked signal set for SIGINT */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto restore_old_pipe;
- }
- if (0 != sigaction(SIGINT, &nint, &oint)) {
- /* ERROR: Failed to set up signal handler for SIGINT */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto restore_old_pipe;
- }
-
- /* Set up signal handling for SIGTERM
- */
- DK4_MEMRES(&nterm, sizeof(nterm));
- nterm.sa_handler = sig_handler_term;
- nterm.sa_flags = 0;
- if (0 != sigemptyset(&nterm.sa_mask)) {
- /* ERROR: Failed to set up masked signal set for SIGTERM */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto restore_old_int;
- }
- if (0 != sigaddset(&nterm.sa_mask, SIGTERM)) {
- /* ERROR: Failed to set up masked signal set for SIGTERM */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto restore_old_int;
- }
- if (0 != sigaction(SIGTERM, &nterm, &oterm)) {
- /* ERROR: Failed to set up signal handler for SIGTERM */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 0);
- goto restore_old_int;
- }
-
- success = 1;
- dk_fic_normal_run();
-
- /* Restore signal handling for SIGTERM.
- */
- if (0 != sigaction(SIGTERM, &oterm, NULL)) {
- /* ERROR: Failed to restore old SIGTERM settings */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 1);
- success = 0;
- }
-
- /* Restore signal handling for SIGINT.
- */
- restore_old_int:
- if (0 != sigaction(SIGINT, &oint, NULL)) {
- /* ERROR: Failed to restore old SIGPIPE settings */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 1);
- success = 0;
- }
-
-#ifdef SIGPIPE
- /* Restore signal handling for SIGPIPE.
- */
- restore_old_pipe:
- if (0 != sigaction(SIGPIPE, &opipe, NULL)) {
- /* ERROR: Failed to restore old SIGPIPE settings */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 1);
- success = 0;
- }
-#endif
-
- /* Set exit status code if error occured.
- */
- finished:
- if (0 == success) { exval = EXIT_FAILURE; }
-}
-#else
-#if DK4_HAVE_SIGSET
-/** Set signal handlers and run.
-*/
-static
-void
-dk_fic_run_with_signal_handlers(void)
-{
-#ifdef SIGPIPE
- dk4_sig_handler_t *oldpipe = NULL;
-#endif
- dk4_sig_handler_t *oldint = NULL;
- dk4_sig_handler_t *oldterm = NULL;
-
-#ifdef SIGPIPE
- oldpipe = sigset(SIGPIPE, sig_handler_pipe);
-#endif
- oldint = sigset(SIGINT, sig_handler_int);
- oldterm = sigset(SIGTERM, sig_handler_term);
- dk_fic_normal_run();
- sigset(SIGTERM, oldterm);
- sigset(SIGINT, oldint);
-#ifdef SIGPIPE
- sigset(SIGPIPE, oldpipe);
-#endif
-}
-#else
-#if DK4_HAVE_SIGNAL
-/** Set signal handlers and run.
-*/
-static
-void
-dk_fic_run_with_signal_handlers(void)
-{
-#ifdef SIGPIPE
- dk4_sig_handler_t *oldpipe = NULL;
-#endif
- dk4_sig_handler_t *oldint = NULL;
- dk4_sig_handler_t *oldterm = NULL;
-
-#ifdef SIGPIPE
- oldpipe = signal(SIGPIPE, sig_handler_pipe);
-#endif
- oldint = signal(SIGINT, sig_handler_int);
- oldterm = signal(SIGTERM, sig_handler_term);
- dk_fic_normal_run();
- signal(SIGTERM, oldterm);
- signal(SIGINT, oldint);
-#ifdef SIGPIPE
- signal(SIGPIPE, oldpipe);
-#endif
-}
-#else
-/** Set signal handlers and run.
-*/
-static
-void
-dk_fic_run_with_signal_handlers(void)
-{
- dk_fic_normal_run();
-}
-#endif
-#endif
-#endif
-
-
-
-/** Main function.
- @param argc Number of command line arguments.
- @param argv Command line arguments array.
- @return 0 on success, all other values indicate errors.
-*/
-#if DK4_CHAR_SIZE > 1
-int wmain(int argc, wchar_t *argv[])
-#else
-int main(int argc, char *argv[])
-#endif
-{
-
-
-#line 2027 "dk-fic.ctr"
-
-
-#line 2028 "dk-fic.ctr"
- dk_fic_num_len = dk4numlength(sizeof(dk4_um_t), 0);
- dk4fput_initialize_stdout();
- dk4fput_initialize_stderr();
- app = dk4app_open_cmd(
- argc, argv, dk_fic_options, dk_fic_sz_options,
- dk_fic_kwnl[0], DKT_VERSION_DK,
- dk_fic_kwnl[1], dk_fic_help_text, dk_fic_license_text
- );
- if (NULL != app) {
- dk_fic_sz_msg = dk4app_string_table_size(dk_fic_kw_def);
- dk_fic_msg = dk4app_string_table(app, dk_fic_kwnl[2], dk_fic_kw_def);
- dk_fic_ie_stdin = dk4app_get_stdin_encoding(app);
- dk_fic_ie_file = dk4app_get_file_in_encoding(app);
- if (0 != dk4app_can_run_normally(app)) {
- dk_fic_run_with_signal_handlers();
- } else {
- if (0 != dk4app_help_version_license(app)) {
- exval = EXIT_SUCCESS;
- }
- }
- if (0 != dk_fic_write_error) {
- /* ERROR While writing output */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 28);
- exval = EXIT_FAILURE;
- }
-#ifdef SIGPIPE
- if (0 != sig_read_atomic(&sig_had_int)) {
- /* Signal PIPE */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 29);
- exval = EXIT_FAILURE;
- }
-#endif
- if (0 != sig_read_atomic(&sig_had_int)) {
- /* Signal INT */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 30);
- exval = EXIT_FAILURE;
- }
- if (0 != sig_read_atomic(&sig_had_term)) {
- /* Signal TERM */
- dk4app_log_1(app, dk_fic_msg, dk_fic_sz_msg, DK4_LL_ERROR, 31);
- exval = EXIT_FAILURE;
- }
- dk4app_close(app);
- }
- fflush(stdout);
- fflush(stderr);
- dk4fput_cleanup_stderr();
- dk4fput_cleanup_stdout();
-
-
-#line 2077 "dk-fic.ctr"
-
-
-#line 2078 "dk-fic.ctr"
- exit (exval); return exval;
-}
-
-