diff --git a/acinclude.m4 b/acinclude.m4 index d7f27a62a..8a0750400 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -2,6 +2,7 @@ m4_include([m4.include/ac_onceonly.m4]) m4_include([m4.include/ax_path_lib_pcre.m4]) m4_include([m4.include/dx_doxygen.m4]) m4_include([m4.include/mc-cflags.m4]) +m4_include([m4.include/ax_gcc_func_attribute.m4]) m4_include([m4.include/mc-check-search-type.m4]) m4_include([m4.include/mode_t.m4]) m4_include([m4.include/stat-size.m4]) diff --git a/configure.ac b/configure.ac index 65618d5e7..bf2e98b2a 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,8 @@ if test "x$enable_werror" = xyes; then mc_CHECK_ONE_CFLAG([-Werror]) fi +AX_GCC_FUNC_ATTRIBUTE([fallthrough]) + AC_PROG_LIBTOOL diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index aace39942..1a02c1e86 100644 --- a/doc/man/mc.1.in +++ b/doc/man/mc.1.in @@ -503,9 +503,7 @@ To untag files, just retag a tagged file. .B M\-e to change charset of panel you may use M\-e (Alt\-e). Recoding is made from selected codepage into system codepage. To -cancel the recoding you may select "directory up" (..) in active panel. -To cancel the charsets in all directories, select "No translation " in -the dialog of encodings. +cancel the recoding, select "No translation" in the dialog of encodings. .TP .B Alt\-g, Alt\-r, Alt\-j used to select the top file in a panel, the middle file and the bottom one, diff --git a/doc/man/ru/mc.1.in b/doc/man/ru/mc.1.in index 4a1ab012d..09ecbc01a 100644 --- a/doc/man/ru/mc.1.in +++ b/doc/man/ru/mc.1.in @@ -8,7 +8,7 @@ mc \- Визуальная оболочка для Unix\-подобных сис .\"SKIP_SECTION" .SH "СИНТАКСИС" .B mc -[\-abcCdfhPstuUVx] [\-l журнал] [каталог1 [каталог2]] [\-e [файл] . ..] [\-v файл] +[\-abcCdfhPstuUVx] [\-l журнал] [каталог1 [каталог2]] [\-e [файл] ...] [\-v файл] .\"NODE "DESCRIPTION" .SH "ОПИСАНИЕ" Что такое Midnight Commander @@ -495,9 +495,7 @@ Midnight Commander\-а. Для возврата к вашему приложен .B M\-e Чтобы поменять кодировку панели, используйте комбинацию M\-e (Alt\-e). Перекодировка производится из выбранной кодировки в системную. Для отмены -перекодировки просто перейдите на каталог вверх '..'. Для отмены -перекодировки всех каталогов выберите "Без перекодировки" в диалоге -выбора кодировок. +перекодировки выберите "Без перекодировки" в диалоге выбора кодировок. .TP .B M\-g, M\-r, M\-j Используются для перемещения подсветки, соответственно, на самый diff --git a/lib/charsets.c b/lib/charsets.c index 66b6bcc18..a8ba1c16b 100644 --- a/lib/charsets.c +++ b/lib/charsets.c @@ -1,7 +1,7 @@ /* Text conversion from one charset to another. - Copyright (C) 2001-2017 + Copyright (C) 2001-2018 Free Software Foundation, Inc. Written by: @@ -106,12 +106,14 @@ load_codepages_list_from_file (GPtrArray ** list, const char *fname) { /* split string into id and cpname */ char *p = buf; - size_t buflen = strlen (buf); + size_t buflen; if (*p == '\n' || *p == '\0' || *p == '#') continue; - if (buflen > 0 && buf[buflen - 1] == '\n') + buflen = strlen (buf); + + if (buflen != 0 && buf[buflen - 1] == '\n') buf[buflen - 1] = '\0'; while (*p != '\0' && !whitespace (*p)) ++p; @@ -181,11 +183,10 @@ translate_character (GIConv cd, char c) gsize bytes_read, bytes_written = 0; const char *ibuf = &c; char ch = UNKNCHAR; - int ibuflen = 1; tmp_buff = g_convert_with_iconv (ibuf, ibuflen, cd, &bytes_read, &bytes_written, NULL); - if (tmp_buff) + if (tmp_buff != NULL) ch = tmp_buff[0]; g_free (tmp_buff); return ch; @@ -245,10 +246,11 @@ int get_codepage_index (const char *id) { size_t i; - if (strcmp (id, OTHER_8BIT) == 0) - return -1; + if (codepages == NULL) return -1; + if (strcmp (id, OTHER_8BIT) == 0) + return -1; for (i = 0; i < codepages->len; i++) if (strcmp (id, ((codepage_desc *) g_ptr_array_index (codepages, i))->id) == 0) return i; @@ -269,7 +271,9 @@ is_supported_encoding (const char *encoding) for (t = 0; t < codepages->len; t++) { - const char *id = ((codepage_desc *) g_ptr_array_index (codepages, t))->id; + const char *id; + + id = ((codepage_desc *) g_ptr_array_index (codepages, t))->id; result |= (g_ascii_strncasecmp (encoding, id, strlen (id)) == 0); } @@ -292,8 +296,8 @@ init_translation_table (int cpsource, int cpdisplay) { conv_displ[i] = i; conv_input[i] = i; - cp_source = cp_display; } + cp_source = cp_display; return NULL; } @@ -339,14 +343,9 @@ init_translation_table (int cpsource, int cpdisplay) void convert_to_display (char *str) { - if (!str) - return; - - while (*str) - { - *str = conv_displ[(unsigned char) *str]; - str++; - } + if (str != NULL) + for (; *str != '\0'; str++) + *str = conv_displ[(unsigned char) *str]; } /* --------------------------------------------------------------------------------------------- */ @@ -355,7 +354,6 @@ GString * str_convert_to_display (const char *str) { return str_nconvert_to_display (str, -1); - } /* --------------------------------------------------------------------------------------------- */ @@ -366,7 +364,7 @@ str_nconvert_to_display (const char *str, int len) GString *buff; GIConv conv; - if (!str) + if (str == NULL) return g_string_new (""); if (cp_display == cp_source) @@ -385,14 +383,9 @@ str_nconvert_to_display (const char *str, int len) void convert_from_input (char *str) { - if (!str) - return; - - while (*str) - { - *str = conv_input[(unsigned char) *str]; - str++; - } + if (str != NULL) + for (; *str != '\0'; str++) + *str = conv_input[(unsigned char) *str]; } /* --------------------------------------------------------------------------------------------- */ @@ -411,7 +404,7 @@ str_nconvert_to_input (const char *str, int len) GString *buff; GIConv conv; - if (!str) + if (str == NULL) return g_string_new (""); if (cp_display == cp_source) @@ -530,37 +523,16 @@ convert_from_8bit_to_utf_c (char input_char, GIConv conv) int convert_from_8bit_to_utf_c2 (char input_char) { - unsigned char str[2]; int ch = '.'; GIConv conv; const char *cp_from; - str[0] = (unsigned char) input_char; - str[1] = '\0'; - cp_from = get_codepage_id (mc_global.source_codepage); - conv = str_crt_conv_to (cp_from); + conv = str_crt_conv_to (cp_from); if (conv != INVALID_CONV) { - unsigned char buf_ch[UTF8_CHAR_LEN + 1]; - - switch (str_translate_char (conv, (char *) str, -1, (char *) buf_ch, sizeof (buf_ch))) - { - case ESTR_SUCCESS: - { - int res; - - res = g_utf8_get_char_validated ((char *) buf_ch, -1); - ch = res >= 0 ? res : buf_ch[0]; - break; - } - case ESTR_PROBLEM: - case ESTR_FAILURE: - default: - ch = '.'; - break; - } + ch = convert_from_8bit_to_utf_c (input_char, conv); str_close_conv (conv); } diff --git a/lib/event.h b/lib/event.h index a347bb093..df6d857db 100644 --- a/lib/event.h +++ b/lib/event.h @@ -34,7 +34,7 @@ void mc_event_del (const gchar *, const gchar *, mc_event_callback_func_t, gpoin void mc_event_destroy (const gchar *, const gchar *); void mc_event_group_del (const gchar *); gboolean mc_event_present (const gchar *, const gchar *); -gboolean mc_event_mass_add (event_init_t *, GError **); +gboolean mc_event_mass_add (const event_init_t *, GError **); /* raise.c: */ gboolean mc_event_raise (const gchar *, const gchar *, gpointer); diff --git a/lib/event/event.c b/lib/event/event.c index 3bb5e9b55..8c5a6596e 100644 --- a/lib/event/event.c +++ b/lib/event/event.c @@ -2,7 +2,7 @@ Handle events in application. Interface functions: init/deinit; start/stop - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: @@ -92,7 +92,7 @@ mc_event_deinit (GError ** mcerror) /* --------------------------------------------------------------------------------------------- */ gboolean -mc_event_mass_add (event_init_t * events, GError ** mcerror) +mc_event_mass_add (const event_init_t * events, GError ** mcerror) { size_t array_index; diff --git a/lib/event/manage.c b/lib/event/manage.c index 85f50be6e..5f253baff 100644 --- a/lib/event/manage.c +++ b/lib/event/manage.c @@ -2,7 +2,7 @@ Handle any events in application. Manage events: add, delete, destroy, search - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/event/raise.c b/lib/event/raise.c index 2bbe37ec8..f33893475 100644 --- a/lib/event/raise.c +++ b/lib/event/raise.c @@ -2,7 +2,7 @@ Handle any events in application. Raise events. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/filehighlight/common.c b/lib/filehighlight/common.c index 04e2451be..4509380dc 100644 --- a/lib/filehighlight/common.c +++ b/lib/filehighlight/common.c @@ -2,7 +2,7 @@ File highlight plugin. Interface functions - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/filehighlight/get-color.c b/lib/filehighlight/get-color.c index 33e3d4fcb..b6f825f70 100644 --- a/lib/filehighlight/get-color.c +++ b/lib/filehighlight/get-color.c @@ -2,7 +2,7 @@ File highlight plugin. Interface functions. get color pair index for highlighted file. - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/filehighlight/ini-file-read.c b/lib/filehighlight/ini-file-read.c index 31e74ec72..96cbb7d6d 100644 --- a/lib/filehighlight/ini-file-read.c +++ b/lib/filehighlight/ini-file-read.c @@ -2,7 +2,7 @@ File highlight plugin. Reading and parse rules from ini-files - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/glibcompat.c b/lib/glibcompat.c index c43bb0b76..f83c30080 100644 --- a/lib/glibcompat.c +++ b/lib/glibcompat.c @@ -1,7 +1,7 @@ /* GLIB - Library of useful routines for C programming - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/global.c b/lib/global.c index 1dc1b6e16..b95e84fb8 100644 --- a/lib/global.c +++ b/lib/global.c @@ -1,7 +1,7 @@ /* Global structure for some library-related variables - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/global.h b/lib/global.h index 8f32c946f..96b20f2e3 100644 --- a/lib/global.h +++ b/lib/global.h @@ -27,6 +27,12 @@ /* for sig_atomic_t */ #include +#ifdef HAVE_FUNC_ATTRIBUTE_FALLTHROUGH +#define MC_FALLTHROUGH __attribute__((fallthrough)) +#else +#define MC_FALLTHROUGH +#endif + /*** typedefs(not structures) and defined constants **********************************************/ /* The O_BINARY definition was taken from gettext */ @@ -128,7 +134,7 @@ #define TMPDIR_DEFAULT "/tmp" #define SCRIPT_SUFFIX "" #define get_default_editor() "vi" -#define OS_SORT_CASE_SENSITIVE_DEFAULT 1 +#define OS_SORT_CASE_SENSITIVE_DEFAULT TRUE #define UTF8_CHAR_LEN 6 /* Used to distinguish between a normal MC termination and */ diff --git a/lib/hook.c b/lib/hook.c index 28f814104..1ebc89574 100644 --- a/lib/hook.c +++ b/lib/hook.c @@ -4,7 +4,7 @@ Slavaz: Warning! this file is deprecated and should be replaced by mcevents functional. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/keybind.c b/lib/keybind.c index 3b53f086f..10c983437 100644 --- a/lib/keybind.c +++ b/lib/keybind.c @@ -1,7 +1,7 @@ /* Definitions of key bindings. - Copyright (C) 2005-2017 + Copyright (C) 2005-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/lock.c b/lib/lock.c index b4cc96cdd..9b0d94f43 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -1,7 +1,7 @@ /* File locking - Copyright (C) 2003-2017 + Copyright (C) 2003-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/logging.c b/lib/logging.c index 0e106280a..3a040b105 100644 --- a/lib/logging.c +++ b/lib/logging.c @@ -1,7 +1,7 @@ /* Provides a log file to ease tracing the program. - Copyright (C) 2006-2017 + Copyright (C) 2006-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index 34444f602..e8091020a 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -1,7 +1,7 @@ /* Configure module for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/lib/mcconfig/get.c b/lib/mcconfig/get.c index e9aaa748a..4118caf3e 100644 --- a/lib/mcconfig/get.c +++ b/lib/mcconfig/get.c @@ -1,7 +1,7 @@ /* Configure module for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index bdbb02764..6ef50cedb 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -1,7 +1,7 @@ /* paths to configuration files - Copyright (C) 2010-2017 + Copyright (C) 2010-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/mcconfig/set.c b/lib/mcconfig/set.c index ff1c59cda..d002d8da8 100644 --- a/lib/mcconfig/set.c +++ b/lib/mcconfig/set.c @@ -1,7 +1,7 @@ /* Configure module for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/lib/search/glob.c b/lib/search/glob.c index 9da89e8ad..69888ecfe 100644 --- a/lib/search/glob.c +++ b/lib/search/glob.c @@ -2,7 +2,7 @@ Search text engine. Glob-style pattern matching - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/search/hex.c b/lib/search/hex.c index 383c92adb..4fd3314cb 100644 --- a/lib/search/hex.c +++ b/lib/search/hex.c @@ -2,7 +2,7 @@ Search text engine. HEX-style pattern matching - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/search/lib.c b/lib/search/lib.c index 85c42a795..3f582e833 100644 --- a/lib/search/lib.c +++ b/lib/search/lib.c @@ -2,7 +2,7 @@ Search text engine. Common share code for module. - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: @@ -61,31 +61,27 @@ gchar * mc_search__recode_str (const char *str, gsize str_len, const char *charset_from, const char *charset_to, gsize * bytes_written) { - gchar *ret; - gsize bytes_read; - GIConv conv; + gchar *ret = NULL; - if (charset_from == NULL || charset_to == NULL - || g_ascii_strcasecmp (charset_to, charset_from) == 0) + if (charset_from != NULL && charset_to != NULL + && g_ascii_strcasecmp (charset_to, charset_from) != 0) { - *bytes_written = str_len; - return g_strndup (str, str_len); - } + GIConv conv; - conv = g_iconv_open (charset_to, charset_from); - if (conv == INVALID_CONV) - { - *bytes_written = str_len; - return g_strndup (str, str_len); - } + conv = g_iconv_open (charset_to, charset_from); + if (conv != INVALID_CONV) + { + gsize bytes_read; - ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL); - g_iconv_close (conv); + ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL); + g_iconv_close (conv); + } + } if (ret == NULL) { *bytes_written = str_len; - return g_strndup (str, str_len); + ret = g_strndup (str, str_len); } return ret; @@ -125,13 +121,8 @@ mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len, converted_str2 = mc_search__recode_str (converted_str, tmp_len, cp_display, charset, &converted_str_len); #endif - if (just_letters) - { - if (str_isalnum (converted_str) && !str_isdigit (converted_str)) - *just_letters = TRUE; - else - *just_letters = FALSE; - } + if (just_letters != NULL) + *just_letters = str_isalnum (converted_str) && !str_isdigit (converted_str); #ifdef HAVE_CHARSET g_free (converted_str); return converted_str2; diff --git a/lib/search/normal.c b/lib/search/normal.c index d074be71f..4b7ffa8d2 100644 --- a/lib/search/normal.c +++ b/lib/search/normal.c @@ -2,7 +2,7 @@ Search text engine. Plain search - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: @@ -71,7 +71,7 @@ mc_search__normal_translate_to_regex (const GString * astr) case '-': case '|': g_string_append_c (buff, '\\'); - /* fall through */ + MC_FALLTHROUGH; default: g_string_append_c (buff, str[loop]); break; diff --git a/lib/search/regex.c b/lib/search/regex.c index a577ea3d5..40da7c02e 100644 --- a/lib/search/regex.c +++ b/lib/search/regex.c @@ -2,7 +2,7 @@ Search text engine. Regex search - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/search/search.c b/lib/search/search.c index e9e160a09..a0fd66e7a 100644 --- a/lib/search/search.c +++ b/lib/search/search.c @@ -2,7 +2,7 @@ Search text engine. Interface functions - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/serialize.c b/lib/serialize.c index 1b71b9704..e2a47655f 100644 --- a/lib/serialize.c +++ b/lib/serialize.c @@ -1,7 +1,7 @@ /* Provides a serialize/unserialize functionality for INI-like formats. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: @@ -133,7 +133,7 @@ mc_deserialize_str (const char prefix, const char *data, GError ** error) { size_t data_len; - if ((data == NULL) || (strlen (data) == 0)) + if ((data == NULL) || (*data == '\0')) { g_set_error (error, MC_ERROR, 0, FUNC_NAME ": Input data is NULL or empty."); return NULL; diff --git a/lib/shell.c b/lib/shell.c index 8bdac765b..971254c9a 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -1,7 +1,7 @@ /* Provides a functions for working with shell. - Copyright (C) 2006-2017 + Copyright (C) 2006-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/skin/colors-old.c b/lib/skin/colors-old.c index e7146868e..60c0d6270 100644 --- a/lib/skin/colors-old.c +++ b/lib/skin/colors-old.c @@ -2,7 +2,7 @@ Skins engine. Work with colors - backward compatibility - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/skin/colors.c b/lib/skin/colors.c index 5f7ce27ed..cb6d6f037 100644 --- a/lib/skin/colors.c +++ b/lib/skin/colors.c @@ -2,7 +2,7 @@ Skins engine. Work with colors - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/skin/common.c b/lib/skin/common.c index 59ae42b2c..b2cbca6b9 100644 --- a/lib/skin/common.c +++ b/lib/skin/common.c @@ -2,7 +2,7 @@ Skins engine. Interface functions - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/skin/hc-skins.c b/lib/skin/hc-skins.c index 987b4b293..36dbf76c8 100644 --- a/lib/skin/hc-skins.c +++ b/lib/skin/hc-skins.c @@ -2,7 +2,7 @@ Skins engine. Set of hardcoded skins - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/skin/ini-file.c b/lib/skin/ini-file.c index 637285f0b..9dd7152cd 100644 --- a/lib/skin/ini-file.c +++ b/lib/skin/ini-file.c @@ -2,7 +2,7 @@ Skins engine. Reading and parse ini-files - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/skin/lines.c b/lib/skin/lines.c index 552ef56f6..23028fdac 100644 --- a/lib/skin/lines.c +++ b/lib/skin/lines.c @@ -2,7 +2,7 @@ Skins engine. Work with line draving chars. - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/strutil.h b/lib/strutil.h index 4683850ee..9bbff6ca3 100644 --- a/lib/strutil.h +++ b/lib/strutil.h @@ -103,10 +103,11 @@ typedef enum /* all functions in str_class must be defined for every encoding */ struct str_class { + /* *INDENT-OFF* */ gchar *(*conv_gerror_message) (GError * error, const char *def_msg); /*I*/ estr_t (*vfs_convert_to) (GIConv coder, const char *string, int size, GString * buffer); /*I*/ void (*insert_replace_char) (GString * buffer); - int (*is_valid_string) (const char *); + gboolean (*is_valid_string) (const char *); /*I*/ int (*is_valid_char) (const char *, size_t); /*I*/ void (*cnext_char) (const char **); void (*cprev_char) (const char **); @@ -114,17 +115,17 @@ struct str_class /*I*/ void (*cprev_char_safe) (const char **); /*I*/ int (*cnext_noncomb_char) (const char **text); /*I*/ int (*cprev_noncomb_char) (const char **text, const char *begin); - /*I*/ int (*char_isspace) (const char *); - /*I*/ int (*char_ispunct) (const char *); - /*I*/ int (*char_isalnum) (const char *); - /*I*/ int (*char_isdigit) (const char *); - /*I*/ int (*char_isprint) (const char *); + /*I*/ gboolean (*char_isspace) (const char *); + /*I*/ gboolean (*char_ispunct) (const char *); + /*I*/ gboolean (*char_isalnum) (const char *); + /*I*/ gboolean (*char_isdigit) (const char *); + /*I*/ gboolean (*char_isprint) (const char *); /*I*/ gboolean (*char_iscombiningmark) (const char *); /*I*/ int (*length) (const char *); /*I*/ int (*length2) (const char *, int); /*I*/ int (*length_noncomb) (const char *); - /*I*/ int (*char_toupper) (const char *, char **, size_t *); - int (*char_tolower) (const char *, char **, size_t *); + /*I*/ gboolean (*char_toupper) (const char *, char **, size_t *); + gboolean (*char_tolower) (const char *, char **, size_t *); void (*fix_string) (char *); /*I*/ const char *(*term_form) (const char *); /*I*/ const char *(*fit_to_term) (const char *, int, align_crt_t); @@ -136,21 +137,22 @@ struct str_class /*I*/ const char *(*trunc) (const char *, int); /*I*/ int (*offset_to_pos) (const char *, size_t); /*I*/ int (*column_to_pos) (const char *, size_t); - /*I*/ char *(*create_search_needle) (const char *, int); - void (*release_search_needle) (char *, int); - const char *(*search_first) (const char *, const char *, int); - const char *(*search_last) (const char *, const char *, int); + /*I*/ char *(*create_search_needle) (const char *, gboolean); + void (*release_search_needle) (char *, gboolean); + const char *(*search_first) (const char *, const char *, gboolean); + const char *(*search_last) (const char *, const char *, gboolean); int (*compare) (const char *, const char *); /*I*/ int (*ncompare) (const char *, const char *); /*I*/ int (*casecmp) (const char *, const char *); /*I*/ int (*ncasecmp) (const char *, const char *); /*I*/ int (*prefix) (const char *, const char *); /*I*/ int (*caseprefix) (const char *, const char *); - /*I*/ char *(*create_key) (const char *text, int case_sen); - /*I*/ char *(*create_key_for_filename) (const char *text, int case_sen); - /*I*/ int (*key_collate) (const char *t1, const char *t2, int case_sen); - /*I*/ void (*release_key) (char *key, int case_sen); - /*I*/}; + /*I*/ char *(*create_key) (const char *text, gboolean case_sen); + /*I*/ char *(*create_key_for_filename) (const char *text, gboolean case_sen); + /*I*/ int (*key_collate) (const char *t1, const char *t2, gboolean case_sen); + /*I*/ void (*release_key) (char *key, gboolean case_sen); + /* *INDENT-ON* */ +}; /*** global variables defined in .c file *********************************************************/ @@ -245,7 +247,7 @@ estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size, /* test, if text is valid in terminal encoding * I */ -int str_is_valid_string (const char *text); +gboolean str_is_valid_string (const char *text); /* test, if first char of ch is valid * size, how many bytes characters occupied, could be (size_t)(-1) @@ -322,27 +324,27 @@ int str_cprev_noncomb_char (const char **text, const char *begin); /* if first characters in ch is space, tabulator or new lines * I */ -int str_isspace (const char *ch); +gboolean str_isspace (const char *ch); /* if first characters in ch is punctuation or symbol * I */ -int str_ispunct (const char *ch); +gboolean str_ispunct (const char *ch); /* if first characters in ch is alphanum * I */ -int str_isalnum (const char *ch); +gboolean str_isalnum (const char *ch); /* if first characters in ch is digit * I */ -int str_isdigit (const char *ch); +gboolean str_isdigit (const char *ch); /* if first characters in ch is printable * I */ -int str_isprint (const char *ch); +gboolean str_isprint (const char *ch); /* if first characters in ch is a combining mark (only in utf-8) * combining makrs are assumed to be zero width @@ -354,13 +356,13 @@ gboolean str_iscombiningmark (const char *ch); * decrase remain by size of returned characters * if out is not big enough, do nothing */ -int str_toupper (const char *ch, char **out, size_t * remain); +gboolean str_toupper (const char *ch, char **out, size_t * remain); /* write upper from of fisrt characters in ch into out * decrase remain by size of returned characters * if out is not big enough, do nothing */ -int str_tolower (const char *ch, char **out, size_t * remain); +gboolean str_tolower (const char *ch, char **out, size_t * remain); /* return length of text in characters * I @@ -455,19 +457,19 @@ const char *str_trunc (const char *text, int width); * so needle can be reused * in UTF-8 return normalized form of needle */ -char *str_create_search_needle (const char *needle, int case_sen); +char *str_create_search_needle (const char *needle, gboolean case_sen); /* free needle returned by str_create_search_needle */ -void str_release_search_needle (char *needle, int case_sen); +void str_release_search_needle (char *needle, gboolean case_sen); /* search for first occurrence of search in text */ -const char *str_search_first (const char *text, const char *needle, int case_sen); +const char *str_search_first (const char *text, const char *needle, gboolean case_sen); /* search for last occurrence of search in text */ -const char *str_search_last (const char *text, const char *needle, int case_sen); +const char *str_search_last (const char *text, const char *needle, gboolean case_sen); /* case sensitive compare two strings * I @@ -507,25 +509,25 @@ int str_caseprefix (const char *text, const char *prefix); /* create a key that is used by str_key_collate * I */ -char *str_create_key (const char *text, int case_sen); +char *str_create_key (const char *text, gboolean case_sen); /* create a key that is used by str_key_collate * should aware dot '.' in text * I */ -char *str_create_key_for_filename (const char *text, int case_sen); +char *str_create_key_for_filename (const char *text, gboolean case_sen); /* compare two string using LC_COLLATE, if is possible * if case_sen is set, comparing is case sensitive, * case_sen must be same for str_create_key, str_key_collate and str_release_key * I */ -int str_key_collate (const char *t1, const char *t2, int case_sen); +int str_key_collate (const char *t1, const char *t2, gboolean case_sen); /* release_key created by str_create_key, only rigth way to release key * I */ -void str_release_key (char *key, int case_sen); +void str_release_key (char *key, gboolean case_sen); /* return TRUE if codeset_name is utf8 or utf-8 * I diff --git a/lib/strutil/replace.c b/lib/strutil/replace.c index 23e97ca47..4c2bab991 100644 --- a/lib/strutil/replace.c +++ b/lib/strutil/replace.c @@ -1,7 +1,7 @@ /* Functions for replacing substrings in strings. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/strutil/strescape.c b/lib/strutil/strescape.c index 4ed6360fa..a45797efd 100644 --- a/lib/strutil/strescape.c +++ b/lib/strutil/strescape.c @@ -1,7 +1,7 @@ /* Functions for escaping and unescaping strings - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/strutil/strutil.c b/lib/strutil/strutil.c index 31b8aa155..698fcce39 100644 --- a/lib/strutil/strutil.c +++ b/lib/strutil/strutil.c @@ -1,7 +1,7 @@ /* Common strings utilities - Copyright (C) 2007-2017 + Copyright (C) 2007-2018 Free Software Foundation, Inc. Written by: @@ -47,14 +47,14 @@ GIConv str_cnv_not_convert = INVALID_CONV; /*** file scope variables ************************************************************************/ /* names, that are used for utf-8 */ -static const char *str_utf8_encodings[] = { +static const char *const str_utf8_encodings[] = { "utf-8", "utf8", NULL }; /* standard 8bit encodings, no wide or multibytes characters */ -static const char *str_8bit_encodings[] = { +static const char *const str_8bit_encodings[] = { "cp-1251", "cp1251", "cp-1250", @@ -219,7 +219,7 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer) /* --------------------------------------------------------------------------------------------- */ static int -str_test_encoding_class (const char *encoding, const char **table) +str_test_encoding_class (const char *encoding, const char *const *table) { int result = 0; @@ -714,7 +714,7 @@ str_column_to_pos (const char *text, size_t pos) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_isspace (const char *ch) { return used_class.char_isspace (ch); @@ -722,7 +722,7 @@ str_isspace (const char *ch) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_ispunct (const char *ch) { return used_class.char_ispunct (ch); @@ -730,7 +730,7 @@ str_ispunct (const char *ch) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_isalnum (const char *ch) { return used_class.char_isalnum (ch); @@ -738,7 +738,7 @@ str_isalnum (const char *ch) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_isdigit (const char *ch) { return used_class.char_isdigit (ch); @@ -746,7 +746,7 @@ str_isdigit (const char *ch) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_toupper (const char *ch, char **out, size_t * remain) { return used_class.char_toupper (ch, out, remain); @@ -754,7 +754,7 @@ str_toupper (const char *ch, char **out, size_t * remain) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_tolower (const char *ch, char **out, size_t * remain) { return used_class.char_tolower (ch, out, remain); @@ -762,7 +762,7 @@ str_tolower (const char *ch, char **out, size_t * remain) /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_isprint (const char *ch) { return used_class.char_isprint (ch); @@ -787,7 +787,7 @@ str_trunc (const char *text, int width) /* --------------------------------------------------------------------------------------------- */ char * -str_create_search_needle (const char *needle, int case_sen) +str_create_search_needle (const char *needle, gboolean case_sen) { return used_class.create_search_needle (needle, case_sen); } @@ -795,7 +795,7 @@ str_create_search_needle (const char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ void -str_release_search_needle (char *needle, int case_sen) +str_release_search_needle (char *needle, gboolean case_sen) { used_class.release_search_needle (needle, case_sen); } @@ -803,7 +803,7 @@ str_release_search_needle (char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ const char * -str_search_first (const char *text, const char *search, int case_sen) +str_search_first (const char *text, const char *search, gboolean case_sen) { return used_class.search_first (text, search, case_sen); } @@ -811,14 +811,14 @@ str_search_first (const char *text, const char *search, int case_sen) /* --------------------------------------------------------------------------------------------- */ const char * -str_search_last (const char *text, const char *search, int case_sen) +str_search_last (const char *text, const char *search, gboolean case_sen) { return used_class.search_last (text, search, case_sen); } /* --------------------------------------------------------------------------------------------- */ -int +gboolean str_is_valid_string (const char *text) { return used_class.is_valid_string (text); @@ -883,7 +883,7 @@ str_fix_string (char *text) /* --------------------------------------------------------------------------------------------- */ char * -str_create_key (const char *text, int case_sen) +str_create_key (const char *text, gboolean case_sen) { return used_class.create_key (text, case_sen); } @@ -891,7 +891,7 @@ str_create_key (const char *text, int case_sen) /* --------------------------------------------------------------------------------------------- */ char * -str_create_key_for_filename (const char *text, int case_sen) +str_create_key_for_filename (const char *text, gboolean case_sen) { return used_class.create_key_for_filename (text, case_sen); } @@ -899,7 +899,7 @@ str_create_key_for_filename (const char *text, int case_sen) /* --------------------------------------------------------------------------------------------- */ int -str_key_collate (const char *t1, const char *t2, int case_sen) +str_key_collate (const char *t1, const char *t2, gboolean case_sen) { return used_class.key_collate (t1, t2, case_sen); } @@ -907,7 +907,7 @@ str_key_collate (const char *t1, const char *t2, int case_sen) /* --------------------------------------------------------------------------------------------- */ void -str_release_key (char *key, int case_sen) +str_release_key (char *key, gboolean case_sen) { used_class.release_key (key, case_sen); } diff --git a/lib/strutil/strutil8bit.c b/lib/strutil/strutil8bit.c index 23911a88b..b4b34af87 100644 --- a/lib/strutil/strutil8bit.c +++ b/lib/strutil/strutil8bit.c @@ -1,7 +1,7 @@ /* 8bit strings utilities - Copyright (C) 2007-2017 + Copyright (C) 2007-2018 Free Software Foundation, Inc. Written by: @@ -84,11 +84,11 @@ str_8bit_insert_replace_char (GString * buffer) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_is_valid_string (const char *text) { (void) text; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -143,42 +143,42 @@ str_8bit_cprev_noncomb_char (const char **text, const char *begin) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_isspace (const char *text) { - return char_isspace (text[0]); + return char_isspace (text[0]) != 0; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_ispunct (const char *text) { - return char_ispunct (text[0]); + return char_ispunct (text[0]) != 0; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_isalnum (const char *text) { - return char_isalnum (text[0]); + return char_isalnum (text[0]) != 0; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_isdigit (const char *text) { - return char_isdigit (text[0]); + return char_isdigit (text[0]) != 0; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_isprint (const char *text) { - return char_isprint (text[0]); + return char_isprint (text[0]) != 0; } /* --------------------------------------------------------------------------------------------- */ @@ -196,26 +196,26 @@ static int str_8bit_toupper (const char *text, char **out, size_t * remain) { if (*remain <= 1) - return 0; + return FALSE; (*out)[0] = char_toupper (text[0]); (*out)++; (*remain)--; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_8bit_tolower (const char *text, char **out, size_t * remain) { if (*remain <= 1) - return 0; + return FALSE; (*out)[0] = char_tolower (text[0]); (*out)++; (*remain)--; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -553,7 +553,7 @@ str_8bit_column_to_pos (const char *text, size_t pos) /* --------------------------------------------------------------------------------------------- */ static char * -str_8bit_create_search_needle (const char *needle, int case_sen) +str_8bit_create_search_needle (const char *needle, gboolean case_sen) { (void) case_sen; return (char *) needle; @@ -562,7 +562,7 @@ str_8bit_create_search_needle (const char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ static void -str_8bit_release_search_needle (char *needle, int case_sen) +str_8bit_release_search_needle (char *needle, gboolean case_sen) { (void) case_sen; (void) needle; @@ -589,14 +589,14 @@ str_8bit_strdown (const char *str) /* --------------------------------------------------------------------------------------------- */ static const char * -str_8bit_search_first (const char *text, const char *search, int case_sen) +str_8bit_search_first (const char *text, const char *search, gboolean case_sen) { char *fold_text; char *fold_search; const char *match; - fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text); - fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search); + fold_text = case_sen ? (char *) text : str_8bit_strdown (text); + fold_search = case_sen ? (char *) search : str_8bit_strdown (search); match = g_strstr_len (fold_text, -1, fold_search); if (match != NULL) @@ -619,14 +619,14 @@ str_8bit_search_first (const char *text, const char *search, int case_sen) /* --------------------------------------------------------------------------------------------- */ static const char * -str_8bit_search_last (const char *text, const char *search, int case_sen) +str_8bit_search_last (const char *text, const char *search, gboolean case_sen) { char *fold_text; char *fold_search; const char *match; - fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text); - fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search); + fold_text = case_sen ? (char *) text : str_8bit_strdown (text); + fold_search = case_sen ? (char *) search : str_8bit_strdown (search); match = g_strrstr_len (fold_text, -1, fold_search); if (match != NULL) @@ -775,26 +775,23 @@ str_8bit_fix_string (char *text) /* --------------------------------------------------------------------------------------------- */ static char * -str_8bit_create_key (const char *text, int case_sen) +str_8bit_create_key (const char *text, gboolean case_sen) { - return (case_sen) ? (char *) text : str_8bit_strdown (text); + return case_sen ? (char *) text : str_8bit_strdown (text); } /* --------------------------------------------------------------------------------------------- */ static int -str_8bit_key_collate (const char *t1, const char *t2, int case_sen) +str_8bit_key_collate (const char *t1, const char *t2, gboolean case_sen) { - if (case_sen) - return strcmp (t1, t2); - else - return strcoll (t1, t2); + return case_sen ? strcmp (t1, t2) : strcoll (t1, t2); } /* --------------------------------------------------------------------------------------------- */ static void -str_8bit_release_key (char *key, int case_sen) +str_8bit_release_key (char *key, gboolean case_sen) { if (!case_sen) g_free (key); diff --git a/lib/strutil/strutilascii.c b/lib/strutil/strutilascii.c index a293566f5..ffa787302 100644 --- a/lib/strutil/strutilascii.c +++ b/lib/strutil/strutilascii.c @@ -1,7 +1,7 @@ /* ASCII strings utilities - Copyright (C) 2007-2017 + Copyright (C) 2007-2018 Free Software Foundation, Inc. Written by: @@ -57,11 +57,11 @@ str_ascii_insert_replace_char (GString * buffer) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_is_valid_string (const char *text) { (void) text; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -116,7 +116,7 @@ str_ascii_cprev_noncomb_char (const char **text, const char *begin) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_isspace (const char *text) { return g_ascii_isspace ((gchar) text[0]); @@ -124,7 +124,7 @@ str_ascii_isspace (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_ispunct (const char *text) { return g_ascii_ispunct ((gchar) text[0]); @@ -132,7 +132,7 @@ str_ascii_ispunct (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_isalnum (const char *text) { return g_ascii_isalnum ((gchar) text[0]); @@ -140,7 +140,7 @@ str_ascii_isalnum (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_isdigit (const char *text) { return g_ascii_isdigit ((gchar) text[0]); @@ -148,7 +148,7 @@ str_ascii_isdigit (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_isprint (const char *text) { return g_ascii_isprint ((gchar) text[0]); @@ -169,26 +169,26 @@ static int str_ascii_toupper (const char *text, char **out, size_t * remain) { if (*remain <= 1) - return 0; + return FALSE; (*out)[0] = (char) g_ascii_toupper ((gchar) text[0]); (*out)++; (*remain)--; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_ascii_tolower (const char *text, char **out, size_t * remain) { if (*remain <= 1) - return 0; + return FALSE; (*out)[0] = (char) g_ascii_tolower ((gchar) text[0]); (*out)++; (*remain)--; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -551,7 +551,7 @@ str_ascii_column_to_pos (const char *text, size_t pos) /* --------------------------------------------------------------------------------------------- */ static char * -str_ascii_create_search_needle (const char *needle, int case_sen) +str_ascii_create_search_needle (const char *needle, gboolean case_sen) { (void) case_sen; return (char *) needle; @@ -560,7 +560,7 @@ str_ascii_create_search_needle (const char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ static void -str_ascii_release_search_needle (char *needle, int case_sen) +str_ascii_release_search_needle (char *needle, gboolean case_sen) { (void) case_sen; (void) needle; @@ -570,14 +570,14 @@ str_ascii_release_search_needle (char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ static const char * -str_ascii_search_first (const char *text, const char *search, int case_sen) +str_ascii_search_first (const char *text, const char *search, gboolean case_sen) { char *fold_text; char *fold_search; const char *match; - fold_text = (case_sen) ? (char *) text : g_ascii_strdown (text, -1); - fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1); + fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1); + fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1); match = g_strstr_len (fold_text, -1, fold_search); if (match != NULL) @@ -600,14 +600,14 @@ str_ascii_search_first (const char *text, const char *search, int case_sen) /* --------------------------------------------------------------------------------------------- */ static const char * -str_ascii_search_last (const char *text, const char *search, int case_sen) +str_ascii_search_last (const char *text, const char *search, gboolean case_sen) { char *fold_text; char *fold_search; const char *match; - fold_text = (case_sen) ? (char *) text : g_ascii_strdown (text, -1); - fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1); + fold_text = case_sen ? (char *) text : g_ascii_strdown (text, -1); + fold_search = case_sen ? (char *) search : g_ascii_strdown (search, -1); match = g_strrstr_len (fold_text, -1, fold_search); if (match != NULL) @@ -671,7 +671,7 @@ str_ascii_fix_string (char *text) /* --------------------------------------------------------------------------------------------- */ static char * -str_ascii_create_key (const char *text, int case_sen) +str_ascii_create_key (const char *text, gboolean case_sen) { (void) case_sen; return (char *) text; @@ -680,15 +680,15 @@ str_ascii_create_key (const char *text, int case_sen) /* --------------------------------------------------------------------------------------------- */ static int -str_ascii_key_collate (const char *t1, const char *t2, int case_sen) +str_ascii_key_collate (const char *t1, const char *t2, gboolean case_sen) { - return (case_sen) ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2); + return case_sen ? strcmp (t1, t2) : g_ascii_strcasecmp (t1, t2); } /* --------------------------------------------------------------------------------------------- */ static void -str_ascii_release_key (char *key, int case_sen) +str_ascii_release_key (char *key, gboolean case_sen) { (void) key; (void) case_sen; diff --git a/lib/strutil/strutilutf8.c b/lib/strutil/strutilutf8.c index c7376beb2..f04c6c957 100644 --- a/lib/strutil/strutilutf8.c +++ b/lib/strutil/strutilutf8.c @@ -1,7 +1,7 @@ /* UTF-8 strings utilities - Copyright (C) 2007-2017 + Copyright (C) 2007-2018 Free Software Foundation, Inc. Written by: @@ -84,7 +84,7 @@ str_utf8_insert_replace_char (GString * buffer) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_is_valid_string (const char *text) { return g_utf8_validate (text, -1, NULL); @@ -171,7 +171,7 @@ str_utf8_fix_string (char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_isspace (const char *text) { gunichar uni; @@ -182,7 +182,7 @@ str_utf8_isspace (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_ispunct (const char *text) { gunichar uni; @@ -193,7 +193,7 @@ str_utf8_ispunct (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_isalnum (const char *text) { gunichar uni; @@ -204,7 +204,7 @@ str_utf8_isalnum (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_isdigit (const char *text) { gunichar uni; @@ -215,7 +215,7 @@ str_utf8_isdigit (const char *text) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_isprint (const char *ch) { gunichar uni; @@ -273,7 +273,7 @@ str_utf8_cprev_noncomb_char (const char **text, const char *begin) /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_toupper (const char *text, char **out, size_t * remain) { gunichar uni; @@ -281,22 +281,22 @@ str_utf8_toupper (const char *text, char **out, size_t * remain) uni = g_utf8_get_char_validated (text, -1); if (uni == (gunichar) (-1) || uni == (gunichar) (-2)) - return 0; + return FALSE; uni = g_unichar_toupper (uni); left = g_unichar_to_utf8 (uni, NULL); if (left >= *remain) - return 0; + return FALSE; left = g_unichar_to_utf8 (uni, *out); (*out) += left; (*remain) -= left; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ -static int +static gboolean str_utf8_tolower (const char *text, char **out, size_t * remain) { gunichar uni; @@ -304,17 +304,17 @@ str_utf8_tolower (const char *text, char **out, size_t * remain) uni = g_utf8_get_char_validated (text, -1); if (uni == (gunichar) (-1) || uni == (gunichar) (-2)) - return 0; + return FALSE; uni = g_unichar_tolower (uni); left = g_unichar_to_utf8 (uni, NULL); if (left >= *remain) - return 0; + return FALSE; left = g_unichar_to_utf8 (uni, *out); (*out) += left; (*remain) -= left; - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -956,7 +956,7 @@ str_utf8_column_to_pos (const char *text, size_t pos) /* --------------------------------------------------------------------------------------------- */ static char * -str_utf8_create_search_needle (const char *needle, int case_sen) +str_utf8_create_search_needle (const char *needle, gboolean case_sen) { char *fold, *result; @@ -966,7 +966,6 @@ str_utf8_create_search_needle (const char *needle, int case_sen) if (case_sen) return g_utf8_normalize (needle, -1, G_NORMALIZE_ALL); - fold = g_utf8_casefold (needle, -1); result = g_utf8_normalize (fold, -1, G_NORMALIZE_ALL); g_free (fold); @@ -976,7 +975,7 @@ str_utf8_create_search_needle (const char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ static void -str_utf8_release_search_needle (char *needle, int case_sen) +str_utf8_release_search_needle (char *needle, gboolean case_sen) { (void) case_sen; g_free (needle); @@ -985,7 +984,7 @@ str_utf8_release_search_needle (char *needle, int case_sen) /* --------------------------------------------------------------------------------------------- */ static const char * -str_utf8_search_first (const char *text, const char *search, int case_sen) +str_utf8_search_first (const char *text, const char *search, gboolean case_sen) { char *fold_text; char *deco_text; @@ -993,7 +992,7 @@ str_utf8_search_first (const char *text, const char *search, int case_sen) const char *result = NULL; const char *m; - fold_text = (case_sen) ? (char *) text : g_utf8_casefold (text, -1); + fold_text = case_sen ? (char *) text : g_utf8_casefold (text, -1); deco_text = g_utf8_normalize (fold_text, -1, G_NORMALIZE_ALL); match = deco_text; @@ -1029,7 +1028,7 @@ str_utf8_search_first (const char *text, const char *search, int case_sen) /* --------------------------------------------------------------------------------------------- */ static const char * -str_utf8_search_last (const char *text, const char *search, int case_sen) +str_utf8_search_last (const char *text, const char *search, gboolean case_sen) { char *fold_text; char *deco_text; @@ -1037,7 +1036,7 @@ str_utf8_search_last (const char *text, const char *search, int case_sen) const char *result = NULL; const char *m; - fold_text = (case_sen) ? (char *) text : g_utf8_casefold (text, -1); + fold_text = case_sen ? (char *) text : g_utf8_casefold (text, -1); deco_text = g_utf8_normalize (fold_text, -1, G_NORMALIZE_ALL); do @@ -1343,7 +1342,7 @@ str_utf8_caseprefix (const char *text, const char *prefix) /* --------------------------------------------------------------------------------------------- */ static char * -str_utf8_create_key_gen (const char *text, int case_sen, +str_utf8_create_key_gen (const char *text, gboolean case_sen, gchar * (*keygen) (const gchar * text, gssize size)) { char *result; @@ -1417,7 +1416,7 @@ str_utf8_create_key_gen (const char *text, int case_sen, /* --------------------------------------------------------------------------------------------- */ static char * -str_utf8_create_key (const char *text, int case_sen) +str_utf8_create_key (const char *text, gboolean case_sen) { return str_utf8_create_key_gen (text, case_sen, g_utf8_collate_key); } @@ -1426,7 +1425,7 @@ str_utf8_create_key (const char *text, int case_sen) #ifdef MC__USE_STR_UTF8_CREATE_KEY_FOR_FILENAME static char * -str_utf8_create_key_for_filename (const char *text, int case_sen) +str_utf8_create_key_for_filename (const char *text, gboolean case_sen) { return str_utf8_create_key_gen (text, case_sen, g_utf8_collate_key_for_filename); } @@ -1435,7 +1434,7 @@ str_utf8_create_key_for_filename (const char *text, int case_sen) /* --------------------------------------------------------------------------------------------- */ static int -str_utf8_key_collate (const char *t1, const char *t2, int case_sen) +str_utf8_key_collate (const char *t1, const char *t2, gboolean case_sen) { (void) case_sen; return strcmp (t1, t2); @@ -1444,7 +1443,7 @@ str_utf8_key_collate (const char *t1, const char *t2, int case_sen) /* --------------------------------------------------------------------------------------------- */ static void -str_utf8_release_key (char *key, int case_sen) +str_utf8_release_key (char *key, gboolean case_sen) { (void) case_sen; g_free (key); diff --git a/lib/strutil/strverscmp.c b/lib/strutil/strverscmp.c index f732df788..07f9cb621 100644 --- a/lib/strutil/strverscmp.c +++ b/lib/strutil/strverscmp.c @@ -1,7 +1,7 @@ /* Compare strings while treating digits characters numerically. - Copyright (C) 1997-2017 + Copyright (C) 1997-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. diff --git a/lib/strutil/xstrtol.c b/lib/strutil/xstrtol.c index 4cb3f1839..afda14cbd 100644 --- a/lib/strutil/xstrtol.c +++ b/lib/strutil/xstrtol.c @@ -1,6 +1,6 @@ /* A more useful interface to strtol. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/lib/timefmt.c b/lib/timefmt.c index 6503dc2d5..26ca4c035 100644 --- a/lib/timefmt.c +++ b/lib/timefmt.c @@ -1,7 +1,7 @@ /* Time formatting functions - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/timer.c b/lib/timer.c index ddcd5c954..2082ac08c 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -1,7 +1,7 @@ /* Simple timer for the Midnight Commander. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/color-internal.c b/lib/tty/color-internal.c index dbccc7d3b..9b15519ab 100644 --- a/lib/tty/color-internal.c +++ b/lib/tty/color-internal.c @@ -1,7 +1,7 @@ /* Internal stuff of color setup - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/color-ncurses.c b/lib/tty/color-ncurses.c index 4154c64c6..5ed46c869 100644 --- a/lib/tty/color-ncurses.c +++ b/lib/tty/color-ncurses.c @@ -1,7 +1,7 @@ /* Color setup for NCurses screen library - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/color-slang.c b/lib/tty/color-slang.c index e96c70fe8..5aec82b16 100644 --- a/lib/tty/color-slang.c +++ b/lib/tty/color-slang.c @@ -1,7 +1,7 @@ /* Color setup for S_Lang screen library - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/color.c b/lib/tty/color.c index 83795576f..14715cd8a 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -2,7 +2,7 @@ Color setup. Interface functions. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/key.c b/lib/tty/key.c index d9bcbf0e4..19ffa8e0a 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -1,7 +1,7 @@ /* Keyboard support routines. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/keyxdef.c b/lib/tty/keyxdef.c index 5e956ddb9..38fa3a51e 100644 --- a/lib/tty/keyxdef.c +++ b/lib/tty/keyxdef.c @@ -3,7 +3,7 @@ /* Additional keyboard support routines. - Copyright (C) 1998-2017 + Copyright (C) 1998-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/mouse.c b/lib/tty/mouse.c index 0a58b57a1..f9af8a92c 100644 --- a/lib/tty/mouse.c +++ b/lib/tty/mouse.c @@ -1,7 +1,7 @@ /* Mouse managing - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index a669f4d3c..a424c88cd 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -2,7 +2,7 @@ Interface to the terminal controlling library. Ncurses wrapper. - Copyright (C) 2005-2017 + Copyright (C) 2005-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index 52f313ecf..30ab3e0fc 100644 --- a/lib/tty/tty-slang.c +++ b/lib/tty/tty-slang.c @@ -2,7 +2,7 @@ Interface to the terminal controlling library. Slang wrapper. - Copyright (C) 2005-2017 + Copyright (C) 2005-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty.c b/lib/tty/tty.c index 19ae8ffe3..488b156bd 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -1,7 +1,7 @@ /* Interface to the terminal controlling library. - Copyright (C) 2005-2017 + Copyright (C) 2005-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/win.c b/lib/tty/win.c index 585e80436..73b4cc575 100644 --- a/lib/tty/win.c +++ b/lib/tty/win.c @@ -1,7 +1,7 @@ /* Terminal management xterm and rxvt support - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/x11conn.c b/lib/tty/x11conn.c index 56800356e..b2f8b21a0 100644 --- a/lib/tty/x11conn.c +++ b/lib/tty/x11conn.c @@ -1,7 +1,7 @@ /* X11 support for the Midnight Commander. - Copyright (C) 2005-2017 + Copyright (C) 2005-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/util.c b/lib/util.c index c23d91fba..2ecfd978d 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,7 +1,7 @@ /* Various utilities - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/util.h b/lib/util.h index 78c7ccbfd..28b834d39 100644 --- a/lib/util.h +++ b/lib/util.h @@ -214,11 +214,7 @@ char *tilde_expand (const char *); void custom_canonicalize_pathname (char *, CANON_PATH_FLAGS); void canonicalize_pathname (char *); -#ifdef HAVE_REALPATH -#define mc_realpath realpath -#else char *mc_realpath (const char *path, char *resolved_path); -#endif /* Looks for "magic" bytes at the start of the VFS file to guess the * compression type. Side effect: modifies the file position. */ diff --git a/lib/utilunix.c b/lib/utilunix.c index 771e0d0d2..92ddd4cf9 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -1,7 +1,7 @@ /* Various utilities - Unix variants - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -454,6 +454,7 @@ my_systemv (const char *command, char *const argv[]) execvp (command, argv); my_exit (127); /* Exec error */ } + MC_FALLTHROUGH; /* no break here, or unreachable-code warning by no returning my_exit() */ default: status = 0; @@ -1093,150 +1094,179 @@ gettimeofday (struct timeval *tp, void *tzp) /* --------------------------------------------------------------------------------------------- */ -#ifndef HAVE_REALPATH char * mc_realpath (const char *path, char *resolved_path) { - char copy_path[PATH_MAX]; - char got_path[PATH_MAX]; - char *new_path = got_path; - char *max_path; +#ifdef HAVE_CHARSET + const char *p = path; + gboolean absolute_path = FALSE; + + if (IS_PATH_SEP (*p)) + { + absolute_path = TRUE; + p++; + } + + /* ignore encoding: skip "#enc:" */ + if (g_str_has_prefix (p, VFS_ENCODING_PREFIX)) + { + p += strlen (VFS_ENCODING_PREFIX); + p = strchr (p, PATH_SEP); + if (p != NULL) + { + if (!absolute_path && p[1] != '\0') + p++; + + path = p; + } + } +#endif /* HAVE_CHARSET */ + +#ifdef HAVE_REALPATH + return realpath (path, resolved_path); +#else + { + char copy_path[PATH_MAX]; + char got_path[PATH_MAX]; + char *new_path = got_path; + char *max_path; #ifdef S_IFLNK - char link_path[PATH_MAX]; - int readlinks = 0; - int n; + char link_path[PATH_MAX]; + int readlinks = 0; + int n; #endif /* S_IFLNK */ - /* Make a copy of the source path since we may need to modify it. */ - if (strlen (path) >= PATH_MAX - 2) - { - errno = ENAMETOOLONG; - return NULL; - } - strcpy (copy_path, path); - path = copy_path; - max_path = copy_path + PATH_MAX - 2; - /* If it's a relative pathname use getwd for starters. */ - if (!IS_PATH_SEP (*path)) - { - new_path = g_get_current_dir (); - if (new_path == NULL) + /* Make a copy of the source path since we may need to modify it. */ + if (strlen (path) >= PATH_MAX - 2) { - strcpy (got_path, ""); + errno = ENAMETOOLONG; + return NULL; + } + strcpy (copy_path, path); + path = copy_path; + max_path = copy_path + PATH_MAX - 2; + /* If it's a relative pathname use getwd for starters. */ + if (!IS_PATH_SEP (*path)) + { + new_path = g_get_current_dir (); + if (new_path == NULL) + { + strcpy (got_path, ""); + } + else + { + g_snprintf (got_path, sizeof (got_path), "%s", new_path); + g_free (new_path); + new_path = got_path; + } + + new_path += strlen (got_path); + if (!IS_PATH_SEP (new_path[-1])) + *new_path++ = PATH_SEP; } else { - g_snprintf (got_path, sizeof (got_path), "%s", new_path); - g_free (new_path); - new_path = got_path; - } - - new_path += strlen (got_path); - if (!IS_PATH_SEP (new_path[-1])) *new_path++ = PATH_SEP; - } - else - { - *new_path++ = PATH_SEP; - path++; - } - /* Expand each slash-separated pathname component. */ - while (*path != '\0') - { - /* Ignore stray "/". */ - if (IS_PATH_SEP (*path)) - { path++; - continue; } - if (*path == '.') + /* Expand each slash-separated pathname component. */ + while (*path != '\0') { - /* Ignore ".". */ - if (path[1] == '\0' || IS_PATH_SEP (path[1])) + /* Ignore stray "/". */ + if (IS_PATH_SEP (*path)) { path++; continue; } - if (path[1] == '.') + if (*path == '.') { - if (path[2] == '\0' || IS_PATH_SEP (path[2])) + /* Ignore ".". */ + if (path[1] == '\0' || IS_PATH_SEP (path[1])) { - path += 2; - /* Ignore ".." at root. */ - if (new_path == got_path + 1) - continue; - /* Handle ".." by backing up. */ - while (!IS_PATH_SEP ((--new_path)[-1])) - ; + path++; continue; } + if (path[1] == '.') + { + if (path[2] == '\0' || IS_PATH_SEP (path[2])) + { + path += 2; + /* Ignore ".." at root. */ + if (new_path == got_path + 1) + continue; + /* Handle ".." by backing up. */ + while (!IS_PATH_SEP ((--new_path)[-1])) + ; + continue; + } + } } - } - /* Safely copy the next pathname component. */ - while (*path != '\0' && !IS_PATH_SEP (*path)) - { - if (path > max_path) + /* Safely copy the next pathname component. */ + while (*path != '\0' && !IS_PATH_SEP (*path)) { - errno = ENAMETOOLONG; - return NULL; + if (path > max_path) + { + errno = ENAMETOOLONG; + return NULL; + } + *new_path++ = *path++; } - *new_path++ = *path++; - } #ifdef S_IFLNK - /* Protect against infinite loops. */ - if (readlinks++ > MAXSYMLINKS) - { - errno = ELOOP; - return NULL; - } - /* See if latest pathname component is a symlink. */ - *new_path = '\0'; - n = readlink (got_path, link_path, PATH_MAX - 1); - if (n < 0) - { - /* EINVAL means the file exists but isn't a symlink. */ - if (errno != EINVAL) + /* Protect against infinite loops. */ + if (readlinks++ > MAXSYMLINKS) { - /* Make sure it's null terminated. */ - *new_path = '\0'; - strcpy (resolved_path, got_path); + errno = ELOOP; return NULL; } - } - else - { - /* Note: readlink doesn't add the null byte. */ - link_path[n] = '\0'; - if (IS_PATH_SEP (*link_path)) - /* Start over for an absolute symlink. */ - new_path = got_path; + /* See if latest pathname component is a symlink. */ + *new_path = '\0'; + n = readlink (got_path, link_path, PATH_MAX - 1); + if (n < 0) + { + /* EINVAL means the file exists but isn't a symlink. */ + if (errno != EINVAL) + { + /* Make sure it's null terminated. */ + *new_path = '\0'; + strcpy (resolved_path, got_path); + return NULL; + } + } else - /* Otherwise back up over this component. */ - while (!IS_PATH_SEP (*(--new_path))) - ; - /* Safe sex check. */ - if (strlen (path) + n >= PATH_MAX - 2) { - errno = ENAMETOOLONG; - return NULL; + /* Note: readlink doesn't add the null byte. */ + link_path[n] = '\0'; + if (IS_PATH_SEP (*link_path)) + /* Start over for an absolute symlink. */ + new_path = got_path; + else + /* Otherwise back up over this component. */ + while (!IS_PATH_SEP (*(--new_path))) + ; + /* Safe sex check. */ + if (strlen (path) + n >= PATH_MAX - 2) + { + errno = ENAMETOOLONG; + return NULL; + } + /* Insert symlink contents into path. */ + strcat (link_path, path); + strcpy (copy_path, link_path); + path = copy_path; } - /* Insert symlink contents into path. */ - strcat (link_path, path); - strcpy (copy_path, link_path); - path = copy_path; - } #endif /* S_IFLNK */ - *new_path++ = PATH_SEP; + *new_path++ = PATH_SEP; + } + /* Delete trailing slash but don't whomp a lone slash. */ + if (new_path != got_path + 1 && IS_PATH_SEP (new_path[-1])) + new_path--; + /* Make sure it's null terminated. */ + *new_path = '\0'; + strcpy (resolved_path, got_path); + return resolved_path; } - /* Delete trailing slash but don't whomp a lone slash. */ - if (new_path != got_path + 1 && IS_PATH_SEP (new_path[-1])) - new_path--; - /* Make sure it's null terminated. */ - *new_path = '\0'; - strcpy (resolved_path, got_path); - return resolved_path; -} #endif /* HAVE_REALPATH */ +} /* --------------------------------------------------------------------------------------------- */ /** diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index 41b42ee3b..3a0159dd1 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -1,7 +1,7 @@ /* Directory cache support - Copyright (C) 1998-2017 + Copyright (C) 1998-2018 Free Software Foundation, Inc. Written by: @@ -141,7 +141,7 @@ vfs_s_resolve_symlink (struct vfs_class *me, struct vfs_s_entry *entry, int foll return entry; if (follow == 0) ERRNOR (ELOOP, NULL); - if (!entry) + if (entry == NULL) ERRNOR (ENOENT, NULL); if (!S_ISLNK (entry->ino->st.st_mode)) return entry; @@ -164,7 +164,7 @@ vfs_s_resolve_symlink (struct vfs_class *me, struct vfs_s_entry *entry, int foll } } - target = (MEDATA->find_entry) (me, entry->dir->super->root, linkname, follow - 1, 0); + target = MEDATA->find_entry (me, entry->dir->super->root, linkname, follow - 1, 0); g_free (fullname); return target; } @@ -300,7 +300,7 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root, vfs_die ("find_linear: success but directory is not there\n"); #if 0 - if (!vfs_s_resolve_symlink (me, ent, follow)) + if (vfs_s_resolve_symlink (me, ent, follow) == NULL) { g_free (path); return NULL; @@ -345,7 +345,7 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super) #if 0 /* FIXME: We currently leak small ammount of memory, sometimes. Fix it if you can. */ - if (super->ino_usage) + if (super->ino_usage != 0) message (D_ERROR, "Direntry warning", "Super ino_usage is %d, memory leak", super->ino_usage); @@ -385,7 +385,7 @@ vfs_s_inode_from_path (const vfs_path_t * vpath, int flags) vfs_s_find_inode (path_element->class, super, q, (flags & FL_FOLLOW) != 0 ? LINK_FOLLOW : LINK_NO_FOLLOW, flags & ~FL_FOLLOW); - if ((!ino) && (!*q)) + if (ino == NULL && *q == '\0') /* We are asking about / directory of ftp server: assume it exists */ ino = vfs_s_find_inode (path_element->class, super, q, @@ -474,7 +474,7 @@ vfs_s_chdir (const vfs_path_t * vpath) data = vfs_s_opendir (vpath); if (data == NULL) - return -1; + return (-1); vfs_s_closedir (data); return 0; } @@ -489,7 +489,7 @@ vfs_s_internal_stat (const vfs_path_t * vpath, struct stat *buf, int flag) ino = vfs_s_inode_from_path (vpath, flag); if (ino == NULL) - return -1; + return (-1); *buf = ino->st; return 0; } @@ -506,19 +506,19 @@ vfs_s_readlink (const vfs_path_t * vpath, char *buf, size_t size) path_element = vfs_path_get_by_index (vpath, -1); ino = vfs_s_inode_from_path (vpath, 0); - if (!ino) - return -1; + if (ino == NULL) + return (-1); if (!S_ISLNK (ino->st.st_mode)) { path_element->class->verrno = EINVAL; - return -1; + return (-1); } if (ino->linkname == NULL) { path_element->class->verrno = EFAULT; - return -1; + return (-1); } len = strlen (ino->linkname); @@ -538,8 +538,8 @@ vfs_s_read (void *fh, char *buffer, size_t count) if (FH->linear == LS_LINEAR_PREOPEN) { - if (!MEDATA->linear_start (me, FH, FH->pos)) - return -1; + if (MEDATA->linear_start (me, FH, FH->pos) == 0) + return (-1); } if (FH->linear == LS_LINEAR_CLOSED) @@ -558,7 +558,7 @@ vfs_s_read (void *fh, char *buffer, size_t count) return n; } vfs_die ("vfs_s_read: This should not happen\n"); - return -1; + return (-1); } /* --------------------------------------------------------------------------------------------- */ @@ -568,10 +568,10 @@ vfs_s_write (void *fh, const char *buffer, size_t count) { struct vfs_class *me = FH_SUPER->me; - if (FH->linear) + if (FH->linear != LS_NOT_LINEAR) vfs_die ("no writing to linear files, please"); - FH->changed = 1; + FH->changed = TRUE; if (FH->handle != -1) { ssize_t n; @@ -597,7 +597,9 @@ vfs_s_lseek (void *fh, off_t offset, int whence) if (FH->handle != -1) { /* If we have local file opened, we want to work with it */ - off_t retval = lseek (FH->handle, offset, whence); + off_t retval; + + retval = lseek (FH->handle, offset, whence); if (retval == -1) FH->ino->super->me->verrno = errno; return retval; @@ -635,17 +637,20 @@ vfs_s_close (void *fh) return (-1); FH_SUPER->fd_usage--; - if (!FH_SUPER->fd_usage) + if (FH_SUPER->fd_usage == 0) vfs_stamp_create (me, FH_SUPER); if (FH->linear == LS_LINEAR_OPEN) MEDATA->linear_close (me, fh); - if (MEDATA->fh_close) + if (MEDATA->fh_close != NULL) res = MEDATA->fh_close (me, fh); - if ((MEDATA->flags & VFS_S_USETMP) && FH->changed && MEDATA->file_store) + if ((MEDATA->flags & VFS_S_USETMP) != 0 && FH->changed && MEDATA->file_store != NULL) { - char *s = vfs_s_fullpath (me, FH->ino); - if (!s) + char *s; + + s = vfs_s_fullpath (me, FH->ino); + + if (s == NULL) res = -1; else { @@ -728,7 +733,7 @@ vfs_s_getlocalcopy (const vfs_path_t * vpath) const struct vfs_class *me; me = vfs_path_get_by_index (vpath, -1)->class; - if ((MEDATA->flags & VFS_S_USETMP) != 0 && (fh->ino != NULL)) + if ((MEDATA->flags & VFS_S_USETMP) != 0 && fh->ino != NULL) local = vfs_path_from_str_flags (fh->ino->localname, VPF_NO_CANON); vfs_s_close (fh); @@ -770,11 +775,11 @@ vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg) ino = vfs_s_inode_from_path (vpath, 0); if (ino == NULL) return 0; - if (arg) - ino->super->want_stale = 1; + if (arg != NULL) + ino->super->want_stale = TRUE; else { - ino->super->want_stale = 0; + ino->super->want_stale = FALSE; vfs_s_invalidate (path_element->class, ino->super); } return 1; @@ -831,16 +836,15 @@ vfs_s_dir_uptodate (struct vfs_class *me, struct vfs_s_inode *ino) { struct timeval tim; - if (MEDATA->flush) + if (MEDATA->flush != 0) { MEDATA->flush = 0; return 0; } gettimeofday (&tim, NULL); - if (tim.tv_sec < ino->timestamp.tv_sec) - return 1; - return 0; + + return (tim.tv_sec < ino->timestamp.tv_sec ? 1 : 0); } @@ -857,7 +861,7 @@ vfs_s_new_inode (struct vfs_class *me, struct vfs_s_super *super, struct stat *i if (ino == NULL) return NULL; - if (initstat) + if (initstat != NULL) ino->st = *initstat; ino->super = super; ino->st.st_nlink = 0; @@ -917,7 +921,6 @@ vfs_s_new_entry (struct vfs_class *me, const char *name, struct vfs_s_inode *ino return entry; } - /* --------------------------------------------------------------------------------------------- */ void @@ -1047,8 +1050,8 @@ vfs_s_find_inode (struct vfs_class *me, const struct vfs_s_super *super, if (((MEDATA->flags & VFS_S_REMOTE) == 0) && (*path == '\0')) return super->root; - ent = (MEDATA->find_entry) (me, super->root, path, follow, flags); - return (ent != NULL) ? ent->ino : NULL; + ent = MEDATA->find_entry (me, super->root, path, follow, flags); + return (ent != NULL ? ent->ino : NULL); } /* --------------------------------------------------------------------------------------------- */ @@ -1072,7 +1075,7 @@ vfs_get_super_by_vpath (const vfs_path_t * vpath) vfs_path_t *vpath_archive; path_element = vfs_path_get_by_index (vpath, -1); - subclass = ((struct vfs_s_subclass *) path_element->class->data); + subclass = (struct vfs_s_subclass *) path_element->class->data; if (subclass == NULL) return NULL; @@ -1135,7 +1138,7 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag if (super != NULL) goto return_success; - if (flags & FL_NO_OPEN) + if ((flags & FL_NO_OPEN) != 0) { path_element->class->verrno = EIO; return NULL; @@ -1143,7 +1146,7 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag super = vfs_s_new_super (path_element->class); - subclass = ((struct vfs_s_subclass *) path_element->class->data); + subclass = (struct vfs_s_subclass *) path_element->class->data; if (subclass->open_archive != NULL) { vfs_path_t *vpath_archive; @@ -1160,9 +1163,9 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag path_element->class->verrno = EIO; return NULL; } - if (!super->name) + if (super->name == NULL) vfs_die ("You have to fill name\n"); - if (!super->root) + if (super->root == NULL) vfs_die ("You have to fill root inode\n"); vfs_s_insert_super (path_element->class, super); @@ -1190,19 +1193,24 @@ vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super) char * vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino) { - if (!ino->ent) + if (ino->ent == NULL) ERRNOR (EAGAIN, NULL); if ((MEDATA->flags & VFS_S_USETMP) == 0) { /* archives */ - char *newpath; - char *path = g_strdup (ino->ent->name); - while (1) + char *path; + + path = g_strdup (ino->ent->name); + + while (TRUE) { + char *newpath; + ino = ino->ent->dir; if (ino == ino->super->root) break; + newpath = g_strconcat (ino->ent->name, PATH_SEP_STR, path, (char *) NULL); g_free (path); path = newpath; @@ -1211,7 +1219,7 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino) } /* remote systems */ - if ((!ino->ent->dir) || (!ino->ent->dir->ent)) + if (ino->ent->dir == NULL || ino->ent->dir->ent == NULL) return g_strdup (ino->ent->name); return g_strconcat (ino->ent->dir->ent->name, PATH_SEP_STR, ino->ent->name, (char *) NULL); @@ -1223,7 +1231,7 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino) void * vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) { - int was_changed = 0; + gboolean was_changed = FALSE; vfs_file_handler_t *fh; struct vfs_s_super *super; const char *q; @@ -1236,19 +1244,20 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) if (q == NULL) return NULL; ino = vfs_s_find_inode (path_element->class, super, q, LINK_FOLLOW, FL_NONE); - if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))) + if (ino != NULL && (flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { path_element->class->verrno = EEXIST; return NULL; } - if (!ino) + + if (ino == NULL) { char *dirname, *name; struct vfs_s_entry *ent; struct vfs_s_inode *dir; /* If the filesystem is read-only, disable file creation */ - if (!(flags & O_CREAT) || !(path_element->class->write)) + if ((flags & O_CREAT) == 0 || path_element->class->write == NULL) return NULL; dirname = g_path_get_dirname (q); @@ -1260,6 +1269,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) g_free (name); return NULL; } + ent = vfs_s_generate_entry (path_element->class, name, dir, 0755); ino = ent->ino; vfs_s_insert_entry (path_element->class, dir, ent); @@ -1282,7 +1292,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) } g_free (dirname); g_free (name); - was_changed = 1; + was_changed = TRUE; } if (S_ISDIR (ino->st.st_mode)) @@ -1296,12 +1306,12 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) fh->ino = ino; fh->handle = -1; fh->changed = was_changed; - fh->linear = 0; + fh->linear = LS_NOT_LINEAR; fh->data = NULL; if (IS_LINEAR (flags)) { - if (VFSDATA (path_element)->linear_start) + if (VFSDATA (path_element)->linear_start != NULL) { vfs_print_message ("%s", _("Starting linear transfer...")); fh->linear = LS_LINEAR_PREOPEN; @@ -1379,7 +1389,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino) vfs_path_t *tmp_vpath; if ((MEDATA->flags & VFS_S_USETMP) == 0) - return -1; + return (-1); memset (&fh, 0, sizeof (fh)); @@ -1395,16 +1405,17 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino) goto error_4; } - if (!MEDATA->linear_start (me, &fh, 0)) + if (MEDATA->linear_start (me, &fh, 0) == 0) goto error_3; /* Clear the interrupt status */ tty_got_interrupt (); tty_enable_interrupt_key (); - while ((n = MEDATA->linear_read (me, &fh, buffer, sizeof (buffer)))) + while ((n = MEDATA->linear_read (me, &fh, buffer, sizeof (buffer))) != 0) { int t; + if (n < 0) goto error_1; @@ -1438,7 +1449,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino) error_4: MC_PTR_FREE (ino->localname); g_free (fh.data); - return -1; + return (-1); } /* --------------------------------------------------------------------------------------------- */ @@ -1453,10 +1464,8 @@ vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub) vclass->open = vfs_s_open; vclass->close = vfs_s_close; vclass->read = vfs_s_read; - if (!(sub->flags & VFS_S_READONLY)) - { + if ((sub->flags & VFS_S_READONLY) == 0) vclass->write = vfs_s_write; - } vclass->opendir = vfs_s_opendir; vclass->readdir = vfs_s_readdir; vclass->closedir = vfs_s_closedir; @@ -1509,13 +1518,14 @@ vfs_s_select_on_two (int fd1, int fd2) fd_set set; struct timeval time_out; int v; - int maxfd = (fd1 > fd2 ? fd1 : fd2) + 1; + int maxfd = MAX (fd1, fd2) + 1; time_out.tv_sec = 1; time_out.tv_usec = 0; FD_ZERO (&set); FD_SET (fd1, &set); FD_SET (fd2, &set); + v = select (maxfd, &set, 0, 0, &time_out); if (v <= 0) return v; @@ -1523,7 +1533,7 @@ vfs_s_select_on_two (int fd1, int fd2) return 1; if (FD_ISSET (fd2, &set)) return 2; - return -1; + return (-1); } /* --------------------------------------------------------------------------------------------- */ @@ -1539,30 +1549,34 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter { if (read (sock, buf, sizeof (char)) <= 0) return 0; - if (logfile) + + if (logfile != NULL) { size_t ret1; int ret2; + ret1 = fwrite (buf, 1, 1, logfile); ret2 = fflush (logfile); (void) ret1; (void) ret2; } + if (*buf == term) { - *buf = 0; + *buf = '\0'; return 1; } } /* Line is too long - terminate buffer and discard the rest of line */ - *buf = 0; + *buf = '\0'; while (read (sock, &c, sizeof (c)) > 0) { - if (logfile) + if (logfile != NULL) { size_t ret1; int ret2; + ret1 = fwrite (&c, 1, 1, logfile); ret2 = fflush (logfile); (void) ret1; @@ -1632,10 +1646,13 @@ vfs_s_normalize_filename_leading_spaces (struct vfs_s_inode *root_inode, size_t for (iter = root_inode->subdir; iter != NULL; iter = g_list_next (iter)) { struct vfs_s_entry *entry = (struct vfs_s_entry *) iter->data; + if ((size_t) entry->ino->data_offset > final_num_spaces) { char *source_name = entry->name; - char *spacer = g_strnfill (entry->ino->data_offset - final_num_spaces, ' '); + char *spacer; + + spacer = g_strnfill (entry->ino->data_offset - final_num_spaces, ' '); entry->name = g_strdup_printf ("%s%s", spacer, source_name); g_free (spacer); g_free (source_name); diff --git a/lib/vfs/gc.c b/lib/vfs/gc.c index 76114690d..c1fa7a126 100644 --- a/lib/vfs/gc.c +++ b/lib/vfs/gc.c @@ -1,7 +1,7 @@ /* Virtual File System garbage collection code - Copyright (C) 2003-2017 + Copyright (C) 2003-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index a3f9f1a6a..349d9ae86 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -1,7 +1,7 @@ /* Virtual File System: interface functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/vfs/netutil.c b/lib/vfs/netutil.c index 82c827f6b..8cde08580 100644 --- a/lib/vfs/netutil.c +++ b/lib/vfs/netutil.c @@ -1,7 +1,7 @@ /* Network utilities for the Midnight Commander Virtual File System. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/lib/vfs/parse_ls_vga.c b/lib/vfs/parse_ls_vga.c index be8d972c8..c29db5ad7 100644 --- a/lib/vfs/parse_ls_vga.c +++ b/lib/vfs/parse_ls_vga.c @@ -1,7 +1,7 @@ /* Routines for parsing output from the 'ls' command. - Copyright (C) 1988-2017 + Copyright (C) 1988-2018 Free Software Foundation, Inc. Copyright (C) 1995, 1996 Miguel de Icaza diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 352df7f7d..a9b285b57 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -1,7 +1,7 @@ /* Virtual File System path handlers - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: @@ -236,13 +236,11 @@ static void vfs_path_url_split (vfs_path_element_t * path_element, const char *path) { char *pcopy; - const char *pend; char *colon, *at, *rest; path_element->port = 0; pcopy = g_strdup (path); - pend = pcopy + strlen (pcopy); /* search for any possible user */ at = strrchr (pcopy, '@'); @@ -252,9 +250,12 @@ vfs_path_url_split (vfs_path_element_t * path_element, const char *path) rest = pcopy; else { + const char *pend; char *inner_colon; + pend = strchr (at, '\0'); *at = '\0'; + inner_colon = strchr (pcopy, ':'); if (inner_colon != NULL) { @@ -280,9 +281,9 @@ vfs_path_url_split (vfs_path_element_t * path_element, const char *path) colon = strchr (++rest, ']'); if (colon != NULL) { - colon[0] = '\0'; - colon[1] = '\0'; + *colon = '\0'; colon++; + *colon = '\0'; path_element->ipv6 = TRUE; } } diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c index 8c7a25695..bd5a410db 100644 --- a/lib/vfs/utilvfs.c +++ b/lib/vfs/utilvfs.c @@ -1,7 +1,7 @@ /* Utilities for VFS modules. - Copyright (C) 1988-2017 + Copyright (C) 1988-2018 Free Software Foundation, Inc. Copyright (C) 1995, 1996 Miguel de Icaza @@ -177,13 +177,13 @@ int vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *param_basename) { const char *p; - char *suffix, *q; + GString *suffix; int shift; int fd; /* Strip directories */ p = strrchr (param_basename, PATH_SEP); - if (!p) + if (p == NULL) p = param_basename; else p++; @@ -193,20 +193,16 @@ vfs_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *param_b if (shift > 0) p += shift; - suffix = g_malloc (MC_MAXPATHLEN); + suffix = g_string_sized_new (32); /* Protection against unusual characters */ - q = suffix; - while (*p && (*p != '#')) - { - if (strchr (".-_@", *p) || isalnum ((unsigned char) *p)) - *q++ = *p; - p++; - } - *q = 0; + for (; *p != '\0' && *p != '#'; p++) + if (strchr (".-_@", *p) != NULL || g_ascii_isalnum (*p)) + g_string_append_c (suffix, *p); + + fd = mc_mkstemps (pname_vpath, prefix, suffix->str); + g_string_free (suffix, TRUE); - fd = mc_mkstemps (pname_vpath, prefix, suffix); - g_free (suffix); return fd; } @@ -240,7 +236,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) char *pcopy; size_t pcopy_len; const char *pend; - char *dir, *colon, *at, *rest; + char *colon, *at, *rest; path_element = g_new0 (vfs_path_element_t, 1); path_element->port = default_port; @@ -248,10 +244,11 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) pcopy_len = strlen (path); pcopy = g_strndup (path, pcopy_len); pend = pcopy + pcopy_len; - dir = pcopy; if ((flags & URL_NOSLASH) == 0) { + char *dir = pcopy; + /* locate path component */ while (!IS_PATH_SEP (*dir) && *dir != '\0') dir++; @@ -293,8 +290,10 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) } if ((flags & URL_USE_ANONYMOUS) == 0) + { + g_free (path_element->user); path_element->user = vfs_get_local_username (); - + } /* Check if the host comes with a port spec, if so, chop it */ if (*rest != '[') colon = strchr (rest, ':'); @@ -310,6 +309,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) else { vfs_path_element_free (path_element); + g_free (pcopy); return NULL; } } @@ -341,6 +341,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) } path_element->host = g_strdup (rest); + g_free (pcopy); #ifdef HAVE_CHARSET path_element->dir.converter = INVALID_CONV; #endif diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 5000fcab3..189ca7b7c 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -1,7 +1,7 @@ /* Virtual File System switch code - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: 1995 Miguel de Icaza diff --git a/lib/vfs/xdirentry.h b/lib/vfs/xdirentry.h index c1b2c9b1d..68073efd2 100644 --- a/lib/vfs/xdirentry.h +++ b/lib/vfs/xdirentry.h @@ -41,11 +41,6 @@ #define FH ((vfs_file_handler_t *) fh) #define FH_SUPER FH->ino->super -#define LS_NOT_LINEAR 0 -#define LS_LINEAR_CLOSED 1 -#define LS_LINEAR_OPEN 2 -#define LS_LINEAR_PREOPEN 3 - /*** enums ***************************************************************************************/ /* For vfs_s_subclass->flags */ @@ -56,6 +51,14 @@ typedef enum VFS_S_USETMP = 1L << 2, } vfs_subclass_flags_t; +typedef enum +{ + LS_NOT_LINEAR = 0, + LS_LINEAR_CLOSED = 1, + LS_LINEAR_OPEN = 2, + LS_LINEAR_PREOPEN = 3 +} vfs_linear_state_t; + /*** structures declarations (and typedefs of structures)*****************************************/ /* Single connection or archive */ @@ -66,7 +69,7 @@ struct vfs_s_super char *name; /* My name, whatever it means */ int fd_usage; /* Number of open files */ int ino_usage; /* Usage count of this superblock */ - int want_stale; /* If set, we do not flush cache properly */ + gboolean want_stale; /* If set, we do not flush cache properly */ #ifdef ENABLE_VFS_NET vfs_path_element_t *path_element; #endif /* ENABLE_VFS_NET */ @@ -106,8 +109,8 @@ typedef struct struct vfs_s_inode *ino; off_t pos; /* This is for module's use */ int handle; /* This is for module's use, but if != -1, will be mc_close()d */ - int changed; /* Did this file change? */ - int linear; /* Is that file open with O_LINEAR? */ + gboolean changed; /* Did this file change? */ + vfs_linear_state_t linear; /* Is that file open with O_LINEAR? */ void *data; /* This is for filesystem-specific use */ } vfs_file_handler_t; diff --git a/lib/widget/button.c b/lib/widget/button.c index fe69493b5..632694670 100644 --- a/lib/widget/button.c +++ b/lib/widget/button.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/buttonbar.c b/lib/widget/buttonbar.c index 7f91b9b8d..cf0783978 100644 --- a/lib/widget/buttonbar.c +++ b/lib/widget/buttonbar.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/check.c b/lib/widget/check.c index 423e10cdd..c47763ded 100644 --- a/lib/widget/check.c +++ b/lib/widget/check.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/dialog-switch.c b/lib/widget/dialog-switch.c index 7fe306002..3a16225b7 100644 --- a/lib/widget/dialog-switch.c +++ b/lib/widget/dialog-switch.c @@ -3,7 +3,7 @@ Original idea and code: Oleg "Olegarch" Konovalov - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index e9cc87418..5501ba46a 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -1,7 +1,7 @@ /* Dialog box features module for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/lib/widget/gauge.c b/lib/widget/gauge.c index a31e835ef..689ecedf4 100644 --- a/lib/widget/gauge.c +++ b/lib/widget/gauge.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/groupbox.c b/lib/widget/groupbox.c index bfceb9ef1..fe6bddf5a 100644 --- a/lib/widget/groupbox.c +++ b/lib/widget/groupbox.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/history.c b/lib/widget/history.c index 186397808..fe2b8e008 100644 --- a/lib/widget/history.c +++ b/lib/widget/history.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/hline.c b/lib/widget/hline.c index 4e7b93ef8..69ef8f552 100644 --- a/lib/widget/hline.c +++ b/lib/widget/hline.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/input.c b/lib/widget/input.c index 02b8d32ba..a0d7cdc73 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: @@ -155,14 +155,12 @@ delete_region (WInput * in, int x_first, int x_last) { int first = MIN (x_first, x_last); int last = MAX (x_first, x_last); - size_t len; input_mark_cmd (in, FALSE); in->point = first; last = str_offset_to_pos (in->buffer, last); first = str_offset_to_pos (in->buffer, first); - len = strlen (&in->buffer[last]) + 1; - memmove (&in->buffer[first], &in->buffer[last], len); + str_move (in->buffer + first, in->buffer + last); in->charpoint = 0; in->need_push = TRUE; } diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index fc6406792..773a78987 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -2,7 +2,7 @@ Input line filename/username/hostname/variable/command completion. (Let mc type for you...) - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: @@ -641,7 +641,7 @@ command_completion_function (const char *text, int state, input_complete_t flags } phase++; words = bash_builtins; - /* fallthrough */ + MC_FALLTHROUGH; case 1: /* Builtin commands */ for (; *words != NULL; words++) if (strncmp (*words, u_text, text_len) == 0) @@ -654,7 +654,7 @@ command_completion_function (const char *text, int state, input_complete_t flags break; cur_path = path; cur_word = NULL; - /* fallthrough */ + MC_FALLTHROUGH; case 2: /* And looking through the $PATH */ while (found == NULL) { @@ -675,7 +675,7 @@ command_completion_function (const char *text, int state, input_complete_t flags if (found == NULL) MC_PTR_FREE (cur_word); } - /* fallthrough */ + MC_FALLTHROUGH; default: break; } @@ -887,11 +887,8 @@ try_complete_find_start_sign (try_complete_automation_state_t * state) /* don't substitute variable in \$ case */ if (strutils_is_char_escaped (state->word, state->q)) { - size_t qlen; - - qlen = strlen (state->q); /* drop '\\' */ - memmove (state->q - 1, state->q, qlen + 1); + str_move (state->q - 1, state->q); /* adjust flags */ state->flags &= ~INPUT_COMPLETE_VARIABLES; state->q = NULL; @@ -1107,7 +1104,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d { case -1: bl = 0; - /* fallthrough */ + MC_FALLTHROUGH; case -2: return MSG_HANDLED; default: diff --git a/lib/widget/label.c b/lib/widget/label.c index 106e6171f..bfa1c0e2a 100644 --- a/lib/widget/label.c +++ b/lib/widget/label.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/listbox-window.c b/lib/widget/listbox-window.c index bbf1dc5fa..977f051e5 100644 --- a/lib/widget/listbox-window.c +++ b/lib/widget/listbox-window.c @@ -1,7 +1,7 @@ /* Widget based utility functions. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 378a3af8a..f56464f1d 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/menu.c b/lib/widget/menu.c index 97472c7f1..af8e4c795 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -1,7 +1,7 @@ /* Pulldown menu code - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/lib/widget/mouse.c b/lib/widget/mouse.c index 9c9fd6853..d00ac46af 100644 --- a/lib/widget/mouse.c +++ b/lib/widget/mouse.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 2016-2017 + Copyright (C) 2016-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/quick.c b/lib/widget/quick.c index 0e834ed7b..887f4083e 100644 --- a/lib/widget/quick.c +++ b/lib/widget/quick.c @@ -1,7 +1,7 @@ /* Widget based utility functions. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: @@ -441,7 +441,7 @@ quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip) break; } } - /* fall through */ + MC_FALLTHROUGH; case quick_checkbox: case quick_radio: if (item->widget->x != x1) diff --git a/lib/widget/radio.c b/lib/widget/radio.c index 2790e1759..cf0940fab 100644 --- a/lib/widget/radio.c +++ b/lib/widget/radio.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index 834f55032..c746f7d6e 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -1,7 +1,7 @@ /* Widgets for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c index e1e0534f6..83daa56b4 100644 --- a/lib/widget/wtools.c +++ b/lib/widget/wtools.c @@ -1,7 +1,7 @@ /* Widget based utility functions. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Authors: @@ -105,7 +105,7 @@ query_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, return MSG_HANDLED; } - /* fallthrough */ + MC_FALLTHROUGH; default: return dlg_default_callback (w, sender, msg, parm, data); diff --git a/m4.include/ax_gcc_func_attribute.m4 b/m4.include/ax_gcc_func_attribute.m4 new file mode 100644 index 000000000..098c9aadf --- /dev/null +++ b/m4.include/ax_gcc_func_attribute.m4 @@ -0,0 +1,238 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE) +# +# DESCRIPTION +# +# This macro checks if the compiler supports one of GCC's function +# attributes; many other compilers also provide function attributes with +# the same syntax. Compiler warnings are used to detect supported +# attributes as unsupported ones are ignored by default so quieting +# warnings when using this macro will yield false positives. +# +# The ATTRIBUTE parameter holds the name of the attribute to be checked. +# +# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_. +# +# The macro caches its result in the ax_cv_have_func_attribute_ +# variable. +# +# The macro currently supports the following function attributes: +# +# alias +# aligned +# alloc_size +# always_inline +# artificial +# cold +# const +# constructor +# constructor_priority for constructor attribute with priority +# deprecated +# destructor +# dllexport +# dllimport +# error +# externally_visible +# fallthrough +# flatten +# format +# format_arg +# gnu_inline +# hot +# ifunc +# leaf +# malloc +# noclone +# noinline +# nonnull +# noreturn +# nothrow +# optimize +# pure +# sentinel +# sentinel_position +# unused +# used +# visibility +# warning +# warn_unused_result +# weak +# weakref +# +# Unsupported function attributes will be tested with a prototype +# returning an int and not accepting any arguments and the result of the +# check might be wrong or meaningless so use with care. +# +# LICENSE +# +# Copyright (c) 2013 Gabriele Svelto +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 9 + +AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [ + AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1]) + + AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([ + m4_case([$1], + [alias], [ + int foo( void ) { return 0; } + int bar( void ) __attribute__(($1("foo"))); + ], + [aligned], [ + int foo( void ) __attribute__(($1(32))); + ], + [alloc_size], [ + void *foo(int a) __attribute__(($1(1))); + ], + [always_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [artificial], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [cold], [ + int foo( void ) __attribute__(($1)); + ], + [const], [ + int foo( void ) __attribute__(($1)); + ], + [constructor_priority], [ + int foo( void ) __attribute__((__constructor__(65535/2))); + ], + [constructor], [ + int foo( void ) __attribute__(($1)); + ], + [deprecated], [ + int foo( void ) __attribute__(($1(""))); + ], + [destructor], [ + int foo( void ) __attribute__(($1)); + ], + [dllexport], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [dllimport], [ + int foo( void ) __attribute__(($1)); + ], + [error], [ + int foo( void ) __attribute__(($1(""))); + ], + [externally_visible], [ + int foo( void ) __attribute__(($1)); + ], + [fallthrough], [ + int foo( void ) {switch (0) { case 1: __attribute__(($1)); case 2: break ; }}; + ], + [flatten], [ + int foo( void ) __attribute__(($1)); + ], + [format], [ + int foo(const char *p, ...) __attribute__(($1(printf, 1, 2))); + ], + [format_arg], [ + char *foo(const char *p) __attribute__(($1(1))); + ], + [gnu_inline], [ + inline __attribute__(($1)) int foo( void ) { return 0; } + ], + [hot], [ + int foo( void ) __attribute__(($1)); + ], + [ifunc], [ + int my_foo( void ) { return 0; } + static int (*resolve_foo(void))(void) { return my_foo; } + int foo( void ) __attribute__(($1("resolve_foo"))); + ], + [leaf], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [malloc], [ + void *foo( void ) __attribute__(($1)); + ], + [noclone], [ + int foo( void ) __attribute__(($1)); + ], + [noinline], [ + __attribute__(($1)) int foo( void ) { return 0; } + ], + [nonnull], [ + int foo(char *p) __attribute__(($1(1))); + ], + [noreturn], [ + void foo( void ) __attribute__(($1)); + ], + [nothrow], [ + int foo( void ) __attribute__(($1)); + ], + [optimize], [ + __attribute__(($1(3))) int foo( void ) { return 0; } + ], + [pure], [ + int foo( void ) __attribute__(($1)); + ], + [sentinel], [ + int foo(void *p, ...) __attribute__(($1)); + ], + [sentinel_position], [ + int foo(void *p, ...) __attribute__(($1(1))); + ], + [returns_nonnull], [ + void *foo( void ) __attribute__(($1)); + ], + [unused], [ + int foo( void ) __attribute__(($1)); + ], + [used], [ + int foo( void ) __attribute__(($1)); + ], + [visibility], [ + int foo_def( void ) __attribute__(($1("default"))); + int foo_hid( void ) __attribute__(($1("hidden"))); + int foo_int( void ) __attribute__(($1("internal"))); + int foo_pro( void ) __attribute__(($1("protected"))); + ], + [warning], [ + int foo( void ) __attribute__(($1(""))); + ], + [warn_unused_result], [ + int foo( void ) __attribute__(($1)); + ], + [weak], [ + int foo( void ) __attribute__(($1)); + ], + [weakref], [ + static int foo( void ) { return 0; } + static int bar( void ) __attribute__(($1("foo"))); + ], + [ + m4_warn([syntax], [Unsupported attribute $1, the test may fail]) + int foo( void ) __attribute__(($1)); + ] + )], []) + ], + dnl GCC doesn't exit with an error if an unknown attribute is + dnl provided but only outputs a warning, so accept the attribute + dnl only if no warning were issued. + [AS_IF([test -s conftest.err], + [AS_VAR_SET([ac_var], [no])], + [AS_VAR_SET([ac_var], [yes])])], + [AS_VAR_SET([ac_var], [no])]) + ]) + + AS_IF([test yes = AS_VAR_GET([ac_var])], + [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1, + [Define to 1 if the system has the `$1' function attribute])], []) + + AS_VAR_POPDEF([ac_var]) +]) diff --git a/m4.include/fsusage.m4 b/m4.include/fsusage.m4 index 72472e2c8..1d6ad41cd 100644 --- a/m4.include/fsusage.m4 +++ b/m4.include/fsusage.m4 @@ -1,7 +1,7 @@ -# serial 31 +# serial 32 # Obtaining file system usage information. -# Copyright (C) 1997-1998, 2000-2001, 2003-2016 Free Software Foundation, Inc. +# Copyright (C) 1997-1998, 2000-2001, 2003-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -295,17 +295,6 @@ if test $ac_fsusage_space = no; then fi fi -if test $ac_fsusage_space = no; then - # SVR2 - # (AIX, HP-UX, OSF/1 already handled above.) - AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include - ]])], - [AC_DEFINE([STAT_READ_FILSYS], [1], - [Define if there is no specific function for reading file systems usage - information and you have the header file. (SVR2)]) - ac_fsusage_space=yes]) -fi - AS_IF([test $ac_fsusage_space = yes], [$1], [$2]) ]) @@ -342,6 +331,6 @@ choke -- this is a workaround for a Sun-specific problem # Prerequisites of lib/fsusage.c not done by gl_FILE_SYSTEM_USAGE. AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA], [ - AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h]) + AC_CHECK_HEADERS([dustat.h sys/fs/s5param.h sys/statfs.h]) gl_STATFS_TRUNCATES ]) diff --git a/m4.include/mc-cflags.m4 b/m4.include/mc-cflags.m4 index af692c79b..9faac606a 100644 --- a/m4.include/mc-cflags.m4 +++ b/m4.include/mc-cflags.m4 @@ -63,6 +63,7 @@ dnl Sorted -W options: mc_CHECK_ONE_CFLAG([-Wformat-security]) mc_CHECK_ONE_CFLAG([-Wformat-signedness]) mc_CHECK_ONE_CFLAG([-Wimplicit]) + mc_CHECK_ONE_CFLAG([-Wimplicit-fallthrough]) mc_CHECK_ONE_CFLAG([-Wignored-qualifiers]) mc_CHECK_ONE_CFLAG([-Wlogical-not-parentheses]) mc_CHECK_ONE_CFLAG([-Wmaybe-uninitialized]) diff --git a/src/args.c b/src/args.c index a9c71a09c..e25c600ca 100644 --- a/src/args.c +++ b/src/args.c @@ -1,7 +1,7 @@ /* Handle command line arguments. - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: @@ -831,7 +831,7 @@ mc_setup_by_args (int argc, char **argv, GError ** mcerror) _("Two files are required to envoke the diffviewer.")); return FALSE; } - /* fallthrough */ + MC_FALLTHROUGH; #endif /* USE_DIFF_VIEW */ case MC_RUN_FULL: diff --git a/src/background.c b/src/background.c index 88d48b75a..717633098 100644 --- a/src/background.c +++ b/src/background.c @@ -2,7 +2,7 @@ /* Background support. - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: diff --git a/src/clipboard.c b/src/clipboard.c index 167ff2865..4019e0442 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -1,7 +1,7 @@ /* Util for external clipboard. - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/src/cons.handler.c b/src/cons.handler.c index ba18d3266..c3d8114e2 100644 --- a/src/cons.handler.c +++ b/src/cons.handler.c @@ -1,7 +1,7 @@ /* Client interface for General purpose Linux console save/restore server - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -42,7 +42,7 @@ #include "lib/unixcompat.h" #include "lib/tty/tty.h" -#include "lib/skin.h" /* tty_set_normal_attrs */ +#include "lib/tty/color.h" /* tty_set_normal_attrs */ #include "lib/tty/win.h" #include "lib/util.h" /* mc_build_filename() */ diff --git a/src/consaver/cons.saver.c b/src/consaver/cons.saver.c index 9f5680723..fe15c428d 100644 --- a/src/consaver/cons.saver.c +++ b/src/consaver/cons.saver.c @@ -11,7 +11,7 @@ Partly rewritten by Jakub Jelinek . - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/diffviewer/search.c b/src/diffviewer/search.c index e7427df34..7a71b9867 100644 --- a/src/diffviewer/search.c +++ b/src/diffviewer/search.c @@ -1,7 +1,7 @@ /* Search functions for diffviewer. - Copyright (C) 2010-2017 + Copyright (C) 2010-2018 Free Software Foundation, Inc. Written by: @@ -123,11 +123,8 @@ mcdiffview_dialog_search (WDiff * dview) GString *tmp; tmp = str_convert_to_input (exp); - if (tmp != NULL) - { - g_free (exp); - exp = g_string_free (tmp, FALSE); - } + g_free (exp); + exp = g_string_free (tmp, FALSE); } #endif diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index fa073693b..3d6ff9d05 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -1,7 +1,7 @@ /* File difference viewer - Copyright (C) 2007-2017 + Copyright (C) 2007-2018 Free Software Foundation, Inc. Written by: @@ -3106,7 +3106,7 @@ dview_ok_to_exit (WDiff * dview) res = mc_util_unlink_backup_if_possible (dview->file[DIFF_LEFT], "~~~"); if (mc_util_restore_from_backup_if_possible (dview->file[DIFF_RIGHT], "~~~")) res = mc_util_unlink_backup_if_possible (dview->file[DIFF_RIGHT], "~~~"); - /* fall through */ + MC_FALLTHROUGH; default: res = TRUE; break; diff --git a/src/editor/bookmark.c b/src/editor/bookmark.c index 63519696b..05a168862 100644 --- a/src/editor/bookmark.c +++ b/src/editor/bookmark.c @@ -1,7 +1,7 @@ /* Editor book mark handling - Copyright (C) 2001-2017 + Copyright (C) 2001-2018 Free Software Foundation, Inc. Written by: diff --git a/src/editor/choosesyntax.c b/src/editor/choosesyntax.c index ee99ecfd5..8e516bdbf 100644 --- a/src/editor/choosesyntax.c +++ b/src/editor/choosesyntax.c @@ -1,7 +1,7 @@ /* User interface for syntax selection. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Copyright (C) 2005, 2006 diff --git a/src/editor/edit.c b/src/editor/edit.c index 06e0ff371..174637253 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -1,7 +1,7 @@ /* Editor low level data handling and cursor fundamentals. - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: @@ -890,11 +890,8 @@ my_type_of (int c) if (c == 0) return 0; if (c == '!') - { - if (*option_chars_move_whole_word == '!') - return 2; - return 0x80000000UL; - } + return 2; + if (g_ascii_isupper ((gchar) c)) c = 'A'; else if (g_ascii_islower ((gchar) c)) @@ -3456,6 +3453,7 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) case CK_MarkColumnDown: if (edit->mark2 == -1) break; /*marking is following the cursor: may need to highlight a whole line */ + MC_FALLTHROUGH; case CK_Left: case CK_Right: case CK_MarkLeft: @@ -3551,18 +3549,21 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) case CK_MarkColumnPageUp: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_PageUp: case CK_MarkPageUp: edit_move_up (edit, w->lines - 1, TRUE); break; case CK_MarkColumnPageDown: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_PageDown: case CK_MarkPageDown: edit_move_down (edit, w->lines - 1, TRUE); break; case CK_MarkColumnLeft: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_Left: case CK_MarkLeft: if (option_fake_half_tabs && is_in_indent (&edit->buffer) && right_of_four_spaces (edit)) @@ -3578,6 +3579,7 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) break; case CK_MarkColumnRight: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_Right: case CK_MarkRight: if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit)) @@ -3608,36 +3610,42 @@ edit_execute_cmd (WEdit * edit, long command, int char_for_insertion) break; case CK_MarkColumnUp: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_Up: case CK_MarkUp: edit_move_up (edit, 1, FALSE); break; case CK_MarkColumnDown: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_Down: case CK_MarkDown: edit_move_down (edit, 1, FALSE); break; case CK_MarkColumnParagraphUp: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_ParagraphUp: case CK_MarkParagraphUp: edit_move_up_paragraph (edit, FALSE); break; case CK_MarkColumnParagraphDown: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_ParagraphDown: case CK_MarkParagraphDown: edit_move_down_paragraph (edit, FALSE); break; case CK_MarkColumnScrollUp: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_ScrollUp: case CK_MarkScrollUp: edit_move_up (edit, 1, TRUE); break; case CK_MarkColumnScrollDown: edit->column_highlight = 1; + MC_FALLTHROUGH; case CK_ScrollDown: case CK_MarkScrollDown: edit_move_down (edit, 1, TRUE); diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index c1038e01b..d092b2c2c 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -1,7 +1,7 @@ /* Editor text keep buffer. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 4e1101db8..ab0758db2 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1,7 +1,7 @@ /* Editor high level editing commands - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: @@ -233,7 +233,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath) { case 0: this_save_mode = EDIT_SAFE_SAVE; - /* fallthrough */ + MC_FALLTHROUGH; case 1: edit->skip_detach_prompt = 1; break; @@ -922,12 +922,9 @@ edit_replace_cmd__conv_to_input (char *str) GString *tmp; tmp = str_convert_to_input (str); - if (tmp != NULL) - { - if (tmp->len != 0) - return g_string_free (tmp, FALSE); - g_string_free (tmp, TRUE); - } + if (tmp->len != 0) + return g_string_free (tmp, FALSE); + g_string_free (tmp, TRUE); #endif return g_strdup (str); } @@ -965,7 +962,7 @@ edit_do_search (WEdit * edit) if (search_create_bookmark) { - int found = 0, books = 0; + gboolean found = FALSE; long l = 0, l_last = -1; long q = 0; @@ -974,20 +971,19 @@ edit_do_search (WEdit * edit) while (mc_search_run (edit->search, (void *) &esm, q, edit->buffer.size, &len)) { - if (found == 0) + if (!found) edit->search_start = edit->search->normal_offset; - found++; + found = TRUE; l += edit_buffer_count_lines (&edit->buffer, q, edit->search->normal_offset); if (l != l_last) { book_mark_insert (edit, l, BOOK_MARK_FOUND_COLOR); - books++; } l_last = l; q = edit->search->normal_offset + 1; } - if (found == 0) + if (!found) edit_error_dialog (_("Search"), _(STR_E_NOTFOUND)); else edit_cursor_move (edit, edit->search_start - edit->buffer.curs1); @@ -1308,9 +1304,9 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, #ifdef HAVE_CHARSET { GString *recoded; - recoded = str_convert_to_display (temp->str); - if (recoded && recoded->len) + recoded = str_convert_to_display (temp->str); + if (recoded->len != 0) g_string_assign (temp, recoded->str); g_string_free (recoded, TRUE); @@ -1777,7 +1773,7 @@ edit_save_as_cmd (WEdit * edit) return TRUE; default: edit_error_dialog (_("Save as"), get_sys_error (_("Cannot save file"))); - /* fallthrough */ + MC_FALLTHROUGH; case -1: /* Failed, so maintain modify (not save) lock */ if (save_lock) diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index bf6795bf6..e426999e2 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -1,7 +1,7 @@ /* Editor dialogs for high level editing commands - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: @@ -150,11 +150,8 @@ editcmd_dialog_search_show (WEdit * edit) GString *tmp; tmp = str_convert_to_input (search_text); - if (tmp != NULL) - { - g_free (search_text); - search_text = g_string_free (tmp, FALSE); - } + g_free (search_text); + search_text = g_string_free (tmp, FALSE); } #endif diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 31af144c2..4a83da7eb 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -1,7 +1,7 @@ /* Editor text drawing. - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: @@ -731,7 +731,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c col++; break; } - /* fallthrough */ + MC_FALLTHROUGH; default: #ifdef HAVE_CHARSET if (mc_global.utf8_display) diff --git a/src/editor/editmenu.c b/src/editor/editmenu.c index e3bca82f0..9a0b4edf6 100644 --- a/src/editor/editmenu.c +++ b/src/editor/editmenu.c @@ -1,7 +1,7 @@ /* Editor menu definitions and initialisation - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c index 002b55c32..ccc7758a5 100644 --- a/src/editor/editoptions.c +++ b/src/editor/editoptions.c @@ -1,7 +1,7 @@ /* Editor options dialog box - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 21d843d58..eb0c349b2 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -1,7 +1,7 @@ /* Editor initialisation and callback handler. - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: @@ -145,7 +145,7 @@ edit_about (void) QUICK_LABEL (N_("A user friendly text editor\n" "written for the Midnight Commander."), NULL), QUICK_SEPARATOR (FALSE), - QUICK_LABEL (N_("Copyright (C) 1996-2016 the Free Software Foundation"), NULL), + QUICK_LABEL (N_("Copyright (C) 1996-2018 the Free Software Foundation"), NULL), QUICK_START_BUTTONS (TRUE, TRUE), QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL), QUICK_END @@ -1115,7 +1115,7 @@ edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) } } - /* fall through to start/stop text selection */ + MC_FALLTHROUGH; /* to start/stop text selection */ case MSG_MOUSE_UP: edit_update_cursor (edit, event); @@ -1435,6 +1435,7 @@ edit_handle_move_resize (WEdit * edit, long command) case CK_WindowMove: edit->drag_state = MCEDIT_DRAG_NONE; edit_status (edit, TRUE); /* redraw frame and status */ + MC_FALLTHROUGH; default: ret = TRUE; break; @@ -1459,6 +1460,7 @@ edit_handle_move_resize (WEdit * edit, long command) case CK_WindowResize: edit->drag_state = MCEDIT_DRAG_NONE; edit_status (edit, TRUE); /* redraw frame and status */ + MC_FALLTHROUGH; default: ret = TRUE; break; diff --git a/src/editor/etags.c b/src/editor/etags.c index 3aa07ce4c..70a253641 100644 --- a/src/editor/etags.c +++ b/src/editor/etags.c @@ -6,7 +6,7 @@ or, if etags utility not installed: $ find . -type f -name "*.[ch]" | ctags --c-kinds=+p --fields=+iaS --extra=+q -e -L- - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: @@ -54,7 +54,7 @@ /* --------------------------------------------------------------------------------------------- */ static gboolean -parse_define (char *buf, char **long_name, char **short_name, long *line) +parse_define (const char *buf, char **long_name, char **short_name, long *line) { /* *INDENT-OFF* */ enum @@ -183,7 +183,7 @@ etags_set_definition_hash (const char *tagfile, const char *start_path, /* *INDENT-ON* */ FILE *f; - static char buf[BUF_LARGE]; + char buf[BUF_LARGE]; char *chekedstr = NULL; @@ -241,14 +241,7 @@ etags_set_definition_hash (const char *tagfile, const char *start_path, canonicalize_pathname (def_hash[num].fullpath); def_hash[num].filename = g_strdup (filename); - if (shortname) - { - def_hash[num].short_define = g_strdup (shortname); - } - else - { - def_hash[num].short_define = g_strdup (longname); - } + def_hash[num].short_define = g_strdup (shortname ? shortname : longname); def_hash[num].line = line; num++; } diff --git a/src/editor/format.c b/src/editor/format.c index 117be5716..e184fad50 100644 --- a/src/editor/format.c +++ b/src/editor/format.c @@ -1,7 +1,7 @@ /* Dynamic paragraph formatting. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Copyright (C) 1996 Paul Sheer diff --git a/src/editor/spell.c b/src/editor/spell.c index 390c6ff86..ff8e5a7c4 100644 --- a/src/editor/spell.c +++ b/src/editor/spell.c @@ -1,7 +1,7 @@ /* Editor spell checker - Copyright (C) 2012-2017 + Copyright (C) 2012-2018 Free Software Foundation, Inc. Written by: diff --git a/src/editor/spell_dialogs.c b/src/editor/spell_dialogs.c index b588f912e..19c5533bd 100644 --- a/src/editor/spell_dialogs.c +++ b/src/editor/spell_dialogs.c @@ -1,7 +1,7 @@ /* Editor spell checker dialogs - Copyright (C) 2012-2017 + Copyright (C) 2012-2018 Free Software Foundation, Inc. Written by: diff --git a/src/editor/syntax.c b/src/editor/syntax.c index bef17dbf0..0ee33f85d 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -1,7 +1,7 @@ /* Editor syntax highlighting. - Copyright (C) 1996-2017 + Copyright (C) 1996-2018 Free Software Foundation, Inc. Written by: diff --git a/src/events_init.c b/src/events_init.c index 0d716a5b2..4f227ab76 100644 --- a/src/events_init.c +++ b/src/events_init.c @@ -1,7 +1,7 @@ /* Event callbacks initialization - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: @@ -58,7 +58,7 @@ gboolean events_init (GError ** mcerror) { /* *INDENT-OFF* */ - event_init_t standard_events[] = + static const event_init_t standard_events[] = { {MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", clipboard_file_to_ext_clip, NULL}, {MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", clipboard_file_from_ext_clip, NULL}, diff --git a/src/execute.c b/src/execute.c index 1fdf47a08..999ae0eb6 100644 --- a/src/execute.c +++ b/src/execute.c @@ -1,7 +1,7 @@ /* Execution routines for GNU Midnight Commander - Copyright (C) 2003-2017 + Copyright (C) 2003-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index 3a9f11b2f..3e3c524f5 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -1,7 +1,7 @@ /* Chown-advanced command -- for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -358,7 +358,7 @@ perm_button_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v { case '*': parm = '='; - /* fallthrough */ + MC_FALLTHROUGH; case '-': case '=': @@ -393,15 +393,15 @@ perm_button_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v case 'x': i++; - /* fallthrough */ + MC_FALLTHROUGH; case 'w': i++; - /* fallthrough */ + MC_FALLTHROUGH; case 'r': b->hotpos = i; - /* fallthrough */ + MC_FALLTHROUGH; case ' ': i = b->hotpos; @@ -416,11 +416,11 @@ perm_button_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v case '4': i++; - /* fallthrough */ + MC_FALLTHROUGH; case '2': i++; - /* fallthrough */ + MC_FALLTHROUGH; case '1': b->hotpos = i; @@ -450,7 +450,7 @@ perm_button_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) case MSG_MOUSE_DOWN: /* place cursor on flag that is being modified */ BUTTON (w)->hotpos = CLAMP (event->x - 1, 0, 2); - /* fallthrough */ + MC_FALLTHROUGH; default: button_mouse_default_callback (w, msg, event); @@ -672,11 +672,11 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm { case ALT ('x'): i++; - /* fallthrough */ + MC_FALLTHROUGH; case ALT ('w'): i++; - /* fallthrough */ + MC_FALLTHROUGH; case ALT ('r'): parm = i + 3; @@ -689,11 +689,11 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm case XCTRL ('x'): i++; - /* fallthrough */ + MC_FALLTHROUGH; case XCTRL ('w'): i++; - /* fallthrough */ + MC_FALLTHROUGH; case XCTRL ('r'): parm = i; diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 00006d142..c30be9750 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -1,7 +1,7 @@ /* Some misc dialog boxes for the program. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/chmod.c b/src/filemanager/chmod.c index 0adcc17d7..4a168f958 100644 --- a/src/filemanager/chmod.c +++ b/src/filemanager/chmod.c @@ -1,7 +1,7 @@ /* Chmod command -- for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/filemanager/chown.c b/src/filemanager/chown.c index a401d4167..e09a81377 100644 --- a/src/filemanager/chown.c +++ b/src/filemanager/chown.c @@ -1,7 +1,7 @@ /* Chown command -- for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 1f6eb4c96..a80cd3f3b 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -2,7 +2,7 @@ Routines invoked by a function key They normally operate on the current panel. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -522,31 +522,30 @@ view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gbool if (plain_view) { - int changed_hex_mode = 0; - int changed_nroff_flag = 0; - int changed_magic_flag = 0; + mcview_mode_flags_t changed_flags; - mcview_altered_hex_mode = 0; - mcview_altered_nroff_flag = 0; - mcview_altered_magic_flag = 0; - if (mcview_default_hex_mode) - changed_hex_mode = 1; - if (mcview_default_nroff_flag) - changed_nroff_flag = 1; - if (mcview_default_magic_flag) - changed_magic_flag = 1; - mcview_default_hex_mode = 0; - mcview_default_nroff_flag = 0; - mcview_default_magic_flag = 0; + mcview_clear_mode_flags (&changed_flags); + mcview_altered_flags.hex = FALSE; + mcview_altered_flags.magic = FALSE; + mcview_altered_flags.nroff = FALSE; + if (mcview_global_flags.hex) + changed_flags.hex = TRUE; + if (mcview_global_flags.magic) + changed_flags.magic = TRUE; + if (mcview_global_flags.nroff) + changed_flags.nroff = TRUE; + mcview_global_flags.hex = FALSE; + mcview_global_flags.magic = FALSE; + mcview_global_flags.nroff = FALSE; ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end); - if (changed_hex_mode && !mcview_altered_hex_mode) - mcview_default_hex_mode = 1; - if (changed_nroff_flag && !mcview_altered_nroff_flag) - mcview_default_nroff_flag = 1; - if (changed_magic_flag && !mcview_altered_magic_flag) - mcview_default_magic_flag = 1; + if (changed_flags.hex && !mcview_altered_flags.hex) + mcview_global_flags.hex = TRUE; + if (changed_flags.magic && !mcview_altered_flags.magic) + mcview_global_flags.magic = TRUE; + if (changed_flags.nroff && !mcview_altered_flags.nroff) + mcview_global_flags.nroff = TRUE; dialog_switch_process_pending (); } diff --git a/src/filemanager/command.c b/src/filemanager/command.c index e2fba4952..8778e3b2b 100644 --- a/src/filemanager/command.c +++ b/src/filemanager/command.c @@ -4,7 +4,7 @@ with all the magic of the command input line, we depend on some help from the program's callback. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: @@ -351,7 +351,7 @@ command_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void /* Special case: we handle the enter key */ if (parm == '\n') return enter (INPUT (w)); - /* fall through */ + MC_FALLTHROUGH; default: return input_callback (w, sender, msg, parm, data); diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index 72433ba35..aa5cfd018 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -1,7 +1,7 @@ /* Directory routines - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -68,7 +68,7 @@ static int reverse = 1; /* Are the files sorted case sensitively? */ -static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT; +static gboolean case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT; /* Are the exec_bit files top in list */ static gboolean exec_first = TRUE; @@ -391,7 +391,7 @@ sort_ext (file_entry_t * a, file_entry_t * b) b->second_sort_key = str_create_key (extension (b->fname), case_sensitive); r = str_key_collate (a->second_sort_key, b->second_sort_key, case_sensitive); - if (r) + if (r != 0) return r * reverse; else return sort_name (a, b); diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index 4ca850e0e..bedb4a013 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -1,7 +1,7 @@ /* Extension dependent execution. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -353,25 +353,34 @@ exec_make_shell_string (const char *lc_data, const vfs_path_t * filename_vpath) static void exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath, int start_line) { - int def_hex_mode = mcview_default_hex_mode, changed_hex_mode = 0; - int def_nroff_flag = mcview_default_nroff_flag, changed_nroff_flag = 0; + mcview_mode_flags_t def_flags = { + /* *INDENT-OFF* */ + .wrap = FALSE, + .hex = mcview_global_flags.hex, + .magic = FALSE, + .nroff = mcview_global_flags.nroff + /* *INDENT-ON* */ + }; - mcview_altered_hex_mode = 0; - mcview_altered_nroff_flag = 0; - if (def_hex_mode != mcview_default_hex_mode) - changed_hex_mode = 1; - if (def_nroff_flag != mcview_default_nroff_flag) - changed_nroff_flag = 1; + mcview_mode_flags_t changed_flags; + + mcview_clear_mode_flags (&changed_flags); + mcview_altered_flags.hex = FALSE; + mcview_altered_flags.nroff = FALSE; + if (def_flags.hex != mcview_global_flags.hex) + changed_flags.hex = TRUE; + if (def_flags.nroff != mcview_global_flags.nroff) + changed_flags.nroff = TRUE; if (target == NULL) mcview_viewer (cmd, filename_vpath, start_line, 0, 0); else mcview_load ((WView *) target, cmd, vfs_path_as_str (filename_vpath), start_line, 0, 0); - if (changed_hex_mode && !mcview_altered_hex_mode) - mcview_default_hex_mode = def_hex_mode; - if (changed_nroff_flag && !mcview_altered_nroff_flag) - mcview_default_nroff_flag = def_nroff_flag; + if (changed_flags.hex && !mcview_altered_flags.hex) + mcview_global_flags.hex = def_flags.hex; + if (changed_flags.nroff && !mcview_altered_flags.nroff) + mcview_global_flags.nroff = def_flags.nroff; dialog_switch_process_pending (); } diff --git a/src/filemanager/file.c b/src/filemanager/file.c index ec35ab06f..09530c76b 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1,7 +1,7 @@ /* File management. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index d6e4d39a6..f0053ecbb 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -10,7 +10,7 @@ Janne Kukonlehto added much error recovery to them for being used in an interactive program. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -702,7 +702,7 @@ check_progress_buttons (file_op_context_t * ctx) ctx->suspended = !ctx->suspended; place_progress_buttons (ui->op_dlg, ctx->suspended); dlg_redraw (ui->op_dlg); - /* fallthrough */ + MC_FALLTHROUGH; default: if (ctx->suspended) goto get_event; @@ -1143,9 +1143,11 @@ file_progress_real_query_replace (file_op_context_t * ctx, case REPLACE_REGET: /* Careful: we fall through and set do_append */ ctx->do_reget = _d_stat->st_size; + MC_FALLTHROUGH; case REPLACE_APPEND: ctx->do_append = TRUE; + MC_FALLTHROUGH; case REPLACE_YES: case REPLACE_ALWAYS: diff --git a/src/filemanager/filenot.c b/src/filemanager/filenot.c index 26ce8fb53..5655757ff 100644 --- a/src/filemanager/filenot.c +++ b/src/filemanager/filenot.c @@ -3,7 +3,7 @@ tree about the changes made to the directory structure. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Author: diff --git a/src/filemanager/fileopctx.c b/src/filemanager/fileopctx.c index ae555c62a..66fde8940 100644 --- a/src/filemanager/fileopctx.c +++ b/src/filemanager/fileopctx.c @@ -1,7 +1,7 @@ /* File operation contexts for the Midnight Commander - Copyright (C) 1999-2017 + Copyright (C) 1999-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 01b0a4bf7..3148dab82 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1,7 +1,7 @@ /* Find file command for the Midnight Commander - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: @@ -540,7 +540,7 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi } first_draw = FALSE; - /* fall through to call MSG_DRAW default handler */ + MC_FALLTHROUGH; /* to call MSG_DRAW default handler */ default: return dlg_default_callback (w, sender, msg, parm, data); diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c index ce3becff0..11740db40 100644 --- a/src/filemanager/hotlist.c +++ b/src/filemanager/hotlist.c @@ -1,7 +1,7 @@ /* Directory hotlist -- for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -449,9 +449,9 @@ hotlist_run_cmd (int action) fill_listbox (list); return 0; } - /* Fall through - go up */ + MC_FALLTHROUGH; /* go up */ } - /* Fall through if list empty - just go up */ + MC_FALLTHROUGH; /* if list empty - just go up */ case B_UP_GROUP: { @@ -466,7 +466,7 @@ hotlist_run_cmd (int action) #ifdef ENABLE_VFS case B_FREE_ALL_VFS: vfs_expire (TRUE); - /* fall through */ + MC_FALLTHROUGH; case B_REFRESH_VFS: listbox_remove_list (l_hotlist); @@ -1289,7 +1289,7 @@ hot_next_token (void) if (c == '\n') goto again; - /* fall through; it is taken as normal character */ + MC_FALLTHROUGH; /* it is taken as normal character */ default: do diff --git a/src/filemanager/info.c b/src/filemanager/info.c index 8a4462191..1bfc7e593 100644 --- a/src/filemanager/info.c +++ b/src/filemanager/info.c @@ -1,7 +1,7 @@ /* Panel managing. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -153,7 +153,7 @@ info_show_info (WInfo * info) /* Note: all cases are fall-throughs */ default: - + MC_FALLTHROUGH; case 16: widget_move (w, 16, 3); if ((myfs_stats.nfree == 0 && myfs_stats.nodes == 0) || @@ -169,7 +169,7 @@ info_show_info (WInfo * info) myfs_stats.nfree, myfs_stats.nodes, myfs_stats.nodes == 0 ? 0 : (int) (100 * (long double) myfs_stats.nfree / myfs_stats.nodes)); - + MC_FALLTHROUGH; case 15: widget_move (w, 15, 3); if (myfs_stats.avail == 0 && myfs_stats.total == 0) @@ -184,36 +184,40 @@ info_show_info (WInfo * info) myfs_stats.total == 0 ? 0 : (int) (100 * (long double) myfs_stats.avail / myfs_stats.total)); } - + MC_FALLTHROUGH; case 14: widget_move (w, 14, 3); tty_printf (_("Type: %s"), myfs_stats.typename ? myfs_stats.typename : _("non-local vfs")); if (myfs_stats.type != 0xffff && myfs_stats.type != -1) tty_printf (" (%Xh)", (unsigned int) myfs_stats.type); - + MC_FALLTHROUGH; case 13: widget_move (w, 13, 3); str_printf (buff, _("Device: %s"), str_trunc (myfs_stats.device, w->cols - i18n_adjust)); tty_print_string (buff->str); g_string_set_size (buff, 0); + MC_FALLTHROUGH; case 12: widget_move (w, 12, 3); str_printf (buff, _("Filesystem: %s"), str_trunc (myfs_stats.mpoint, w->cols - i18n_adjust)); tty_print_string (buff->str); g_string_set_size (buff, 0); + MC_FALLTHROUGH; case 11: widget_move (w, 11, 3); str_printf (buff, _("Accessed: %s"), file_date (st.st_atime)); tty_print_string (buff->str); g_string_set_size (buff, 0); + MC_FALLTHROUGH; case 10: widget_move (w, 10, 3); str_printf (buff, _("Modified: %s"), file_date (st.st_mtime)); tty_print_string (buff->str); g_string_set_size (buff, 0); + MC_FALLTHROUGH; case 9: widget_move (w, 9, 3); /* The field st_ctime is changed by writing or by setting inode @@ -222,7 +226,7 @@ info_show_info (WInfo * info) str_printf (buff, _("Changed: %s"), file_date (st.st_ctime)); tty_print_string (buff->str); g_string_set_size (buff, 0); - + MC_FALLTHROUGH; case 8: widget_move (w, 8, 3); #ifdef HAVE_STRUCT_STAT_ST_RDEV @@ -240,24 +244,24 @@ info_show_info (WInfo * info) (unsigned long) st.st_blocks), (unsigned long) st.st_blocks); #endif } - + MC_FALLTHROUGH; case 7: widget_move (w, 7, 3); tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid)); - + MC_FALLTHROUGH; case 6: widget_move (w, 6, 3); tty_printf (_("Links: %d"), (int) st.st_nlink); - + MC_FALLTHROUGH; case 5: widget_move (w, 5, 3); tty_printf (_("Mode: %s (%04o)"), string_perm (st.st_mode), (unsigned) st.st_mode & 07777); - + MC_FALLTHROUGH; case 4: widget_move (w, 4, 3); tty_printf (_("Location: %Xh:%Xh"), (unsigned int) st.st_dev, (unsigned int) st.st_ino); - + MC_FALLTHROUGH; case 3: { const char *fname; @@ -267,9 +271,11 @@ info_show_info (WInfo * info) str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust)); tty_print_string (buff->str); } - + MC_FALLTHROUGH; case 2: + MC_FALLTHROUGH; case 1: + MC_FALLTHROUGH; case 0: ; } /* switch */ diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 10f06643c..b14973efe 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -1,7 +1,7 @@ /* Panel layout module for the Midnight Commander - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/listmode.c b/src/filemanager/listmode.c index 9d7f6a7cd..6fc81b176 100644 --- a/src/filemanager/listmode.c +++ b/src/filemanager/listmode.c @@ -1,7 +1,7 @@ /* Directory panel listing format editor -- for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 01d196eea..e8e43735a 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -1,7 +1,7 @@ /* Main dialog (file panels) of the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -694,19 +694,6 @@ create_panels (void) #endif /* ENABLE_VFS */ mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL); - - /* Create the nice widgets */ - cmdline = command_new (0, 0, 0); - the_prompt = label_new (0, 0, mc_prompt); - the_prompt->transparent = 1; - the_bar = buttonbar_new (mc_global.keybar_visible); - - the_hint = label_new (0, 0, 0); - the_hint->transparent = 1; - the_hint->auto_adjust_cols = 0; - WIDGET (the_hint)->cols = COLS; - - the_menubar = menubar_new (0, 0, COLS, NULL, menubar_visible); } /* --------------------------------------------------------------------------------------------- */ @@ -929,30 +916,37 @@ done_mc (void) /* --------------------------------------------------------------------------------------------- */ static void -create_panels_and_run_mc (void) +create_file_manager (void) { midnight_dlg->get_shortcut = midnight_get_shortcut; midnight_dlg->get_title = midnight_get_title; /* allow rebind tab */ widget_want_tab (WIDGET (midnight_dlg), TRUE); - create_panels (); - + the_menubar = menubar_new (0, 0, COLS, NULL, menubar_visible); add_widget (midnight_dlg, the_menubar); init_menu (); + create_panels (); add_widget (midnight_dlg, get_panel_widget (0)); add_widget (midnight_dlg, get_panel_widget (1)); + the_hint = label_new (0, 0, 0); + the_hint->transparent = 1; + the_hint->auto_adjust_cols = 0; + WIDGET (the_hint)->cols = COLS; add_widget (midnight_dlg, the_hint); + + cmdline = command_new (0, 0, 0); add_widget (midnight_dlg, cmdline); + + the_prompt = label_new (0, 0, mc_prompt); + the_prompt->transparent = TRUE; add_widget (midnight_dlg, the_prompt); + the_bar = buttonbar_new (mc_global.keybar_visible); add_widget (midnight_dlg, the_bar); midnight_set_buttonbar (the_bar); - - /* Run the Midnight Commander if no file was specified in the command line */ - dlg_run (midnight_dlg); } /* --------------------------------------------------------------------------------------------- */ @@ -1792,7 +1786,10 @@ do_nc (void) setup_mc (); mc_filehighlight = mc_fhl_new (TRUE); - create_panels_and_run_mc (); + + create_file_manager (); + (void) dlg_run (midnight_dlg); + mc_fhl_free (&mc_filehighlight); ret = TRUE; diff --git a/src/filemanager/mountlist.c b/src/filemanager/mountlist.c index c22154667..12c5c264e 100644 --- a/src/filemanager/mountlist.c +++ b/src/filemanager/mountlist.c @@ -1,7 +1,7 @@ /* Return a list of mounted file systems - Copyright (C) 1991-2017 + Copyright (C) 1991-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -75,9 +75,6 @@ #ifdef HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ #include #endif -#if defined HAVE_SYS_FILSYS_H && !defined _CRAY -#include /* SVR2 */ -#endif #ifdef HAVE_SYS_STATFS_H #include #endif @@ -119,10 +116,6 @@ #include #endif -#ifdef MOUNTED_FREAD /* SVR2. */ -#include -#endif - #ifdef MOUNTED_FREAD_FSTYP /* SVR3. */ #include #include @@ -309,17 +302,6 @@ me_remote (char const *fs_name, char const *fs_type) #endif #endif -#ifdef STAT_READ_FILSYS /* SVR2 */ -/* Set errno to zero upon EOF. */ -#define ZERO_BYTE_TRANSFER_ERRNO 0 - -#ifdef EINTR -#define IS_EINTR(x) ((x) == EINTR) -#else -#define IS_EINTR(x) 0 -#endif -#endif /* STAT_READ_FILSYS */ - /*** file scope type declarations ****************************************************************/ /* A mount table entry. */ @@ -1406,76 +1388,6 @@ read_file_system_list (void) /* --------------------------------------------------------------------------------------------- */ -#ifdef STAT_READ_FILSYS /* SVR2 */ - -/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if - interrupted. Return the actual number of bytes read(written), zero for EOF, - or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */ -static size_t -safe_read (int fd, void *buf, size_t count) -{ - /* Work around a bug in Tru64 5.1. Attempting to read more than - INT_MAX bytes fails with errno == EINVAL. See - . - When decreasing COUNT, keep it block-aligned. */ - /* *INDENT-OFF* */ - enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 }; - /* *INDENT-ON* */ - - while (TRUE) - { - ssize_t result; - - result = read (fd, buf, count); - - if (0 <= result) - return result; - else if (IS_EINTR (errno)) - continue; - else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count) - count = BUGGY_READ_MAXIMUM; - else - return result; - } -} - -/* --------------------------------------------------------------------------------------------- */ - -/* Read COUNT bytes at BUF to(from) descriptor FD, retrying if - interrupted or if a partial write(read) occurs. Return the number - of bytes transferred. - When writing, set errno if fewer than COUNT bytes are written. - When reading, if fewer than COUNT bytes are read, you must examine - errno to distinguish failure from EOF (errno == 0). */ - -static size_t -full_read (int fd, void *buf, size_t count) -{ - size_t total = 0; - char *ptr = (char *) buf; - - while (count > 0) - { - size_t n_rw = safe_read (fd, ptr, count); - if (n_rw == (size_t) (-1)) - break; - if (n_rw == 0) - { - errno = ZERO_BYTE_TRANSFER_ERRNO; - break; - } - total += n_rw; - ptr += n_rw; - count -= n_rw; - } - - return total; -} - -#endif /* STAT_READ_FILSYS */ - -/* --------------------------------------------------------------------------------------------- */ - #ifdef HAVE_INFOMOUNT /* Fill in the fields of FSP with information about space usage for the file system on which FILE resides. @@ -1541,40 +1453,6 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); -#elif defined STAT_READ_FILSYS /* SVR2 */ -#ifndef SUPERBOFF -#define SUPERBOFF (SUPERB * 512) -#endif - - struct filsys fsd; - int fd; - - if (!disk) - { - errno = 0; - return -1; - } - - fd = open (disk, O_RDONLY); - if (fd < 0) - return -1; - lseek (fd, (off_t) SUPERBOFF, 0); - if (full_read (fd, (char *) &fsd, sizeof (fsd)) != sizeof (fsd)) - { - close (fd); - return -1; - } - close (fd); - - fsp->fsu_blocksize = (fsd.s_type == Fs2b ? 1024 : 512); - fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.s_fsize); - fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.s_tfree); - fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree); - fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0; - fsp->fsu_files = (fsd.s_isize == -1 - ? UINTMAX_MAX : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); - fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); - #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ struct statfs fsd; diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index f4dcb42a8..c653b821d 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -1,7 +1,7 @@ /* Panel managing. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -3873,7 +3873,7 @@ panel_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) if (!is_active) change_panel (); - /* fall through */ + MC_FALLTHROUGH; case MSG_MOUSE_DRAG: { @@ -4185,7 +4185,7 @@ panel_recursive_cd_to_parent (const vfs_path_t * vpath) /* check if path contains only '/' */ panel_cwd_path = vfs_path_as_str (cwd_vpath); - if (IS_PATH_SEP (panel_cwd_path[0]) && panel_cwd_path[1] == '\0') + if (panel_cwd_path != NULL && IS_PATH_SEP (panel_cwd_path[0]) && panel_cwd_path[1] == '\0') return NULL; tmp_vpath = vfs_path_vtokens_get (cwd_vpath, 0, -1); diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 4808840bc..c4ef2a733 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -1,7 +1,7 @@ /* External panelize - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 6c5649b82..f4aa4120c 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -6,7 +6,7 @@ created and destroyed. This is required for the future vfs layer, it will be possible to have tree views over virtual file systems. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c index 92ffca2d2..26ecf9895 100644 --- a/src/filemanager/treestore.c +++ b/src/filemanager/treestore.c @@ -8,7 +8,7 @@ created and destroyed. This is required for the future vfs layer, it will be possible to have tree views over virtual file systems. - Copyright (C) 1999-2017 + Copyright (C) 1999-2018 Free Software Foundation, Inc. Written by: diff --git a/src/help.c b/src/help.c index 48d9cb796..4974b0808 100644 --- a/src/help.c +++ b/src/help.c @@ -1,7 +1,7 @@ /* Hypertext file browser. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c index ff267544c..662520954 100644 --- a/src/keybind-defaults.c +++ b/src/keybind-defaults.c @@ -1,7 +1,7 @@ /* Default values for keybinding engine - Copyright (C) 2009-2017 + Copyright (C) 2009-2018 Free Software Foundation, Inc. Written by: diff --git a/src/learn.c b/src/learn.c index 2d6f98b76..941be749d 100644 --- a/src/learn.c +++ b/src/learn.c @@ -1,7 +1,7 @@ /* Learn keys - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: diff --git a/src/main.c b/src/main.c index 001e67dd3..85bf48617 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ /* Main program for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/selcodepage.c b/src/selcodepage.c index 11c41fdf2..b5dd78a19 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -3,7 +3,7 @@ Copyright (C) 2001 Walery Studennikov - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/setup.c b/src/setup.c index 430075ced..9f4361cfe 100644 --- a/src/setup.c +++ b/src/setup.c @@ -1,7 +1,7 @@ /* Setup loading/saving. - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -302,7 +302,7 @@ static const struct { "mouse_close_dialog", &mouse_close_dialog}, { "fast_refresh", &fast_refresh }, { "drop_menus", &drop_menus }, - { "wrap_mode", &mcview_global_wrap_mode }, + { "wrap_mode", &mcview_global_flags.wrap }, { "old_esc_mode", &old_esc_mode }, { "cd_symlinks", &mc_global.vfs.cd_symlinks }, { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous }, @@ -1456,12 +1456,13 @@ panel_load_setup (WPanel * panel, const char *section) size_t i; char *buffer, buffer2[BUF_TINY]; - panel->sort_info.reverse = mc_config_get_int (mc_global.panels_config, section, "reverse", 0); + panel->sort_info.reverse = + mc_config_get_bool (mc_global.panels_config, section, "reverse", FALSE); panel->sort_info.case_sensitive = - mc_config_get_int (mc_global.panels_config, section, "case_sensitive", - OS_SORT_CASE_SENSITIVE_DEFAULT); + mc_config_get_bool (mc_global.panels_config, section, "case_sensitive", + OS_SORT_CASE_SENSITIVE_DEFAULT); panel->sort_info.exec_first = - mc_config_get_int (mc_global.panels_config, section, "exec_first", 0); + mc_config_get_bool (mc_global.panels_config, section, "exec_first", FALSE); /* Load sort order */ buffer = mc_config_get_string (mc_global.panels_config, section, "sort_order", "name"); @@ -1514,10 +1515,11 @@ panel_save_setup (WPanel * panel, const char *section) char buffer[BUF_TINY]; size_t i; - mc_config_set_int (mc_global.panels_config, section, "reverse", panel->sort_info.reverse); - mc_config_set_int (mc_global.panels_config, section, "case_sensitive", - panel->sort_info.case_sensitive); - mc_config_set_int (mc_global.panels_config, section, "exec_first", panel->sort_info.exec_first); + mc_config_set_bool (mc_global.panels_config, section, "reverse", panel->sort_info.reverse); + mc_config_set_bool (mc_global.panels_config, section, "case_sensitive", + panel->sort_info.case_sensitive); + mc_config_set_bool (mc_global.panels_config, section, "exec_first", + panel->sort_info.exec_first); mc_config_set_string (mc_global.panels_config, section, "sort_order", panel->sort_field->id); diff --git a/src/subshell/common.c b/src/subshell/common.c index 772d2c939..eca94311e 100644 --- a/src/subshell/common.c +++ b/src/subshell/common.c @@ -1,7 +1,7 @@ /* Concurrent shell support for the Midnight Commander - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/subshell/proxyfunc.c b/src/subshell/proxyfunc.c index b34f25829..a81519361 100644 --- a/src/subshell/proxyfunc.c +++ b/src/subshell/proxyfunc.c @@ -1,7 +1,7 @@ /* Proxy functions for getting access to public variables into 'filemanager' module. - Copyright (C) 2015-2017 + Copyright (C) 2015-2018 Free Software Foundation, Inc. Written by: diff --git a/src/textconf.c b/src/textconf.c index 8ffe48069..3acebb87d 100644 --- a/src/textconf.c +++ b/src/textconf.c @@ -1,7 +1,7 @@ /* Print features specific for this build - Copyright (C) 2000-2017 + Copyright (C) 2000-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/usermenu.c b/src/usermenu.c index 26fe21f80..ab20f39cc 100644 --- a/src/usermenu.c +++ b/src/usermenu.c @@ -1,7 +1,7 @@ /* User Menu implementation - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -448,6 +448,7 @@ execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean vfs_path_free (file_name_vpath); return; } + cmd_file = fdopen (cmd_file_fd, "w"); fputs ("#! /bin/sh\n", cmd_file); commands++; @@ -520,33 +521,32 @@ execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean g_free (text); } } - else + else if (*commands == '%') { - if (*commands == '%') - { - int i; + int i; - i = check_format_view (commands + 1); - if (i != 0) - { - commands += i; - run_view = TRUE; - } - else - { - do_quote = TRUE; /* Default: Quote expanded macro */ - expand_prefix_found = TRUE; - } + i = check_format_view (commands + 1); + if (i != 0) + { + commands += i; + run_view = TRUE; } else - fputc (*commands, cmd_file); + { + do_quote = TRUE; /* Default: Quote expanded macro */ + expand_prefix_found = TRUE; + } } + else + fputc (*commands, cmd_file); } + fclose (cmd_file); mc_chmod (file_name_vpath, S_IRWXU); + if (run_view) { - mcview_viewer (vfs_path_as_str (file_name_vpath), NULL, 0, 0, 0); + mcview_viewer (NULL, file_name_vpath, 0, 0, 0); dialog_switch_process_pending (); } else @@ -556,15 +556,12 @@ execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean char *cmd; cmd = g_strconcat ("/bin/sh ", vfs_path_as_str (file_name_vpath), (char *) NULL); - if (!show_prompt) - { - if (system (cmd) == -1) - message (D_ERROR, MSG_ERROR, "%s", _("Error calling program")); - } - else - { + + if (show_prompt) shell_execute (cmd, EXECUTE_HIDE); - } + else if (system (cmd) == -1) + message (D_ERROR, MSG_ERROR, "%s", _("Error calling program")); + g_free (cmd); } mc_unlink (file_name_vpath); @@ -640,22 +637,22 @@ check_format_view (const char *p) { if (strncmp (q, DEFAULT_CHARSET, 5) == 0) { - mcview_default_hex_mode = 0; + mcview_global_flags.hex = FALSE; q += 4; } else if (strncmp (q, "hex", 3) == 0) { - mcview_default_hex_mode = 1; + mcview_global_flags.hex = TRUE; q += 2; } else if (strncmp (q, "nroff", 5) == 0) { - mcview_default_nroff_flag = 1; + mcview_global_flags.nroff = TRUE; q += 4; } else if (strncmp (q, "unform", 6) == 0) { - mcview_default_nroff_flag = 0; + mcview_global_flags.nroff = FALSE; q += 5; } } @@ -683,14 +680,14 @@ check_format_cd (const char *p) int check_format_var (const char *p, char **v) { - const char *q = p; - char *var_name; - *v = NULL; + if (strncmp (p, "var{", 4) == 0) { + const char *q = p; const char *dots = NULL; const char *value; + char *var_name; for (q += 4; *q != '\0' && *q != '}'; q++) { @@ -711,16 +708,14 @@ check_format_var (const char *p, char **v) /* Copy the variable name */ var_name = g_strndup (p + 4, dots - 2 - (p + 3)); - value = getenv (var_name); g_free (var_name); + if (value != NULL) - { *v = g_strdup (value); - return q - p; - } - var_name = g_strndup (dots, q - dots); - *v = var_name; + else + *v = g_strndup (dots, q - dots); + return q - p; } return 0; @@ -883,7 +878,7 @@ expand_format (const WEdit * edit_widget, char c, gboolean do_quote) goto ret; } - /* Fall through */ + MC_FALLTHROUGH; case 't': case 'u': @@ -969,7 +964,6 @@ user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en else menu = mc_config_get_full_path (MC_USERMENU_FILE); - if (!exist_file (menu)) { g_free (menu); @@ -1019,7 +1013,6 @@ user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en menu_limit += MAX_ENTRIES; new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit); - if (new_entries == NULL) break; @@ -1028,18 +1021,19 @@ user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en while (--new_entries >= &entries[menu_lines]) *new_entries = NULL; } + if (col == 0 && entries[menu_lines] == NULL) - { - if (*p == '#') + switch (*p) { + case '#': /* show prompt if first line of external script is #interactive */ if (selected_entry >= 0 && strncmp (p, "#silent", 7) == 0) interactive = FALSE; /* A commented menu entry */ accept_entry = TRUE; - } - else if (*p == '+') - { + break; + + case '+': if (*(p + 1) == '=') { /* Combined adding and default */ @@ -1052,9 +1046,9 @@ user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en /* A condition for adding the entry */ p = test_line (edit_widget, p, &accept_entry); } - } - else if (*p == '=') - { + break; + + case '=': if (*(p + 1) == '+') { /* Combined adding and default */ @@ -1070,16 +1064,20 @@ user_menu_cmd (const WEdit * edit_widget, const char *menu_file, int selected_en if (selected == 0 && i != 0) selected = menu_lines; } + break; + + default: + if (!whitespace (*p) && str_isprint (p)) + { + /* A menu entry title line */ + if (accept_entry) + entries[menu_lines] = p; + else + accept_entry = TRUE; + } + break; } - else if (!whitespace (*p) && str_isprint (p)) - { - /* A menu entry title line */ - if (accept_entry) - entries[menu_lines] = p; - else - accept_entry = TRUE; - } - } + if (*p == '\n') { if (entries[menu_lines] != NULL) diff --git a/src/util.c b/src/util.c index 9b2e5fc0b..c288118a2 100644 --- a/src/util.c +++ b/src/util.c @@ -1,7 +1,7 @@ /* Various non-library utilities - Copyright (C) 2003-2017 + Copyright (C) 2003-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/cpio/cpio.c b/src/vfs/cpio/cpio.c index ffe6267cf..de55806e7 100644 --- a/src/vfs/cpio/cpio.c +++ b/src/vfs/cpio/cpio.c @@ -1,7 +1,7 @@ /* Virtual File System: GNU Tar file system. - Copyright (C) 2000-2017 + Copyright (C) 2000-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index 82c42593a..aa69b9db0 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -1,7 +1,7 @@ /* Virtual File System: External file system. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index 12ca2f272..d14631565 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -2,7 +2,7 @@ Virtual File System: FISH implementation for transfering files over shell connections. - Copyright (C) 1998-2017 + Copyright (C) 1998-2018 Free Software Foundation, Inc. Written by: @@ -262,30 +262,26 @@ fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len /* --------------------------------------------------------------------------------------------- */ static int -G_GNUC_PRINTF (4, 5) -fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...) +fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *cmd, + size_t cmd_len) { - va_list ap; - char *str; ssize_t status; FILE *logfile = MEDATA->logfile; - va_start (ap, fmt); - str = g_strdup_vprintf (fmt, ap); - va_end (ap); + if (cmd_len == (size_t) (-1)) + cmd_len = strlen (cmd); if (logfile != NULL) { size_t ret; - ret = fwrite (str, strlen (str), 1, logfile); + ret = fwrite (cmd, cmd_len, 1, logfile); ret = fflush (logfile); (void) ret; } tty_enable_interrupt_key (); - status = write (SUP->sockw, str, strlen (str)); - g_free (str); + status = write (SUP->sockw, cmd, cmd_len); tty_disable_interrupt_key (); if (status < 0) @@ -293,20 +289,79 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, c if (wait_reply) return fish_get_reply (me, SUP->sockr, - (wait_reply & WANT_STRING) ? reply_str : + (wait_reply & WANT_STRING) != 0 ? reply_str : NULL, sizeof (reply_str) - 1); return COMPLETE; } /* --------------------------------------------------------------------------------------------- */ +static int +G_GNUC_PRINTF (5, 0) +fish_command_va (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *scr, + const char *vars, va_list ap) +{ + int r; + GString *command; + + command = g_string_new (SUP->scr_env); + g_string_append_vprintf (command, vars, ap); + g_string_append (command, scr); + r = fish_command (me, super, wait_reply, command->str, command->len); + g_string_free (command, TRUE); + + return r; +} + +/* --------------------------------------------------------------------------------------------- */ + +static int +G_GNUC_PRINTF (5, 6) +fish_command_v (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *scr, + const char *vars, ...) +{ + int r; + va_list ap; + + va_start (ap, vars); + r = fish_command_va (me, super, wait_reply, scr, vars, ap); + va_end (ap); + + return r; +} + +/* --------------------------------------------------------------------------------------------- */ + +static int +G_GNUC_PRINTF (5, 6) +fish_send_command (struct vfs_class *me, struct vfs_s_super *super, int flags, const char *scr, + const char *vars, ...) +{ + int r; + va_list ap; + + va_start (ap, vars); + r = fish_command_va (me, super, WAIT_REPLY, scr, vars, ap); + va_end (ap); + vfs_stamp_create (&vfs_fish_ops, super); + + if (r != COMPLETE) + ERRNOR (E_REMOTE, -1); + if ((flags & OPT_FLUSH) != 0) + vfs_s_invalidate (me, super); + + return 0; +} + +/* --------------------------------------------------------------------------------------------- */ + static void fish_free_archive (struct vfs_class *me, struct vfs_s_super *super) { if ((SUP->sockw != -1) || (SUP->sockr != -1)) { vfs_print_message (_("fish: Disconnecting from %s"), super->name ? super->name : "???"); - fish_command (me, super, NONE, "%s", "#BYE\nexit\n"); + fish_command (me, super, NONE, "#BYE\nexit\n", -1); close (SUP->sockw); close (SUP->sockr); SUP->sockw = SUP->sockr = -1; @@ -409,7 +464,7 @@ fish_set_env (int flags) static gboolean fish_info (struct vfs_class *me, struct vfs_s_super *super) { - if (fish_command (me, super, NONE, "%s", SUP->scr_info) == COMPLETE) + if (fish_command (me, super, NONE, SUP->scr_info, -1) == COMPLETE) { while (TRUE) { @@ -551,18 +606,19 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) */ if (fish_command - (me, super, WAIT_REPLY, "%s", - "#FISH\necho; start_fish_server 2>&1; echo '### 200'\n") != COMPLETE) + (me, super, WAIT_REPLY, "#FISH\necho; start_fish_server 2>&1; echo '### 200'\n", + -1) != COMPLETE) ERRNOR (E_PROTO, -1); vfs_print_message ("%s", _("fish: Handshaking version...")); - if (fish_command (me, super, WAIT_REPLY, "%s", "#VER 0.0.3\necho '### 000'\n") != COMPLETE) + if (fish_command (me, super, WAIT_REPLY, "#VER 0.0.3\necho '### 000'\n", -1) != COMPLETE) ERRNOR (E_PROTO, -1); /* Set up remote locale to C, otherwise dates cannot be recognized */ if (fish_command - (me, super, WAIT_REPLY, "%s", - "LANG=C LC_ALL=C LC_TIME=C; export LANG LC_ALL LC_TIME;\n" "echo '### 200'\n") != COMPLETE) + (me, super, WAIT_REPLY, + "LANG=C LC_ALL=C LC_TIME=C; export LANG LC_ALL LC_TIME;\n" "echo '### 200'\n", + -1) != COMPLETE) ERRNOR (E_PROTO, -1); vfs_print_message ("%s", _("fish: Getting host info...")); @@ -678,7 +734,6 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) FILE *logfile; char *quoted_path; int reply_code; - gchar *shell_commands; /* * Simple FISH debug interface :] @@ -693,11 +748,11 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) gettimeofday (&dir->timestamp, NULL); dir->timestamp.tv_sec += fish_directory_timeout; + quoted_path = strutils_shell_escape (remote_path); - shell_commands = g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_ls, (char *) NULL); - fish_command (me, super, NONE, shell_commands, quoted_path); - g_free (shell_commands); + (void) fish_command_v (me, super, NONE, SUP->scr_ls, "FISH_FILENAME=%s;\n", quoted_path); g_free (quoted_path); + ent = vfs_s_generate_entry (me, NULL, dir, 0); while (TRUE) @@ -890,7 +945,6 @@ static int fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char *localname) { fish_fh_data_t *fish = (fish_fh_data_t *) fh->data; - gchar *shell_commands = NULL; struct vfs_s_super *super = FH_SUPER; int code; off_t total = 0; @@ -941,26 +995,9 @@ fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char vfs_print_message (_("fish: store %s: sending command..."), quoted_name); /* FIXME: File size is limited to ULONG_MAX */ - if (fish->append) - { - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILESIZE=%" PRIuMAX ";\n", - SUP->scr_append, (char *) NULL); - - code = fish_command (me, super, WAIT_REPLY, shell_commands, quoted_name, - (uintmax_t) s.st_size); - g_free (shell_commands); - } - else - { - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILESIZE=%" PRIuMAX ";\n", - SUP->scr_send, (char *) NULL); - code = fish_command (me, super, WAIT_REPLY, shell_commands, quoted_name, - (uintmax_t) s.st_size); - g_free (shell_commands); - } - + code = fish_command_v (me, super, WAIT_REPLY, fish->append ? SUP->scr_append : SUP->scr_send, + "FISH_FILENAME=%s FISH_FILESIZE=%" PRIuMAX ";\n", quoted_name, + (uintmax_t) s.st_size); g_free (quoted_name); if (code != PRELIM) @@ -1017,7 +1054,6 @@ static int fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset) { fish_fh_data_t *fish; - gchar *shell_commands = NULL; struct vfs_s_super *super = FH_SUPER; char *name; char *quoted_name; @@ -1041,12 +1077,12 @@ fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset) * standard output (i.e. over the network). */ - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_START_OFFSET=%" PRIuMAX ";\n", - SUP->scr_get, (char *) NULL); - offset = fish_command (me, super, WANT_STRING, shell_commands, quoted_name, (uintmax_t) offset); - g_free (shell_commands); + offset = + fish_command_v (me, super, WANT_STRING, SUP->scr_get, + "FISH_FILENAME=%s FISH_START_OFFSET=%" PRIuMAX ";\n", quoted_name, + (uintmax_t) offset); g_free (quoted_name); + if (offset != PRELIM) ERRNOR (E_REMOTE, 0); fh->linear = LS_LINEAR_OPEN; @@ -1150,7 +1186,7 @@ fish_ctl (void *fh, int ctlop, void *arg) { int v; - if (FH->linear == 0) + if (FH->linear == LS_NOT_LINEAR) vfs_die ("You may not do this"); if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN) return 0; @@ -1167,31 +1203,14 @@ fish_ctl (void *fh, int ctlop, void *arg) /* --------------------------------------------------------------------------------------------- */ -static int -fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *cmd, int flags) -{ - int r; - - r = fish_command (me, super, WAIT_REPLY, "%s", cmd); - vfs_stamp_create (&vfs_fish_ops, super); - if (r != COMPLETE) - ERRNOR (E_REMOTE, -1); - if ((flags & OPT_FLUSH) != 0) - vfs_s_invalidate (me, super); - return 0; -} - -/* --------------------------------------------------------------------------------------------- */ - static int fish_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2) { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath1, *crpath2; char *rpath1, *rpath2; struct vfs_s_super *super, *super2; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath1, -1); @@ -1205,13 +1224,15 @@ fish_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2) rpath1 = strutils_shell_escape (crpath1); rpath2 = strutils_shell_escape (crpath2); - shell_commands = g_strconcat (SUP->scr_env, "FISH_FILEFROM=%s FISH_FILETO=%s;\n", - SUP->scr_mv, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath1, rpath2); - g_free (shell_commands); + + ret = + fish_send_command (path_element->class, super2, OPT_FLUSH, SUP->scr_mv, + "FISH_FILEFROM=%s FISH_FILETO=%s;\n", rpath1, rpath2); + g_free (rpath1); g_free (rpath2); - return fish_send_command (path_element->class, super2, buf, OPT_FLUSH); + + return ret; } /* --------------------------------------------------------------------------------------------- */ @@ -1219,12 +1240,11 @@ fish_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2) static int fish_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2) { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath1, *crpath2; char *rpath1, *rpath2; struct vfs_s_super *super, *super2; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath1, -1); @@ -1238,15 +1258,16 @@ fish_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2) rpath1 = strutils_shell_escape (crpath1); rpath2 = strutils_shell_escape (crpath2); - shell_commands = g_strconcat (SUP->scr_env, "FISH_FILEFROM=%s FISH_FILETO=%s;\n", - SUP->scr_hardlink, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath1, rpath2); - g_free (shell_commands); + + ret = + fish_send_command (path_element->class, super2, OPT_FLUSH, SUP->scr_hardlink, + "FISH_FILEFROM=%s FISH_FILETO=%s;\n", rpath1, rpath2); + g_free (rpath1); g_free (rpath2); - return fish_send_command (path_element->class, super2, buf, OPT_FLUSH); -} + return ret; +} /* --------------------------------------------------------------------------------------------- */ @@ -1254,12 +1275,11 @@ static int fish_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2) { char *qsetto; - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath; char *rpath; struct vfs_s_super *super; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath2, -1); @@ -1270,13 +1290,14 @@ fish_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2) rpath = strutils_shell_escape (crpath); qsetto = strutils_shell_escape (vfs_path_get_by_index (vpath1, -1)->path); - shell_commands = g_strconcat (SUP->scr_env, "FISH_FILEFROM=%s FISH_FILETO=%s;\n", - SUP->scr_ln, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, qsetto, rpath); - g_free (shell_commands); + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_ln, + "FISH_FILEFROM=%s FISH_FILETO=%s;\n", qsetto, rpath); + g_free (qsetto); g_free (rpath); - return fish_send_command (path_element->class, super, buf, OPT_FLUSH); + + return ret; } /* --------------------------------------------------------------------------------------------- */ @@ -1320,26 +1341,27 @@ fish_fstat (void *vfs_info, struct stat *buf) static int fish_chmod (const vfs_path_t * vpath, mode_t mode) { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath; char *rpath; struct vfs_s_super *super; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath, -1); crpath = vfs_s_get_path (vpath, &super, 0); if (crpath == NULL) return -1; + rpath = strutils_shell_escape (crpath); - shell_commands = g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n", - SUP->scr_chmod, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath, (int) (mode & 07777)); - g_free (shell_commands); + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_chmod, + "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n", rpath, (int) (mode & 07777)); + g_free (rpath); - return fish_send_command (path_element->class, super, buf, OPT_FLUSH); + + return ret;; } /* --------------------------------------------------------------------------------------------- */ @@ -1350,6 +1372,11 @@ fish_chown (const vfs_path_t * vpath, uid_t owner, gid_t group) char *sowner, *sgroup; struct passwd *pw; struct group *gr; + const char *crpath; + char *rpath; + struct vfs_s_super *super; + const vfs_path_element_t *path_element; + int ret; pw = getpwuid (owner); if (pw == NULL) @@ -1362,32 +1389,23 @@ fish_chown (const vfs_path_t * vpath, uid_t owner, gid_t group) sowner = pw->pw_name; sgroup = gr->gr_name; - { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; - const char *crpath; - char *rpath; - struct vfs_s_super *super; - const vfs_path_element_t *path_element; + path_element = vfs_path_get_by_index (vpath, -1); - path_element = vfs_path_get_by_index (vpath, -1); + crpath = vfs_s_get_path (vpath, &super, 0); + if (crpath == NULL) + return -1; - crpath = vfs_s_get_path (vpath, &super, 0); - if (crpath == NULL) - return -1; - rpath = strutils_shell_escape (crpath); + rpath = strutils_shell_escape (crpath); - shell_commands = g_strconcat (SUP->scr_env, - "FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n", - SUP->scr_chown, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath, sowner, sgroup); - g_free (shell_commands); - fish_send_command (path_element->class, super, buf, OPT_FLUSH); - /* FIXME: what should we report if chgrp succeeds but chown fails? */ - /* fish_send_command(me, super, buf, OPT_FLUSH); */ - g_free (rpath); - return fish_send_command (path_element->class, super, buf, OPT_FLUSH); - } + /* FIXME: what should we report if chgrp succeeds but chown fails? */ + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_chown, + "FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n", rpath, sowner, + sgroup); + + g_free (rpath); + + return ret; } /* --------------------------------------------------------------------------------------------- */ @@ -1423,13 +1441,11 @@ fish_get_mtime (mc_timesbuf_t * times, time_t * sec, long *nsec) static int fish_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) { - gchar *shell_commands = NULL; char utcatime[16], utcmtime[16]; char utcatime_w_nsec[30], utcmtime_w_nsec[30]; time_t atime, mtime; long atime_nsec, mtime_nsec; struct tm *gmt; - char *cmd; const char *crpath; char *rpath; struct vfs_s_super *super; @@ -1441,6 +1457,7 @@ fish_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) crpath = vfs_s_get_path (vpath, &super, 0); if (crpath == NULL) return -1; + rpath = strutils_shell_escape (crpath); fish_get_atime (times, &atime, &atime_nsec); @@ -1461,18 +1478,13 @@ fish_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday, gmt->tm_hour, gmt->tm_min, gmt->tm_sec, mtime_nsec); - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILEATIME=%ld FISH_FILEMTIME=%ld ", - "FISH_TOUCHATIME=%s FISH_TOUCHMTIME=%s ", - "FISH_TOUCHATIME_W_NSEC=\"%s\" FISH_TOUCHMTIME_W_NSEC=\"%s\";\n", - SUP->scr_utime, (char *) NULL); - cmd = - g_strdup_printf (shell_commands, rpath, (long) atime, (long) mtime, utcatime, utcmtime, - utcatime_w_nsec, utcmtime_w_nsec); - g_free (shell_commands); + ret = fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_utime, + "FISH_FILENAME=%s FISH_FILEATIME=%ld FISH_FILEMTIME=%ld " + "FISH_TOUCHATIME=%s FISH_TOUCHMTIME=%s FISH_TOUCHATIME_W_NSEC=\"%s\" " + "FISH_TOUCHMTIME_W_NSEC=\"%s\";\n", rpath, (long) atime, (long) mtime, + utcatime, utcmtime, utcatime_w_nsec, utcmtime_w_nsec); + g_free (rpath); - ret = fish_send_command (path_element->class, super, cmd, OPT_FLUSH); - g_free (cmd); return ret; } @@ -1482,26 +1494,27 @@ fish_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) static int fish_unlink (const vfs_path_t * vpath) { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath; char *rpath; struct vfs_s_super *super; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath, -1); crpath = vfs_s_get_path (vpath, &super, 0); if (crpath == NULL) return -1; + rpath = strutils_shell_escape (crpath); - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_unlink, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath); - g_free (shell_commands); + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_unlink, + "FISH_FILENAME=%s;\n", rpath); + g_free (rpath); - return fish_send_command (path_element->class, super, buf, OPT_FLUSH); + + return ret; } /* --------------------------------------------------------------------------------------------- */ @@ -1509,27 +1522,27 @@ fish_unlink (const vfs_path_t * vpath) static int fish_exists (const vfs_path_t * vpath) { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath; char *rpath; struct vfs_s_super *super; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath, -1); crpath = vfs_s_get_path (vpath, &super, 0); if (crpath == NULL) return -1; + rpath = strutils_shell_escape (crpath); - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_exists, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath); - g_free (shell_commands); + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_exists, + "FISH_FILENAME=%s;\n", rpath); + g_free (rpath); - return (fish_send_command (path_element->class, super, buf, OPT_FLUSH) == 0) ? 1 : 0; + return (ret == 0 ? 1 : 0); } /* --------------------------------------------------------------------------------------------- */ @@ -1537,13 +1550,11 @@ fish_exists (const vfs_path_t * vpath) static int fish_mkdir (const vfs_path_t * vpath, mode_t mode) { - gchar *shell_commands = NULL; - int ret_code; - char buf[BUF_LARGE]; const char *crpath; char *rpath; struct vfs_s_super *super; const vfs_path_element_t *path_element; + int ret; (void) mode; @@ -1552,18 +1563,16 @@ fish_mkdir (const vfs_path_t * vpath, mode_t mode) crpath = vfs_s_get_path (vpath, &super, 0); if (crpath == NULL) return -1; + rpath = strutils_shell_escape (crpath); - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_mkdir, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath); - g_free (shell_commands); - + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_mkdir, + "FISH_FILENAME=%s;\n", rpath); g_free (rpath); - ret_code = fish_send_command (path_element->class, super, buf, OPT_FLUSH); - if (ret_code != 0) - return ret_code; + if (ret != 0) + return ret; if (fish_exists (vpath) == 0) { @@ -1578,26 +1587,27 @@ fish_mkdir (const vfs_path_t * vpath, mode_t mode) static int fish_rmdir (const vfs_path_t * vpath) { - gchar *shell_commands = NULL; - char buf[BUF_LARGE]; const char *crpath; char *rpath; struct vfs_s_super *super; const vfs_path_element_t *path_element; + int ret; path_element = vfs_path_get_by_index (vpath, -1); crpath = vfs_s_get_path (vpath, &super, 0); if (crpath == NULL) return -1; + rpath = strutils_shell_escape (crpath); - shell_commands = - g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_rmdir, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath); - g_free (shell_commands); + ret = + fish_send_command (path_element->class, super, OPT_FLUSH, SUP->scr_rmdir, + "FISH_FILENAME=%s;\n", rpath); + g_free (rpath); - return fish_send_command (path_element->class, super, buf, OPT_FLUSH); + + return ret; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/fish/helpers/ls b/src/vfs/fish/helpers/ls index 909a77d72..7165b51f8 100644 --- a/src/vfs/fish/helpers/ls +++ b/src/vfs/fish/helpers/ls @@ -130,20 +130,20 @@ my $dirname = $ARGV[0]; if (opendir (DIR, $dirname)) { while((my $filename = readdir (DIR))){ my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat("$dirname/$filename"); - my $mloctime= strftime("%%m-%%d-%%Y %%H:%%M", localtime $mtime); + my $mloctime= strftime("%m-%d-%Y %H:%M", localtime $mtime); my $strutils_shell_escape_regex = s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'\''"\ \\])/\\$1/g; my $e_filename = $filename; $e_filename =~ $strutils_shell_escape_regex; if (S_ISLNK ($mode)) { my $linkname = readlink ("$dirname/$filename"); $linkname =~ $strutils_shell_escape_regex; - printf("R%%o %%o $uid.$gid\nS$size\nd$mloctime\n:\"%%s\" -> \"%%s\"\n\n", S_IMODE($mode), S_IFMT($mode), $e_filename, $linkname); + printf("R%o %o $uid.$gid\nS$size\nd$mloctime\n:\"%s\" -> \"%s\"\n\n", S_IMODE($mode), S_IFMT($mode), $e_filename, $linkname); } elsif (S_ISCHR ($mode) || S_ISBLK ($mode)) { - my $minor = $rdev %% 256; + my $minor = $rdev % 256; my $major = int( $rdev / 256 ); - printf("R%%o %%o $uid.$gid\nE$major,$minor\nd$mloctime\n:\"%%s\"\n\n", S_IMODE($mode), S_IFMT($mode), $e_filename); + printf("R%o %o $uid.$gid\nE$major,$minor\nd$mloctime\n:\"%s\"\n\n", S_IMODE($mode), S_IFMT($mode), $e_filename); } else { - printf("R%%o %%o $uid.$gid\nS$size\nd$mloctime\n:\"%%s\"\n\n", S_IMODE($mode), S_IFMT($mode), $e_filename); + printf("R%o %o $uid.$gid\nS$size\nd$mloctime\n:\"%s\"\n\n", S_IMODE($mode), S_IFMT($mode), $e_filename); } } printf("### 200\n"); diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index a6ebc05b9..7f5926471 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -1,7 +1,7 @@ /* Virtual File System: FTP file system. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: @@ -96,6 +96,7 @@ What to do with this? #include "lib/global.h" #include "lib/util.h" +#include "lib/strutil.h" /* str_move() */ #include "lib/mcconfig.h" #include "lib/tty/tty.h" /* enable/disable interrupt key */ @@ -327,7 +328,7 @@ ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const cha /* replace first occurrence of ":/" with ":" */ p = strchr (ret, ':'); if (p != NULL && IS_PATH_SEP (p[1])) - memmove (p + 1, p + 2, strlen (p + 2) + 1); + str_move (p + 1, p + 2); /* strip trailing "/." */ p = strrchr (ret, PATH_SEP); @@ -477,30 +478,26 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, ...) { va_list ap; - char *cmdstr; - int status, cmdlen; + GString *cmdstr; + int status; static int retry = 0; static int level = 0; /* ftpfs_login_server() use ftpfs_command() */ + cmdstr = g_string_sized_new (32); va_start (ap, fmt); - cmdstr = g_strdup_vprintf (fmt, ap); + g_string_vprintf (cmdstr, fmt, ap); va_end (ap); + g_string_append (cmdstr, "\r\n"); - cmdlen = strlen (cmdstr); - cmdstr = g_realloc (cmdstr, cmdlen + 3); - strcpy (cmdstr + cmdlen, "\r\n"); - cmdlen += 2; - - if (MEDATA->logfile) + if (MEDATA->logfile != NULL) { - if (strncmp (cmdstr, "PASS ", 5) == 0) - { + if (strncmp (cmdstr->str, "PASS ", 5) == 0) fputs ("PASS \r\n", MEDATA->logfile); - } else { size_t ret; - ret = fwrite (cmdstr, cmdlen, 1, MEDATA->logfile); + + ret = fwrite (cmdstr->str, cmdstr->len, 1, MEDATA->logfile); (void) ret; } @@ -509,7 +506,7 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, got_sigpipe = 0; tty_enable_interrupt_key (); - status = write (SUP->sock, cmdstr, cmdlen); + status = write (SUP->sock, cmdstr->str, cmdstr->len); if (status < 0) { @@ -522,15 +519,13 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, level = 1; status = ftpfs_reconnect (me, super); level = 0; - if (status && (write (SUP->sock, cmdstr, cmdlen) > 0)) - { + if (status && (write (SUP->sock, cmdstr->str, cmdstr->len) > 0)) goto ok; - } } got_sigpipe = 1; } - g_free (cmdstr); + g_string_free (cmdstr, TRUE); tty_disable_interrupt_key (); return TRANSIENT; } @@ -549,16 +544,15 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, level = 1; status = ftpfs_reconnect (me, super); level = 0; - if (status && (write (SUP->sock, cmdstr, cmdlen) > 0)) - { + if (status && (write (SUP->sock, cmdstr->str, cmdstr->len) > 0)) goto ok; - } } retry = 0; - g_free (cmdstr); + g_string_free (cmdstr, TRUE); return status; } - g_free (cmdstr); + + g_string_free (cmdstr, TRUE); return COMPLETE; } @@ -570,7 +564,7 @@ ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super) if (SUP->sock != -1) { vfs_print_message (_("ftpfs: Disconnecting from %s"), super->path_element->host); - ftpfs_command (me, super, NONE, "QUIT"); + ftpfs_command (me, super, NONE, "%s", "QUIT"); close (SUP->sock); } g_free (SUP->current_dir); @@ -687,7 +681,7 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char } if (code != COMPLETE) break; - /* fall through */ + MC_FALLTHROUGH; case COMPLETE: vfs_print_message ("%s", _("ftpfs: logged in")); @@ -1052,7 +1046,7 @@ ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super) { char buf[MC_MAXPATHLEN + 1]; - if (ftpfs_command (me, super, NONE, "PWD") == COMPLETE && + if (ftpfs_command (me, super, NONE, "%s", "PWD") == COMPLETE && ftpfs_get_reply (me, SUP->sock, buf, sizeof (buf)) == COMPLETE) { char *bufp = NULL; @@ -1104,7 +1098,7 @@ ftpfs_setup_passive_pasv (struct vfs_class *me, struct vfs_s_super *super, char n[6]; int xa, xb, xc, xd, xe, xf; - if (ftpfs_command (me, super, WAIT_REPLY | WANT_STRING, "PASV") != COMPLETE) + if (ftpfs_command (me, super, WAIT_REPLY | WANT_STRING, "%s", "PASV") != COMPLETE) return 0; /* Parse remote parameters */ @@ -1144,7 +1138,7 @@ ftpfs_setup_passive_epsv (struct vfs_class *me, struct vfs_s_super *super, char *c; int port; - if (ftpfs_command (me, super, WAIT_REPLY | WANT_STRING, "EPSV") != COMPLETE) + if (ftpfs_command (me, super, WAIT_REPLY | WANT_STRING, "%s", "EPSV") != COMPLETE) return 0; /* (||||) */ @@ -1996,7 +1990,7 @@ ftpfs_ctl (void *fh, int ctlop, void *arg) { int v; - if (!FH->linear) + if (FH->linear == LS_NOT_LINEAR) vfs_die ("You may not do this"); if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN) return 0; diff --git a/src/vfs/local/local.c b/src/vfs/local/local.c index 2f55d3dbf..bab279ec6 100644 --- a/src/vfs/local/local.c +++ b/src/vfs/local/local.c @@ -1,7 +1,7 @@ /* Virtual File System: local file system. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/plugins_init.c b/src/vfs/plugins_init.c index 7cde8a61c..a75dec441 100644 --- a/src/vfs/plugins_init.c +++ b/src/vfs/plugins_init.c @@ -1,7 +1,7 @@ /* Init VFS plugins. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index 3447482af..57d3ad52b 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -1,7 +1,7 @@ /* Single File fileSystem - Copyright (C) 1998-2017 + Copyright (C) 1998-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/config_parser.c b/src/vfs/sftpfs/config_parser.c index 5e6d06036..ff2547165 100644 --- a/src/vfs/sftpfs/config_parser.c +++ b/src/vfs/sftpfs/config_parser.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The SSH config parser - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/connection.c b/src/vfs/sftpfs/connection.c index 75b13ed0f..537159129 100644 --- a/src/vfs/sftpfs/connection.c +++ b/src/vfs/sftpfs/connection.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The internal functions: connections - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/dir.c b/src/vfs/sftpfs/dir.c index d3b4d59e9..367ab6725 100644 --- a/src/vfs/sftpfs/dir.c +++ b/src/vfs/sftpfs/dir.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The internal functions: dirs - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/file.c b/src/vfs/sftpfs/file.c index b4b15c579..76c64d077 100644 --- a/src/vfs/sftpfs/file.c +++ b/src/vfs/sftpfs/file.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The internal functions: files - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/init.c b/src/vfs/sftpfs/init.c index 0298be4a9..af7d97f9d 100644 --- a/src/vfs/sftpfs/init.c +++ b/src/vfs/sftpfs/init.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The interface function - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/internal.c b/src/vfs/sftpfs/internal.c index c79435821..443126e95 100644 --- a/src/vfs/sftpfs/internal.c +++ b/src/vfs/sftpfs/internal.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The internal functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/sftpfs/vfs_class.c b/src/vfs/sftpfs/vfs_class.c index f1f3f03c0..897f21c60 100644 --- a/src/vfs/sftpfs/vfs_class.c +++ b/src/vfs/sftpfs/vfs_class.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The VFS class functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: @@ -150,7 +150,7 @@ sftpfs_cb_open (const vfs_path_t * vpath, int flags, mode_t mode) file_handler->ino = path_inode; file_handler->handle = -1; file_handler->changed = is_changed; - file_handler->linear = 0; + file_handler->linear = LS_NOT_LINEAR; file_handler->data = NULL; if (!sftpfs_open_file (file_handler, flags, mode, &mcerror)) diff --git a/src/vfs/sftpfs/vfs_subclass.c b/src/vfs/sftpfs/vfs_subclass.c index bbfa98905..5cc5bbcca 100644 --- a/src/vfs/sftpfs/vfs_subclass.c +++ b/src/vfs/sftpfs/vfs_subclass.c @@ -1,7 +1,7 @@ /* Virtual File System: SFTP file system. The VFS subclass functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/smbfs/helpers/lib/charcnv.c b/src/vfs/smbfs/helpers/lib/charcnv.c index 9e604de95..9fcc1a00f 100644 --- a/src/vfs/smbfs/helpers/lib/charcnv.c +++ b/src/vfs/smbfs/helpers/lib/charcnv.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/charset.c b/src/vfs/smbfs/helpers/lib/charset.c index ce02106fe..4450a8ca0 100644 --- a/src/vfs/smbfs/helpers/lib/charset.c +++ b/src/vfs/smbfs/helpers/lib/charset.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/debug.c b/src/vfs/smbfs/helpers/lib/debug.c index a51723d5b..4b5c22731 100644 --- a/src/vfs/smbfs/helpers/lib/debug.c +++ b/src/vfs/smbfs/helpers/lib/debug.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/interface.c b/src/vfs/smbfs/helpers/lib/interface.c index fb94328fa..936941b53 100644 --- a/src/vfs/smbfs/helpers/lib/interface.c +++ b/src/vfs/smbfs/helpers/lib/interface.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -258,7 +258,7 @@ load_interfaces (void) interpret_interfaces (lp_interfaces (), &local_interfaces, "interface"); } - +#if 0 /**************************************************************************** override the defaults **************************************************************************/ @@ -283,7 +283,7 @@ iface_set_default (char *ip, char *bcast, char *nmask) default_nmask = *interpret_addr2 (nmask); } } - +#endif /* 0 */ /**************************************************************************** check if an IP is one of mine @@ -298,6 +298,7 @@ ismyip (struct in_addr ip) return False; } +#if 0 /**************************************************************************** check if a packet is from a local (known) net **************************************************************************/ @@ -310,6 +311,7 @@ is_local_net (struct in_addr from) return True; return False; } +#endif /* 0 */ /**************************************************************************** how many interfaces do we have @@ -325,6 +327,7 @@ iface_count (void) return ret; } +#if 0 /**************************************************************************** True if we have two or more interfaces. **************************************************************************/ @@ -354,7 +357,7 @@ get_interface (int n) return i; return NULL; } - +#endif /* 0 */ /**************************************************************************** return IP of the Nth interface **************************************************************************/ @@ -388,7 +391,7 @@ iface_find (struct in_addr ip) return NULL; } - +#if 0 /**************************************************************************** this function provides a simple hash of the configured interfaces. It is used to detect a change in interfaces to tell us whether to discard @@ -410,7 +413,7 @@ iface_hash (void) return ret; } - +#endif /* 0 */ /* these 3 functions return the ip/bcast/nmask for the interface most appropriate for the given ip address. If they can't find diff --git a/src/vfs/smbfs/helpers/lib/kanji.c b/src/vfs/smbfs/helpers/lib/kanji.c index 7e567ddf7..5bf27f937 100644 --- a/src/vfs/smbfs/helpers/lib/kanji.c +++ b/src/vfs/smbfs/helpers/lib/kanji.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Adding for Japanese language by 1994.9.5 diff --git a/src/vfs/smbfs/helpers/lib/md4.c b/src/vfs/smbfs/helpers/lib/md4.c index 26b70da3d..b4ebc9e1b 100644 --- a/src/vfs/smbfs/helpers/lib/md4.c +++ b/src/vfs/smbfs/helpers/lib/md4.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1997-1998. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/netmask.c b/src/vfs/smbfs/helpers/lib/netmask.c index 8d410ef9e..fe6c39e54 100644 --- a/src/vfs/smbfs/helpers/lib/netmask.c +++ b/src/vfs/smbfs/helpers/lib/netmask.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/slprintf.c b/src/vfs/smbfs/helpers/lib/slprintf.c index b154c1614..3243099c0 100644 --- a/src/vfs/smbfs/helpers/lib/slprintf.c +++ b/src/vfs/smbfs/helpers/lib/slprintf.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/system.c b/src/vfs/smbfs/helpers/lib/system.c index af6667d33..9dfd7fe6b 100644 --- a/src/vfs/smbfs/helpers/lib/system.c +++ b/src/vfs/smbfs/helpers/lib/system.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -103,7 +103,6 @@ sys_select (int maxfd, fd_set * fds, struct timeval *tval) #else /* !NO_SELECT */ int sys_select (int maxfd, fd_set * fds, struct timeval *tval) -/* cppcheck-suppress syntaxError */ { #ifdef USE_POLL struct pollfd pfd[256]; @@ -154,8 +153,8 @@ sys_select (int maxfd, fd_set * fds, struct timeval *tval) while (selrtn < 0 && errno == EINTR); return (selrtn); -} #endif /* USE_POLL */ +} #endif /* NO_SELECT */ /******************************************************************* @@ -197,7 +196,7 @@ sys_ftell (FILE * fp) { return (SMB_OFF_T) ftell (fp); } -#endif /* 0 */ + /******************************************************************* An open() wrapper that will deal with 64 bit filesizes. ********************************************************************/ @@ -211,6 +210,7 @@ sys_open (const char *path, int oflag, mode_t mode) /******************************************************************* An fopen() wrapper that will deal with 64 bit filesizes. ********************************************************************/ +#endif /* 0 */ FILE * sys_fopen (const char *path, const char *type) @@ -304,38 +304,3 @@ sys_gethostbyname (const char *name) return (gethostbyname (name)); #endif /* REDUCE_ROOT_DNS_LOOKUPS */ } - -/************************************************************************** - Wrapper for random(). -****************************************************************************/ -#if 0 -long -sys_random (void) -{ -#if defined(HAVE_RANDOM) - return (long) random (); -#elif defined(HAVE_RAND) - return (long) rand (); -#else - DEBUG (0, ("Error - no random function available !\n")); - exit (1); -#endif -} - -/************************************************************************** - Wrapper for srandom(). -****************************************************************************/ - -void -sys_srandom (unsigned int seed) -{ -#if defined(HAVE_SRANDOM) - srandom (seed); -#elif defined(HAVE_SRAND) - srand (seed); -#else - DEBUG (0, ("Error - no srandom function available !\n")); - exit (1); -#endif -} -#endif /* 0 */ diff --git a/src/vfs/smbfs/helpers/lib/time.c b/src/vfs/smbfs/helpers/lib/time.c index 9cc71dc26..f6de46b5e 100644 --- a/src/vfs/smbfs/helpers/lib/time.c +++ b/src/vfs/smbfs/helpers/lib/time.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -424,6 +424,7 @@ put_dos_date (char *buf, int offset, time_t unixdate) SIVAL (buf, offset, x); } +#if 0 /******************************************************************* put a dos date into a buffer (date/time format) This takes GMT time and puts local time in the buffer @@ -435,6 +436,7 @@ put_dos_date2 (char *buf, int offset, time_t unixdate) x = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16); SIVAL (buf, offset, x); } +#endif /* 0 */ /******************************************************************* put a dos 32 bit "unix like" date into a buffer. This routine takes diff --git a/src/vfs/smbfs/helpers/lib/username.c b/src/vfs/smbfs/helpers/lib/username.c index a378d6d0a..8bfb7ee5b 100644 --- a/src/vfs/smbfs/helpers/lib/username.c +++ b/src/vfs/smbfs/helpers/lib/username.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/util.c b/src/vfs/smbfs/helpers/lib/util.c index 28eb19a7d..97afceb52 100644 --- a/src/vfs/smbfs/helpers/lib/util.c +++ b/src/vfs/smbfs/helpers/lib/util.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -59,8 +59,6 @@ #ifdef WITH_SSL #include #undef Realloc /* SSLeay defines this and samba has a function of this name */ -extern SSL *ssl; -extern int sslFd; #endif /* WITH_SSL */ extern int DEBUGLEVEL; @@ -76,9 +74,6 @@ extern int Client; /* this is used by the chaining code */ const int chain_size = 0; -#if 0 -int trans_num = 0; -#endif /*0 */ /* case handling on filenames @@ -105,7 +100,7 @@ static const char *remote_proto = "UNKNOWN"; pstring myhostname = ""; pstring user_socket_options = ""; -pstring sesssetup_user = ""; +static const char sesssetup_user[] = ""; static const char *const samlogon_user = ""; const BOOL sam_logon_in_ssb = False; @@ -342,7 +337,7 @@ name_mangle (char *In, char *Out, char name_type) p[0] = '\0'; /* Add the scope string. */ - for (i = 0, len = 0; NULL != global_scope; i++, len++) + for (i = 0, len = 0;; i++, len++) { switch (global_scope[i]) { @@ -437,22 +432,25 @@ return a string representing an attribute for a file char * attrib_string (uint16 mode) { - static fstring attrstr; + static char attrstr[7]; + int i = 0; attrstr[0] = 0; if (mode & aVOLID) - fstrcat (attrstr, "V"); + attrstr[i++] = 'V'; if (mode & aDIR) - fstrcat (attrstr, "D"); + attrstr[i++] = 'D'; if (mode & aARCH) - fstrcat (attrstr, "A"); + attrstr[i++] = 'A'; if (mode & aHIDDEN) - fstrcat (attrstr, "H"); + attrstr[i++] = 'H'; if (mode & aSYSTEM) - fstrcat (attrstr, "S"); + attrstr[i++] = 'S'; if (mode & aRONLY) - fstrcat (attrstr, "R"); + attrstr[i++] = 'R'; + + attrstr[i] = 0; return (attrstr); } @@ -2498,7 +2496,7 @@ Get_Hostbyname (const char *name) return (NULL); } - +#if 0 /******************************************************************* turn a uid into a user name ********************************************************************/ @@ -2512,7 +2510,7 @@ uidtoname (uid_t uid) slprintf (name, sizeof (name) - 1, "%d", (int) uid); return (name); } - +#endif /* 0 */ /******************************************************************* turn a gid into a group name @@ -2529,6 +2527,7 @@ gidtoname (gid_t gid) return (name); } +#if 0 /******************************************************************* turn a user name into a uid ********************************************************************/ @@ -2540,7 +2539,7 @@ nametouid (const char *name) return (pass->pw_uid); return (uid_t) - 1; } - +#endif /* 0 */ /******************************************************************* something really nasty happened - panic! ********************************************************************/ @@ -2769,121 +2768,6 @@ free_namearray (name_compare_entry * name_array) free ((char *) name_array); } -/**************************************************************************** -routine to do file locking -****************************************************************************/ -BOOL -fcntl_lock (int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) -{ -#ifdef HAVE_FCNTL_LOCK - SMB_STRUCT_FLOCK lock; - int ret; - - if (lp_ole_locking_compat ()) - { - SMB_OFF_T mask2 = ((SMB_OFF_T) 0x3) << (SMB_OFF_T_BITS - 4); - SMB_OFF_T mask = (mask2 << 2); - - /* make sure the count is reasonable, we might kill the lockd otherwise */ - count &= ~mask; - - /* the offset is often strange - remove 2 of its bits if either of - the top two bits are set. Shift the top ones by two bits. This - still allows OLE2 apps to operate, but should stop lockd from - dieing */ - if ((offset & mask) != 0) - offset = (offset & ~mask) | (((offset & mask) >> 2) & mask2); - } - else - { - SMB_OFF_T mask2 = ((SMB_OFF_T) 0x4) << (SMB_OFF_T_BITS - 4); - SMB_OFF_T mask = (mask2 << 1); - SMB_OFF_T neg_mask = ~mask; - - /* interpret negative counts as large numbers */ - if (count < 0) - count &= ~mask; - - /* no negative offsets */ - if (offset < 0) - offset &= ~mask; - - /* count + offset must be in range */ - while ((offset < 0 || (offset + count < 0)) && mask) - { - offset &= ~mask; - mask = ((mask >> 1) & neg_mask); - } - } - - DEBUG (8, ("fcntl_lock %d %d %.0f %.0f %d\n", fd, op, (double) offset, (double) count, type)); - - lock.l_type = type; - lock.l_whence = SEEK_SET; - lock.l_start = offset; - lock.l_len = count; - lock.l_pid = 0; - - errno = 0; - - ret = fcntl (fd, op, &lock); - if (errno == EFBIG) - { - if (DEBUGLVL (0)) - { - dbgtext ("fcntl_lock: WARNING: lock request at offset %.0f, length %.0f returned\n", - (double) offset, (double) count); - dbgtext ("a 'file too large' error. This can happen when using 64 bit lock offsets\n"); - dbgtext - ("on 32 bit NFS mounted file systems. Retrying with 32 bit truncated length.\n"); - } - /* 32 bit NFS file system, retry with smaller offset */ - errno = 0; - lock.l_len = count & 0xffffffff; - ret = fcntl (fd, op, &lock); - } - - if (errno != 0) - DEBUG (3, ("fcntl lock gave errno %d (%s)\n", errno, unix_error_string (errno))); - - /* a lock query */ - if (op == SMB_F_GETLK) - { - if ((ret != -1) && - (lock.l_type != F_UNLCK) && (lock.l_pid != 0) && (lock.l_pid != getpid ())) - { - DEBUG (3, ("fd %d is locked by pid %d\n", fd, (int) lock.l_pid)); - return (True); - } - - /* it must be not locked or locked by me */ - return (False); - } - - /* a lock set or unset */ - if (ret == -1) - { - DEBUG (3, ("lock failed at offset %.0f count %.0f op %d type %d (%s)\n", - (double) offset, (double) count, op, type, unix_error_string (errno))); - - /* perhaps it doesn't support this sort of locking?? */ - if (errno == EINVAL) - { - DEBUG (3, ("locking not supported? returning True\n")); - return (True); - } - - return (False); - } - - /* everything went OK */ - DEBUG (8, ("Lock call successful\n")); - - return (True); -#else - return (False); -#endif -} /******************************************************************* is the name specified one of my netbios names @@ -3073,6 +2957,7 @@ dump_data (int level, char *buf1, int len) } } +#if 0 /***************************************************************************** * Provide a checksum on a string * @@ -3101,8 +2986,6 @@ str_checksum (const char *s) } /* str_checksum */ - -#if 0 /***************************************************************** zero a memory area then free it. Used to catch bugs faster *****************************************************************/ @@ -3112,67 +2995,4 @@ zero_free (void *p, size_t size) memset (p, 0, size); free (p); } - - -/***************************************************************** -set our open file limit to a requested max and return the limit -*****************************************************************/ -int -set_maxfiles (int requested_max) -{ -#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)) - struct rlimit rlp; - int saved_current_limit; - - if (getrlimit (RLIMIT_NOFILE, &rlp)) - { - DEBUG (0, ("set_maxfiles: getrlimit (1) for RLIMIT_NOFILE failed with error %s\n", - unix_error_string (errno))); - /* just guess... */ - return requested_max; - } - - /* - * Set the fd limit to be real_max_open_files + MAX_OPEN_FUDGEFACTOR to - * account for the extra fd we need - * as well as the log files and standard - * handles etc. Save the limit we want to set in case - * we are running on an OS that doesn't support this limit (AIX) - * which always returns RLIM_INFINITY for rlp.rlim_max. - */ - - saved_current_limit = rlp.rlim_cur = MIN (requested_max, rlp.rlim_max); - - if (setrlimit (RLIMIT_NOFILE, &rlp)) - { - DEBUG (0, ("set_maxfiles: setrlimit for RLIMIT_NOFILE for %d files failed with error %s\n", - (int) rlp.rlim_cur, unix_error_string (errno))); - /* just guess... */ - return saved_current_limit; - } - - if (getrlimit (RLIMIT_NOFILE, &rlp)) - { - DEBUG (0, ("set_maxfiles: getrlimit (2) for RLIMIT_NOFILE failed with error %s\n", - unix_error_string (errno))); - /* just guess... */ - return saved_current_limit; - } - -#if defined(RLIM_INFINITY) - if (rlp.rlim_cur == RLIM_INFINITY) - return saved_current_limit; -#endif - - if ((int) rlp.rlim_cur > saved_current_limit) - return saved_current_limit; - - return rlp.rlim_cur; -#else /* !defined(HAVE_GETRLIMIT) || !defined(RLIMIT_NOFILE) */ - /* - * No way to know - just guess... - */ - return requested_max; -#endif -} #endif /* 0 */ diff --git a/src/vfs/smbfs/helpers/lib/util_file.c b/src/vfs/smbfs/helpers/lib/util_file.c index 0dffd34fb..2f7d2f5ba 100644 --- a/src/vfs/smbfs/helpers/lib/util_file.c +++ b/src/vfs/smbfs/helpers/lib/util_file.c @@ -3,7 +3,7 @@ Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/lib/util_sock.c b/src/vfs/smbfs/helpers/lib/util_sock.c index 37e2fb114..3866406ae 100644 --- a/src/vfs/smbfs/helpers/lib/util_sock.c +++ b/src/vfs/smbfs/helpers/lib/util_sock.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -51,7 +51,7 @@ int lastport = 0; int smb_read_error = 0; - +#if 0 /**************************************************************************** determine if a file descriptor is in fact a socket ****************************************************************************/ @@ -63,7 +63,7 @@ is_a_socket (int fd) l = sizeof (int); return (getsockopt (fd, SOL_SOCKET, SO_TYPE, (char *) &v, &l) == 0); } - +#endif /* 0 */ enum SOCK_OPT_TYPES { OPT_BOOL, OPT_INT, OPT_ON }; @@ -385,7 +385,7 @@ read_with_timeout (int fd, char *buf, size_t mincnt, size_t maxcnt, unsigned int return ((ssize_t) nread); } - +#if 0 /**************************************************************************** send a keepalive packet (rfc1002) ****************************************************************************/ @@ -399,7 +399,7 @@ send_keepalive (int client) return (write_data (client, (char *) buf, 4) == 4); } - +#endif /* 0 */ /**************************************************************************** diff --git a/src/vfs/smbfs/helpers/lib/util_str.c b/src/vfs/smbfs/helpers/lib/util_str.c index d0e6bfb44..959b58b2f 100644 --- a/src/vfs/smbfs/helpers/lib/util_str.c +++ b/src/vfs/smbfs/helpers/lib/util_str.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/libsmb/clientgen.c b/src/vfs/smbfs/helpers/libsmb/clientgen.c index a7fbdb13e..41170fef5 100644 --- a/src/vfs/smbfs/helpers/libsmb/clientgen.c +++ b/src/vfs/smbfs/helpers/libsmb/clientgen.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1994-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -1690,7 +1690,7 @@ cli_getattrE (struct cli_state * cli, int fd, return True; } - +#if 0 /**************************************************************************** do a SMBgetatr call ****************************************************************************/ @@ -1741,7 +1741,7 @@ cli_getatr (struct cli_state * cli, char *fname, uint16 * attr, size_t * size, t return True; } - +#endif /* 0 */ /**************************************************************************** do a SMBsetatr call @@ -2720,6 +2720,7 @@ cli_error (struct cli_state *cli, uint8 * eclass, uint32 * num, uint32 * nt_rpc_ return EINVAL; } +#if 0 /**************************************************************************** set socket options on a open connection ****************************************************************************/ @@ -2739,6 +2740,7 @@ cli_setpid (struct cli_state *cli, uint16 pid) cli->pid = pid; return ret; } +#endif /* 0 */ /**************************************************************************** re-establishes a connection diff --git a/src/vfs/smbfs/helpers/libsmb/namequery.c b/src/vfs/smbfs/helpers/libsmb/namequery.c index 2e515f106..14ccaf26f 100644 --- a/src/vfs/smbfs/helpers/libsmb/namequery.c +++ b/src/vfs/smbfs/helpers/libsmb/namequery.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1994-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -303,8 +303,7 @@ resolve_bcast (const char *name, struct in_addr *return_ip, int name_type) struct in_addr *iplist = NULL; int count; int num_interfaces = iface_count (); - static char so_broadcast[] = "SO_BROADCAST"; - set_socket_options (sock, so_broadcast); + set_socket_options (sock, "SO_BROADCAST"); /* * Lookup the name on all the interfaces, return on * the first successful match. diff --git a/src/vfs/smbfs/helpers/libsmb/nmblib.c b/src/vfs/smbfs/helpers/libsmb/nmblib.c index 4575d3152..c415802e7 100644 --- a/src/vfs/smbfs/helpers/libsmb/nmblib.c +++ b/src/vfs/smbfs/helpers/libsmb/nmblib.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1994-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/libsmb/nterr.c b/src/vfs/smbfs/helpers/libsmb/nterr.c index 12ed382c5..3a26e299a 100644 --- a/src/vfs/smbfs/helpers/libsmb/nterr.c +++ b/src/vfs/smbfs/helpers/libsmb/nterr.c @@ -1,6 +1,6 @@ /* NT error codes. please read nterr.h - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/libsmb/pwd_cache.c b/src/vfs/smbfs/helpers/libsmb/pwd_cache.c index a20dfc575..aeb5f3bba 100644 --- a/src/vfs/smbfs/helpers/libsmb/pwd_cache.c +++ b/src/vfs/smbfs/helpers/libsmb/pwd_cache.c @@ -5,7 +5,7 @@ Copyright (C) Luke Kenneth Casson Leighton 1996-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -102,7 +102,7 @@ pwd_read (struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt) pwd_set_cleartext (pwd, user_pass); } } -#endif + /**************************************************************************** stores a cleartext password @@ -116,6 +116,7 @@ pwd_set_nullpwd (struct pwd_info *pwd) pwd->null_pwd = True; pwd->crypted = False; } +#endif /* 0 */ /**************************************************************************** stores a cleartext password diff --git a/src/vfs/smbfs/helpers/libsmb/smbdes.c b/src/vfs/smbfs/helpers/libsmb/smbdes.c index a71b5c116..ed22ed15d 100644 --- a/src/vfs/smbfs/helpers/libsmb/smbdes.c +++ b/src/vfs/smbfs/helpers/libsmb/smbdes.c @@ -7,7 +7,7 @@ Copyright (C) Andrew Tridgell 1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. @@ -347,6 +347,7 @@ E_P24 (unsigned char *p21, unsigned char *c8, unsigned char *p24) smbhash (p24 + 16, c8, p21 + 14, 1); } +#if 0 void D_P16 (unsigned char *p14, unsigned char *in, unsigned char *out) { @@ -431,3 +432,4 @@ SamOEMhash (unsigned char *data, unsigned char *key, int val) data[ind] = data[ind] ^ s_box[t]; } } +#endif /* 0 */ diff --git a/src/vfs/smbfs/helpers/libsmb/smbencrypt.c b/src/vfs/smbfs/helpers/libsmb/smbencrypt.c index d43497c41..a4779cc64 100644 --- a/src/vfs/smbfs/helpers/libsmb/smbencrypt.c +++ b/src/vfs/smbfs/helpers/libsmb/smbencrypt.c @@ -5,7 +5,7 @@ Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Modified by Jeremy Allison 1995. @@ -165,6 +165,7 @@ SMBOWFencrypt (uchar passwd[16], uchar * c8, uchar p24[24]) E_P24 (p21, c8, p24); } +#if 0 /* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ void NTLMSSPOWFencrypt (uchar passwd[8], uchar * ntlmchalresp, uchar p24[24]) @@ -183,7 +184,7 @@ NTLMSSPOWFencrypt (uchar passwd[8], uchar * ntlmchalresp, uchar p24[24]) dump_data (100, (char *) p24, 24); #endif } - +#endif /* 0 */ /* Does the NT MD4 hash then des encryption. */ diff --git a/src/vfs/smbfs/helpers/libsmb/smberr.c b/src/vfs/smbfs/helpers/libsmb/smberr.c index 36e016bdd..940dbf722 100644 --- a/src/vfs/smbfs/helpers/libsmb/smberr.c +++ b/src/vfs/smbfs/helpers/libsmb/smberr.c @@ -4,7 +4,7 @@ Copyright (C) Andrew Tridgell 1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/src/vfs/smbfs/helpers/param/loadparm.c b/src/vfs/smbfs/helpers/param/loadparm.c index 5e384d1d9..3da8f5a9b 100644 --- a/src/vfs/smbfs/helpers/param/loadparm.c +++ b/src/vfs/smbfs/helpers/param/loadparm.c @@ -5,7 +5,7 @@ Copyright (C) Karl Auer 1993-1998 - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Largely re-written by Andrew Tridgell, September 1994 @@ -1953,7 +1953,7 @@ init_copymap (service * pservice) pservice->copymap[i] = True; } - +#if 0 /*************************************************************************** return the local pointer to a parameter given the service number and the pointer into the default structure @@ -1963,6 +1963,7 @@ lp_local_ptr (int snum, void *ptr) { return (void *) (((char *) pSERVICE (snum)) + PTR_DIFF (ptr, &sDefault)); } +#endif /* 0 */ /*************************************************************************** Process a parameter for a particular service number. If snum < 0 @@ -2449,7 +2450,7 @@ lp_load (const char *pszFname, BOOL global_only, BOOL save_defaults, BOOL add_ip return (bRetval); } - +#if 0 /*************************************************************************** reset the max number of services ***************************************************************************/ @@ -2468,7 +2469,7 @@ lp_numservices (void) { return (iNumServices); } - +#endif /* 0 */ /*************************************************************************** Return the number of the service with the given name, or -1 if it doesn't @@ -2503,7 +2504,6 @@ volume_label (int snum) return (lp_servicename (snum)); return (ret); } -#endif /* 0 */ /*********************************************************** Set the global name resolution order (used in smbclient). @@ -2514,3 +2514,4 @@ lp_set_name_resolve_order (char *new_order) { Globals.szNameResolveOrder = new_order; } +#endif /* 0 */ diff --git a/src/vfs/smbfs/smbfs.c b/src/vfs/smbfs/smbfs.c index d6e09a0c5..08c303f47 100644 --- a/src/vfs/smbfs/smbfs.c +++ b/src/vfs/smbfs/smbfs.c @@ -1,7 +1,7 @@ /* Virtual File System: Midnight Commander file system. - Copyright (C) 1999-2017 + Copyright (C) 1999-2018 Free Software Foundation, Inc. Written by: diff --git a/src/vfs/tar/tar.c b/src/vfs/tar/tar.c index 7a5be43db..95f12e731 100644 --- a/src/vfs/tar/tar.c +++ b/src/vfs/tar/tar.c @@ -1,7 +1,7 @@ /* Virtual File System: GNU Tar file system. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: @@ -817,7 +817,7 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath, { message (D_ERROR, MSG_ERROR, _("%s\ndoesn't look like a tar archive."), vfs_path_as_str (vpath)); - /* FALL THRU */ + MC_FALLTHROUGH; /* Error after header rec */ } @@ -836,7 +836,7 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath, /* Record of zeroes */ case STATUS_EOFMARK: /* If error after 0's */ - /* FALL THRU */ + MC_FALLTHROUGH; /* exit from loop */ case STATUS_EOF: /* End of archive */ break; diff --git a/src/vfs/undelfs/undelfs.c b/src/vfs/undelfs/undelfs.c index 5ee099b82..5b06009c1 100644 --- a/src/vfs/undelfs/undelfs.c +++ b/src/vfs/undelfs/undelfs.c @@ -7,7 +7,7 @@ Parts of this program were taken from the lsdel.c and dump.c files written by Ted Ts'o (tytso@mit.edu) for the ext2fs package. - Copyright (C) 1995-2017 + Copyright (C) 1995-2018 Free Software Foundation, Inc. Written by: diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 87743fb8b..2f333ddd6 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Callback function for some actions (hotkeys, menu) - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -105,7 +105,7 @@ mcview_search (WView * view, gboolean start_search) { if (mcview_dialog_search (view)) { - if (view->hex_mode) + if (view->mode_flags.hex) want_search_start = view->hex_cursor; mcview_do_search (view, want_search_start); @@ -113,7 +113,7 @@ mcview_search (WView * view, gboolean start_search) } else { - if (view->hex_mode) + if (view->mode_flags.hex) { if (!mcview_search_options.backwards) want_search_start = view->hex_cursor + 1; @@ -459,11 +459,11 @@ mcview_execute_cmd (WView * view, long command) mcview_move_right (view, 1); break; case CK_LeftQuick: - if (!view->hex_mode) + if (!view->mode_flags.hex) mcview_move_left (view, 10); break; case CK_RightQuick: - if (!view->hex_mode) + if (!view->mode_flags.hex) mcview_move_right (view, 10); break; case CK_SearchContinue: @@ -552,7 +552,7 @@ mcview_handle_key (WView * view, int key) key = convert_from_input_c (key); #endif - if (view->hex_mode) + if (view->mode_flags.hex) { if (view->hexedit_mode && (mcview_handle_editkey (view, key) == MSG_HANDLED)) return MSG_HANDLED; @@ -667,7 +667,7 @@ mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * return MSG_HANDLED; case MSG_CURSOR: - if (view->hex_mode) + if (view->mode_flags.hex) mcview_place_cursor (view); return MSG_HANDLED; diff --git a/src/viewer/ascii.c b/src/viewer/ascii.c index f4b9dcbb4..a2d391172 100644 --- a/src/viewer/ascii.c +++ b/src/viewer/ascii.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for plain view - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -402,7 +402,7 @@ mcview_get_next_maybe_nroff_char (WView * view, mcview_state_machine_t * state, if (color != NULL) *color = VIEW_NORMAL_COLOR; - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) return mcview_get_next_char (view, state, c); if (!mcview_get_next_char (view, state, c)) @@ -583,7 +583,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, const screen_dimen top = view->data_area.top; const screen_dimen width = view->data_area.width; const screen_dimen height = view->data_area.height; - off_t dpy_text_column = view->text_wrap_mode ? 0 : view->dpy_text_column; + off_t dpy_text_column = view->mode_flags.wrap ? 0 : view->dpy_text_column; screen_dimen col = 0; int cs[1 + MAX_COMBINING_CHARS]; char str[(1 + MAX_COMBINING_CHARS) * UTF8_CHAR_LEN + 1]; @@ -592,7 +592,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, if (paragraph_ended != NULL) *paragraph_ended = TRUE; - if (!view->text_wrap_mode && (row < 0 || row >= (int) height) && linewidth == NULL) + if (!view->mode_flags.wrap && (row < 0 || row >= (int) height) && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully * parsing and then not actually displaying it. */ @@ -661,7 +661,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, /* In wrap mode only: We're done with this row if the character sequence wouldn't fit. * Except if at the first column, because then it wouldn't fit in the next row either. * In this extreme case let the unwrapped code below do its best to display it. */ - if (view->text_wrap_mode && (off_t) col + charwidth > dpy_text_column + (off_t) width + if (view->mode_flags.wrap && (off_t) col + charwidth > dpy_text_column + (off_t) width && col > 0) { *state = state_saved; @@ -730,7 +730,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, col += charwidth; state->unwrapped_column += charwidth; - if (!view->text_wrap_mode && (off_t) col >= dpy_text_column + (off_t) width + if (!view->mode_flags.wrap && (off_t) col >= dpy_text_column + (off_t) width && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully @@ -870,7 +870,7 @@ mcview_display_text (WView * view) mcview_display_clean (view); mcview_display_ruler (view); - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) mcview_state_machine_init (&state, view->dpy_start); else { @@ -888,7 +888,7 @@ mcview_display_text (WView * view) * scroll the file and display again. This happens when e.g. the * window is made bigger, or the file becomes shorter due to * charset change or enabling nroff. */ - if ((view->text_wrap_mode ? view->dpy_state_top.offset : view->dpy_start) > 0) + if ((view->mode_flags.wrap ? view->dpy_state_top.offset : view->dpy_start) > 0) { mcview_ascii_move_up (view, height - row); again = TRUE; @@ -940,7 +940,7 @@ mcview_ascii_move_down (WView * view, off_t lines) /* Okay, there's enough data. Move by 1 row at the top, too. No need to check for * EOF, that can't happen. */ - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { view->dpy_start = mcview_eol (view, view->dpy_start); view->dpy_paragraph_skip_lines = 0; @@ -977,7 +977,7 @@ mcview_ascii_move_down (WView * view, off_t lines) void mcview_ascii_move_up (WView * view, off_t lines) { - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { while (lines-- != 0) view->dpy_start = mcview_bol (view, view->dpy_start - 1, 0); @@ -1027,7 +1027,7 @@ mcview_ascii_move_up (WView * view, off_t lines) void mcview_ascii_moveto_bol (WView * view) { - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) view->dpy_text_column = 0; } @@ -1036,7 +1036,7 @@ mcview_ascii_moveto_bol (WView * view) void mcview_ascii_moveto_eol (WView * view) { - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { mcview_state_machine_t state; off_t linewidth; diff --git a/src/viewer/coord_cache.c b/src/viewer/coord_cache.c index 8091c5047..b0ec698a0 100644 --- a/src/viewer/coord_cache.c +++ b/src/viewer/coord_cache.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for work with coordinate cache (ccache) - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -312,7 +312,7 @@ mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_typ if (sorter == CCACHE_OFFSET) cmp_func = mcview_coord_cache_entry_less_offset; - else if (view->text_nroff_mode) + else if (view->mode_flags.nroff) cmp_func = mcview_coord_cache_entry_less_nroff; else cmp_func = mcview_coord_cache_entry_less_plain; @@ -342,7 +342,8 @@ mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_typ if (!cmp_func (¤t, coord)) { - if (lookup_what == CCACHE_OFFSET && view->text_nroff_mode && nroff_state != NROFF_START) + if (lookup_what == CCACHE_OFFSET && view->mode_flags.nroff + && nroff_state != NROFF_START) { /* don't break here */ } diff --git a/src/viewer/datasource.c b/src/viewer/datasource.c index 94e6f06f0..6fc5a60cd 100644 --- a/src/viewer/datasource.c +++ b/src/viewer/datasource.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Functions for datasources - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/viewer/dialogs.c b/src/viewer/dialogs.c index a382878dc..9af23372e 100644 --- a/src/viewer/dialogs.c +++ b/src/viewer/dialogs.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for paint dialogs - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -128,11 +128,8 @@ mcview_dialog_search (WView * view) GString *tmp; tmp = str_convert_to_input (exp); - if (tmp != NULL) - { - g_free (exp); - exp = g_string_free (tmp, FALSE); - } + g_free (exp); + exp = g_string_free (tmp, FALSE); } #endif @@ -251,12 +248,12 @@ mcview_dialog_goto (WView * view, off_t * offset) if (view->growbuf_in_use) mcview_growbuf_read_all_data (view); *offset = addr * mcview_get_filesize (view) / 100; - if (!view->hex_mode) + if (!view->mode_flags.hex) *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_OFFSET_DEC: case MC_VIEW_GOTO_OFFSET_HEX: - if (!view->hex_mode) + if (!view->mode_flags.hex) { if (view->growbuf_in_use) mcview_growbuf_read_until (view, addr); diff --git a/src/viewer/display.c b/src/viewer/display.c index 12e59deea..dc9eb0bd3 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for whow info on display - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -80,11 +80,11 @@ mcview_set_buttonbar (WView * view) { WDialog *h = WIDGET (view)->owner; WButtonBar *b = find_buttonbar (h); - const global_keymap_t *keymap = view->hex_mode ? viewer_hex_map : viewer_map; + const global_keymap_t *keymap = view->mode_flags.hex ? viewer_hex_map : viewer_map; buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, WIDGET (view)); - if (view->hex_mode) + if (view->mode_flags.hex) { if (view->hexedit_mode) buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, WIDGET (view)); @@ -100,7 +100,7 @@ mcview_set_buttonbar (WView * view) } else { - buttonbar_set_label (b, 2, view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap") + buttonbar_set_label (b, 2, view->mode_flags.wrap ? Q_ ("ButtonBar|UnWrap") : Q_ ("ButtonBar|Wrap"), keymap, WIDGET (view)); buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, WIDGET (view)); buttonbar_set_label (b, 6, "", keymap, WIDGET (view)); @@ -108,13 +108,13 @@ mcview_set_buttonbar (WView * view) } buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, WIDGET (view)); - buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw") + buttonbar_set_label (b, 8, view->mode_flags.magic ? Q_ ("ButtonBar|Raw") : Q_ ("ButtonBar|Parse"), keymap, WIDGET (view)); if (!mcview_is_in_panel (view)) /* don't override some panel buttonbar keys */ { buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, WIDGET (view)); - buttonbar_set_label (b, 9, view->text_nroff_mode ? Q_ ("ButtonBar|Unform") + buttonbar_set_label (b, 9, view->mode_flags.nroff ? Q_ ("ButtonBar|Unform") : Q_ ("ButtonBar|Format"), keymap, WIDGET (view)); buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, WIDGET (view)); } @@ -165,7 +165,7 @@ mcview_display_status (WView * view) if (width > 40) { widget_move (view, top, width - 32); - if (view->hex_mode) + if (view->mode_flags.hex) tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor); else { @@ -188,7 +188,7 @@ mcview_display_status (WView * view) else tty_print_string (str_fit_to_term (file_label, width - 5, J_LEFT_FIT)); if (width > 26) - mcview_display_percent (view, view->hex_mode ? view->hex_cursor : view->dpy_end); + mcview_display_percent (view, view->mode_flags.hex ? view->hex_cursor : view->dpy_end); } /* --------------------------------------------------------------------------------------------- */ @@ -244,14 +244,10 @@ mcview_update (WView * view) void mcview_display (WView * view) { - if (view->hex_mode) - { + if (view->mode_flags.hex) mcview_display_hex (view); - } else - { mcview_display_text (view); - } mcview_display_status (view); } @@ -285,7 +281,7 @@ mcview_compute_areas (WView * view) view->status_area.height = height; rest -= height; - height = (ruler == RULER_NONE || view->hex_mode) ? 0 : 2; + height = (ruler == RULER_NONE || view->mode_flags.hex) ? 0 : 2; height = MIN (rest, height); view->ruler_area.height = height; rest -= height; diff --git a/src/viewer/growbuf.c b/src/viewer/growbuf.c index c1172b6d6..08c96eb6c 100644 --- a/src/viewer/growbuf.c +++ b/src/viewer/growbuf.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for work with growing bufers - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/viewer/hex.c b/src/viewer/hex.c index a672b03da..89011e070 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for hex view - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: diff --git a/src/viewer/internal.h b/src/viewer/internal.h index 1f01195b6..5a14fc4df 100644 --- a/src/viewer/internal.h +++ b/src/viewer/internal.h @@ -134,13 +134,13 @@ struct WView growing buffer */ gboolean growbuf_finished; /* TRUE when all data has been read. */ - /* Editor modes */ - gboolean hex_mode; /* Hexview or Hexedit */ - gboolean hexedit_mode; /* Hexedit */ + mcview_mode_flags_t mode_flags; + + /* Hex editor modes */ + gboolean hexedit_mode; /* Hexview or Hexedit */ gboolean hexview_in_text; /* Is the hexview cursor in the text area? */ - gboolean text_nroff_mode; /* Nroff-style highlighting */ - gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */ - gboolean magic_mode; /* Preprocess the file using external programs */ + int bytes_per_line; /* Number of bytes per line in hex mode */ + off_t hex_cursor; /* Hexview cursor position in file */ gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */ gboolean locked; /* We hold lock on current file */ @@ -160,7 +160,6 @@ struct WView gboolean dpy_wrap_dirty; /* dpy_state_top needs to be recomputed */ off_t dpy_text_column; /* Number of skipped columns in non-wrap * text mode */ - off_t hex_cursor; /* Hexview cursor position in file */ screen_dimen cursor_col; /* Cursor column */ screen_dimen cursor_row; /* Cursor row */ struct hexedit_change_node *change_list; /* Linked list of changes */ @@ -173,31 +172,25 @@ struct WView int dirty; /* Number of skipped updates */ gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */ - /* Mode variables */ - int bytes_per_line; /* Number of bytes per line in hex mode */ - - /* Search variables */ - off_t search_start; /* First character to start searching from */ - off_t search_end; /* Length of found string or 0 if none was found */ - - /* Markers */ - int marker; /* mark to use */ - off_t marks[10]; /* 10 marks: 0..9 */ - - off_t update_steps; /* The number of bytes between percent - * increments */ - off_t update_activate; /* Last point where we updated the status */ - - /* converter for translation of text */ - GIConv converter; /* handle of search engine */ mc_search_t *search; gchar *last_search_string; struct mcview_nroff_struct *search_nroff_seq; - + off_t search_start; /* First character to start searching from */ + off_t search_end; /* Length of found string or 0 if none was found */ int search_numNeedSkipChar; + /* Markers */ + int marker; /* mark to use */ + off_t marks[10]; /* 10 marks: 0..9 */ + + off_t update_steps; /* The number of bytes between percent increments */ + off_t update_activate; /* Last point where we updated the status */ + + /* converter for translation of text */ + GIConv converter; + GArray *saved_bookmarks; dir_list *dir; /* List of current directory files diff --git a/src/viewer/lib.c b/src/viewer/lib.c index b623b8a65..0ed66bc86 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Common finctions (used from some other mcviewer functions) - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -35,6 +35,7 @@ #include +#include /* memset() */ #include #include "lib/global.h" @@ -74,8 +75,8 @@ mcview_toggle_magic_mode (WView * view) dir_list *dir; int *dir_idx; - mcview_altered_magic_flag = 1; - view->magic_mode = !view->magic_mode; + mcview_altered_flags.magic = TRUE; + view->mode_flags.magic = !view->mode_flags.magic; /* reinit view */ filename = g_strdup (vfs_path_as_str (view->filename_vpath)); @@ -101,7 +102,7 @@ mcview_toggle_magic_mode (WView * view) void mcview_toggle_wrap_mode (WView * view) { - view->text_wrap_mode = !view->text_wrap_mode; + view->mode_flags.wrap = !view->mode_flags.wrap; view->dpy_wrap_dirty = TRUE; view->dpy_bbar_dirty = TRUE; view->dirty++; @@ -112,8 +113,8 @@ mcview_toggle_wrap_mode (WView * view) void mcview_toggle_nroff_mode (WView * view) { - view->text_nroff_mode = !view->text_nroff_mode; - mcview_altered_nroff_flag = 1; + view->mode_flags.nroff = !view->mode_flags.nroff; + mcview_altered_flags.nroff = TRUE; view->dpy_wrap_dirty = TRUE; view->dpy_bbar_dirty = TRUE; view->dirty++; @@ -124,9 +125,9 @@ mcview_toggle_nroff_mode (WView * view) void mcview_toggle_hex_mode (WView * view) { - view->hex_mode = !view->hex_mode; + view->mode_flags.hex = !view->mode_flags.hex; - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = view->dpy_start; view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line); @@ -138,7 +139,7 @@ mcview_toggle_hex_mode (WView * view) view->hex_cursor = view->dpy_start; widget_want_cursor (WIDGET (view), FALSE); } - mcview_altered_hex_mode = 1; + mcview_altered_flags.hex = TRUE; view->dpy_paragraph_skip_lines = 0; view->dpy_wrap_dirty = TRUE; view->dpy_bbar_dirty = TRUE; @@ -206,21 +207,16 @@ mcview_done (WView * view) if (mcview_remember_file_position && view->filename_vpath != NULL) { save_file_position (view->filename_vpath, -1, 0, - view->hex_mode ? view->hex_cursor : view->dpy_start, + view->mode_flags.hex ? view->hex_cursor : view->dpy_start, view->saved_bookmarks); view->saved_bookmarks = NULL; } /* Write back the global viewer mode */ - mcview_default_hex_mode = view->hex_mode; - mcview_default_nroff_flag = view->text_nroff_mode; - mcview_default_magic_flag = view->magic_mode; - mcview_global_wrap_mode = view->text_wrap_mode; + mcview_global_flags = view->mode_flags; /* Free memory used by the viewer */ - /* view->widget needs no destructor */ - vfs_path_free (view->filename_vpath); view->filename_vpath = NULL; vfs_path_free (view->workdir_vpath); @@ -417,7 +413,7 @@ mcview_calc_percent (WView * view, off_t p) return (-1); filesize = mcview_get_filesize (view); - if (view->hex_mode && filesize > 0) + if (view->mode_flags.hex && filesize > 0) { /* p can't be beyond the last char, only over that. Compensate for this. */ filesize--; @@ -434,3 +430,11 @@ mcview_calc_percent (WView * view, off_t p) } /* --------------------------------------------------------------------------------------------- */ + +void +mcview_clear_mode_flags (mcview_mode_flags_t * flags) +{ + memset (flags, 0, sizeof (*flags)); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 111fafb27..c34ab61ed 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Interface functions - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc Written by: @@ -50,14 +50,19 @@ /*** global variables ****************************************************************************/ -int mcview_default_hex_mode = 0; -int mcview_default_nroff_flag = 0; -gboolean mcview_global_wrap_mode = TRUE; -int mcview_default_magic_flag = 1; +mcview_mode_flags_t mcview_global_flags = { + .wrap = TRUE, + .hex = FALSE, + .magic = TRUE, + .nroff = FALSE +}; -int mcview_altered_hex_mode = 0; -int mcview_altered_magic_flag = 0; -int mcview_altered_nroff_flag = 0; +mcview_mode_flags_t mcview_altered_flags = { + .wrap = FALSE, + .hex = FALSE, + .magic = FALSE, + .nroff = FALSE +}; gboolean mcview_remember_file_position = FALSE; @@ -106,10 +111,10 @@ mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) change_panel (); } } - /* fall through */ + MC_FALLTHROUGH; case MSG_MOUSE_CLICK: - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { /* Scrolling left and right */ screen_dimen x; @@ -197,26 +202,23 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel) widget_init (w, y, x, lines, cols, mcview_callback, mcview_mouse_callback); w->options |= WOP_SELECTABLE | WOP_TOP_SELECT; - view->hex_mode = FALSE; + mcview_clear_mode_flags (&view->mode_flags); view->hexedit_mode = FALSE; - view->locked = FALSE; view->hexview_in_text = FALSE; - view->text_nroff_mode = FALSE; - view->text_wrap_mode = FALSE; - view->magic_mode = FALSE; + view->locked = FALSE; view->dpy_frame_size = is_panel ? 1 : 0; view->converter = str_cnv_from_term; mcview_init (view); - if (mcview_default_hex_mode) + if (mcview_global_flags.hex) mcview_toggle_hex_mode (view); - if (mcview_default_nroff_flag) + if (mcview_global_flags.nroff) mcview_toggle_nroff_mode (view); - if (mcview_global_wrap_mode) + if (mcview_global_flags.wrap) mcview_toggle_wrap_mode (view); - if (mcview_default_magic_flag) + if (mcview_global_flags.magic) mcview_toggle_magic_mode (view); return view; @@ -306,7 +308,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line mcview_set_codeset (view); - if (command != NULL && (view->magic_mode || file == NULL || file[0] == '\0')) + if (command != NULL && (view->mode_flags.magic || file == NULL || file[0] == '\0')) retval = mcview_load_command_output (view, command); else if (file != NULL && file[0] != '\0') { @@ -364,7 +366,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line } else { - if (view->magic_mode) + if (view->mode_flags.magic) { int type; @@ -426,7 +428,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line new_offset = 0; else new_offset = MIN (new_offset, max_offset); - if (!view->hex_mode) + if (!view->mode_flags.hex) { view->dpy_start = mcview_bol (view, new_offset, 0); view->dpy_wrap_dirty = TRUE; diff --git a/src/viewer/mcviewer.h b/src/viewer/mcviewer.h index 28c05f0ab..d90716c6e 100644 --- a/src/viewer/mcviewer.h +++ b/src/viewer/mcviewer.h @@ -16,16 +16,18 @@ struct WView; typedef struct WView WView; +typedef struct +{ + gboolean wrap; /* Wrap text lines to fit them on the screen */ + gboolean hex; /* Plainview or hexview */ + gboolean magic; /* Preprocess the file using external programs */ + gboolean nroff; /* Nroff-style highlighting */ +} mcview_mode_flags_t; + /*** global variables defined in .c file *********************************************************/ -extern int mcview_default_hex_mode; -extern int mcview_default_nroff_flag; -extern gboolean mcview_global_wrap_mode; -extern int mcview_default_magic_flag; - -extern int mcview_altered_hex_mode; -extern int mcview_altered_magic_flag; -extern int mcview_altered_nroff_flag; +extern mcview_mode_flags_t mcview_global_flags; +extern mcview_mode_flags_t mcview_altered_flags; extern gboolean mcview_remember_file_position; extern int mcview_max_dirt_limit; @@ -49,5 +51,7 @@ extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpat extern gboolean mcview_load (WView * view, const char *command, const char *file, int start_line, off_t search_start, off_t search_end); +extern void mcview_clear_mode_flags (mcview_mode_flags_t * flags); + /*** inline functions ****************************************************************************/ #endif /* MC__VIEWER_H */ diff --git a/src/viewer/move.c b/src/viewer/move.c index 1c7eb8c18..dc5a45f72 100644 --- a/src/viewer/move.c +++ b/src/viewer/move.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Functions for handle cursor movement - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -70,7 +70,7 @@ static void mcview_scroll_to_cursor (WView * view) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t bytes = view->bytes_per_line; off_t cursor = view->hex_cursor; @@ -96,7 +96,7 @@ mcview_movement_fixups (WView * view, gboolean reset_search) mcview_scroll_to_cursor (view); if (reset_search) { - view->search_start = view->hex_mode ? view->hex_cursor : view->dpy_start; + view->search_start = view->mode_flags.hex ? view->hex_cursor : view->dpy_start; view->search_end = view->search_start; } view->dirty++; @@ -109,9 +109,10 @@ mcview_movement_fixups (WView * view, gboolean reset_search) void mcview_move_up (WView * view, off_t lines) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t bytes = lines * view->bytes_per_line; + if (view->hex_cursor >= bytes) { view->hex_cursor -= bytes; @@ -140,8 +141,10 @@ void mcview_move_down (WView * view, off_t lines) { off_t last_byte; + last_byte = mcview_get_filesize (view); - if (view->hex_mode) + + if (view->mode_flags.hex) { off_t i, limit; @@ -170,7 +173,7 @@ mcview_move_down (WView * view, off_t lines) void mcview_move_left (WView * view, off_t columns) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t old_cursor = view->hex_cursor; @@ -185,7 +188,7 @@ mcview_move_left (WView * view, off_t columns) if (old_cursor > 0 || view->hexedit_lownibble) view->hexedit_lownibble = !view->hexedit_lownibble; } - else if (!view->text_wrap_mode) + else if (!view->mode_flags.wrap) view->dpy_text_column = mcview_offset_doz (view->dpy_text_column, columns); mcview_movement_fixups (view, FALSE); } @@ -195,7 +198,7 @@ mcview_move_left (WView * view, off_t columns) void mcview_move_right (WView * view, off_t columns) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t last_byte; off_t old_cursor = view->hex_cursor; @@ -213,7 +216,7 @@ mcview_move_right (WView * view, off_t columns) if (old_cursor < last_byte || !view->hexedit_lownibble) view->hexedit_lownibble = !view->hexedit_lownibble; } - else if (!view->text_wrap_mode) + else if (!view->mode_flags.wrap) { view->dpy_text_column += columns; } @@ -247,7 +250,7 @@ mcview_moveto_bottom (WView * view) filesize = mcview_get_filesize (view); - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = mcview_offset_doz (filesize, 1); mcview_movement_fixups (view, TRUE); @@ -268,7 +271,7 @@ mcview_moveto_bottom (WView * view) void mcview_moveto_bol (WView * view) { - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor -= view->hex_cursor % view->bytes_per_line; view->dpy_text_column = 0; @@ -286,7 +289,8 @@ void mcview_moveto_eol (WView * view) { off_t bol; - if (view->hex_mode) + + if (view->mode_flags.hex) { off_t filesize; @@ -313,7 +317,7 @@ mcview_moveto_eol (WView * view) void mcview_moveto_offset (WView * view, off_t offset) { - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = offset; view->dpy_start = offset - offset % view->bytes_per_line; @@ -365,7 +369,7 @@ mcview_offset_to_coord (WView * view, off_t * ret_line, off_t * ret_column, off_ mcview_ccache_lookup (view, &coord, CCACHE_LINECOL); *ret_line = coord.cc_line; - *ret_column = (view->text_nroff_mode) ? coord.cc_nroff_column : coord.cc_column; + *ret_column = view->mode_flags.nroff ? coord.cc_nroff_column : coord.cc_column; } /* --------------------------------------------------------------------------------------------- */ @@ -389,7 +393,7 @@ mcview_place_cursor (WView * view) void mcview_moveto_match (WView * view) { - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = view->search_start; view->hexedit_lownibble = FALSE; diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index 5791efce3..32a820c9e 100644 --- a/src/viewer/nroff.c +++ b/src/viewer/nroff.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Functions for searching in nroff-like view - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -97,7 +97,7 @@ mcview__get_nroff_real_len (WView * view, off_t start, off_t length) int ret = 0; off_t i = 0; - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) return 0; nroff = mcview_nroff_seq_new_num (view, start); diff --git a/src/viewer/search.c b/src/viewer/search.c index 453826618..4575dbcf0 100644 --- a/src/viewer/search.c +++ b/src/viewer/search.c @@ -2,7 +2,7 @@ Internal file viewer for the Midnight Commander Function for search data - Copyright (C) 1994-2017 + Copyright (C) 1994-2018 Free Software Foundation, Inc. Written by: @@ -148,7 +148,7 @@ mcview_find (mcview_search_status_msg_t * ssm, off_t search_start, off_t search_ ok = mc_search_run (view->search, (void *) ssm, search_start, search_end, len); if (ok && view->search->normal_offset == search_start) { - if (view->text_nroff_mode) + if (view->mode_flags.nroff) view->search->normal_offset++; return TRUE; } @@ -178,17 +178,17 @@ mcview_search_show_result (WView * view, size_t match_len) int nroff_len; nroff_len = - view->text_nroff_mode + view->mode_flags.nroff ? mcview__get_nroff_real_len (view, view->search->start_buffer, view->search->normal_offset - view->search->start_buffer) : 0; view->search_start = view->search->normal_offset + nroff_len; - if (!view->hex_mode) + if (!view->mode_flags.hex) view->search_start++; nroff_len = - view->text_nroff_mode ? mcview__get_nroff_real_len (view, view->search_start - 1, - match_len) : 0; + view->mode_flags.nroff ? mcview__get_nroff_real_len (view, view->search_start - 1, + match_len) : 0; view->search_end = view->search_start + match_len + nroff_len; mcview_moveto_match (view); @@ -204,7 +204,7 @@ mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *curre WView *view = ((const mcview_search_status_msg_t *) user_data)->view; /* view_read_continue (view, &view->search_onechar_info); *//* AB:FIXME */ - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) { mcview_get_byte (view, char_offset, current_char); return MC_SEARCH_CB_OK; @@ -309,7 +309,7 @@ mcview_do_search (WView * view, off_t want_search_start) if (view->search_start != 0) { - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) search_start = view->search_start + (mcview_search_options.backwards ? -2 : 0); else { diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index d48fbd717..9e8b3d76e 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -6,7 +6,12 @@ AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@ AM_LDFLAGS = @TESTS_LDFLAGS@ -LIBS = @CHECK_LIBS@ $(top_builddir)/lib/libmc.la +LIBS = @CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la + +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif EXTRA_DIST = utilunix__my_system-common.c @@ -20,6 +25,10 @@ TESTS = \ utilunix__my_system_fork_child \ x_basename +if CHARSET +TESTS += mc_realpath +endif + check_PROGRAMS = $(TESTS) library_independ_SOURCES = \ @@ -28,6 +37,9 @@ library_independ_SOURCES = \ mc_build_filename_SOURCES = \ mc_build_filename.c +mc_realpath_SOURCES = \ + mc_realpath.c + name_quote_SOURCES = \ name_quote.c diff --git a/tests/lib/library_independ.c b/tests/lib/library_independ.c index 739ddf9c8..e6f734ee2 100644 --- a/tests/lib/library_independ.c +++ b/tests/lib/library_independ.c @@ -1,7 +1,7 @@ /* libmc - check if library is independ to $(topsrc)/src directory - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/mc_build_filename.c b/tests/lib/mc_build_filename.c index b29498973..00a2b0864 100644 --- a/tests/lib/mc_build_filename.c +++ b/tests/lib/mc_build_filename.c @@ -1,7 +1,7 @@ /* lib/vfs - mc_build_filename() function testing - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/mc_realpath.c b/tests/lib/mc_realpath.c new file mode 100644 index 000000000..0a7e66c92 --- /dev/null +++ b/tests/lib/mc_realpath.c @@ -0,0 +1,139 @@ +/* + lib - realpath + + Copyright (C) 2017-2018 + Free Software Foundation, Inc. + + Written by: + Andrew Borodin , 2017 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#define TEST_SUITE_NAME "/lib/util" + +#include "tests/mctest.h" + +#include "lib/strutil.h" +#include "lib/vfs/vfs.h" /* VFS_ENCODING_PREFIX, vfs_init(), vfs_shut() */ +#include "src/vfs/local/local.c" + +#include "lib/util.h" /* mc_realpath() */ + +/* --------------------------------------------------------------------------------------------- */ + +static char resolved_path[PATH_MAX]; + +/* --------------------------------------------------------------------------------------------- */ + +/* @Before */ +static void +setup (void) +{ + str_init_strings (NULL); + vfs_init (); + init_localfs (); + vfs_setup_work_dir (); +} + +/* @After */ +static void +teardown (void) +{ + vfs_shut (); + str_uninit_strings (); +} + +/* --------------------------------------------------------------------------------------------- */ + +/* @DataSource("data_source") */ +/* *INDENT-OFF* */ +static const struct data_source +{ + const char *input_string; + const char *expected_string; +} data_source[] = +{ + /* absolute paths */ + { "/", "/"}, + { "/" VFS_ENCODING_PREFIX "UTF-8/", "/" }, + { "/usr/bin", "/usr/bin" }, + { "/" VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/usr/bin" }, + + /* relative paths are relative to / */ + { VFS_ENCODING_PREFIX "UTF-8/", "/" }, + { "usr/bin", "/usr/bin" }, + { VFS_ENCODING_PREFIX "UTF-8/usr/bin", "/usr/bin" } +}; +/* *INDENT-ON* */ + +/* @Test(dataSource = "data_source") */ +/* *INDENT-OFF* */ +START_PARAMETRIZED_TEST (realpath_test, data_source) +/* *INDENT-ON* */ +{ + int ret; + + /* realpath(3) produces a canonicalized absolute pathname using curent directory. + * Change the current directory to produce correct pathname. */ + ret = chdir ("/"); + + /* when */ + if (mc_realpath (data->input_string, resolved_path) == NULL) + resolved_path[0] = '\0'; + + /* then */ + mctest_assert_str_eq (resolved_path, data->expected_string); + + (void) ret; +} +/* *INDENT-OFF* */ +END_PARAMETRIZED_TEST +/* *INDENT-ON* */ + +/* --------------------------------------------------------------------------------------------- */ + +int +main (void) +{ + int number_failed; + char *cwd, *logname; + + Suite *s = suite_create (TEST_SUITE_NAME); + TCase *tc_core = tcase_create ("Core"); + SRunner *sr; + + cwd = g_get_current_dir (); + logname = g_strconcat (cwd, "realpath.log", (char *) NULL); + g_free (cwd); + + tcase_add_checked_fixture (tc_core, setup, teardown); + + /* Add new tests here: *************** */ + mctest_add_parameterized_test (tc_core, realpath_test, data_source); + /* *********************************** */ + + suite_add_tcase (s, tc_core); + sr = srunner_create (s); + srunner_set_log (sr, logname); + srunner_run_all (sr, CK_ENV); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + g_free (logname); + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/mcconfig/Makefile.am b/tests/lib/mcconfig/Makefile.am index 08a6052c5..930d3f2fe 100644 --- a/tests/lib/mcconfig/Makefile.am +++ b/tests/lib/mcconfig/Makefile.am @@ -8,7 +8,12 @@ AM_CPPFLAGS = \ AM_LDFLAGS = @TESTS_LDFLAGS@ -LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la +LIBS = @CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la + +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif TESTS = \ config_string \ diff --git a/tests/lib/mcconfig/config_string.c b/tests/lib/mcconfig/config_string.c index f96a47261..393d82d23 100644 --- a/tests/lib/mcconfig/config_string.c +++ b/tests/lib/mcconfig/config_string.c @@ -1,7 +1,7 @@ /* libmc - check mcconfig submodule. read and write config files - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/mcconfig/user_configs_path.c b/tests/lib/mcconfig/user_configs_path.c index d1cb6a24b..6fcf73a21 100644 --- a/tests/lib/mcconfig/user_configs_path.c +++ b/tests/lib/mcconfig/user_configs_path.c @@ -1,7 +1,7 @@ /* libmc - check mcconfig submodule. Get full paths to user's config files. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/name_quote.c b/tests/lib/name_quote.c index 6690a844a..7bad49c60 100644 --- a/tests/lib/name_quote.c +++ b/tests/lib/name_quote.c @@ -1,7 +1,7 @@ /* lib/vfs - Quote file names - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/search/Makefile.am b/tests/lib/search/Makefile.am index a9e3f0c07..d01c0dc94 100644 --- a/tests/lib/search/Makefile.am +++ b/tests/lib/search/Makefile.am @@ -7,7 +7,12 @@ AM_CPPFLAGS = \ @CHECK_CFLAGS@ \ @PCRE_CPPFLAGS@ -LIBS = @CHECK_LIBS@ $(top_builddir)/lib/libmc.la @PCRE_LIBS@ +LIBS = @CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la @PCRE_LIBS@ + +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif TESTS = \ glob_prepare_replace_str \ diff --git a/tests/lib/search/glob_prepare_replace_str.c b/tests/lib/search/glob_prepare_replace_str.c index 4d6e25d2d..326b0b11d 100644 --- a/tests/lib/search/glob_prepare_replace_str.c +++ b/tests/lib/search/glob_prepare_replace_str.c @@ -1,7 +1,7 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/search/glob_translate_to_regex.c b/tests/lib/search/glob_translate_to_regex.c index 87b0c170b..8ec70fc3d 100644 --- a/tests/lib/search/glob_translate_to_regex.c +++ b/tests/lib/search/glob_translate_to_regex.c @@ -1,7 +1,7 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/search/hex_translate_to_regex.c b/tests/lib/search/hex_translate_to_regex.c index b851024bd..fb85e8af1 100644 --- a/tests/lib/search/hex_translate_to_regex.c +++ b/tests/lib/search/hex_translate_to_regex.c @@ -1,7 +1,7 @@ /* libmc - checks for hex pattern parsing - Copyright (C) 2017 + Copyright (C) 2017-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander. diff --git a/tests/lib/search/regex_process_escape_sequence.c b/tests/lib/search/regex_process_escape_sequence.c index 5632af7fc..ff244466e 100644 --- a/tests/lib/search/regex_process_escape_sequence.c +++ b/tests/lib/search/regex_process_escape_sequence.c @@ -1,7 +1,7 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/search/regex_replace_esc_seq.c b/tests/lib/search/regex_replace_esc_seq.c index 681847052..503341973 100644 --- a/tests/lib/search/regex_replace_esc_seq.c +++ b/tests/lib/search/regex_replace_esc_seq.c @@ -1,7 +1,7 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/search/translate_replace_glob_to_regex.c b/tests/lib/search/translate_replace_glob_to_regex.c index ef1a9f0c2..83fb42d81 100644 --- a/tests/lib/search/translate_replace_glob_to_regex.c +++ b/tests/lib/search/translate_replace_glob_to_regex.c @@ -1,7 +1,7 @@ /* libmc - checks for processing esc sequences in replace string - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/serialize.c b/tests/lib/serialize.c index 69a65958f..59fa8da44 100644 --- a/tests/lib/serialize.c +++ b/tests/lib/serialize.c @@ -1,7 +1,7 @@ /* lib/vfs - common serialize/deserialize functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/strutil/Makefile.am b/tests/lib/strutil/Makefile.am index c3ce5405a..29b2f5219 100644 --- a/tests/lib/strutil/Makefile.am +++ b/tests/lib/strutil/Makefile.am @@ -6,7 +6,12 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/search \ @CHECK_CFLAGS@ -LIBS = @CHECK_LIBS@ $(top_builddir)/lib/libmc.la +LIBS = @CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la + +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif TESTS = \ replace__str_replace_all \ diff --git a/tests/lib/strutil/parse_integer.c b/tests/lib/strutil/parse_integer.c index a0996470b..19cb1ef4d 100644 --- a/tests/lib/strutil/parse_integer.c +++ b/tests/lib/strutil/parse_integer.c @@ -1,7 +1,7 @@ /* lib/strutil - tests for lib/strutil/parse_integer function. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/strutil/replace__str_replace_all.c b/tests/lib/strutil/replace__str_replace_all.c index a30b8bee8..100bdbc4a 100644 --- a/tests/lib/strutil/replace__str_replace_all.c +++ b/tests/lib/strutil/replace__str_replace_all.c @@ -1,7 +1,7 @@ /* lib/strutil - tests for lib/strutil/replace:str_replace_all() function. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/utilunix__my_system-common.c b/tests/lib/utilunix__my_system-common.c index 980f312e3..4c7a45908 100644 --- a/tests/lib/utilunix__my_system-common.c +++ b/tests/lib/utilunix__my_system-common.c @@ -1,7 +1,7 @@ /* lib - common code for testing lib/utilinux:my_system() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/utilunix__my_system-fork_child.c b/tests/lib/utilunix__my_system-fork_child.c index f53d31804..1e3603d65 100644 --- a/tests/lib/utilunix__my_system-fork_child.c +++ b/tests/lib/utilunix__my_system-fork_child.c @@ -1,7 +1,7 @@ /* lib - tests lib/utilinux:my_system() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/utilunix__my_system-fork_child_shell.c b/tests/lib/utilunix__my_system-fork_child_shell.c index 2d00475ec..0fd46faf7 100644 --- a/tests/lib/utilunix__my_system-fork_child_shell.c +++ b/tests/lib/utilunix__my_system-fork_child_shell.c @@ -1,7 +1,7 @@ /* lib - tests lib/utilinux:my_system() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/utilunix__my_system-fork_fail.c b/tests/lib/utilunix__my_system-fork_fail.c index 1b6b49e59..4f53ecb19 100644 --- a/tests/lib/utilunix__my_system-fork_fail.c +++ b/tests/lib/utilunix__my_system-fork_fail.c @@ -1,7 +1,7 @@ /* lib - tests lib/utilinux:my_system() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/Makefile.am b/tests/lib/vfs/Makefile.am index ebb531ac7..62ebe9fcc 100644 --- a/tests/lib/vfs/Makefile.am +++ b/tests/lib/vfs/Makefile.am @@ -11,8 +11,12 @@ AM_LDFLAGS = @TESTS_LDFLAGS@ EXTRA_DIST = mc.charsets -LIBS=@CHECK_LIBS@ \ - $(top_builddir)/lib/libmc.la +LIBS = @CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la + +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif TESTS = \ canonicalize_pathname \ diff --git a/tests/lib/vfs/canonicalize_pathname.c b/tests/lib/vfs/canonicalize_pathname.c index 92b1f7bba..de00ebd14 100644 --- a/tests/lib/vfs/canonicalize_pathname.c +++ b/tests/lib/vfs/canonicalize_pathname.c @@ -1,7 +1,7 @@ /* lib - canonicalize path - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/current_dir.c b/tests/lib/vfs/current_dir.c index 442bee08d..e9ade658e 100644 --- a/tests/lib/vfs/current_dir.c +++ b/tests/lib/vfs/current_dir.c @@ -1,7 +1,7 @@ /* lib/vfs - manipulate with current directory - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/path_cmp.c b/tests/lib/vfs/path_cmp.c index 0ab05e0a6..64f1828a8 100644 --- a/tests/lib/vfs/path_cmp.c +++ b/tests/lib/vfs/path_cmp.c @@ -1,6 +1,6 @@ /* lib/vfs - vfs_path_t compare functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/path_len.c b/tests/lib/vfs/path_len.c index 300c62624..e9161fe47 100644 --- a/tests/lib/vfs/path_len.c +++ b/tests/lib/vfs/path_len.c @@ -1,6 +1,6 @@ /* lib/vfs - tests for vfspath_len() function. - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/path_manipulations.c b/tests/lib/vfs/path_manipulations.c index 54cec9d75..d08b414b5 100644 --- a/tests/lib/vfs/path_manipulations.c +++ b/tests/lib/vfs/path_manipulations.c @@ -1,6 +1,6 @@ /* lib/vfs - test vfs_path_t manipulation functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/path_recode.c b/tests/lib/vfs/path_recode.c index 2bd34fae0..be418c23f 100644 --- a/tests/lib/vfs/path_recode.c +++ b/tests/lib/vfs/path_recode.c @@ -1,7 +1,7 @@ /* lib/vfs - vfs_path_t charset recode functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/path_serialize.c b/tests/lib/vfs/path_serialize.c index cd5416f41..030ee3076 100644 --- a/tests/lib/vfs/path_serialize.c +++ b/tests/lib/vfs/path_serialize.c @@ -1,7 +1,7 @@ /* lib/vfs - vfs_path_t serialize/deserialize functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/relative_cd.c b/tests/lib/vfs/relative_cd.c index 2fd490c85..49466724c 100644 --- a/tests/lib/vfs/relative_cd.c +++ b/tests/lib/vfs/relative_cd.c @@ -1,6 +1,6 @@ /* lib/vfs - test vfs_path_t manipulation functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/tempdir.c b/tests/lib/vfs/tempdir.c index 338b3a710..20b6f8f5f 100644 --- a/tests/lib/vfs/tempdir.c +++ b/tests/lib/vfs/tempdir.c @@ -1,7 +1,7 @@ /* lib/vfs - manipulations with temp files and dirs - Copyright (C) 2012-2017 + Copyright (C) 2012-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_adjust_stat.c b/tests/lib/vfs/vfs_adjust_stat.c index ea8fda69f..ce1d82fbf 100644 --- a/tests/lib/vfs/vfs_adjust_stat.c +++ b/tests/lib/vfs/vfs_adjust_stat.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_adjust_stat() functionality - Copyright (C) 2017 + Copyright (C) 2017-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_get_encoding.c b/tests/lib/vfs/vfs_get_encoding.c index a62ecd90f..bf714be9e 100644 --- a/tests/lib/vfs/vfs_get_encoding.c +++ b/tests/lib/vfs/vfs_get_encoding.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_get_encoding() functionality - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_parse_ls_lga.c b/tests/lib/vfs/vfs_parse_ls_lga.c index cb455eaf6..fae4e3b0d 100644 --- a/tests/lib/vfs/vfs_parse_ls_lga.c +++ b/tests/lib/vfs/vfs_parse_ls_lga.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_parse_ls_lga() functionality - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_path_from_str_flags.c b/tests/lib/vfs/vfs_path_from_str_flags.c index d405f570b..c40ef11d7 100644 --- a/tests/lib/vfs/vfs_path_from_str_flags.c +++ b/tests/lib/vfs/vfs_path_from_str_flags.c @@ -1,6 +1,6 @@ /* lib/vfs - test vfs_path_from_str_flags() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_path_string_convert.c b/tests/lib/vfs/vfs_path_string_convert.c index e1e22f188..732dc18a1 100644 --- a/tests/lib/vfs/vfs_path_string_convert.c +++ b/tests/lib/vfs/vfs_path_string_convert.c @@ -1,7 +1,7 @@ /* lib/vfs - get vfs_path_t from string - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_prefix_to_class.c b/tests/lib/vfs/vfs_prefix_to_class.c index df5f962c8..8c2d7d525 100644 --- a/tests/lib/vfs/vfs_prefix_to_class.c +++ b/tests/lib/vfs/vfs_prefix_to_class.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_prefix_to_class() functionality - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_s_get_path.c b/tests/lib/vfs/vfs_s_get_path.c index 4e4db7aa8..99e836a28 100644 --- a/tests/lib/vfs/vfs_s_get_path.c +++ b/tests/lib/vfs/vfs_s_get_path.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_s_get_path() function - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_setup_cwd.c b/tests/lib/vfs/vfs_setup_cwd.c index b259c4cca..0c96a96bf 100644 --- a/tests/lib/vfs/vfs_setup_cwd.c +++ b/tests/lib/vfs/vfs_setup_cwd.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_setup_cwd() functionality - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/vfs/vfs_split.c b/tests/lib/vfs/vfs_split.c index ba0d2ac90..a64901578 100644 --- a/tests/lib/vfs/vfs_split.c +++ b/tests/lib/vfs/vfs_split.c @@ -1,7 +1,7 @@ /* lib/vfs - test vfs_split() functionality - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/widget/Makefile.am b/tests/lib/widget/Makefile.am index 259cde10b..0d619edb5 100644 --- a/tests/lib/widget/Makefile.am +++ b/tests/lib/widget/Makefile.am @@ -8,8 +8,12 @@ AM_CPPFLAGS = \ AM_LDFLAGS = @TESTS_LDFLAGS@ -LIBS=@CHECK_LIBS@ \ - $(top_builddir)/lib/libmc.la +LIBS = @CHECK_LIBS@ \ + $(top_builddir)/lib/libmc.la + +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif TESTS = \ complete_engine diff --git a/tests/lib/widget/complete_engine.c b/tests/lib/widget/complete_engine.c index 60c048723..a164d9b9c 100644 --- a/tests/lib/widget/complete_engine.c +++ b/tests/lib/widget/complete_engine.c @@ -1,7 +1,7 @@ /* lib/widget - tests for autocomplete feature - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/lib/x_basename.c b/tests/lib/x_basename.c index e58cb77e7..249a3e94b 100644 --- a/tests/lib/x_basename.c +++ b/tests/lib/x_basename.c @@ -1,7 +1,7 @@ /* lib - x_basename() function testing - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/Makefile.am b/tests/src/Makefile.am index 2fac02c37..a6ba9290f 100644 --- a/tests/src/Makefile.am +++ b/tests/src/Makefile.am @@ -14,7 +14,7 @@ AM_CPPFLAGS = \ AM_LDFLAGS = @TESTS_LDFLAGS@ -LIBS=@CHECK_LIBS@ \ +LIBS = @CHECK_LIBS@ \ $(top_builddir)/src/libinternal.la \ $(top_builddir)/lib/libmc.la @@ -23,6 +23,10 @@ if ENABLE_VFS_SMB LIBS += $(top_builddir)/src/vfs/smbfs/helpers/libsamba.a endif +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif + EXTRA_DIST = execute__common.c TESTS = \ diff --git a/tests/src/editor/Makefile.am b/tests/src/editor/Makefile.am index f0b2a9c50..4cbb4fb09 100644 --- a/tests/src/editor/Makefile.am +++ b/tests/src/editor/Makefile.am @@ -9,7 +9,7 @@ AM_CPPFLAGS = \ AM_LDFLAGS = @TESTS_LDFLAGS@ -LIBS=@CHECK_LIBS@ \ +LIBS = @CHECK_LIBS@ \ $(top_builddir)/src/libinternal.la \ $(top_builddir)/lib/libmc.la \ @PCRE_LIBS@ @@ -19,6 +19,10 @@ if ENABLE_VFS_SMB LIBS += $(top_builddir)/src/vfs/smbfs/helpers/libsamba.a endif +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif + EXTRA_DIST = mc.charsets test-data.txt.in TESTS = \ diff --git a/tests/src/editor/editcmd__edit_complete_word_cmd.c b/tests/src/editor/editcmd__edit_complete_word_cmd.c index 591f72763..81706fe48 100644 --- a/tests/src/editor/editcmd__edit_complete_word_cmd.c +++ b/tests/src/editor/editcmd__edit_complete_word_cmd.c @@ -1,7 +1,7 @@ /* src/editor - tests for edit_complete_word_cmd() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/execute__common.c b/tests/src/execute__common.c index 864f9f014..8692d9734 100644 --- a/tests/src/execute__common.c +++ b/tests/src/execute__common.c @@ -1,7 +1,7 @@ /* Common code for testing functions in src/execute.c file. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. diff --git a/tests/src/execute__execute_external_editor_or_viewer.c b/tests/src/execute__execute_external_editor_or_viewer.c index b6a8d1074..01969d38e 100644 --- a/tests/src/execute__execute_external_editor_or_viewer.c +++ b/tests/src/execute__execute_external_editor_or_viewer.c @@ -1,7 +1,7 @@ /* src - tests for execute_external_editor_or_viewer() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/execute__execute_get_external_cmd_opts_from_config.c b/tests/src/execute__execute_get_external_cmd_opts_from_config.c index 1ebc49838..2817f8301 100644 --- a/tests/src/execute__execute_get_external_cmd_opts_from_config.c +++ b/tests/src/execute__execute_get_external_cmd_opts_from_config.c @@ -1,7 +1,7 @@ /* src - tests for execute_external_editor_or_viewer() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/execute__execute_with_vfs_arg.c b/tests/src/execute__execute_with_vfs_arg.c index 73b94d04b..9dfce1f0c 100644 --- a/tests/src/execute__execute_with_vfs_arg.c +++ b/tests/src/execute__execute_with_vfs_arg.c @@ -1,7 +1,7 @@ /* src - tests for execute_with_vfs_arg() function - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/filemanager/Makefile.am b/tests/src/filemanager/Makefile.am index 23b61fbf7..19a9ba955 100644 --- a/tests/src/filemanager/Makefile.am +++ b/tests/src/filemanager/Makefile.am @@ -10,7 +10,7 @@ AM_CPPFLAGS = \ AM_LDFLAGS = @TESTS_LDFLAGS@ -LIBS=@CHECK_LIBS@ \ +LIBS = @CHECK_LIBS@ \ $(top_builddir)/src/libinternal.la \ $(top_builddir)/lib/libmc.la \ @PCRE_LIBS@ @@ -20,6 +20,10 @@ if ENABLE_VFS_SMB LIBS += $(top_builddir)/src/vfs/smbfs/helpers/libsamba.a endif +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif + EXTRA_DIST = hints/mc.hint TESTS = \ diff --git a/tests/src/filemanager/do_cd_command.c b/tests/src/filemanager/do_cd_command.c index 6048914e8..c96c87214 100644 --- a/tests/src/filemanager/do_cd_command.c +++ b/tests/src/filemanager/do_cd_command.c @@ -1,7 +1,7 @@ /* src/filemanager - tests for do_cd_command() function - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/filemanager/examine_cd.c b/tests/src/filemanager/examine_cd.c index fb8aae377..9d2760f33 100644 --- a/tests/src/filemanager/examine_cd.c +++ b/tests/src/filemanager/examine_cd.c @@ -1,7 +1,7 @@ /* src/filemanager - examine_cd() function testing - Copyright (C) 2012-2017 + Copyright (C) 2012-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/filemanager/exec_get_export_variables_ext.c b/tests/src/filemanager/exec_get_export_variables_ext.c index 940a20af4..ef5bb8aeb 100644 --- a/tests/src/filemanager/exec_get_export_variables_ext.c +++ b/tests/src/filemanager/exec_get_export_variables_ext.c @@ -1,7 +1,7 @@ /* src/filemanager - filemanager functions - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/filemanager/filegui_is_wildcarded.c b/tests/src/filemanager/filegui_is_wildcarded.c index dd03331a2..e7c06fa34 100644 --- a/tests/src/filemanager/filegui_is_wildcarded.c +++ b/tests/src/filemanager/filegui_is_wildcarded.c @@ -1,7 +1,7 @@ /* src/filemanager - tests for is_wildcarded() function - Copyright (C) 2011-2017 + Copyright (C) 2011-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/filemanager/get_random_hint.c b/tests/src/filemanager/get_random_hint.c index 3e8f0cf9a..60e87af31 100644 --- a/tests/src/filemanager/get_random_hint.c +++ b/tests/src/filemanager/get_random_hint.c @@ -2,7 +2,7 @@ src/filemanager - filemanager functions. Tests for getting random hints. - Copyright (C) 2013-2017 + Copyright (C) 2013-2018 Free Software Foundation, Inc. Written by: diff --git a/tests/src/vfs/extfs/helpers-list/Makefile.am b/tests/src/vfs/extfs/helpers-list/Makefile.am index 75aa24ac7..94ddcf903 100644 --- a/tests/src/vfs/extfs/helpers-list/Makefile.am +++ b/tests/src/vfs/extfs/helpers-list/Makefile.am @@ -10,6 +10,10 @@ AM_LDFLAGS = @TESTS_LDFLAGS@ LIBS = $(top_builddir)/lib/libmc.la +if ENABLE_MCLIB +LIBS += $(GLIB_LIBS) +endif + # Programs/scripts to build on 'make check'. check_PROGRAMS = mc_parse_ls_l check_SCRIPTS = run diff --git a/tests/src/vfs/extfs/helpers-list/mc_parse_ls_l.c b/tests/src/vfs/extfs/helpers-list/mc_parse_ls_l.c index 08c5eb93c..90a760cd7 100644 --- a/tests/src/vfs/extfs/helpers-list/mc_parse_ls_l.c +++ b/tests/src/vfs/extfs/helpers-list/mc_parse_ls_l.c @@ -1,7 +1,7 @@ /* A parser for file-listings formatted like 'ls -l'. - Copyright (C) 2016-2017 + Copyright (C) 2016-2018 Free Software Foundation, Inc. This file is part of the Midnight Commander.