From f4c1030435f0bf29246e577ddc191909848bbdfc Mon Sep 17 00:00:00 2001 From: ampli Date: Tue, 28 May 2024 22:28:59 +0300 Subject: [PATCH 01/15] link-parser save_default_opts(): Bugfix saving string defaults The test and debug parse options defaults were incorrectly recorded when set by link-parser's arguments. The program crashes upon command completion of !dialect= if the dialect variable differs from the default. Fix this by setting them to a static empty string. --- link-parser/command-line.c | 13 ++++++++++++- link-parser/link-parser.c | 20 ++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index bb9b762526..a325cb6fea 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -125,12 +125,23 @@ Switch default_switches[] = static void put_opts_in_local_vars(Command_Options *); /* - * A way to record the options default values. + * Record the parse options default values. + * + * We must set here the string parse options to their static default + * value so they don't point to a static memory returned by the library + * (but anyway we need to do that for the test,debug and verbosity parse + * options because they might have been set by command line arguments + * just before this function is invoked.) */ void save_default_opts(Command_Options *copts) { put_opts_in_local_vars(copts); saved_defaults = local; + // XXX Set defaults assuming stable library settings + saved_defaults.test = (char *)""; + saved_defaults.debug = (char *)""; + saved_defaults.dialect = (char *)""; + saved_defaults.verbosity = 1; } static void restore_default_local_vars(void) diff --git a/link-parser/link-parser.c b/link-parser/link-parser.c index 335a2de7dc..35f23906c2 100644 --- a/link-parser/link-parser.c +++ b/link-parser/link-parser.c @@ -641,22 +641,10 @@ int main(int argc, char * argv[]) parse_options_set_disjunct_cost(opts, linkgrammar_get_dict_max_disjunct_cost(dict)); - /* Remember the debug setting, because we temporary neglect it below. */ - int verbosity_tmp = parse_options_get_verbosity(opts); - char *debug_tmp = strdup(parse_options_get_debug(opts)); - char *test_tmp = strdup(parse_options_get_test(opts)); - - parse_options_set_verbosity(opts, 1); /* XXX assuming 1 is the default */ - parse_options_set_debug(opts, ""); - parse_options_set_test(opts, ""); - save_default_opts(copts); /* Options so far are the defaults */ - - /* Restore the debug setting. */ - parse_options_set_verbosity(opts, verbosity_tmp); - parse_options_set_debug(opts, debug_tmp); - parse_options_set_test(opts, test_tmp); - free(debug_tmp); - free(test_tmp); + /* Options so far are the defaults (save_default_opts() ensures + * saving the defaults for debug, test, and verbosity, which may have + * already been set by the program's arguments at this point.) */ + save_default_opts(copts); /* Process non-debug command line variable-setting commands (only). */ for (int i = 1; i < argc; i++) From f3695cda074d6fddb12ebacff193531c5d3a88a1 Mon Sep 17 00:00:00 2001 From: ampli Date: Sun, 26 May 2024 23:28:51 +0300 Subject: [PATCH 02/15] Move D_USER_FILES from command-line.c to command-line.h --- link-parser/command-line.c | 1 - link-parser/command-line.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index a325cb6fea..f495c2ba5b 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -283,7 +283,6 @@ static const char *switch_value_string(const Switch *as) #define HELPFILE_LANG_TEMPLATE_SIZE (sizeof(HELPFILE_LANG_TEMPLATE)-1) #define HELPFILE_TEMPLATE_SIZE \ (sizeof(HELPFILE_BASE HELPFILE_EXT)+HELPFILE_LANG_TEMPLATE_SIZE) -#define D_USER_FILES 4 /* Debug level for files, see error.h. */ #define DEFAULT_HELP_LANG "en" static FILE *help_file; diff --git a/link-parser/command-line.h b/link-parser/command-line.h index 6badb0df8b..896617fde5 100644 --- a/link-parser/command-line.h +++ b/link-parser/command-line.h @@ -16,6 +16,8 @@ #include +#define D_USER_FILES 4 /* Debug level for files, see error.h. */ + #define COMMENT_CHAR '%' /* input lines beginning with this are ignored */ #define WHITESPACE " \t\v\r\n" /* ASCII-only is sufficient here */ #define FIELD_WIDTH(str, width) (int)((width)+strlen(str)-utf8_strwidth(str)) From 37badb4d8017ed91772815b588ab992672cbd3e4 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 00:00:22 +0300 Subject: [PATCH 03/15] link-parser.c: Move initialize_screen_width() --- link-parser/link-parser.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/link-parser/link-parser.c b/link-parser/link-parser.c index 35f23906c2..7e1976b703 100644 --- a/link-parser/link-parser.c +++ b/link-parser/link-parser.c @@ -676,8 +676,6 @@ int main(int argc, char * argv[]) } } - initialize_screen_width(copts); - if ((parse_options_get_verbosity(opts)) > 0 && (quiet_start == 0)) { prt_error("Info: Dictionary version %s, locale %s\n", @@ -687,6 +685,7 @@ int main(int argc, char * argv[]) linkgrammar_get_version()); } + initialize_screen_width(copts); if (isatty_io) { find_history_filepath(dictionary_get_lang(dict), argv[0], "link-parser"); From 3770adc6f46a7a0f091a1ae5be453f1b69c48784 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 00:08:42 +0300 Subject: [PATCH 04/15] command-line.c: Add get_verbosity() --- link-parser/command-line.c | 13 ++++++++++--- link-parser/command-line.h | 1 + link-parser/link-parser.c | 1 + link-parser/parser-utilities.h | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index f495c2ba5b..af45804f22 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -122,8 +122,6 @@ Switch default_switches[] = {NULL, Cmd, NULL, NULL} }; -static void put_opts_in_local_vars(Command_Options *); - /* * Record the parse options default values. * @@ -149,6 +147,15 @@ static void restore_default_local_vars(void) local = saved_defaults; } +// Return the value of the static verbosity. +// This avoids the need to define "verbosity" as extern, which may clash +// with the library "verbosity", and make the parse options "verbosity" +// available before the main loop in link-parser.c. +int get_verbosity(void) +{ + return local.verbosity; +} + /** * Gets rid of all the white space in the string s. */ @@ -1009,7 +1016,7 @@ static int x_issue_special_command(char * line, Command_Options *copts, Dictiona return -1; } -static void put_opts_in_local_vars(Command_Options* copts) +void put_opts_in_local_vars(Command_Options* copts) { Parse_Options opts = copts->popts; local.verbosity = parse_options_get_verbosity(opts); diff --git a/link-parser/command-line.h b/link-parser/command-line.h index 896617fde5..f98076dde5 100644 --- a/link-parser/command-line.h +++ b/link-parser/command-line.h @@ -63,6 +63,7 @@ typedef struct { } Command_Options; void put_local_vars_in_opts(Command_Options *); +void put_opts_in_local_vars(Command_Options *); void setup_panic_parse_options(Command_Options *, int); typedef enum diff --git a/link-parser/link-parser.c b/link-parser/link-parser.c index 7e1976b703..7aa075c93d 100644 --- a/link-parser/link-parser.c +++ b/link-parser/link-parser.c @@ -685,6 +685,7 @@ int main(int argc, char * argv[]) linkgrammar_get_version()); } + put_opts_in_local_vars(copts); /* Update local.verbosity etc. */ initialize_screen_width(copts); if (isatty_io) { diff --git a/link-parser/parser-utilities.h b/link-parser/parser-utilities.h index 3322ec8648..62f660a601 100644 --- a/link-parser/parser-utilities.h +++ b/link-parser/parser-utilities.h @@ -21,6 +21,7 @@ char *expand_homedir(const char *fn); void set_screen_width(Command_Options*); void initialize_screen_width(Command_Options *); +int get_verbosity(void); // Defined in command-line.c #define MAX_INPUT_LINE 2048 From 9dd0517efc87d70a2af221896def845122950b69 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 00:47:48 +0300 Subject: [PATCH 05/15] make_dirpath(): Bugfix dir memory leak on MS Windows --- link-parser/lg_xdg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/link-parser/lg_xdg.c b/link-parser/lg_xdg.c index 955efc48d0..ea104684f2 100644 --- a/link-parser/lg_xdg.c +++ b/link-parser/lg_xdg.c @@ -84,22 +84,23 @@ static bool is_sep(int c) */ static bool make_dirpath(const char *path) { - char *dir = strdup(path); struct stat sb; #if defined(_WIN32) || defined(__CYGWIN__) // Skip Windows UNC path \\X - if (is_sep(dir[0]) && is_sep(dir[1])) + if (is_sep(path[0]) && is_sep(path[1])) { const char *p; // Start from the root or network share - for (p = dir + 2; *p != '\0'; p++) + for (p = path + 2; *p != '\0'; p++) if (is_sep(*p)) break; if (*p == '\0') return true; // No further subdirectories } #endif + char *dir = strdup(path); + for (char *p = dir+1; '\0' != *p; p++) { char sep = *p; From 1d9770f0191c19a863ef67c4d34126c2bbe4c0a1 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 01:03:09 +0300 Subject: [PATCH 06/15] lg_xdg.c: Fix typos --- link-parser/lg_xdg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/link-parser/lg_xdg.c b/link-parser/lg_xdg.c index ea104684f2..74aeb05860 100644 --- a/link-parser/lg_xdg.c +++ b/link-parser/lg_xdg.c @@ -38,7 +38,7 @@ typedef struct xdg_definition xdg_def[] = { - { "/.local/state", "XDG_STATE_HOME" }, + { "/.local/state", "XDG_STATE_HOME" }, // Add more definitions if needed. }; @@ -108,7 +108,7 @@ static bool make_dirpath(const char *path) { if (is_sep(p[-1])) continue; // Ignore directory separator sequences *p = '\0'; // Now dir is the path up to this point - //prt_error("DEBUG: mkdir: '%s'\n", dir); + //prt_error("Debug: mkdir: '%s'\n", dir); if (mkdir(dir, S_IRWXU) == -1) { int save_errno = errno; From 4f4c4b0fa2bbfe5307cb831530e9ba08a8604b1e Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 01:04:13 +0300 Subject: [PATCH 07/15] lg_readline.c: At verbosity 4, print the history file location --- link-parser/lg_readline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/link-parser/lg_readline.c b/link-parser/lg_readline.c index bf715d1eea..4b288ec433 100644 --- a/link-parser/lg_readline.c +++ b/link-parser/lg_readline.c @@ -83,10 +83,11 @@ void find_history_filepath(const char *dictname, const char *argv0, prt_error("Warning: xdg_get_home(XDG_BD_STATE) failed; " "input history will not be supported.\n"); history_file = strdup("dev/null"); - return; } history_file = hfile; + if (get_verbosity() == D_USER_FILES) + prt_error("Debug: Using history file \"%s\"\n", history_file); } /** From bc3ab7929328eeb2fc3004d447e7e11252915233 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 01:51:50 +0300 Subject: [PATCH 08/15] command-line.c: Correctly use D_USER_FILES The printouts for verbosity level D_USER_FILES are to be done exactly at this verbosity. --- link-parser/command-line.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index af45804f22..09ff849dbb 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -428,7 +428,7 @@ static FILE *open_help_file(int verbosity) help_file = linkgrammar_open_data_file(help_filename); } - if ((NULL == help_file) && (verbosity > D_USER_FILES)) + if ((NULL == help_file) && (verbosity == D_USER_FILES)) { prt_error("Error: Cannot open help file '%s': %s\n", help_filename, strerror(errno)); @@ -531,7 +531,7 @@ static void display_help(const Switch *sp, Command_Options *copts) if (feof(hf)) { - if (local.verbosity >= D_USER_FILES) + if (local.verbosity == D_USER_FILES) prt_error("Error: Cannot find command \"%s\" in help file\n", sp->string); } From 4c65644fcf0bc6fb8339eef84865410ee3a719db Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 02:32:47 +0300 Subject: [PATCH 09/15] command_line.c: Add Error label in prt_error() --- link-parser/command-line.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index 09ff849dbb..df306adbac 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -175,7 +175,7 @@ static void clean_up_string(char * s) if (0 == w) break; if (0 > (ssize_t)w) { - prt_error("Unable to process UTF8 command input string.\n"); + prt_error("Error: Unable to process UTF8 command input string.\n"); break; } len -= w; @@ -212,7 +212,7 @@ static bool is_numerical_rhs(char *s) if (0 == w) break; if (0 > (ssize_t)w) { - prt_error("Unable to process UTF8 command input string.\n"); + prt_error("Error: Unable to process UTF8 command input string.\n"); break; } len -= w; @@ -789,9 +789,9 @@ static int handle_help_command(const Switch *as, char *line, { rc = -1; /* Error indication. */ if (count > 1) - prt_error("Ambiguous command: \"%s\". %s\n", s, helpmsg); + prt_error("Error: Ambiguous command: \"%s\". %s\n", s, helpmsg); else - prt_error("Undefined command: \"%s\". %s\n", s, helpmsg); + prt_error("Error: Undefined command: \"%s\". %s\n", s, helpmsg); } } } @@ -868,7 +868,7 @@ static int x_issue_special_command(char * line, Command_Options *copts, Dictiona if (count > 1) { - prt_error("Ambiguous command \"%s\". %s\n", s, helpmsg); + prt_error("Error: Ambiguous command \"%s\". %s\n", s, helpmsg); return -1; } if (count == 1) @@ -879,7 +879,7 @@ static int x_issue_special_command(char * line, Command_Options *copts, Dictiona size_t junk = strcspn(s, WHITESPACE); if (junk != strlen(s)) { - prt_error("Junk after a boolean variable: \"%s\". %s\n", + prt_error("Error: Junk after a boolean variable: \"%s\". %s\n", &s[junk], helpmsg); return -1; } From b8d3d026f40dcda8562fd1a073d042a08fa31f16 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 03:05:44 +0300 Subject: [PATCH 10/15] link-parser.c: Create a function to set the default parse options --- link-parser/link-parser.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/link-parser/link-parser.c b/link-parser/link-parser.c index 7aa075c93d..5fb2d8f9d1 100644 --- a/link-parser/link-parser.c +++ b/link-parser/link-parser.c @@ -69,6 +69,21 @@ static const char *use_prompt(int verbosity_level) return (0 == verbosity_level)? "" : prompt; } +/** + * Set link-parser's default parse options. + */ +static void set_default_parse_options(Parse_Options opts) +{ + parse_options_set_max_parse_time(opts, 30); + parse_options_set_linkage_limit(opts, 1000); + parse_options_set_min_null_count(opts, 0); + parse_options_set_max_null_count(opts, 0); + parse_options_set_short_length(opts, 16); + parse_options_set_islands_ok(opts, false); + parse_options_set_display_morphology(opts, false); + parse_options_set_spell_guess(opts, 7); +} + typedef enum { UNGRAMMATICAL = '*', @@ -604,14 +619,7 @@ int main(int argc, char * argv[]) } opts = copts->popts; - parse_options_set_max_parse_time(opts, 30); - parse_options_set_linkage_limit(opts, 1000); - parse_options_set_min_null_count(opts, 0); - parse_options_set_max_null_count(opts, 0); - parse_options_set_short_length(opts, 16); - parse_options_set_islands_ok(opts, false); - parse_options_set_display_morphology(opts, false); - parse_options_set_spell_guess(opts, 7); + set_default_parse_options(opts); /* Get the panic disjunct cost from the dictionary. */ const char *panic_max_cost_str = From ea7e6582ceaa3e70e03dd1b4a9c0a420bf9d6dc8 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 03:19:14 +0300 Subject: [PATCH 11/15] link-parser.c: Consolidate copts-related operations --- link-parser/link-parser.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/link-parser/link-parser.c b/link-parser/link-parser.c index 5fb2d8f9d1..e7071b88c5 100644 --- a/link-parser/link-parser.c +++ b/link-parser/link-parser.c @@ -532,6 +532,12 @@ int main(int argc, char * argv[]) } copts = command_options_create(); + if (copts == NULL || copts->popts == NULL) + { + prt_error("Fatal error: unable to create parse options\n"); + exit(-1); + } + opts = copts->popts; /* First set the debug options, to allow dictionary-related debug. */ const char * const debug_vars[] = { "verbosity", "debug", "test" }; @@ -612,13 +618,6 @@ int main(int argc, char * argv[]) } } - if (copts == NULL || copts->popts == NULL) - { - prt_error("Fatal error: unable to create parse options\n"); - exit(-1); - } - opts = copts->popts; - set_default_parse_options(opts); /* Get the panic disjunct cost from the dictionary. */ From bfd69dddf09b60f094c8aea19bb6d30f9a4c26ec Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 03:50:53 +0300 Subject: [PATCH 12/15] link-parser.c: Be really silent on --quite --- link-parser/link-parser.c | 57 ++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/link-parser/link-parser.c b/link-parser/link-parser.c index e7071b88c5..09837d7d27 100644 --- a/link-parser/link-parser.c +++ b/link-parser/link-parser.c @@ -497,6 +497,43 @@ static const char *fbasename(const char *fpath) return progf + 1; } +/** + * Return a dictionary handle for \p languege. Return NULL on failure. + * silence library verbose output if needed. + */ +static Dictionary dictionary_setup(const char *language, bool quiet, + Parse_Options opts) +{ + Dictionary dict; + int save_verbosity = parse_options_get_verbosity(opts); + + if (quiet && (save_verbosity == 1)) + parse_options_set_verbosity(opts, 0); + + if (language && *language) + { + dict = dictionary_create_lang(language); + if (dict == NULL) + { + prt_error("Fatal error: Unable to open dictionary.\n"); + return NULL; + } + } + else + { + dict = dictionary_create_default_lang(); + if (dict == NULL) + { + prt_error("Fatal error: Unable to open default dictionary.\n"); + return NULL; + } + } + + parse_options_set_verbosity(opts, save_verbosity); + + return dict; +} + static void print_usage(FILE *out, char *argv0, Command_Options *copts, int exit_value) { @@ -599,24 +636,8 @@ int main(int argc, char * argv[]) } /* End of debug options setup. */ - if (language && *language) - { - dict = dictionary_create_lang(language); - if (dict == NULL) - { - prt_error("Fatal error: Unable to open dictionary.\n"); - exit(-1); - } - } - else - { - dict = dictionary_create_default_lang(); - if (dict == NULL) - { - prt_error("Fatal error: Unable to open default dictionary.\n"); - exit(-1); - } - } + dict = dictionary_setup(language, quiet_start > 0, opts); + if (dict == NULL) exit(-1); set_default_parse_options(opts); From b56ff8627192138d7a4d5e6854c344c96db40df2 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 20:22:59 +0300 Subject: [PATCH 13/15] lg_complete(): Improve the comment of failed fchdir() --- link-parser/command-line.c | 10 +++++----- link-parser/lg_readline.c | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index df306adbac..04da4c4ec5 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -125,11 +125,11 @@ Switch default_switches[] = /* * Record the parse options default values. * - * We must set here the string parse options to their static default - * value so they don't point to a static memory returned by the library - * (but anyway we need to do that for the test,debug and verbosity parse - * options because they might have been set by command line arguments - * just before this function is invoked.) + * Set the string parse options to their static default value so they + * don't point to a static (test, debug) or dynamic (dialect) memory of + * the library (but anyway we need to do that for the test,debug and + * verbosity parse options because they might have been set by command + * line arguments just before this function is invoked.) */ void save_default_opts(Command_Options *copts) { diff --git a/link-parser/lg_readline.c b/link-parser/lg_readline.c index 4b288ec433..3b96f6e903 100644 --- a/link-parser/lg_readline.c +++ b/link-parser/lg_readline.c @@ -376,8 +376,9 @@ static unsigned char lg_complete(EditLine *el, int ch) { if (fchdir(cwdfd) < 0) { - /* This shouldn't happen, unless maybe the directory to which - * cwdfd reveres becomes unreadable after cwdfd is created. */ + /* Unexpected error: may occur only if the directory + * referenced by cwdfd becomes unreadable after cwdfd + * has been established. */ printf("\nfchdir(): Cannot change directory back: %s\n", strerror(errno)); } From a9ed4e5d724cf01f1f741df17fbe27a9494c4323 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 May 2024 20:30:23 +0300 Subject: [PATCH 14/15] link-parser: Fix comment whitespace --- link-parser/command-line.c | 2 +- link-parser/lg_readline.c | 6 +++--- link-parser/parser-utilities.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/link-parser/command-line.c b/link-parser/command-line.c index 04da4c4ec5..dfe332af4d 100644 --- a/link-parser/command-line.c +++ b/link-parser/command-line.c @@ -157,7 +157,7 @@ int get_verbosity(void) } /** - * Gets rid of all the white space in the string s. + * Gets rid of all the white space in the string s. */ static void clean_up_string(char * s) { diff --git a/link-parser/lg_readline.c b/link-parser/lg_readline.c index 3b96f6e903..4bcdf1c1b3 100644 --- a/link-parser/lg_readline.c +++ b/link-parser/lg_readline.c @@ -421,7 +421,7 @@ char *lg_readline(const char *mb_prompt) wc_prompt = malloc (sz*sizeof(wchar_t)); mbstowcs(wc_prompt, mb_prompt, sz); - hist = history_winit(); /* Init built-in history */ + hist = history_winit(); /* Init built-in history */ el = el_init("link-parser", stdin, stdout, stderr); history_w(hist, &ev, H_SETSIZE, 100); history_w(hist, &ev, H_SETUNIQUE, 1); @@ -444,7 +444,7 @@ char *lg_readline(const char *mb_prompt) el_source(el, NULL); /* Source the user's defaults file. */ } - int numc = 1; /* Uninitialized at libedit. */ + int numc = 1; /* Uninitialized at libedit. */ const wchar_t *wc_line = el_wgets(el, &numc); /* Received end-of-file */ @@ -469,7 +469,7 @@ char *lg_readline(const char *mb_prompt) /* fwprintf(stderr, L"==> got %d %ls", numc, wc_line); */ size_t byte_len = wcstombs(NULL, wc_line, 0) + 4; - free(mb_line); // free previous. + free(mb_line); // free previous. if (byte_len == (size_t)-1) { prt_error("Error: Unable to process UTF8 in input string.\n"); diff --git a/link-parser/parser-utilities.c b/link-parser/parser-utilities.c index a0d3610591..36e6020ba8 100644 --- a/link-parser/parser-utilities.c +++ b/link-parser/parser-utilities.c @@ -146,7 +146,7 @@ int get_console_line(char *inbuf, int inbuf_size) snprintf(inbuf, inbuf_size, "ReadConsoleW: Error %lu\n", GetLastError()); return -1; } - winbuf[nchar] = L'\0'; /* nchar is always <= INPUT_UTF16_SIZE-1. */ + winbuf[nchar] = L'\0'; /* nchar is always <= INPUT_UTF16_SIZE-1. */ nchar = WideCharToMultiByte(CP_UTF8, 0, winbuf, -1, inbuf, inbuf_size, NULL, NULL); From a4546e3394336d3ae1cb7c2a6f0afeacb1609355 Mon Sep 17 00:00:00 2001 From: ampli Date: Thu, 30 May 2024 20:10:14 +0300 Subject: [PATCH 15/15] parser-utilities.c: Remove a dead ifdef --- link-parser/parser-utilities.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/link-parser/parser-utilities.c b/link-parser/parser-utilities.c index 36e6020ba8..64578061f4 100644 --- a/link-parser/parser-utilities.c +++ b/link-parser/parser-utilities.c @@ -11,10 +11,6 @@ /* */ /***************************************************************************/ -/* Used for terminal resizing */ -#ifndef _WIN32 -#endif /* _WIN32 */ - #ifdef _WIN32 #include #include