diff options
Diffstat (limited to 'support/dktools/dk4applog.c')
-rw-r--r-- | support/dktools/dk4applog.c | 1666 |
1 files changed, 1666 insertions, 0 deletions
diff --git a/support/dktools/dk4applog.c b/support/dktools/dk4applog.c new file mode 100644 index 0000000000..c066252d0e --- /dev/null +++ b/support/dktools/dk4applog.c @@ -0,0 +1,1666 @@ +/* + 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: dk4applog.ctr +*/ + +/* +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. +*/ + +/** @file dk4applog.c The dk4applog module. +*/ + + +#line 9 "dk4applog.ctr" + + +#ifndef DK4APP_H_INCLUDED +#include "dk4app.h" +#endif + +#ifndef DK4CONST_H_INCLUDED +#include "dk4const.h" +#endif + +#ifndef DK4TIME_H_INCLUDED +#include "dk4time.h" +#endif + +#ifndef DK4TIMEDK_H_INCLUDED +#include "dk4timedk.h" +#endif + +#ifndef DK4MAODD_H_INCLUDED +#include "dk4maodd.h" +#endif + +#ifndef DK4FPUT_H_INCLUDED +#include "dk4fput.h" +#endif + +#ifndef DK4MEM_H_INCLUDED +#include "dk4mem.h" +#endif + +#ifndef DK4FOP8_H_INCLUDED +#include "dk4fopc8.h" +#endif + +#ifndef DK4FOPD_H_INCLUDED +#include "dk4fopd.h" +#endif + +#ifndef DK4MAODD_H_INCLUDED +#include "dk4maodd.h" +#endif + +#ifndef DK4ENC_H_INCLUDED +#include "dk4enc.h" +#endif + +#ifndef DK4APPMKDH_H_INCLUDED +#include "dk4appmkdh.h" +#endif + +#ifndef DK4MPL_H_INCLUDED +#include "dk4mpl.h" +#endif + +#ifndef DK4FS_H_INCLUDED +#include "dk4fs.h" +#endif + + + + + +#line 70 "dk4applog.ctr" + + + +/** Constant char texts used by the module, not localized. +*/ +static const dkChar * const dk4app_log_kwnl[] = { +/* 0 */ +dkT("w"), + +/* 1 */ +dkT("a"), + +/* 2 */ +dkT("dk4debug.str"), + +/* 3 */ +dkT("-"), + +/* 4 */ +dkT("+"), + +/* 5 */ +dkT("ascii"), + +/* 6 */ +dkT("ansi"), + +/* 7 */ +dkT("utf-8"), + +/* 8 */ +dkT("utf-16"), + +/* 9 */ +dkT("utf-16-le"), + +/* 10 */ +dkT("utf-16-be"), + +/* 11 */ +dkT("c32"), + +/* 12 */ +dkT("c32-le"), + +/* 13 */ +dkT("c32-be"), + +/* 14 */ +dkT("dk3pref.conf"), + +/* 15 */ +dkT("dk4pref.conf"), + +NULL + + +#line 109 "dk4applog.ctr" +}; + + + +/** The message texts for the base log domain, nearly always loaded. +*/ +static const dkChar * const dk4app_def_msg_base[] = { +/* 0 */ +dkT("NONE"), + +/* 1 */ +dkT("Panic"), + +/* 2 */ +dkT("Fatal"), + +/* 3 */ +dkT("Error"), + +/* 4 */ +dkT("Warning"), + +/* 5 */ +dkT("Info"), + +/* 6 */ +dkT("Progress"), + +/* 7 */ +dkT("Debug"), + +/* 8 */ +dkT("Ignore"), + +/* 9 */ +dkT("Illegal option: \""), + +/* 10 */ +dkT("\"!"), + +/* 11 */ +dkT("Option \""), + +/* 12 */ +dkT("\" requires argument!"), + +/* 13 */ +dkT("Option \""), + +/* 14 */ +dkT("\" requires a boolean argument!\n\tRejected text: \""), + +/* 15 */ +dkT("\"!"), + +/* 16 */ +dkT("Option \""), + +/* 17 */ +dkT("\" requires a size argument!\n\tRejected text: \""), + +/* 18 */ +dkT("\"!"), + +/* 19 */ +dkT("Option \""), + +/* 20 */ +dkT("\" requires integer argument!\n\tRejected text: \""), + +/* 21 */ +dkT("\"!"), + +/* 22 */ +dkT("Option \""), + +/* 23 */ +dkT("\" requires unsigned integer argument!\n\tRejected text: \""), + +/* 24 */ +dkT("\"!"), + +/* 25 */ +dkT("Option \""), + +/* 26 */ +dkT("\" requires floating point (double) argument!\n\tRejected text: \""), + +/* 27 */ +dkT("\"!"), + +/* 28 */ +dkT("Option \"--"), + +/* 29 */ +dkT("Option \"--"), + +/* 30 */ +dkT("Option \"--"), + +/* 31 */ +dkT("Option \"--"), + +/* 32 */ +dkT("Option \"--"), + +/* 33 */ +dkT("Option \"--"), + +/* 34 */ +dkT("Failed to save preference value!\n\t\""), + +/* 35 */ +dkT("\"=\""), + +/* 36 */ +dkT("\"!"), + +/* 37 */ +dkT("Value required for command line preference \""), + +/* 38 */ +dkT("\"!"), + +/* 39 */ +dkT("Option too long!\n\t\""), + +/* 40 */ +dkT("\"!"), + +/* 41 */ +dkT("Failed to remove file:\n\t\""), + +/* 42 */ +dkT("\"!\n\tPath name too long."), + +/* 43 */ +dkT("Failed to create directory:\n\t\""), + +/* 44 */ +dkT("\"!\n\tPath exists, but is not a directory!"), + +/* 45 */ +dkT("\n\tLocal network interface is down!"), + +/* 46 */ +dkT("Failed to create directory:\n\t\""), + +/* 47 */ +dkT("\"!\n\tIllegal path."), + +/* 48 */ +dkT("\"!\n\tFile or directory in use."), + +/* 49 */ +dkT("\"!\n\tPath already exists."), + +/* 50 */ +dkT("\"!\n\tPath name points outside accessible address space."), + +/* 51 */ +dkT("\"!\n\tPath not found (one path component does not exist)."), + +/* 52 */ +dkT("\"!\n\tPath specifies a directory."), + +/* 53 */ +dkT("\"!\n\tNo function for wide-char mkdir available."), + +/* 54 */ +dkT("No wide-char function to remove files available."), + +/* 55 */ +dkT("\"!\n\tInsufficient permissions."), + +/* 56 */ +dkT("\"!\n\tFile system is mounted read-only."), + +/* 57 */ +dkT("\"!\n\tConflict with extended attribute."), + +/* 58 */ +dkT("\"!\n\tNot allowed for this file system type."), + +/* 59 */ +dkT("\"!\n\tI/O error on device."), + +/* 60 */ +dkT("\"!\n\tDisk space or quota problem."), + +/* 61 */ +dkT("\"!\n\tToo many symbolic links in path (probably symlink loop)."), + +/* 62 */ +dkT("\"!\n\tInsufficient kernel memory."), + +/* 63 */ +dkT("\"!\n\tToo many entries in parent directory."), + +/* 64 */ +dkT("\"!\n\tFile server not available."), + +/* 65 */ +dkT("\"!\n\tName too long."), + +/* 66 */ +dkT("Failed to remove directory:\n\t\""), + +/* 67 */ +dkT("\"!\n\tDirectory not empty."), + +/* 68 */ +dkT("\"!\n\tInvalid path name."), + +/* 69 */ +dkT("\"!\n\tWindows error code: "), + +/* 70 */ +dkT(" (0x"), + +/* 71 */ +dkT(")."), + +/* 72 */ +dkT("\"!"), + +/* 73 */ +dkT("\"!\n\tParent directory not found (device or server share)!"), + +/* 74 */ +dkT("\"!\n\tBad network resource name (share name)!"), + +/* 75 */ +dkT("\"!\n\tBad network resource name (server name)!"), + +/* 76 */ +dkT("\n\tNo route to network destination available!"), + +/* 77 */ +dkT("\"!"), + +/* 78 */ +dkT("\n\tAttempt to read from outside file!"), + +/* 79 */ +dkT("\"!\n\tError code: "), + +/* 80 */ +dkT("."), + +/* 81 */ +dkT("Options --help, --version, and --license are mutually exclusive!"), + +/* 82 */ +dkT("Numeric overflow in size calculation!"), + +/* 83 */ +dkT("Numeric overflow in size calculation!\n\t"), + +/* 84 */ +dkT(" elements of "), + +/* 85 */ +dkT(" bytes."), + +/* 86 */ +dkT("Memory allocation failed! Invalid size(s) specified."), + +/* 87 */ +dkT("Memory allocation failed! Invalid size(s) specified.\n\tNumber of elements: "), + +/* 88 */ +dkT(", element size: "), + +/* 89 */ +dkT("."), + +/* 90 */ +dkT("Not enough memory! Allcation failed."), + +/* 91 */ +dkT("Not enough memory! Allcation failed.\n\tNumber of elements: "), + +/* 92 */ +dkT(", element size: "), + +/* 93 */ +dkT("."), + +/* 94 */ +dkT("Further file removal attempts failed in:\n\t\""), + +/* 95 */ +dkT("\"!"), + +/* 96 */ +dkT("Further subdirectory removal attempts failed in:\n\t\""), + +/* 97 */ +dkT("\"!"), + +/* 98 */ +dkT("File or directory name too long:\n\t\""), + +/* 99 */ +dkT("\"!"), + +/* 100 */ +dkT("Failed to expand file name:\n\t\""), + +/* 101 */ +dkT("\"!"), + +/* 102 */ +dkT("\"!\n\tNo function for directory traversal available!"), + +/* 103 */ +dkT("\"!\n\tMemory allocation failed!"), + +/* 104 */ +dkT("\"!\n\tFailed to open directory for traversal!"), + +/* 105 */ +dkT("\"!\n\tDirectory or file name too large!"), + +/* 106 */ +dkT("\"!\n\tMultiple matching files!"), + +/* 107 */ +dkT("\"!\n\tNo matching file!"), + +/* 108 */ +dkT("Failed to open file:\n\t\""), + +/* 109 */ +dkT("\"!\n\tNot a regular file!"), + +/* 110 */ +dkT("\"!\n\tPath contains symbolic links!"), + +/* 111 */ +dkT("\"!\n\tPath is a symbolic link!"), + +/* 112 */ +dkT("\"!\n\tSymbolic link owner is not target owner!"), + +/* 113 */ +dkT("\"!\n\tSignal received!"), + +/* 114 */ +dkT("\"!\n\tToo many open files in process!"), + +/* 115 */ +dkT("\"!\n\tToo many open files on system!"), + +/* 116 */ +dkT("\"!\n\tDevice for special file does not exist!"), + +/* 117 */ +dkT("\"!\n\tFile size too large for off_t data type!"), + +/* 118 */ +dkT("Read operation failed!"), + +/* 119 */ +dkT("Read operation failed, error code:"), + +/* 120 */ +dkT("."), + +/* 121 */ +dkT("\n\tOperation would block!"), + +/* 122 */ +dkT("\n\tBad file descriptor (bug)!"), + +/* 123 */ +dkT("\n\tBuffer is outside usable address space (bug)!"), + +/* 124 */ +dkT("\n\tSignal received!"), + +/* 125 */ +dkT("\n\tFile descriptor attached to unsuitable object (bug)!"), + +/* 126 */ +dkT("\n\tI/O error!"), + +/* 127 */ +dkT("\n\tFile descriptor attachted to directory (bug)!"), + +/* 128 */ +dkT("Write operation failed!"), + +/* 129 */ +dkT("Write operation failed, error code:"), + +/* 130 */ +dkT("."), + +/* 131 */ +dkT("\n\tNo space left on device!"), + +/* 132 */ +dkT("\n\tFile size would exceed limits!"), + +/* 133 */ +dkT("\n\tNo reader attached to pipe or socket!"), + +/* 134 */ +dkT("\n\tSocket not connected!"), + +/* 135 */ +dkT("\n\tBuffer size outside supported range!"), + +/* 136 */ +dkT("\n\tInsufficient system resources available!"), + +/* 137 */ +dkT("\n\tNonexistent or incapable device!"), + +/* 138 */ +dkT("\n\tInsufficient permissions!"), + +/* 139 */ +dkT("\n\tUnexpected control part in normal-mode message!"), + +/* 140 */ +dkT("\n\tConnection reset by peer!"), + +/* 141 */ +dkT("\n\tTimed out!"), + +/* 142 */ +dkT("\n\tInsufficient memory available!"), + +/* 143 */ +dkT("\n\tFile descriptor is socket or FIFO!"), + +/* 144 */ +dkT("Failed to open directory:\n\t\""), + +/* 145 */ +dkT("\"!\n\tNo function found for directory traversal!"), + +/* 146 */ +dkT("\"!\n\tNumeric overflow in size calculation!"), + +/* 147 */ +dkT("\"!\n\tPath not found!"), + +/* 148 */ +dkT("\"!\n\tDirectory does not exist!"), + +/* 149 */ +dkT("Failed to obtain information about file/directory:\n\t\""), + +/* 150 */ +dkT("\"!\n\tOne path component is not a directory."), + +/* 151 */ +dkT("\"!\n\tCurrently used by another process."), + +/* 152 */ +dkT("Not a directory:\n\t\""), + +/* 153 */ +dkT("\"!"), + +/* 154 */ +dkT("\" in \""), + +/* 155 */ +dkT("Failed to change file buffering!"), + +/* 156 */ +dkT("Failed to change buffering for file\n\""), + +/* 157 */ +dkT("\"!"), + +/* 158 */ +dkT("Neither setvbuf() nor setbuffer() function available!"), + +/* 159 */ +dkT("Syntax error, expected line:\n\"name = width height [border-left border-right border-top border-bottom]\""), + +/* 160 */ +dkT("Preference value found: \""), + +/* 161 */ +dkT("\"=\""), + +/* 162 */ +dkT("\"."), + +/* 163 */ +dkT("Preference value too long: \""), + +/* 164 */ +dkT("\"=\""), + +/* 165 */ +dkT("\"!"), + +/* 166 */ +dkT("Preference value not found: \""), + +/* 167 */ +dkT("\"!"), + +NULL + + +#line 574 "dk4applog.ctr" +}; + + + +static const dkChar * const dk4app_def_msg_debug[] = { +/* 0 */ +dkT("Host name: "), + +/* 1 */ +dkT("User name: "), + +/* 2 */ +dkT("Home directory: "), + +/* 3 */ +dkT("Language: "), + +/* 4 */ +dkT("Region: "), + +/* 5 */ +dkT("Encoding: "), + +/* 6 */ +dkT("Encoding expected on standard input: "), + +/* 7 */ +dkT("Encoding expected on files: "), + +/* 8 */ +dkT("Program name: "), + +/* 9 */ +dkT("Program group: "), + +/* 10 */ +dkT("Directory etc: "), + +/* 11 */ +dkT("Directory bin: "), + +/* 12 */ +dkT("Directory share: "), + +/* 13 */ +dkT("Directory lib: "), + +/* 14 */ +dkT("Directory var: "), + +/* 15 */ +dkT("Directory tmp: "), + +/* 16 */ +dkT("Logging enabled: "), + +/* 17 */ +dkT("Log file: "), + +/* 18 */ +dkT("Log level to log on stderr: "), + +/* 19 */ +dkT("Log level to log to file: "), + +/* 20 */ +dkT("Log level to keep log file: "), + +/* 21 */ +dkT("Data file search for \""), + +/* 22 */ +dkT("\" failed."), + +/* 23 */ +dkT("\" succeeded.\n\t"), + +/* 24 */ +dkT("Configuration file search for \""), + +/* 25 */ +dkT("Delete directory: "), + +/* 26 */ +dkT("Delete file: "), + +/* 27 */ +dkT("Delete file or directory: "), + +/* 28 */ +dkT("Preference files:"), + +/* 29 */ +dkT("UNUSED"), + +/* 30 */ +dkT("+ "), + +/* 31 */ +dkT("- "), + +/* 32 */ +dkT("Search for data file \""), + +/* 33 */ +dkT("Search for configuration file \""), + +/* 34 */ +dkT("\" (compression allowed):"), + +/* 35 */ +dkT("\" (no compression allowed):"), + +/* 36 */ +dkT("Collecting paper size data."), + +/* 37 */ +dkT("\" (gzip compression allowed):"), + +/* 38 */ +dkT("\" (bzip2 compression allowed):"), + +/* 39 */ +dkT("\" (gzip/bzip2 compression allowed):"), + +/* 40 */ +dkT("String copy allocated: \""), + +/* 41 */ +dkT("\"."), + +/* 42 */ +dkT("Successfully converted to integer."), + +/* 43 */ +dkT("Not an integer!"), + +/* 44 */ +dkT("Successfully converted to unsigned integer."), + +/* 45 */ +dkT("Not an unsigned integer!"), + +/* 46 */ +dkT("Successfully converted to boolean."), + +/* 47 */ +dkT("Not a boolean!"), + +/* 48 */ +dkT("Successfully converted to size specification."), + +/* 49 */ +dkT("Not a size specification!"), + +NULL + + +#line 673 "dk4applog.ctr" +}; + + + +/** Ensure the messages texts for the base log domain are loaded. + @param app Application structure. + @param logdom Log text domain. +*/ +static +void +dk4app_log_load_base_texts(dk4_app_t *app) +{ + + +#line 686 "dk4applog.ctr" + if (NULL != app) { + +#line 687 "dk4applog.ctr" + if ((NULL == app->msg_base) || (0 == app->sz_msg_base)) { + + +#line 689 "dk4applog.ctr" + app->sz_msg_base = dk4app_string_table_size(dk4app_def_msg_base); + app->msg_base = dk4app_string_table( + app, dkT("dk4base.str"), dk4app_def_msg_base + ); + } else { + +#line 694 "dk4applog.ctr" + } + } else { + +#line 696 "dk4applog.ctr" + } + +#line 697 "dk4applog.ctr" +} + + + +/** Check whether there is at least one non-NULL pointer in array. + CRT on Windows: Not used. + @param msg Array to check. + @param sz Size of array. + @return 1 if any valid pointer was found, 0 otherwise. +*/ +static +int +dk4app_log_any_non_null(const dkChar * const *msg, size_t sz) +{ + size_t i; + int back = 0; + for (i = 0; ((i < sz) && (0 == back)); i++) { + if (NULL != msg[i]) { back = 1; } + } + return back; +} + + + +int +dk4app_log_do(dk4_app_t *app, int ll) +{ + int back = 0; + if (NULL != app) { +#if (!(DK4_ON_WINDOWS && DK4_WIN_DENY_CRT)) + if (0 != app->log_enabled) { + if (app->ll_stderr >= ll) { + back = 1; + } + if (app->ll_file >= ll) { + back = 1; + } + } +#endif + } + return back; +} + + + +/** Log multi part message to one file. + CRT on Windows: Required. + @param app Application structure, may be NULL. + @param priority Log priority. + @param msg Pointer to message parts array. + @param sz Number of message parts. + @param outfile Output file + @param showtime Flag: Show timestamp. + @param timer Timestamp of previous log message if any. + @param havetime Flag: Timer already contains a value. +*/ +static +void +dk4app_log_msg_to_file( + dk4_app_t *app, + int priority, + const dkChar * const *msg, + size_t sz, + FILE *outfile, + int showtime, + dk4_time_t *timer, + int *havetime +) +{ +#if (!(DK4_ON_WINDOWS && DK4_WIN_DENY_CRT)) + dkChar lnb[64]; + dkChar buf[64]; + size_t i; + dk4_time_t ct; + int res; + + dk4time_get(&ct); + /* Print timestamp */ + if ((0 != showtime) && ((0 == *havetime) || (ct != *timer))) { + *havetime = 1; + *timer = ct; + if (0 != dk4time_as_text(buf, DK4_SIZEOF(buf,dkChar), &ct, NULL)) { + dk4fputs(dkT("# "), outfile, NULL); + dk4fputs(buf, outfile, NULL); + dk4fputc(dkT('\n'), outfile, NULL); + } + } + /* Print error position */ + if (NULL != app->source_file_name) { + dk4fputs(app->source_file_name, outfile, NULL); + dk4fputc(dkT(':'), outfile, NULL); + if ((dk4_um_t)0UL != app->source_file_line) { + res = dk4ma_write_decimal_unsigned( + lnb, DK4_SIZEOF(lnb,dkChar), app->source_file_line, 0, NULL + ); + if (0 != res) { + dk4fputs(lnb, outfile, NULL); + dk4fputc(dkT(':'), outfile, NULL); + } + } + dk4fputc(dkT(' '), outfile, NULL); + } + /* Print message */ + switch (priority) { + case DK4_LL_PANIC: + case DK4_LL_FATAL: + case DK4_LL_ERROR: + case DK4_LL_WARNING: + { + dk4fputs((app->msg_base)[priority], outfile, NULL); + dk4fputs(dkT(": "), outfile, NULL); + } break; + } + for (i = 0; i < sz; i++) { + dk4fputs(msg[i], outfile, NULL); + } + dk4fputc(dkT('\n'), outfile, NULL); + fflush(outfile); +#endif +} + + + +void +dk4app_log_msg( + dk4_app_t *app, + int priority, + const dkChar * const *msg, + size_t sz +) +{ + FILE *fipo; + + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + if (0 != dk4app_log_any_non_null(msg, sz)) { +#if (!(DK4_ON_WINDOWS && DK4_WIN_DENY_CRT)) + if (app->ll_stderr >= priority) { + if (0 == app->have_stderr_init) { + dk4fput_initialize_stderr(); + app->have_stderr_init = 1; + } + dk4app_log_msg_to_file( + app, priority, msg, sz, stderr, + app->log_stderr_time, &(app->timer_stderr), &(app->have_stderr_time) + ); + } + if (app->ll_file >= priority) { + if (NULL != app->log_file_name) { +#if VERSION_BEFORE_20160127 +#else + if (0 == app->have_file_opened) { + (void)dk4app_mkdir_hierarchy(app->log_file_name, 0, NULL); + } +#endif + fipo = dk4fopen( + app->log_file_name, + dk4app_log_kwnl[(0 != app->have_file_opened) ? 1 : 0], + (DK4_FOPEN_SC_WR_SYMLINK_OWNER | DK4_FOPEN_SC_IS_REGULAR), + NULL + ); + app->have_file_opened = 1; + if (NULL != fipo) { + dk4app_log_msg_to_file( + app, priority, msg, sz, fipo, + app->log_stderr_time, &(app->timer_file), &(app->have_file_time) + ); + fclose(fipo); + } + } + } + if (priority < app->ll_found) { + app->ll_found = priority; + } +#endif + } + } + } +} + + + +void +dk4app_log_1( + dk4_app_t *app, + const dkChar * const *msg, + size_t sz_msg, + int priority, + size_t msgind +) +{ + const dkChar *msgtext; + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + if ((NULL != msg) && (0 < sz_msg) && (msgind < sz_msg)) { + msgtext = msg[msgind]; + dk4app_log_msg(app, priority, &msgtext, 1); + } + } + } +} + + + +void +dk4app_log_2( + dk4_app_t *app, + const dkChar * const *msg, + size_t sz_msg, + int priority, + size_t i1, + const dkChar *t1 +) +{ + const dkChar *msgtext[3]; + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + if ((NULL != msg) && (0 < sz_msg) && (i1 < sz_msg)) { + msgtext[0] = msg[i1]; + msgtext[1] = t1; + dk4app_log_msg(app, priority, msgtext, 2); + } + } + } +} + + + +void +dk4app_log_3( + dk4_app_t *app, + const dkChar * const *msg, + size_t sz_msg, + int priority, + size_t i1, + size_t i2, + const dkChar *t1 +) +{ + const dkChar *msgtext[3]; + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + if ((NULL != msg) && (0 < sz_msg) && (i1 < sz_msg) && (i2 < sz_msg)) { + msgtext[0] = msg[i1]; + msgtext[1] = t1; + msgtext[2] = msg[i2]; + dk4app_log_msg(app, priority, msgtext, 3); + } + } + } +} + + + +void +dk4app_log_5( + dk4_app_t *app, + const dkChar * const *msg, + size_t sz_msg, + int priority, + size_t i1, + size_t i2, + size_t i3, + const dkChar *t1, + const dkChar *t2 +) +{ + const dkChar *msgtext[5]; + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + if ((NULL != msg) && (0 < sz_msg) && (i1 < sz_msg) && (i2 < sz_msg)) { + msgtext[0] = msg[i1]; + msgtext[1] = t1; + msgtext[2] = msg[i2]; + msgtext[3] = t2; + msgtext[4] = msg[i3]; + dk4app_log_msg(app, priority, msgtext, 5); + } + } + } +} + + + +void +dk4app_log_7( + dk4_app_t *app, + const dkChar * const *msg, + size_t sz_msg, + int priority, + size_t i1, + size_t i2, + size_t i3, + size_t i4, + const dkChar *t1, + const dkChar *t2, + const dkChar *t3 +) +{ + const dkChar *msgtext[7]; + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + if ( + (NULL != msg) + && (0 < sz_msg) && (i1 < sz_msg) && (i2 < sz_msg) && (i3 < sz_msg) + ) + { + msgtext[0] = msg[i1]; + msgtext[1] = t1; + msgtext[2] = msg[i2]; + msgtext[3] = t2; + msgtext[4] = msg[i3]; + msgtext[5] = t3; + msgtext[6] = msg[i4]; + dk4app_log_msg(app, priority, msgtext, 7); + } + } + } +} + + + +void +dk4app_log_base1( + dk4_app_t *app, + int priority, + size_t msgind +) +{ + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + dk4app_log_1(app, app->msg_base, app->sz_msg_base, priority, msgind); + } + } +} + + + +void +dk4app_log_base2( + dk4_app_t *app, + int priority, + size_t i1, + const dkChar *t1 +) +{ + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + dk4app_log_2(app,app->msg_base,app->sz_msg_base,priority,i1,t1); + } + } +} + + + +void +dk4app_log_base2c( + dk4_app_t *app, + int priority, + size_t i1, + size_t i2 +) +{ + const dkChar *msgptr[2]; + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + if ((app->sz_msg_base > i1) && (app->sz_msg_base > i2)) { + dk4app_log_load_base_texts(app); + msgptr[0] = (app->msg_base)[i1]; + msgptr[1] = (app->msg_base)[i2]; + dk4app_log_msg(app, priority, msgptr, 2); + } + } + } +} + + + +void +dk4app_log_base3( + dk4_app_t *app, + int priority, + size_t i1, + size_t i2, + const dkChar *t1 +) +{ + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + dk4app_log_3(app,app->msg_base,app->sz_msg_base,priority,i1,i2,t1); + } + } +} + + + +void +dk4app_log_base5( + dk4_app_t *app, + int priority, + size_t i1, + size_t i2, + size_t i3, + const dkChar *t1, + const dkChar *t2 +) +{ + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + dk4app_log_5(app,app->msg_base,app->sz_msg_base,priority,i1,i2,i3,t1,t2); + } + } +} + + + +void +dk4app_log_base7( + dk4_app_t *app, + int priority, + size_t i1, + size_t i2, + size_t i3, + size_t i4, + const dkChar *t1, + const dkChar *t2, + const dkChar *t3 +) +{ + if (NULL != app) { + if (0 != dk4app_log_do(app, priority)) { + dk4app_log_load_base_texts(app); + dk4app_log_7( + app,app->msg_base,app->sz_msg_base,priority,i1,i2,i3,i4,t1,t2,t3 + ); + } + } +} + + + +void +dk4app_log_with_errno( + dk4_app_t *app, + int priority, + size_t i1, + size_t i2, + size_t i3, + size_t i4, + size_t i5, + const dkChar *t1, + int errn +) +{ + dkChar enb[64]; + int res; + if (NULL != app) { + res = dk4ma_write_decimal_signed( + enb, DK4_SIZEOF(enb,dkChar), (dk4_im_t)errn, 0, NULL + ); + if (0 != res) { + dk4app_log_base5(app, priority, i1, i2, i3, t1, enb); + } else { + dk4app_log_base3(app, priority, i4, i5, t1); + } + } +} + + + +const dkChar * +dk4app_get_log_source_file(dk4_app_t *app) +{ + const dkChar *back = NULL; + if (NULL != app) { + back = app->source_file_name; + } + return back; +} + + + +dk4_um_t +dk4app_get_log_source_line(dk4_app_t *app) +{ + dk4_um_t back = (dk4_um_t)0UL; + if (NULL != app) { + back = app->source_file_line; + } + return back; +} + + + +void +dk4app_set_log_source_file(dk4_app_t *app, const dkChar *fn) +{ + if (NULL != app) { + app->source_file_name = fn; + } +} + + + +void +dk4app_set_log_source_line(dk4_app_t *app, dk4_um_t lineno) +{ + if (NULL != app) { + app->source_file_line = lineno; + } +} + + + +const dkChar * const * +dk4app_log_debug_texts(dk4_app_t *app, size_t *szptr) +{ + const dkChar * const *back = NULL; + + +#line 1226 "dk4applog.ctr" + if (NULL != app) { + +#line 1227 "dk4applog.ctr" + dk4app_log_load_base_texts(app); + if ((NULL != app->msg_debug) && (0 < app->sz_msg_debug)) { + back = app->msg_debug; + +#line 1230 "dk4applog.ctr" + } else { + +#line 1231 "dk4applog.ctr" + app->msg_debug = dk4app_string_table( + app, dk4app_log_kwnl[2], dk4app_def_msg_debug + ); + app->sz_msg_debug = dk4app_string_table_size(app->msg_debug); + back = app->msg_debug; + } + } else { + +#line 1238 "dk4applog.ctr" + back = dk4app_def_msg_debug; + } + if (NULL != szptr) { + *szptr = dk4app_string_table_size(dk4app_def_msg_debug); + } + + +#line 1244 "dk4applog.ctr" + return back; +} + + + +static +void +dk4app_log_two_strings_at_startup( + dk4_app_t *app, + const dkChar *title, + const dkChar *value +) +{ + const dkChar *msg[3]; + msg[0] = title; + msg[1] = value; + if (NULL == value) { + msg[1] = dk4app_log_kwnl[3]; + } + msg[2] = NULL; + dk4app_log_msg(app, DK4_LL_DEBUG, msg, 2); +} + + + +static +void +dk4app_log_startup_log_level( + dk4_app_t *app, + const dkChar *title, + int ll +) +{ + const dkChar *llstr = NULL; + if ((DK4_LL_NONE <= ll) && (DK4_LL_IGNORE >= ll)) { + llstr = (app->msg_base)[(size_t)ll]; + } + dk4app_log_two_strings_at_startup(app, title, llstr); +} + + + +static +void +dk4app_log_startup_encoding( + dk4_app_t *app, + const dkChar *title, + int enc, + int isfileenc +) +{ + const dkChar *encstr = NULL; + if (0 != isfileenc) { + switch (enc) { + case DK4_FILE_ENCODING_ASCII : { + encstr = dk4app_log_kwnl[5]; + } break; + case DK4_FILE_ENCODING_ANSI : { + encstr = dk4app_log_kwnl[6]; + } break; + case DK4_FILE_ENCODING_UTF8 : { + encstr = dk4app_log_kwnl[7]; + } break; + case DK4_FILE_ENCODING_UTF16_LE : { + encstr = dk4app_log_kwnl[9]; + } break; + case DK4_FILE_ENCODING_UTF16_BE : { + encstr = dk4app_log_kwnl[10]; + } break; + case DK4_FILE_ENCODING_32_LE : { + encstr = dk4app_log_kwnl[12]; + } break; + case DK4_FILE_ENCODING_32_BE : { + encstr = dk4app_log_kwnl[13]; + } break; + } + } else { + switch (enc) { + case DK4_ENCODING_ASCII : { + encstr = dk4app_log_kwnl[5]; + } break; + case DK4_ENCODING_ANSI : { + encstr = dk4app_log_kwnl[6]; + } break; + case DK4_ENCODING_UTF8 : { + encstr = dk4app_log_kwnl[7]; + } break; + case DK4_ENCODING_UTF16 : { + encstr = dk4app_log_kwnl[8]; + } break; + case DK4_ENCODING_32 : { + encstr = dk4app_log_kwnl[11]; + } break; + } + } + dk4app_log_two_strings_at_startup(app, title, encstr); +} + + + +void +dk4app_log_startup_debug(dk4_app_t *app) +{ + dkChar fnb[DK4_MAX_PATH]; + dk4_er_t er; + const dkChar *msgtxt[3]; + const dkChar * const *debmsg = NULL; + size_t szdebmsg = 0; + int res = 0; + int pn = 0; + + +#line 1355 "dk4applog.ctr" + if (NULL != app) { + if (0 != dk4app_log_do(app, DK4_LL_DEBUG)) { + /* Obtain localized texts */ + dk4app_log_load_base_texts(app); + debmsg = dk4app_log_debug_texts(app, &szdebmsg); + + /* 0 Host name */ + dk4app_log_two_strings_at_startup(app, debmsg[0], app->host_name); + + /* 1 User name */ + dk4app_log_two_strings_at_startup(app, debmsg[1], app->user_name); + + /* 2 Home dir */ + dk4app_log_two_strings_at_startup(app, debmsg[2], app->user_home); + + /* 3 Language */ + dk4app_log_two_strings_at_startup(app, debmsg[3], app->language); + + /* 4 Region */ + dk4app_log_two_strings_at_startup(app, debmsg[4], app->region); + + /* 5 Encoding */ + dk4app_log_startup_encoding(app, debmsg[5], app->encoding, 0); + + /* 6 Encoding stdin */ + dk4app_log_startup_encoding(app, debmsg[6], app->enc_in_std, 1); + + /* 7 Encoding files */ + dk4app_log_startup_encoding(app, debmsg[7], app->enc_in_file, 1); + + /* 8 Program name */ + dk4app_log_two_strings_at_startup(app, debmsg[8], app->prog_name); + + /* 9 Program group */ + dk4app_log_two_strings_at_startup(app, debmsg[9], app->group_name); + + /* 10 etc */ + dk4app_log_two_strings_at_startup(app, debmsg[10], app->dir_etc); + + /* 11 bin */ + dk4app_log_two_strings_at_startup(app, debmsg[11], app->dir_bin); + + /* 12 share */ + dk4app_log_two_strings_at_startup(app, debmsg[12], app->dir_share); + + /* 13 lib */ + dk4app_log_two_strings_at_startup(app, debmsg[13], app->dir_lib); + + /* 14 var */ + dk4app_log_two_strings_at_startup(app, debmsg[14], app->dir_var); + + /* 15 tmp */ + dk4app_log_two_strings_at_startup(app, debmsg[15], app->dir_tmp); + + /* 17 Log file */ + dk4app_log_two_strings_at_startup(app, debmsg[17], app->log_file_name); + + /* 16 Logging enabled */ + dk4app_log_two_strings_at_startup( + app, debmsg[16], dk4app_log_kwnl[(0 != app->log_enabled) ? 4 : 3] + ); + + /* 18 Log level stderr */ + dk4app_log_startup_log_level(app, debmsg[18], app->ll_stderr); + + /* 19 Log level file */ + dk4app_log_startup_log_level(app, debmsg[19], app->ll_file); + + /* 20 Log level keep */ + dk4app_log_startup_log_level(app, debmsg[20], app->ll_file_keep); + + /* Preferences files */ + dk4app_log_1(app, debmsg, szdebmsg, DK4_LL_DEBUG, 28); + for (pn = 0; (pn <= DK4_FS_CONF_MAX); pn++) { +#if DK4_HAVE_COMPATDKTOOLS3 + dk4error_init(&er); + res = dk4fs_config_construct_compat_one( + fnb, DK4_SIZEOF(fnb,dkChar), dk4app_log_kwnl[14], + app->dir_share, app->dir_etc, app->user_home, + app->prog_name, app->group_name, pn, 1, &er + ); + if (0 != res) { + res = dk4fs_attempt_file_name(fnb, DK4_SIZEOF(fnb,dkChar), 1, NULL); + if (0 != res) { + msgtxt[0] = debmsg[30]; + msgtxt[1] = fnb; + dk4app_log_msg(app, DK4_LL_DEBUG, msgtxt, 2); + } else { + msgtxt[0] = debmsg[31]; + msgtxt[1] = fnb; + dk4app_log_msg(app, DK4_LL_DEBUG, msgtxt, 2); + } + } +#endif + dk4error_init(&er); + res = dk4fs_config_construct_compat_one( + fnb, DK4_SIZEOF(fnb,dkChar), dk4app_log_kwnl[15], + app->dir_share, app->dir_etc, app->user_home, + app->prog_name, app->group_name, pn, 0, &er + ); + if (0 != res) { + res = dk4fs_attempt_file_name(fnb, DK4_SIZEOF(fnb,dkChar), 1, NULL); + if (0 != res) { + msgtxt[0] = debmsg[30]; + msgtxt[1] = fnb; + dk4app_log_msg(app, DK4_LL_DEBUG, msgtxt, 2); + } else { + msgtxt[0] = debmsg[31]; + msgtxt[1] = fnb; + dk4app_log_msg(app, DK4_LL_DEBUG, msgtxt, 2); + } + } + } +#if VERSION_BEFORE_2017_03_13 + dk4app_log_1(app, debmsg, szdebmsg, DK4_LL_DEBUG, 29); +#endif + } + } + + +#line 1474 "dk4applog.ctr" +} + |