From 428e233f37519aeb2c8fc26bbeebad60322cd493 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:21:17 +0100 Subject: [PATCH 01/17] Revert "Resolve some issues in mhl Rollang Illig pointed us to:" This reverts commit 60f2d8d3c08e3dd7d53f5a5f14abc8ac1fed12de. --- mhl/env.h | 4 ++-- mhl/escape.h | 8 ++++---- mhl/memory.h | 6 +++--- mhl/strhash.h | 4 ++-- mhl/string.h | 22 +++++++++------------- mhl/types.h | 8 +++----- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/mhl/env.h b/mhl/env.h index 6598e0cbf..8d5633797 100644 --- a/mhl/env.h +++ b/mhl/env.h @@ -1,5 +1,5 @@ -#ifndef MHL_ENV_H -#define MHL_ENV_H +#ifndef __MHL_ENV_H +#define __MHL_ENV_H #include diff --git a/mhl/escape.h b/mhl/escape.h index 485579c59..ed25b608a 100644 --- a/mhl/escape.h +++ b/mhl/escape.h @@ -1,5 +1,5 @@ -#ifndef MHL_ESCAPE_H -#define MHL_ESCAPE_H +#ifndef __MHL_SHELL_ESCAPE_H +#define __MHL_SHELL_ESCAPE_H /* Micro helper library: shell escaping functions */ @@ -63,7 +63,7 @@ static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src) /** Unescape paths or other strings for e.g the internal cd shell-unescape within a given buffer (writing to it!) - /params const char * src + /params const char * in string for unescaping /returns return unescaped string @@ -112,7 +112,7 @@ static inline char* mhl_shell_unescape_buf(char* text) case '`': case '"': case ';': - case '\0': /* end of string! malformed escape string */ + case '\0': /* end of line! malformed escape string */ goto out; default: (*writeptr) = c; writeptr++; break; diff --git a/mhl/memory.h b/mhl/memory.h index 3268e93a1..b00617700 100644 --- a/mhl/memory.h +++ b/mhl/memory.h @@ -1,5 +1,5 @@ -#ifndef MHL_MEMORY_H -#define MHL_MEMORY_H +#ifndef __MHL_MEM +#define __MHL_MEM #include #include @@ -17,7 +17,7 @@ static inline void mhl_mem_free(void* ptr) } /* free an ptr and NULL it */ -#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0) +#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0); /* allocate a chunk on stack - automatically free'd on function exit */ #define mhl_stack_alloc(sz) (alloca(sz)) diff --git a/mhl/strhash.h b/mhl/strhash.h index 8ff17cba6..1f195053c 100644 --- a/mhl/strhash.h +++ b/mhl/strhash.h @@ -1,5 +1,5 @@ -#ifndef MHL_STRHASH_H -#define MHL_STRHASH_H +#ifndef __MHL_STRHASH_H +#define __MHL_STRHASH_H #include #include diff --git a/mhl/string.h b/mhl/string.h index 3b4c421f1..47f097f1e 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -1,5 +1,5 @@ -#ifndef MHL_STRING_H -#define MHL_STRING_H +#ifndef __MHL_STRING_H +#define __MHL_STRING_H #include #include @@ -10,9 +10,6 @@ #define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup(""))) #define mhl_str_len(str) ((str ? strlen(str) : 0)) -#define ISSPACE(c) isspace((unsigned char)(c)) -#define TOUPPER(c) toupper((unsigned char)(c)) - static inline char * mhl_str_dup_range(const char * s_start, const char * s_bound) { return mhl_str_ndup(s_start, s_bound - s_start); @@ -23,26 +20,26 @@ static inline char* mhl_str_trim(char* str) if (!str) return NULL; /* NULL string ?! bail out. */ /* find the first non-space */ - char* start; for (start=str; ((*str) && (!ISSPACE(*str))); str++); + char* start; for (start=str; ((*str) && (!isspace(*str))); str++); /* only spaces ? */ if (!(*str)) { *str = 0; return str; } - /* get the size (cannot be empty - caught above) */ + /* get the size (cannot be empty - catched above) */ size_t _sz = strlen(str); /* find the proper end */ char* end; - for (end=(str+_sz-1); ((end>str) && (ISSPACE(*end))); end--); + for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--); end[1] = 0; /* terminate, just to be sure */ /* if we have no leading spaces, just trucate */ if (start==str) { end++; *end = 0; return str; } - /* if it's only one char, dont need memmove for that */ + /* if it' only one char, dont need memmove for that */ if (start==end) { str[0]=*start; str[1]=0; return str; } - /* by here we have a (non-empty) region between start and end */ + /* by here we have a (non-empty) region between start end end */ memmove(str,start,(end-start+1)); return str; } @@ -51,7 +48,7 @@ static inline void mhl_str_toupper(char* str) { if (str) for (;*str;str++) - *str = TOUPPER(*str); + *str = toupper(*str); } /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ @@ -130,7 +127,6 @@ static inline char * mhl_strmove(char * dest, const char * src) { size_t n = strlen (src) + 1; /* + '\0' */ - /* strictly speaking, this invokes undefined behavior as soon as dest and src are pointers into different objects. */ assert (dest<=src); return memmove(dest, src, n); @@ -169,4 +165,4 @@ static inline char* mhl_str_dir_plus_file(const char* dirname, const char* filen return buffer; } -#endif /* MHL_STRING_H */ +#endif /* __MHL_STRING_H */ diff --git a/mhl/types.h b/mhl/types.h index 977c27a2c..1f8400299 100644 --- a/mhl/types.h +++ b/mhl/types.h @@ -4,15 +4,13 @@ */ -#ifndef MHL_TYPES_H -#define MHL_TYPES_H +#ifndef __MHL_TYPES_H +#define __MHL_TYPES_H -#if !defined(__bool_true_false_are_defined) && !defined(false) && !defined(true) && !defined(bool) -typedef enum +typedef enum { false = 0, true = 1 } bool; -#endif #endif From dd1b7941d6f0bef3778183739a14e8e63dca742a Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:21:34 +0100 Subject: [PATCH 02/17] Revert "Added enhancements from Sergei which he attached to #241." This reverts commit 34fe2312b4aec7be01470bb7be2453a96b53413a. --- mhl/string.h | 62 ++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/mhl/string.h b/mhl/string.h index 47f097f1e..fcbbd864f 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -51,52 +51,56 @@ static inline void mhl_str_toupper(char* str) *str = toupper(*str); } -/* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ -static const char * mhl_s_c_sep__ = (const char *)1; +#define __STR_CONCAT_MAX 32 /* _NEVER_ call this function directly ! */ -static inline char* mhl_str_concat_hlp__(const char* va_start_dummy, ...) +static inline char* __mhl_str_concat_hlp(const char* base, ...) { - char * result; - size_t result_len = 0; - char * p; - const char * chunk; + static const char* arg_ptr[__STR_CONCAT_MAX]; + static size_t arg_sz[__STR_CONCAT_MAX]; + int count = 0; + size_t totalsize = 0; + + if (base) + { + arg_ptr[0] = base; + arg_sz[0] = totalsize = strlen(base); + count = 1; + } va_list args; - va_start(args,va_start_dummy); - while ((chunk = va_arg(args, const char*)) != mhl_s_c_sep__) + va_start(args,base); + char* a; + /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ + while ((a = va_arg(args, char*))!=(char*)1 && count < __STR_CONCAT_MAX ) { - if (chunk) + if (a) { - result_len += strlen (chunk); + arg_ptr[count] = a; + arg_sz[count] = strlen(a); + totalsize += arg_sz[count]; + count++; } } va_end(args); - if (result_len == 0) + if (!count) return mhl_str_dup(""); - /* now as we know how much to copy, allocate the buffer + '\0'*/ - result = (char*)mhl_mem_alloc_u (result_len + 1); - - p = result; - - va_start(args,va_start_dummy); - while ((chunk = va_arg(args, const char*)) != mhl_s_c_sep__) + /* now as we know how much to copy, allocate the buffer */ + char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); + char* current = buffer; + int x=0; + for (x=0; x Date: Tue, 10 Feb 2009 13:21:45 +0100 Subject: [PATCH 03/17] Revert "Call va_end after the iteration as we need to free the list again." This reverts commit 51388bd012248fa30d0d18209ad02d5a2ffb63a5. --- mhl/string.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mhl/string.h b/mhl/string.h index fcbbd864f..da8658406 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -71,7 +71,7 @@ static inline char* __mhl_str_concat_hlp(const char* base, ...) va_start(args,base); char* a; /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ - while ((a = va_arg(args, char*))!=(char*)1 && count < __STR_CONCAT_MAX ) + while ((a = va_arg(args, char*))!=(char*)1 && count <= 31 ) { if (a) { @@ -81,7 +81,6 @@ static inline char* __mhl_str_concat_hlp(const char* base, ...) count++; } } - va_end(args); if (!count) return mhl_str_dup(""); From d7fa1ecdb456eb4aaf80347ebecea0881d6bed39 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:21:58 +0100 Subject: [PATCH 04/17] Revert "Fixing a theoretical buffer overflow which was reported by Roland Illig" This reverts commit f148fc29d2737eef087a6ce62d6369b1260a5327. --- mhl/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mhl/string.h b/mhl/string.h index da8658406..ee74e1d48 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -71,7 +71,7 @@ static inline char* __mhl_str_concat_hlp(const char* base, ...) va_start(args,base); char* a; /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ - while ((a = va_arg(args, char*))!=(char*)1 && count <= 31 ) + while ((a = va_arg(args, char*))!=(char*)1) { if (a) { From b87a08ce1ce77da26db3a7603e55107b8e65814c Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:23:28 +0100 Subject: [PATCH 05/17] Revert "fixed #240" This reverts commit 1d8ef0b089bcb6828b0dde62076493178ed185ec. Conflicts: ChangeLog --- ChangeLog | 14 ++++++-------- mhl/escape.h | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74b6e0f9b..e02a81632 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,3 @@ -2009-02-04 Enrico Weigelt, metux ITS - - * lib/mc.sh.in: fixes for non-bash shells (fixing #196) - -2009-02-04 Enrico Weigelt, metux ITS - - * mhl/types.h, mhl/escape.h: replaced bool type by stdbool.h (fixing #240) - 2009-02-03 Enrico Weigelt, metux ITS * lib/mc.lib: added patch on #219 by angel_il @@ -24,6 +16,9 @@ * src/find.c, src/main.c, src/panelize.c, src/util.c, src/utilunix.c, * src/widget.c, src/widget.h, src/wtools.c, vfs/fish.c: fixed shell escaping issues in commandline completion engine + +2009-01-31 Enrico Weigelt, metux ITS + * replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file() (in mhl/string.h) 2009-01-30 Enrico Weigelt, metux ITS @@ -45,6 +40,9 @@ * mhl/escape.h, src/complete.c, vfs/fish.c: introduced new type SHELL_ESCAPED_STR for more type safety + +2009-01-27 Enrico Weigelt, metux IT service + * mhl/escape.h, mhl/string.h: fixed comments to use /* ... */ 2009-01-27 Sergei Trofimovich diff --git a/mhl/escape.h b/mhl/escape.h index ed25b608a..2ec4e0d46 100644 --- a/mhl/escape.h +++ b/mhl/escape.h @@ -5,7 +5,8 @@ #include #include -#include + +#include #define mhl_shell_escape_toesc(x) \ (((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \ From d6da1ead5c8eeb91eaa7cc80648cfbc87ac1ff92 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:24:04 +0100 Subject: [PATCH 06/17] Revert "cleanup: mhl_str_dir_plus_file(): int -> size_t (suggested by Andrew Borodin)" This reverts commit 80a68972718b68c5c5ae050999b187f1676c653b. --- mhl/string.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mhl/string.h b/mhl/string.h index ee74e1d48..f4c56e5ec 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -149,11 +149,11 @@ static inline char* mhl_str_dir_plus_file(const char* dirname, const char* filen filename++; /* skip trailing slashes on dirname */ - size_t dnlen = strlen(dirname); - while ((dnlen != 0) && (dirname[dnlen-1]=='/')) + int dnlen = strlen(dirname); + while (dnlen && (dirname[dnlen-1]=='/')) dnlen--; - size_t fnlen = strlen(filename); + int fnlen = strlen(filename); char* buffer = mhl_mem_alloc_z(dnlen+fnlen+2); /* enough space for dirname, /, filename, zero */ char* ptr = buffer; From 1f656eb6be758d09c1bdccce887cc540b9507868 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:24:32 +0100 Subject: [PATCH 07/17] Revert "build fix: added missing declaration of mhl_dir_plus_file (reported by andrew_b)" This reverts commit c697fb3753fe9d3daddfed545115942506b90a23. --- vfs/smbfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/vfs/smbfs.c b/vfs/smbfs.c index e027da80c..f4d2345f1 100644 --- a/vfs/smbfs.c +++ b/vfs/smbfs.c @@ -49,8 +49,6 @@ #include -#include - #include "vfs.h" #include "vfs-impl.h" #include "smbfs.h" From 5bbeba0b8b97903177eec1926f264f3151f0a34f Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:24:57 +0100 Subject: [PATCH 08/17] Revert "mhl: mhl_shell_unescape_buf(): fixed memory array OOB." This reverts commit 7a51b50d5ce442970eb3909cddae236b53025877. --- mhl/escape.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/mhl/escape.h b/mhl/escape.h index 2ec4e0d46..efc0aac52 100644 --- a/mhl/escape.h +++ b/mhl/escape.h @@ -113,8 +113,6 @@ static inline char* mhl_shell_unescape_buf(char* text) case '`': case '"': case ';': - case '\0': /* end of line! malformed escape string */ - goto out; default: (*writeptr) = c; writeptr++; break; } @@ -126,7 +124,6 @@ static inline char* mhl_shell_unescape_buf(char* text) } readptr++; } -out: *writeptr = 0; return text; From e4e135399f768c1990656f6a5f345d3dcd511657 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:29:18 +0100 Subject: [PATCH 09/17] Revert "replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file()" This reverts commit 54d6ec88dcb9648d77ae84d063fdaedb76233b39. Conflicts: ChangeLog mhl/string.h src/command.c src/complete.c src/util.c --- edit/edit.c | 5 ++--- edit/editcmd.c | 8 ++++---- edit/editwidget.c | 5 ++--- edit/syntax.c | 7 +++---- edit/usermap.c | 5 ++--- src/charsets.c | 2 +- src/cmd.c | 26 ++++++++++++-------------- src/command.c | 8 ++------ src/complete.c | 16 +++++++--------- src/cons.handler.c | 4 +--- src/cons.saver.c | 2 -- src/ext.c | 7 +++---- src/file.c | 24 ++++++++++++------------ src/filenot.c | 6 ++---- src/find.c | 13 ++++++------- src/hotlist.c | 5 ++--- src/main.c | 5 ++--- src/screen.c | 15 +++++++-------- src/setup.c | 15 +++++++-------- src/treestore.c | 13 ++++++------- src/user.c | 6 ++---- src/util.c | 25 +++++++++++++++++-------- src/util.h | 1 + src/widget.c | 7 +++---- vfs/extfs.c | 11 ++++------- vfs/ftpfs.c | 10 ++++------ vfs/gc.c | 4 +--- vfs/mcfs.c | 2 +- vfs/sfs.c | 4 +--- vfs/smbfs.c | 2 +- vfs/vfs.c | 4 +--- 31 files changed, 119 insertions(+), 148 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index bec84d78d..8f2bca76e 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -30,9 +30,8 @@ #include #include #include -#include -#include +#include #include "../src/global.h" @@ -2666,7 +2665,7 @@ user_menu (WEdit * edit) int nomark; struct stat status; long start_mark, end_mark; - char *block_file = mhl_str_dir_plus_file (home_dir, BLOCK_FILE); + char *block_file = concat_dir_and_file (home_dir, BLOCK_FILE); int rc = 0; nomark = eval_marks (edit, &start_mark, &end_mark); diff --git a/edit/editcmd.c b/edit/editcmd.c index d223c35cd..8b5f19fac 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -28,6 +28,7 @@ #include #include + #include #include #include @@ -35,9 +36,8 @@ #include #include #include -#include -#include +#include #include "../src/global.h" #include "../src/history.h" @@ -235,7 +235,7 @@ edit_save_file (WEdit *edit, const char *filename) return 0; if (*filename != PATH_SEP && edit->dir) { - savename = mhl_str_dir_plus_file (edit->dir, filename); + savename = concat_dir_and_file (edit->dir, filename); filename = catstrs (savename, (char *) NULL); g_free (savename); } @@ -301,7 +301,7 @@ edit_save_file (WEdit *edit, const char *filename) savedir[slashpos - filename + 1] = '\0'; } else savedir = g_strdup ("."); - saveprefix = mhl_str_dir_plus_file (savedir, "cooledit"); + saveprefix = concat_dir_and_file (savedir, "cooledit"); g_free (savedir); fd = mc_mkstemps (&savename, saveprefix, NULL); g_free (saveprefix); diff --git a/edit/editwidget.c b/edit/editwidget.c index 8ae8cf0e8..2b248a069 100644 --- a/edit/editwidget.c +++ b/edit/editwidget.c @@ -33,9 +33,8 @@ #include #include #include -#include -#include +#include #include "../src/global.h" @@ -175,7 +174,7 @@ edit_file (const char *_file, int line) WButtonBar *edit_bar; if (!made_directory) { - char *dir = mhl_str_dir_plus_file (home_dir, EDIT_DIR); + char *dir = concat_dir_and_file (home_dir, EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); } diff --git a/edit/syntax.c b/edit/syntax.c index 2cfe97628..23e8b6ccd 100644 --- a/edit/syntax.c +++ b/edit/syntax.c @@ -30,9 +30,8 @@ #include #include #include -#include -#include +#include #include "../src/global.h" @@ -1027,7 +1026,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file, f = fopen (syntax_file, "r"); if (!f){ - lib_file = mhl_str_dir_plus_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); + lib_file = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); f = fopen (lib_file, "r"); g_free (lib_file); if (!f) @@ -1189,7 +1188,7 @@ edit_load_syntax (WEdit *edit, char ***pnames, const char *type) if (!*edit->filename && !type) return; } - f = mhl_str_dir_plus_file (home_dir, SYNTAX_FILE); + f = concat_dir_and_file (home_dir, SYNTAX_FILE); r = edit_read_syntax_file (edit, pnames, f, edit ? edit->filename : 0, get_first_editor_line (edit), type); if (r == -1) { diff --git a/edit/usermap.c b/edit/usermap.c index ebb6880cc..af0f02343 100644 --- a/edit/usermap.c +++ b/edit/usermap.c @@ -26,12 +26,11 @@ #include #include #include + #include #include #include -#include - #include "../src/global.h" #include "edit.h" @@ -597,7 +596,7 @@ edit_load_user_map(WEdit *edit) if (edit_key_emulation != EDIT_KEY_EMULATION_USER) return TRUE; - file = mhl_str_dir_plus_file(home_dir, MC_USERMAP); + file = concat_dir_and_file(home_dir, MC_USERMAP); if (stat(file, &s) < 0) { char *msg = g_strdup_printf(_("%s not found!"), file); diff --git a/src/charsets.c b/src/charsets.c index f2e69e0b2..10bbefc91 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -50,7 +50,7 @@ load_codepages_list (void) extern int display_codepage; char *default_codepage = NULL; - fname = mhl_str_dir_plus_file (mc_home, CHARSETS_INDEX); + fname = concat_dir_and_file (mc_home, CHARSETS_INDEX); if (!(f = fopen (fname, "r"))) { fprintf (stderr, _("Warning: file %s not found\n"), fname); g_free (fname); diff --git a/src/cmd.c b/src/cmd.c index f82165c96..7892bd3ad 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -34,8 +34,6 @@ #endif #include -#include - #include "global.h" #include "cmd.h" /* Our definitions */ #include "fileopctx.h" /* file_op_context_new() */ @@ -364,7 +362,7 @@ mkdir_cmd (void) if (dir[0] == '/' || dir[0] == '~') absdir = g_strdup (dir); else - absdir = mhl_str_dir_plus_file (current_panel->cwd, dir); + absdir = concat_dir_and_file (current_panel->cwd, dir); save_cwds_stat (); if (my_mkdir (absdir, 0777) == 0) { @@ -570,10 +568,10 @@ void ext_cmd (void) _(" Which extension file you want to edit? "), 0, 2, _("&User"), _("&System Wide")); } - extdir = mhl_str_dir_plus_file (mc_home, MC_LIB_EXT); + extdir = concat_dir_and_file (mc_home, MC_LIB_EXT); if (dir == 0){ - buffer = mhl_str_dir_plus_file (home_dir, MC_USER_EXT); + buffer = concat_dir_and_file (home_dir, MC_USER_EXT); check_for_default (extdir, buffer); do_edit (buffer); g_free (buffer); @@ -600,7 +598,7 @@ menu_edit_cmd (int where) _("&Local"), _("&User"), _("&System Wide") ); - menufile = mhl_str_dir_plus_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); + menufile = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); switch (dir) { case 0: @@ -609,12 +607,12 @@ menu_edit_cmd (int where) break; case 1: - buffer = mhl_str_dir_plus_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU); + buffer = concat_dir_and_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU); check_for_default (menufile, buffer); break; case 2: - buffer = mhl_str_dir_plus_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); + buffer = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); break; default: @@ -673,10 +671,10 @@ edit_syntax_cmd (void) _(" Which syntax file you want to edit? "), 0, 2, _("&User"), _("&System Wide")); } - extdir = mhl_str_dir_plus_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); + extdir = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); if (dir == 0) { - buffer = mhl_str_dir_plus_file (home_dir, SYNTAX_FILE); + buffer = concat_dir_and_file (home_dir, SYNTAX_FILE); check_for_default (extdir, buffer); do_edit (buffer); g_free (buffer); @@ -807,8 +805,8 @@ compare_dir (WPanel *panel, WPanel *other, enum CompareMode mode) } /* Thorough compare on, do byte-by-byte comparison */ - src_name = mhl_str_dir_plus_file (panel->cwd, source->fname); - dst_name = mhl_str_dir_plus_file (other->cwd, target->fname); + src_name = concat_dir_and_file (panel->cwd, source->fname); + dst_name = concat_dir_and_file (other->cwd, target->fname); if (compare_files (src_name, dst_name, source->st.st_size)) do_file_mark (panel, i, 1); g_free (src_name); @@ -922,10 +920,10 @@ do_link (int symbolic_link, const char *fname) char *d; /* suggest the full path for symlink */ - s = mhl_str_dir_plus_file (current_panel->cwd, fname); + s = concat_dir_and_file (current_panel->cwd, fname); if (get_other_type () == view_listing) { - d = mhl_str_dir_plus_file (other_panel->cwd, fname); + d = concat_dir_and_file (other_panel->cwd, fname); } else { d = g_strdup (fname); } diff --git a/src/command.c b/src/command.c index e608bf033..9692f0922 100644 --- a/src/command.c +++ b/src/command.c @@ -27,10 +27,6 @@ #include #include -#include -#include -#include - #include "global.h" /* home_dir */ #include "tty.h" #include "widget.h" /* WInput */ @@ -128,7 +124,7 @@ examine_cd (char *path) c = *s; *s = 0; if (*p) { - r = mhl_str_dir_plus_file (p, q); + r = concat_dir_and_file (p, q); result = do_cd (r, cd_parse_command); g_free (r); } @@ -181,7 +177,7 @@ void do_cd_command (char *cmd) } else { char *old = current_panel->cwd; char *new; - new = mhl_str_dir_plus_file (old, cmd+3); + new = concat_dir_and_file (old, cmd+3); sync_tree (new); g_free (new); } diff --git a/src/complete.c b/src/complete.c index 94e18953c..3f8d77877 100644 --- a/src/complete.c +++ b/src/complete.c @@ -26,14 +26,11 @@ #include #include #include + #include #include #include -#include -#include -#include - #include "global.h" #include "tty.h" #include "win.h" @@ -520,7 +517,7 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) if (cur_path >= path_end) break; expanded = tilde_expand (*cur_path ? cur_path : "."); - cur_word = mhl_str_dir_plus_file (expanded, text); + cur_word = concat_dir_and_file (expanded, text); g_free (expanded); canonicalize_pathname (cur_word); cur_path = strchr (cur_path, 0) + 1; @@ -815,10 +812,11 @@ try_complete (char *text, int *start, int *end, INPUT_COMPLETE_FLAGS flags) c = *s; *s = 0; if (*cdpath){ - r = mhl_str_dir_plus_file (cdpath, word); - SHOW_C_CTX("try_complete:filename_subst_2"); - matches = completion_matches (r, filename_completion_function, flags); - g_free (r); + r = concat_dir_and_file (cdpath, word); + ignore_filenames = 1; + matches = completion_matches (r, filename_completion_function); + ignore_filenames = 0; + g_free (r); } *s = c; cdpath = s + 1; diff --git a/src/cons.handler.c b/src/cons.handler.c index 1fe35b0b3..b08c2662d 100644 --- a/src/cons.handler.c +++ b/src/cons.handler.c @@ -28,8 +28,6 @@ #endif #include -#include - #include "global.h" #include "tty.h" #include "cons.saver.h" @@ -145,7 +143,7 @@ handle_console_linux (unsigned char action) open ("/dev/null", O_WRONLY); if (tty_name) { /* Exec the console save/restore handler */ - mc_conssaver = mhl_str_dir_plus_file (SAVERDIR, "cons.saver"); + mc_conssaver = concat_dir_and_file (SAVERDIR, "cons.saver"); execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL); } /* Console is not a tty or execl() failed */ diff --git a/src/cons.saver.c b/src/cons.saver.c index 7086cd64e..ccd0647ec 100644 --- a/src/cons.saver.c +++ b/src/cons.saver.c @@ -53,8 +53,6 @@ #endif #include -#include - #define LINUX_CONS_SAVER_C #include "cons.saver.h" diff --git a/src/ext.c b/src/ext.c index a0bee25f3..a4468bd8e 100644 --- a/src/ext.c +++ b/src/ext.c @@ -25,9 +25,8 @@ #include #include #include -#include -#include +#include #include "global.h" #include "tty.h" @@ -441,11 +440,11 @@ regex_command (const char *filename, const char *action, int *move_dir) int mc_user_ext = 1; int home_error = 0; - extension_file = mhl_str_dir_plus_file (home_dir, MC_USER_EXT); + extension_file = concat_dir_and_file (home_dir, MC_USER_EXT); if (!exist_file (extension_file)) { g_free (extension_file); check_stock_mc_ext: - extension_file = mhl_str_dir_plus_file (mc_home, MC_LIB_EXT); + extension_file = concat_dir_and_file (mc_home, MC_LIB_EXT); mc_user_ext = 0; } data = load_file (extension_file); diff --git a/src/file.c b/src/file.c index 6400e3e5f..a575b604a 100644 --- a/src/file.c +++ b/src/file.c @@ -922,7 +922,7 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel, } /* Dive into subdir if exists */ if (toplevel && ctx->dive_into_subdirs) { - dest_dir = mhl_str_dir_plus_file (d, x_basename (s)); + dest_dir = concat_dir_and_file (d, x_basename (s)); } else { dest_dir = g_strdup (d); goto dont_mkdir; @@ -968,11 +968,11 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel, continue; /* get the filename and add it to the src directory */ - path = mhl_str_dir_plus_file (s, next->d_name); + path = concat_dir_and_file (s, next->d_name); (*ctx->stat_func) (path, &buf); if (S_ISDIR (buf.st_mode)) { - mdpath = mhl_str_dir_plus_file (dest_dir, next->d_name); + mdpath = concat_dir_and_file (dest_dir, next->d_name); /* * From here, we just intend to recursively copy subdirs, not * the double functionality of copying different when the target @@ -983,7 +983,7 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel, parent_dirs, progress_count, progress_bytes); g_free (mdpath); } else { - dest_file = mhl_str_dir_plus_file (dest_dir, x_basename (path)); + dest_file = concat_dir_and_file (dest_dir, x_basename (path)); return_status = copy_file_file (ctx, path, dest_file, 1, progress_count, progress_bytes, 0); g_free (dest_file); @@ -1173,7 +1173,7 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d, destdir = g_strdup (d); move_over = 1; } else - destdir = mhl_str_dir_plus_file (d, x_basename (s)); + destdir = concat_dir_and_file (d, x_basename (s)); if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) { int msize = COLS - 36; @@ -1330,7 +1330,7 @@ recursive_erase (FileOpContext *ctx, const char *s, off_t *progress_count, continue; if (!strcmp (next->d_name, "..")) continue; - path = mhl_str_dir_plus_file (s, next->d_name); + path = concat_dir_and_file (s, next->d_name); if (mc_lstat (path, &buf)) { g_free (path); mc_closedir (reading); @@ -1521,7 +1521,7 @@ compute_dir_size (const char *dirname, off_t *ret_marked, double *ret_total) if (strcmp (dirent->d_name, "..") == 0) continue; - fullname = mhl_str_dir_plus_file (dirname, dirent->d_name); + fullname = concat_dir_and_file (dirname, dirent->d_name); res = mc_lstat (fullname, &s); @@ -1578,7 +1578,7 @@ panel_compute_totals (WPanel *panel, off_t *ret_marked, double *ret_total) double subdir_bytes = 0; dir_name = - mhl_str_dir_plus_file (panel->cwd, panel->dir.list[i].fname); + concat_dir_and_file (panel->cwd, panel->dir.list[i].fname); compute_dir_size (dir_name, &subdir_count, &subdir_bytes); *ret_marked += subdir_count; @@ -1886,7 +1886,7 @@ panel_operate (void *source_panel, FileOperation operation, /* The source and src_stat variables have been initialized before */ #ifdef WITH_FULL_PATHS - source_with_path = mhl_str_dir_plus_file (panel->cwd, source); + source_with_path = concat_dir_and_file (panel->cwd, source); #endif /* WITH_FULL_PATHS */ if (operation == OP_DELETE) { @@ -1901,7 +1901,7 @@ panel_operate (void *source_panel, FileOperation operation, if (temp == NULL) { value = transform_error; } else { - char *temp2 = mhl_str_dir_plus_file (dest, temp); + char *temp2 = concat_dir_and_file (dest, temp); g_free (dest); dest = temp2; temp = NULL; @@ -1979,7 +1979,7 @@ panel_operate (void *source_panel, FileOperation operation, #ifdef WITH_FULL_PATHS g_free (source_with_path); - source_with_path = mhl_str_dir_plus_file (panel->cwd, source); + source_with_path = concat_dir_and_file (panel->cwd, source); #endif /* WITH_FULL_PATHS */ if (operation == OP_DELETE) { @@ -1995,7 +1995,7 @@ panel_operate (void *source_panel, FileOperation operation, if (temp == NULL) value = transform_error; else { - char *temp2 = mhl_str_dir_plus_file (dest, temp); + char *temp2 = concat_dir_and_file (dest, temp); source_with_path = mhl_shell_unescape_buf(source_with_path); temp2 = mhl_shell_unescape_buf(temp2); diff --git a/src/filenot.c b/src/filenot.c index 01e0d784d..f614ce1e6 100644 --- a/src/filenot.c +++ b/src/filenot.c @@ -27,8 +27,6 @@ #include #include -#include - #include "global.h" static char * @@ -39,7 +37,7 @@ get_absolute_name (const char *file) if (file[0] == PATH_SEP) return g_strdup (file); mc_get_current_wd (dir, MC_MAXPATHLEN); - return mhl_str_dir_plus_file (dir, file); + return concat_dir_and_file (dir, file); } static int @@ -62,7 +60,7 @@ my_mkdir_rec (char *s, mode_t mode) return -1; } - p = mhl_str_dir_plus_file (s, ".."); + p = concat_dir_and_file (s, ".."); q = vfs_canon (p); g_free (p); diff --git a/src/find.c b/src/find.c index 9ff1ef720..4b9bc231a 100644 --- a/src/find.c +++ b/src/find.c @@ -25,9 +25,8 @@ #include #include #include -#include -#include +#include #include "global.h" #include "tty.h" @@ -355,7 +354,7 @@ push_directory (const char *dir) dir_stack *new; new = g_new (dir_stack, 1); - new->name = mhl_str_dir_plus_file (dir, NULL); + new->name = concat_dir_and_file (dir, ""); new->prev = dir_stack_base; dir_stack_base = new; } @@ -517,7 +516,7 @@ search_content (Dlg_head *h, const char *directory, const char *filename) int file_fd; int ret_val = 0; - fname = mhl_str_dir_plus_file (directory, filename); + fname = concat_dir_and_file (directory, filename); if (mc_stat (fname, &s) != 0 || !S_ISREG (s.st_mode)){ g_free (fname); @@ -693,7 +692,7 @@ do_search (struct Dlg_head *h) } if (subdirs_left && find_recursively && directory) { /* Can directory be NULL ? */ - char *tmp_name = mhl_str_dir_plus_file (directory, dp->d_name); + char *tmp_name = concat_dir_and_file (directory, dp->d_name); if (!mc_lstat (tmp_name, &tmp_stat) && S_ISDIR (tmp_stat.st_mode)) { push_directory (tmp_name); @@ -753,8 +752,8 @@ make_fullname (const char *dirname, const char *filename) if (strcmp(dirname, ".") == 0 || strcmp(dirname, "."PATH_SEP_STR) == 0) return g_strdup (filename); if (strncmp(dirname, "."PATH_SEP_STR, 2) == 0) - return mhl_str_dir_plus_file (dirname + 2, filename); - return mhl_str_dir_plus_file (dirname, filename); + return concat_dir_and_file (dirname + 2, filename); + return concat_dir_and_file (dirname, filename); } static void diff --git a/src/hotlist.c b/src/hotlist.c index 737c9c174..90678fe00 100644 --- a/src/hotlist.c +++ b/src/hotlist.c @@ -32,12 +32,11 @@ #include #include #include + #include #include #include -#include - #include "global.h" #include "tty.h" /* COLS */ #include "color.h" /* dialog_colors */ @@ -1448,7 +1447,7 @@ load_hotlist (void) } if (!hotlist_file_name) - hotlist_file_name = mhl_str_dir_plus_file (home_dir, HOTLIST_FILENAME); + hotlist_file_name = concat_dir_and_file (home_dir, HOTLIST_FILENAME); hotlist = new_hotlist (); hotlist->type = HL_TYPE_GROUP; diff --git a/src/main.c b/src/main.c index db26945b8..f8a6bb2af 100644 --- a/src/main.c +++ b/src/main.c @@ -29,12 +29,11 @@ #include #include #include + #include #include #include -#include - #include "global.h" #include "tty.h" #include "dir.h" @@ -1137,7 +1136,7 @@ copy_readlink (WPanel *panel) if (S_ISLNK (selection (panel)->st.st_mode)) { char buffer[MC_MAXPATHLEN]; char *p = - mhl_str_dir_plus_file (panel->cwd, selection (panel)->fname); + concat_dir_and_file (panel->cwd, selection (panel)->fname); int i; i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1); diff --git a/src/screen.c b/src/screen.c index 6c3821b74..d1121d8d1 100644 --- a/src/screen.c +++ b/src/screen.c @@ -25,9 +25,8 @@ #include #include #include -#include -#include +#include #include "global.h" #include "tty.h" @@ -710,7 +709,7 @@ display_mini_info (WPanel *panel) char *link, link_target [MC_MAXPATHLEN]; int len; - link = mhl_str_dir_plus_file (panel->cwd, panel->dir.list [panel->selected].fname); + link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname); len = mc_readlink (link, link_target, MC_MAXPATHLEN - 1); g_free (link); if (len > 0){ @@ -1975,7 +1974,7 @@ do_enter_on_file_entry (file_entry *fe) return 1; /* Check if the file is executable */ - full_name = mhl_str_dir_plus_file (current_panel->cwd, fe->fname); + full_name = concat_dir_and_file (current_panel->cwd, fe->fname); if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) { g_free (full_name); return 0; @@ -1994,7 +1993,7 @@ do_enter_on_file_entry (file_entry *fe) char *tmp; int ret; - tmp = mhl_str_dir_plus_file (vfs_get_current_dir (), fe->fname); + tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname); ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL); g_free (tmp); /* We took action only if the dialog was shown or the execution @@ -2031,10 +2030,10 @@ chdir_other_panel (WPanel *panel) } if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) { - new_dir = mhl_str_dir_plus_file (panel->cwd, ".."); + new_dir = concat_dir_and_file (panel->cwd, ".."); sel_entry = strrchr(panel->cwd, PATH_SEP); } else - new_dir = mhl_str_dir_plus_file (panel->cwd, panel->dir.list [panel->selected].fname); + new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname); change_panel (); do_cd (new_dir, cd_exact); @@ -2100,7 +2099,7 @@ chdir_to_readlink (WPanel *panel) if (*buffer == PATH_SEP) new_dir = g_strdup (buffer); else - new_dir = mhl_str_dir_plus_file (panel->cwd, buffer); + new_dir = concat_dir_and_file (panel->cwd, buffer); change_panel (); do_cd (new_dir, cd_exact); diff --git a/src/setup.c b/src/setup.c index 67dec4a9f..ef4249692 100644 --- a/src/setup.c +++ b/src/setup.c @@ -20,11 +20,10 @@ #include #include + #include #include -#include - #include "global.h" #include "tty.h" #include "dir.h" @@ -282,7 +281,7 @@ save_layout (void) int i; char buffer [BUF_TINY]; - profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); + profile = concat_dir_and_file (home_dir, PROFILE_NAME); /* Save integer options */ for (i = 0; layout [i].opt_name; i++){ @@ -299,7 +298,7 @@ save_configure (void) char *profile; int i; - profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); + profile = concat_dir_and_file (home_dir, PROFILE_NAME); /* Save integer options */ for (i = 0; int_options[i].opt_name; i++) @@ -347,7 +346,7 @@ save_setup (void) char *profile; saving_setup = 1; - profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); + profile = concat_dir_and_file (home_dir, PROFILE_NAME); save_configure (); @@ -482,9 +481,9 @@ setup_init (void) if (profile_name) return profile_name; - profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); + profile = concat_dir_and_file (home_dir, PROFILE_NAME); if (!exist_file (profile)){ - inifile = mhl_str_dir_plus_file (mc_home, "mc.ini"); + inifile = concat_dir_and_file (mc_home, "mc.ini"); if (exist_file (inifile)){ g_free (profile); profile = inifile; @@ -507,7 +506,7 @@ load_setup (void) /* mc.lib is common for all users, but has priority lower than ~/.mc/ini. FIXME: it's only used for keys and treestore now */ - global_profile_name = mhl_str_dir_plus_file (mc_home, "mc.lib"); + global_profile_name = concat_dir_and_file (mc_home, "mc.lib"); /* Load integer boolean options */ for (i = 0; int_options[i].opt_name; i++) diff --git a/src/treestore.c b/src/treestore.c index 323b8915c..426b0c289 100644 --- a/src/treestore.c +++ b/src/treestore.c @@ -37,12 +37,11 @@ #include #include #include + #include #include #include -#include - #include "global.h" #include "treestore.h" #include "profile.h" @@ -266,7 +265,7 @@ tree_store_load(void) char *name; int retval; - name = mhl_str_dir_plus_file(home_dir, MC_TREE); + name = concat_dir_and_file(home_dir, MC_TREE); retval = tree_store_load_from(name); g_free(name); @@ -372,7 +371,7 @@ tree_store_save(void) char *name; int retval; - tmp = mhl_str_dir_plus_file(home_dir, MC_TREE_TMP); + tmp = concat_dir_and_file(home_dir, MC_TREE_TMP); retval = tree_store_save_to(tmp); if (retval) { @@ -380,7 +379,7 @@ tree_store_save(void) return retval; } - name = mhl_str_dir_plus_file(home_dir, MC_TREE); + name = concat_dir_and_file(home_dir, MC_TREE); retval = rename(tmp, name); g_free(tmp); @@ -606,7 +605,7 @@ tree_store_mark_checked(const char *subname) if (ts.check_name[0] == PATH_SEP && ts.check_name[1] == 0) name = g_strconcat(PATH_SEP_STR, subname, (char *) NULL); else - name = mhl_str_dir_plus_file(ts.check_name, subname); + name = concat_dir_and_file(ts.check_name, subname); /* Search for the subdirectory */ current = ts.check_start; @@ -796,7 +795,7 @@ tree_store_rescan(const char *dir) continue; } - full_name = mhl_str_dir_plus_file(dir, dp->d_name); + full_name = concat_dir_and_file(dir, dp->d_name); if (mc_lstat(full_name, &buf) != -1) { if (S_ISDIR(buf.st_mode)) tree_store_mark_checked(dp->d_name); diff --git a/src/user.c b/src/user.c index 49e5d06ce..7cb617c3b 100644 --- a/src/user.c +++ b/src/user.c @@ -23,8 +23,6 @@ #include #include -#include - #include "global.h" #include "tty.h" #include "color.h" @@ -723,11 +721,11 @@ user_menu_cmd (struct WEdit *edit_widget) menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)){ g_free (menu); - menu = mhl_str_dir_plus_file \ + menu = concat_dir_and_file \ (home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU); if (!exist_file (menu)){ g_free (menu); - menu = mhl_str_dir_plus_file \ + menu = concat_dir_and_file \ (mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); } } diff --git a/src/util.c b/src/util.c index aebf59a27..27d5e9dc9 100644 --- a/src/util.c +++ b/src/util.c @@ -35,9 +35,6 @@ #include #include -#include -#include - #include "global.h" #include "profile.h" #include "main.h" /* mc_home */ @@ -694,7 +691,7 @@ load_mc_home_file (const char *filename, char **allocated_filename) char *lang; char *data; - hintfile_base = mhl_str_dir_plus_file (mc_home, filename); + hintfile_base = concat_dir_and_file (mc_home, filename); lang = guess_message_value (); hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); @@ -1253,6 +1250,18 @@ diff_two_paths (const char *first, const char *second) return buf; } +/* If filename is NULL, then we just append PATH_SEP to the dir */ +char * +concat_dir_and_file (const char *dir, const char *file) +{ + int i = strlen (dir); + + if (dir [i-1] == PATH_SEP) + return g_strconcat (dir, file, (char *) NULL); + else + return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL); +} + /* Append text to GList, remove all entries with the same text */ GList * list_append_unique (GList *list, char *text) @@ -1313,7 +1322,7 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix) if (strchr (prefix, PATH_SEP) == NULL) { /* Add prefix first to find the position of XXXXXX */ - tmpbase = mhl_str_dir_plus_file (mc_tmpdir (), prefix); + tmpbase = concat_dir_and_file (mc_tmpdir (), prefix); } else { tmpbase = g_strdup (prefix); } @@ -1381,7 +1390,7 @@ load_file_position (const char *filename, long *line, long *column) *column = 0; /* open file with positions */ - fn = mhl_str_dir_plus_file (home_dir, MC_FILEPOS); + fn = concat_dir_and_file (home_dir, MC_FILEPOS); f = fopen (fn, "r"); g_free (fn); if (!f) @@ -1428,8 +1437,8 @@ save_file_position (const char *filename, long line, long column) len = strlen (filename); - tmp = mhl_str_dir_plus_file (home_dir, MC_FILEPOS_TMP); - fn = mhl_str_dir_plus_file (home_dir, MC_FILEPOS); + tmp = concat_dir_and_file (home_dir, MC_FILEPOS_TMP); + fn = concat_dir_and_file (home_dir, MC_FILEPOS); /* open temporary file */ t = fopen (tmp, "w"); diff --git a/src/util.h b/src/util.h index 86009f01b..f68156688 100644 --- a/src/util.h +++ b/src/util.h @@ -66,6 +66,7 @@ char *strip_password (char *path, int has_prefix); const char *strip_home_and_password (const char *dir); const char *extension (const char *); +char *concat_dir_and_file (const char *dir, const char *file); const char *unix_error_string (int error_num); const char *skip_separators (const char *s); const char *skip_numbers (const char *s); diff --git a/src/widget.c b/src/widget.c index f85cc2a88..6328f49fe 100644 --- a/src/widget.c +++ b/src/widget.c @@ -32,9 +32,8 @@ #include #include #include -#include -#include +#include #include "global.h" #include "tty.h" @@ -866,7 +865,7 @@ history_get (const char *input_name) return NULL; if (!*input_name) return NULL; - profile = mhl_str_dir_plus_file (home_dir, HISTORY_FILE_NAME); + profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME); for (i = 0;; i++) { char key_name[BUF_TINY]; char this_entry[BUF_LARGE]; @@ -904,7 +903,7 @@ history_put (const char *input_name, GList *h) if (!num_history_items_recorded) /* this is how to disable */ return; - profile = mhl_str_dir_plus_file (home_dir, HISTORY_FILE_NAME); + profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME); if ((i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) != -1) close (i); diff --git a/vfs/extfs.c b/vfs/extfs.c index 03bbf254f..d634e3309 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -35,9 +35,6 @@ #include #endif #include - -#include - #include "../src/global.h" #include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/wtools.h" /* message() */ @@ -249,7 +246,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc) tmp = name_quote (name, 0); } - mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR); + mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR); cmd = g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ", local_name ? local_name : tmp, (char *) NULL); @@ -624,7 +621,7 @@ extfs_cmd (const char *extfs_cmd, struct archive *archive, archive_name = name_quote (extfs_get_archive_name (archive), 0); quoted_localname = name_quote (localname, 0); - mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR); + mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR); cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype], extfs_cmd, archive_name, " ", quoted_file, " ", quoted_localname, (char *) NULL); @@ -653,7 +650,7 @@ extfs_run (struct vfs_class *me, const char *file) g_free (p); archive_name = name_quote (extfs_get_archive_name (archive), 0); - mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR); + mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR); cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype], " run ", archive_name, " ", q, (char *) NULL); g_free (mc_extfsdir); @@ -1298,7 +1295,7 @@ static int extfs_init (struct vfs_class *me) (void) me; - mc_extfsini = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini"); + mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini"); cfg = fopen (mc_extfsini, "r"); /* We may not use vfs_die() message or message or similar, diff --git a/vfs/ftpfs.c b/vfs/ftpfs.c index 68f6967ff..5d8ac1f22 100644 --- a/vfs/ftpfs.c +++ b/vfs/ftpfs.c @@ -44,7 +44,7 @@ What to do with this? int f = !strcmp( remote_path, "/~" ); if (f || !strncmp( remote_path, "/~/", 3 )) { char *s; - s = mhl_str_dir_plus_file( qhome (*bucket), remote_path +3-f ); + s = concat_dir_and_file( qhome (*bucket), remote_path +3-f ); g_free (remote_path); remote_path = s; } @@ -69,8 +69,6 @@ What to do with this? #include #include -#include - #include "../src/global.h" #include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/wtools.h" /* message() */ @@ -557,7 +555,7 @@ ftpfs_load_no_proxy_list (void) if (mc_file) return; - mc_file = mhl_str_dir_plus_file (mc_home, "mc.no_proxy"); + mc_file = concat_dir_and_file (mc_home, "mc.no_proxy"); if (exist_file (mc_file) && (npf = fopen (mc_file, "r"))) { while (fgets (s, sizeof (s), npf)) { @@ -1232,7 +1230,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path ftpfs_open_data_connection (me, super, "LIST -la", 0, TYPE_ASCII, 0); else { /* Trailing "/." is necessary if remote_path is a symlink */ - char *path = mhl_str_dir_plus_file (remote_path, "."); + char *path = concat_dir_and_file (remote_path, "."); sock = ftpfs_open_data_connection (me, super, "LIST -la", path, TYPE_ASCII, 0); @@ -1888,7 +1886,7 @@ static int ftpfs_netrc_lookup (const char *host, char **login, char **pass) } /* Load current .netrc */ - netrcname = mhl_str_dir_plus_file (home_dir, ".netrc"); + netrcname = concat_dir_and_file (home_dir, ".netrc"); netrcp = netrc = load_file (netrcname); if (netrc == NULL) { g_free (netrcname); diff --git a/vfs/gc.c b/vfs/gc.c index 8da894618..a0376d8fe 100644 --- a/vfs/gc.c +++ b/vfs/gc.c @@ -31,8 +31,6 @@ #include #include /* is_digit() */ -#include - #include "../src/global.h" #include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/wtools.h" /* message() */ @@ -124,7 +122,7 @@ vfs_getid (struct vfs_class *vclass, const char *dir) vfsid id = NULL; /* append slash if needed */ - dir1 = mhl_str_dir_plus_file (dir, ""); + dir1 = concat_dir_and_file (dir, ""); if (vclass->getid) id = (*vclass->getid) (vclass, dir1); diff --git a/vfs/mcfs.c b/vfs/mcfs.c index 796db653b..07de5a34e 100644 --- a/vfs/mcfs.c +++ b/vfs/mcfs.c @@ -406,7 +406,7 @@ mcfs_get_path (mcfs_connection **mc, const char *path) int f = !strcmp (remote_path, "/~"); if (f || !strncmp (remote_path, "/~/", 3)) { char *s; - s = mhl_str_dir_plus_file (mcfs_gethome (*mc), + s = concat_dir_and_file (mcfs_gethome (*mc), remote_path + 3 - f); g_free (remote_path); remote_path = s; diff --git a/vfs/sfs.c b/vfs/sfs.c index 42df544ef..f4989ca30 100644 --- a/vfs/sfs.c +++ b/vfs/sfs.c @@ -34,8 +34,6 @@ #include #include -#include - #include "../src/global.h" #include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/wtools.h" /* message() */ @@ -338,7 +336,7 @@ static int sfs_init (struct vfs_class *me) (void) me; - mc_sfsini = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR "sfs.ini"); + mc_sfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "sfs.ini"); cfg = fopen (mc_sfsini, "r"); if (!cfg){ diff --git a/vfs/smbfs.c b/vfs/smbfs.c index f4d2345f1..a133fa341 100644 --- a/vfs/smbfs.c +++ b/vfs/smbfs.c @@ -1211,7 +1211,7 @@ smbfs_get_path (smbfs_connection ** sc, const char *path) int f = !strcmp (remote_path, "/~"); if (f || !strncmp (remote_path, "/~/", 3)) { char *s; - s = mhl_str_dir_plus_file ((*sc)->home, remote_path + 3 - f); + s = concat_dir_and_file ((*sc)->home, remote_path + 3 - f); g_free (remote_path); return s; } diff --git a/vfs/vfs.c b/vfs/vfs.c index 39fdc7366..21b5404a3 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -38,8 +38,6 @@ #include #include /* is_digit() */ -#include - #include "../src/global.h" #include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/wtools.h" /* message() */ @@ -658,7 +656,7 @@ vfs_canon (const char *path) if (*path != PATH_SEP){ char *local, *result; - local = mhl_str_dir_plus_file (current_dir, path); + local = concat_dir_and_file (current_dir, path); result = vfs_canon (local); g_free (local); From f237a14635ca6f26c083f591391e59782c7f8fb9 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:52:27 +0100 Subject: [PATCH 10/17] Revert some functions (mhl_mem_free to g_free, etc) Signed-off-by: Patrick Winnertz --- src/command.c | 4 +-- src/complete.c | 16 +++++----- src/file.c | 8 ++--- vfs/fish.c | 80 +++++++++++++++++++++++++------------------------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/command.c b/src/command.c index 9692f0922..40e913ab7 100644 --- a/src/command.c +++ b/src/command.c @@ -63,7 +63,7 @@ examine_cd (char *path) const char *t; /* Tilde expansion */ - path = mhl_shell_unescape_buf(path); + path = shell_unescape(path); path_tilde = tilde_expand (path); /* Leave space for further expansion */ @@ -135,7 +135,7 @@ examine_cd (char *path) } g_free (q); g_free (path_tilde); -// mhl_mem_free(path); +// g_free(path); return result; } diff --git a/src/complete.c b/src/complete.c index 3f8d77877..ee1b8ef9f 100644 --- a/src/complete.c +++ b/src/complete.c @@ -83,7 +83,7 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) SHOW_C_CTX("filename_completion_function"); if (text && (flags & INPUT_COMPLETE_SHELL_ESC)) - text = mhl_shell_unescape_buf (text); + text = shell_unescape (text); /* If we're starting the match process, initialize us a bit. */ if (!state){ @@ -203,8 +203,8 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) if (temp && (flags & INPUT_COMPLETE_SHELL_ESC)) { - SHELL_ESCAPED_STR e_temp = mhl_shell_escape_dup(temp); - mhl_mem_free (temp); + SHELL_ESCAPED_STR e_temp = shell_escape(temp); + g_free (temp); temp = e_temp.s; } return temp; @@ -460,7 +460,7 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) if (!(flags & INPUT_COMPLETE_COMMANDS)) return 0; - text = mhl_shell_unescape_buf(text); + text = shell_unescape(text); flags &= ~INPUT_COMPLETE_SHELL_ESC; if (!state) { /* Initialize us a little bit */ @@ -483,8 +483,8 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) p = filename_completion_function (text, state, flags); if (!p) return 0; - SHELL_ESCAPED_STR e_p = mhl_shell_escape_dup(p); - mhl_mem_free(p); + SHELL_ESCAPED_STR e_p = shell_escape(p); + g_free(p); return e_p.s; } @@ -541,8 +541,8 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) if ((p = strrchr (found, PATH_SEP)) != NULL) { p++; - SHELL_ESCAPED_STR e_p = mhl_shell_escape_dup(p); - mhl_mem_free(found); + SHELL_ESCAPED_STR e_p = shell_escape(p); + g_free(found); return e_p.s; } return found; diff --git a/src/file.c b/src/file.c index a575b604a..1fa461e1a 100644 --- a/src/file.c +++ b/src/file.c @@ -1809,7 +1809,7 @@ panel_operate (void *source_panel, FileOperation operation, else /* add trailing separator */ if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) { - dest_dir_ = mhl_str_concat (dest_dir, PATH_SEP_STR); + dest_dir_ = g_concat (dest_dir, PATH_SEP_STR); } else { dest_dir_ = mhl_str_dup (dest_dir); } @@ -1821,7 +1821,7 @@ panel_operate (void *source_panel, FileOperation operation, dest = file_mask_dialog (ctx, operation, cmd_buf, dest_dir_, single_entry, &do_bg); - mhl_mem_free(dest_dir_); + g_free(dest_dir_); if (!dest) { file_op_context_destroy (ctx); @@ -1997,8 +1997,8 @@ panel_operate (void *source_panel, FileOperation operation, else { char *temp2 = concat_dir_and_file (dest, temp); - source_with_path = mhl_shell_unescape_buf(source_with_path); - temp2 = mhl_shell_unescape_buf(temp2); + source_with_path = shell_unescape(source_with_path); + temp2 = shell_unescape(temp2); switch (operation) { case OP_COPY: diff --git a/vfs/fish.c b/vfs/fish.c index 7df2e1e6a..ea1d0c954 100644 --- a/vfs/fish.c +++ b/vfs/fish.c @@ -144,7 +144,7 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super, enable_interrupt_key (); status = write (SUP.sockw, str, strlen (str)); - mhl_mem_free (str); + g_free (str); disable_interrupt_key (); if (status < 0) @@ -168,10 +168,10 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super) close (SUP.sockr); SUP.sockw = SUP.sockr = -1; } - mhl_mem_free (SUP.host); - mhl_mem_free (SUP.user); - mhl_mem_free (SUP.cwdir); - mhl_mem_free (SUP.password); + g_free (SUP.host); + g_free (SUP.user); + g_free (SUP.cwdir); + g_free (SUP.password); } static void @@ -251,7 +251,7 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) p = g_strconcat (_(" fish: Password required for "), SUP.user, " ", (char *) NULL); op = vfs_get_password (p); - mhl_mem_free (p); + g_free (p); if (op == NULL) ERRNOR (EPERM, -1); SUP.password = op; @@ -314,7 +314,7 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super, p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, &password, 0, URL_NOSLASH); - mhl_mem_free (p); + g_free (p); SUP.host = host; SUP.user = user; @@ -341,12 +341,12 @@ fish_archive_same (struct vfs_class *me, struct vfs_s_super *super, op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0, URL_NOSLASH); - mhl_mem_free (op); + g_free (op); flags = ((strcmp (host, SUP.host) == 0) && (strcmp (user, SUP.user) == 0) && (flags == SUP.flags)); - mhl_mem_free (host); - mhl_mem_free (user); + g_free (host); + g_free (user); return flags; } @@ -377,7 +377,7 @@ 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 = mhl_shell_escape_dup (remote_path); + quoted_path = shell_escape (remote_path); fish_command (me, super, NONE, "#LIST /%s\n" "if `perl -v > /dev/null 2>&1` ; then\n" @@ -454,7 +454,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) "echo '### 500'\n" "fi\n", quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s); - mhl_mem_free (quoted_path.s); + g_free (quoted_path.s); ent = vfs_s_generate_entry(me, NULL, dir, 0); while (1) { int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr); @@ -515,11 +515,11 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) --linkname_bound; // skip trailing " } - ent->name = mhl_str_dup_range(filename, filename_bound); - mhl_shell_unescape_buf(ent->name); + ent->name = str_dup_range(filename, filename_bound); + shell_unescape(ent->name); - ent->ino->linkname = mhl_str_dup_range(linkname, linkname_bound); - mhl_shell_unescape_buf(ent->ino->linkname); + ent->ino->linkname = str_dup_range(linkname, linkname_bound); + shell_unescape(ent->ino->linkname); } else { // we expect: "escaped-name" if (filename_bound - filename > 2) @@ -532,8 +532,8 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) --filename_bound; } - ent->name = mhl_str_dup_range(filename, filename_bound); - mhl_shell_unescape_buf(ent->name); + ent->name = str_dup_range(filename, filename_bound); + shell_unescape(ent->name); } break; } @@ -585,7 +585,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) vfs_s_free_entry (me, ent); reply_code = fish_decode_reply(buffer + 4, 0); if (reply_code == COMPLETE) { - mhl_mem_free (SUP.cwdir); + g_free (SUP.cwdir); SUP.cwdir = g_strdup (remote_path); print_vfs_message (_("%s: done."), me->name); return 0; @@ -649,7 +649,7 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc * algorithm for file appending case, therefore just "dd" is used for it. */ - quoted_name = mhl_shell_escape_dup(name); + quoted_name = shell_escape(name); print_vfs_message(_("fish: store %s: sending command..."), quoted_name.s ); /* FIXME: File size is limited to ULONG_MAX */ @@ -726,14 +726,14 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc (unsigned long) s.st_size); } close(h); - mhl_mem_free(quoted_name.s); + g_free(quoted_name.s); if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error) ERRNOR (E_REMOTE, -1); return 0; error_return: close(h); fish_get_reply(me, SUP.sockr, NULL, 0); - mhl_mem_free(quoted_name.s); + g_free(quoted_name.s); return -1; } @@ -747,7 +747,7 @@ fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset) name = vfs_s_fullpath (me, fh->ino); if (!name) return 0; - quoted_name = mhl_shell_escape_dup(name); + quoted_name = shell_escape(name); fh->u.fish.append = 0; /* @@ -771,7 +771,7 @@ fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset) "echo '### 500'\n" "fi\n", quoted_name.s, quoted_name.s, quoted_name.s, quoted_name.s ); - mhl_mem_free (quoted_name.s); + g_free (quoted_name.s); if (offset != PRELIM) ERRNOR (E_REMOTE, 0); fh->linear = LS_LINEAR_OPEN; fh->u.fish.got = 0; @@ -884,14 +884,14 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c SHELL_ESCAPED_STR rpath; \ struct vfs_s_super *super; \ if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \ - mhl_mem_free (mpath); \ + g_free (mpath); \ return -1; \ } \ - rpath = mhl_shell_escape_dup(crpath); \ - mhl_mem_free (mpath); + rpath = shell_escape(crpath); \ + g_free (mpath); #define POSTFIX(flags) \ - mhl_mem_free (rpath.s); \ + g_free (rpath.s); \ return fish_send_command(me, super, buf, flags); static int @@ -914,21 +914,21 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat char *mpath1, *mpath2; \ struct vfs_s_super *super1, *super2; \ if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \ - mhl_mem_free (mpath1); \ + g_free (mpath1); \ return -1; \ } \ if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) { \ - mhl_mem_free (mpath1); \ - mhl_mem_free (mpath2); \ + g_free (mpath1); \ + g_free (mpath2); \ return -1; \ } \ - SHELL_ESCAPED_STR rpath1 = mhl_shell_escape_dup (crpath1); \ - mhl_mem_free (mpath1); \ - SHELL_ESCAPED_STR rpath2 = mhl_shell_escape_dup (crpath2); \ - mhl_mem_free (mpath2); \ + SHELL_ESCAPED_STR rpath1 = shell_escape (crpath1); \ + g_free (mpath1); \ + SHELL_ESCAPED_STR rpath2 = shell_escape (crpath2); \ + g_free (mpath2); \ g_snprintf(buf, sizeof(buf), string "\n", rpath1.s, rpath2.s, rpath1.s, rpath2.s); \ - mhl_mem_free (rpath1.s); \ - mhl_mem_free (rpath2.s); \ + g_free (rpath1.s); \ + g_free (rpath2.s); \ return fish_send_command(me, super2, buf, OPT_FLUSH); \ } @@ -943,13 +943,13 @@ static int fish_symlink (struct vfs_class *me, const char *setto, const char *pa { SHELL_ESCAPED_STR qsetto; PREFIX - qsetto = mhl_shell_escape_dup (setto); + qsetto = shell_escape (setto); g_snprintf(buf, sizeof(buf), "#SYMLINK %s /%s\n" "ln -s %s /%s 2>/dev/null\n" "echo '### 000'\n", qsetto.s, rpath.s, qsetto.s, rpath.s); - mhl_mem_free (qsetto.s); + g_free (qsetto.s); POSTFIX(OPT_FLUSH); } @@ -1079,7 +1079,7 @@ fish_fill_names (struct vfs_class *me, fill_names_f func) name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags, "/", SUP.cwdir, (char *) NULL); (*func)(name); - mhl_mem_free (name); + g_free (name); super = super->next; } } From 7d0fa9afced7e65468499757607fb3b21a7bf378 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 13:54:23 +0100 Subject: [PATCH 11/17] fixed canonicalize_pathname() breakage: fixed str_move() function (memmove semantics) again and add shell_(un)escape again This patch reintroduces fix firstly appeared in (and recently broken by mhl revert) > commit e48cb7c89ff3e54de70130a3de2136a9902a023d > Author: Sergei Trofimovich > Date: Fri Jan 30 09:31:28 2009 +0200 > > mhl: added mhl_strmove() function (memmove semantics) ... > Snippet of man strcpy: > DESCRIPTION > The strcpy() function copies the string pointed to by src, including the terminating > null byte ('\0'), to the buffer pointed to by dest. ___The strings may not overlap___, > and the destination string dest must be large enough to receive the copy. > We used strcpy to move data chunk in memory: "./foo" -> "foo", etc. > > This patch introduces mhl_strmove and fixed canonicalize_pathname. Conflicts: src/util.h Signed-off-by: Patrick Winnertz --- src/util.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 35 +++++++++++- 2 files changed, 188 insertions(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index 27d5e9dc9..1f7150c6a 100644 --- a/src/util.c +++ b/src/util.c @@ -1531,3 +1531,157 @@ Q_ (const char *s) sep = strchr(result, '|'); return (sep != NULL) ? sep + 1 : result; } + +#define shell_escape_toesc(x) \ + (((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \ + ((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')|| \ + ((x)=='{')||((x)=='}')||((x)=='[')||((x)==']')||((x)=='`')|| \ + ((x)=='?')||((x)=='|')||((x)=='<')||((x)=='>')||((x)==';')|| \ + ((x)=='*')||((x)=='\\')||((x)=='"')) + +#define shell_escape_nottoesc(x) \ + (((x)!=0) && (!shell_escape_toesc((x)))) +/** To be compatible with the general posix command lines we have to escape + strings for the command line + + \params in + string for escaping + + \returns + return escaped string (which needs to be freed later) + */ +char* +shell_escape(const char* src) +{ + GString *str; + char *result = NULL; + + if ((src==NULL)||(!(*src))) + return strdup(""); + + str = g_string_new(""); + + /* look for the first char to escape */ + while (1) + { + char c; + /* copy over all chars not to escape */ + while ((c=(*src)) && shell_escape_nottoesc(c)) + { + g_string_append_c(str,c); + src++; + } + + /* at this point we either have an \0 or an char to escape */ + if (!c) { + result = str->str; + g_string_free(str,FALSE); + return result; + } + + g_string_append_c(str,'\\'); + g_string_append_c(str,c); + src++; + } +} + +/** Unescape paths or other strings for e.g the internal cd + shell-unescape within a given buffer (writing to it!) + + \params src + string for unescaping + + \returns + return unescaped string (which needs to be freed) + */ +char* +shell_unescape(const char* text) +{ + GString *str; + char *result = NULL; + + if (!text) + return NULL; + + + /* look for the first \ - that's quick skipover if there's nothing to escape */ + const char* readptr = text; + while ((*readptr) && ((*readptr)!='\\')) readptr++; + if (!(*readptr)) { + result = g_strdup(text); + return result; + } + str = g_string_new_len(text, readptr - text); + + /* if we're here, we're standing on the first '\' */ + char c; + while ((c = *readptr)) + { + if (c=='\\') + { + readptr++; + switch ((c = *readptr)) + { + case '\0': /* end of string! malformed escape string */ + goto out; + + case 'n': g_string_append_c(str,'\n'); break; + case 'r': g_string_append_c(str,'\r'); break; + case 't': g_string_append_c(str,'\t'); break; + + case ' ': + case '\\': + case '#': + case '$': + case '%': + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + case '<': + case '>': + case '!': + case '*': + case '?': + case '~': + case '`': + case '"': + case ';': + default: + g_string_append_c(str,c); break; + } + } + else /* got a normal character */ + { + g_string_append_c(str,c); + } + readptr++; + } +out: + + result = str->str; + g_string_free(str,FALSE); + return result; +} + +/** Check if char in pointer contain escape'd chars + + \params in + string for checking + + \returns + return TRUE if string contain escaped chars + otherwise return FALSE + */ +gboolean +shell_is_char_escaped ( const char *in ) +{ + if (in == NULL || !*in || in[0] != '\\') + return FALSE; + if (shell_escape_toesc(in[1])) + return TRUE; + return FALSE; +} + diff --git a/src/util.h b/src/util.h index f68156688..a81777662 100644 --- a/src/util.h +++ b/src/util.h @@ -1,7 +1,9 @@ #ifndef MC_UTIL_H -#define MC_UTIL_H +#define MC_UTIL_H96fc77bc3ee1f2ae2ae7c0a14d3bf08975b4cb66 #include +#include +#include /* Returns its argument as a "modifiable" string. This function is * intended to pass strings to legacy libraries that don't know yet @@ -256,4 +258,35 @@ extern int ascii_alpha_to_cntrl (int ch); #undef Q_ const char *Q_ (const char *s); + +gboolean shell_is_char_escaped ( const char * ); +char *shell_unescape( const char * ); +char *shell_escape( const char * ); + +#define str_dup_range(s_start, s_bound) (g_strndup(s_start, s_bound - s_start)) + +/* + * strcpy is unsafe on overlapping memory areas, so define memmove-alike + * string function. + * Have sense only when: + * * dest <= src + * AND + * * dest and str are pointers to one object (as Roland Illig pointed). + * + * We can't use str*cpy funs here: + * http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294 + */ +static inline char * str_move(char * dest, const char * src) +{ + size_t n; + + assert (dest<=src); + + n = strlen (src) + 1; /* + '\0' */ + + return memmove (dest, src, n); +} + +#define MC_PTR_FREE(ptr) do { g_free(ptr); (ptr) = NULL; } while (0) + #endif From 8b7e47d9cca63bff63d4920466b522f63946b0a2 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 14:11:30 +0100 Subject: [PATCH 12/17] Last bunch of reverts and removal of mhl/* Signed-off-by: Patrick Winnertz --- mhl/.gitignore | 3 - mhl/README | 103 ----------------------------- mhl/env.h | 8 --- mhl/escape.h | 150 ------------------------------------------- mhl/memory.h | 28 -------- mhl/strhash.h | 49 -------------- mhl/string.h | 171 ------------------------------------------------- mhl/types.h | 16 ----- src/charsets.c | 2 - src/file.c | 10 +-- src/utilunix.c | 12 ++-- vfs/fish.c | 5 +- 12 files changed, 9 insertions(+), 548 deletions(-) delete mode 100644 mhl/.gitignore delete mode 100644 mhl/README delete mode 100644 mhl/env.h delete mode 100644 mhl/escape.h delete mode 100644 mhl/memory.h delete mode 100644 mhl/strhash.h delete mode 100644 mhl/string.h delete mode 100644 mhl/types.h diff --git a/mhl/.gitignore b/mhl/.gitignore deleted file mode 100644 index e99558847..000000000 --- a/mhl/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.deps -Makefile -Makefile.in diff --git a/mhl/README b/mhl/README deleted file mode 100644 index dbf3490bf..000000000 --- a/mhl/README +++ /dev/null @@ -1,103 +0,0 @@ - -Micro helper library. --- - -This is a tiny library of helper functions/macros. - - * MACRO-FUNC: macro w/ function syntax. (might become inline func) - * INLINE-FUNC: inline function (might become macro func) - * MACRO: strictly a macro (may never become a inline func) - --- - -mhl/memory.h: Memory management functions - - * mhl_mem_alloc_u(sz) [MACRO-FUNC] - - Allocate sz bytes on stack, unitialized - - * mhl_mem_alloc_z(sz) [INLINE-FUNC] - - Allocate sz bytes on stack, zero'ed - - * mhl_mem_free(ptr) [INLINE-FUNC] - - Free chunk @ptr (MUST be allocated w/ mhl_mem_alloc_*()), - passing NULL is graciously allowed - - * mhl_mem_realloc(ptr,newsize) -> returns newptr - - Re-allocates a heap chunk, just like realloc() - - * MHL_PTR_FREE(ptr) [MACRO-ONLY] - - like mhl_mem_free(), but with ptr as a variable that gets cleared - (use this as shortcut to "mhl_mem_free(foo); foo = NULL") - -mhl/string.h: String helpers - - * mhl_str_dup(const char*s) -> char* - - [MACRO-FUNC] Safe version of strdup(), when NULL passed, returns strdup("") - - * mhl_str_ndup(const char* s) -> char* - - [MACRO-FUNC] Safe version of strndup(), when NULL passed, returns strdup("") - - * mhl_str_trim(char* s) -> char* - - [INLINE-FUNC] Trims the string (removing leading and trailing whitespacs), - WITHIN the passed buffer, returning the string s itself. - When NULL passed returns NULL. - - * mhl_str_toupper(char* s) -> char* - - [INLINE-FUNC] Converts the string in passed buffer to uppercase, returns that - buffer. When NULL passed returns NULL. - - * mhl_str_concat_1(const char* base, const char* one) -> char* - - [INLINE-FUNC] Concatenates the string one onto the string base and returns the - result in a newly allocated buffer (free it w/ mhl_mem_free()). - For NULL strings, "" is assumed. - - * mhl_str_concat_2(const char* base,const char* one,const char* two) -> char* - mhl_str_concat_3(const char* base,const char* one,const char* two,const char* three) -> char* - mhl_str_concat_4(const char* base,const char* one,const char* two,const char* three,const char* four) -> char* - mhl_str_concat_5(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five) -> char* - mhl_str_concat_6(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six) -> char* - mhl_str_concat_7(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six,const char* seven) -> char* - - [INLINE-FUNC] Like str_concat_1() but adding more strings. - - * mhl_str_reverse(char* str) -> char* - - [INLINE-FUNC] Reverses the string in passed buffer and returns the buffer ptr itself. - If NULL is passed, returns NULL. - -mhl/escape.h: Shell-style string escaping - - * mhl_shell_escape_toesc(char c) -> bool - - [MACRO-FUNC] returns true when given char has to be escaped - - * mhl_shell_escape_nottoesc(char c) -> bool - - [MACRO-FUNC] opposite of mhl_shell_escape_toesc() - - * mhl_shell_escape_dup(const char* s) -> char* - - [INLINE-FUNC] escapes an string and returns the result in a malloc()'ed chunk - Passing NULL returns an empty malloc()ed string. - - * mhl_shell_unescape_buf(char* s) -> char* - - [INLINE-FUNC] unescapes the string into given buffer (changes buffer!) and - returns ptr to the buffer itself. When NULL passed returns NULL. - -mhl/env.h: Environment variable helpers - - * mhl_getenv_dup(const char* n) -> char* - - [MACRO-FUNC] like getenv() but returns an strdup()'ed copy. When NULL passed, - returns strdup("") diff --git a/mhl/env.h b/mhl/env.h deleted file mode 100644 index 8d5633797..000000000 --- a/mhl/env.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __MHL_ENV_H -#define __MHL_ENV_H - -#include - -#define mhl_getenv_dup(name) (mhl_str_dup(name ? getenv(name) : "")) - -#endif diff --git a/mhl/escape.h b/mhl/escape.h deleted file mode 100644 index efc0aac52..000000000 --- a/mhl/escape.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef __MHL_SHELL_ESCAPE_H -#define __MHL_SHELL_ESCAPE_H - -/* Micro helper library: shell escaping functions */ - -#include -#include - -#include - -#define mhl_shell_escape_toesc(x) \ - (((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \ - ((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')|| \ - ((x)=='{')||((x)=='}')||((x)=='[')||((x)==']')||((x)=='`')|| \ - ((x)=='?')||((x)=='|')||((x)=='<')||((x)=='>')||((x)==';')|| \ - ((x)=='*')||((x)=='\\')||((x)=='"')) - -#define mhl_shell_escape_nottoesc(x) \ - (((x)!=0) && (!mhl_shell_escape_toesc((x)))) - -/* type for escaped string - just for a bit more type safety ;-p */ -typedef struct { char* s; } SHELL_ESCAPED_STR; - -/** To be compatible with the general posix command lines we have to escape - strings for the command line - - /params const char * in - string for escaping - /returns - return escaped string (later need to free) - */ -static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src) -{ - if ((src==NULL)||(!(*src))) - return (SHELL_ESCAPED_STR){ .s = strdup("") }; - - char* buffer = calloc(1, strlen(src)*2+2); - char* ptr = buffer; - - /* look for the first char to escape */ - while (1) - { - char c; - /* copy over all chars not to escape */ - while ((c=(*src)) && mhl_shell_escape_nottoesc(c)) - { - *ptr = c; - ptr++; - src++; - } - - /* at this point we either have an \0 or an char to escape */ - if (!c) - return (SHELL_ESCAPED_STR){ .s = buffer }; - - *ptr = '\\'; - ptr++; - *ptr = c; - ptr++; - src++; - } -} - -/** Unescape paths or other strings for e.g the internal cd - shell-unescape within a given buffer (writing to it!) - - /params const char * in - string for unescaping - /returns - return unescaped string -*/ -static inline char* mhl_shell_unescape_buf(char* text) -{ - if (!text) - return NULL; - - /* look for the first \ - that's quick skipover if there's nothing to escape */ - char* readptr = text; - while ((*readptr) && ((*readptr)!='\\')) readptr++; - if (!(*readptr)) return text; - - /* if we're here, we're standing on the first '\' */ - char* writeptr = readptr; - char c; - while ((c = *readptr)) - { - if (c=='\\') - { - readptr++; - switch ((c = *readptr)) - { - case 'n': (*writeptr) = '\n'; writeptr++; break; - case 'r': (*writeptr) = '\r'; writeptr++; break; - case 't': (*writeptr) = '\t'; writeptr++; break; - - case ' ': - case '\\': - case '#': - case '$': - case '%': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '<': - case '>': - case '!': - case '*': - case '?': - case '~': - case '`': - case '"': - case ';': - default: - (*writeptr) = c; writeptr++; break; - } - } - else /* got a normal character */ - { - (*writeptr) = *readptr; - writeptr++; - } - readptr++; - } - *writeptr = 0; - - return text; -} - -/** Check if char in pointer contain escape'd chars - - /params const char * in - string for checking - /returns - return TRUE if string contain escaped chars - otherwise return FALSE - */ -static inline bool -mhl_shell_is_char_escaped ( const char *in ) -{ - if (in == NULL || !*in || in[0] != '\\') - return false; - if (mhl_shell_escape_toesc(in[1])) - return true; - return false; -} - -#endif diff --git a/mhl/memory.h b/mhl/memory.h deleted file mode 100644 index b00617700..000000000 --- a/mhl/memory.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __MHL_MEM -#define __MHL_MEM - -#include -#include - -/* allocate a chunk of stack memory, uninitialized */ -#define mhl_mem_alloc_u(sz) (malloc(sz)) - -/* allocate a chunk of stack memory, zeroed */ -#define mhl_mem_alloc_z(sz) (calloc(1,sz)) - -/* free a chunk of memory from stack, passing NULL does no harm */ -static inline void mhl_mem_free(void* ptr) -{ - if (ptr) free(ptr); -} - -/* free an ptr and NULL it */ -#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0); - -/* allocate a chunk on stack - automatically free'd on function exit */ -#define mhl_stack_alloc(sz) (alloca(sz)) - -/* re-alloc memory chunk */ -#define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz)) - -#endif diff --git a/mhl/strhash.h b/mhl/strhash.h deleted file mode 100644 index 1f195053c..000000000 --- a/mhl/strhash.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __MHL_STRHASH_H -#define __MHL_STRHASH_H - -#include -#include - -static void __mhl_strhash_free_key(void* ptr) -{ - mhl_mem_free(ptr); -} - -static void __mhl_strhash_free_dummy(void* ptr) -{ -} - -typedef hash MHL_STRHASH; - -#define MHL_STRHASH_DECLARE(n) MHL_STRHASH n; - -#define MHL_STRHASH_INIT(h) \ - hash_initialise(h, 997U, \ - hash_hash_string, \ - hash_compare_string, \ - hash_copy_string, \ - __mhl_strhash_free_key, \ - __mhl_strhash_free_dummy) - -#define MHL_STRHASH_DECLARE_INIT(n) \ - MHL_STRHASH_DECLARE(n); \ - MHL_STRHASH_INIT(&n); - -#define MHL_STRHASH_DEINIT(ht) \ - hash_deinitialise(ht) - -static inline void mhl_strhash_addkey(MHL_STRHASH* ht, const char* key, void* value) -{ - hash_insert(ht, (char*)key, value); -} - -static inline void* mhl_strhash_lookup(MHL_STRHASH* ht, const char* key) -{ - void* retptr; - if (hash_retrieve(ht, (char*)key, &retptr)) - return retptr; - else - return NULL; -} - -#endif diff --git a/mhl/string.h b/mhl/string.h deleted file mode 100644 index f4c56e5ec..000000000 --- a/mhl/string.h +++ /dev/null @@ -1,171 +0,0 @@ -#ifndef __MHL_STRING_H -#define __MHL_STRING_H - -#include -#include -#include -#include - -#define mhl_str_dup(str) ((str ? strdup(str) : strdup(""))) -#define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup(""))) -#define mhl_str_len(str) ((str ? strlen(str) : 0)) - -static inline char * mhl_str_dup_range(const char * s_start, const char * s_bound) -{ - return mhl_str_ndup(s_start, s_bound - s_start); -} - -static inline char* mhl_str_trim(char* str) -{ - if (!str) return NULL; /* NULL string ?! bail out. */ - - /* find the first non-space */ - char* start; for (start=str; ((*str) && (!isspace(*str))); str++); - - /* only spaces ? */ - if (!(*str)) { *str = 0; return str; } - - /* get the size (cannot be empty - catched above) */ - size_t _sz = strlen(str); - - /* find the proper end */ - char* end; - for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--); - end[1] = 0; /* terminate, just to be sure */ - - /* if we have no leading spaces, just trucate */ - if (start==str) { end++; *end = 0; return str; } - - /* if it' only one char, dont need memmove for that */ - if (start==end) { str[0]=*start; str[1]=0; return str; } - - /* by here we have a (non-empty) region between start end end */ - memmove(str,start,(end-start+1)); - return str; -} - -static inline void mhl_str_toupper(char* str) -{ - if (str) - for (;*str;str++) - *str = toupper(*str); -} - -#define __STR_CONCAT_MAX 32 -/* _NEVER_ call this function directly ! */ -static inline char* __mhl_str_concat_hlp(const char* base, ...) -{ - static const char* arg_ptr[__STR_CONCAT_MAX]; - static size_t arg_sz[__STR_CONCAT_MAX]; - int count = 0; - size_t totalsize = 0; - - if (base) - { - arg_ptr[0] = base; - arg_sz[0] = totalsize = strlen(base); - count = 1; - } - - va_list args; - va_start(args,base); - char* a; - /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ - while ((a = va_arg(args, char*))!=(char*)1) - { - if (a) - { - arg_ptr[count] = a; - arg_sz[count] = strlen(a); - totalsize += arg_sz[count]; - count++; - } - } - - if (!count) - return mhl_str_dup(""); - - /* now as we know how much to copy, allocate the buffer */ - char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); - char* current = buffer; - int x=0; - for (x=0; x -#include - #include "global.h" #include "charsets.h" diff --git a/src/file.c b/src/file.c index 1fa461e1a..efd19fd01 100644 --- a/src/file.c +++ b/src/file.c @@ -50,10 +50,6 @@ #include #include -#include -#include -#include - #include "global.h" #include "tty.h" #include "eregex.h" @@ -181,7 +177,7 @@ do_transform_source (FileOpContext *ctx, const char *source) for (next_reg = 1, j = 0, k = 0; j < strlen (ctx->dest_mask); j++) { switch (ctx->dest_mask[j]) { case '\\': - if (mhl_shell_is_char_escaped (&ctx->dest_mask[j])){ + if (shell_is_char_escaped (&ctx->dest_mask[j])){ fntarget[k++] = ctx->dest_mask[j++]; fntarget[k++] = ctx->dest_mask[j]; break; @@ -1805,13 +1801,13 @@ panel_operate (void *source_panel, FileOperation operation, */ if (force_single) /* just copy */ - dest_dir_ = mhl_str_dup (dest_dir); + dest_dir_ = g_strdup (dest_dir); else /* add trailing separator */ if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) { dest_dir_ = g_concat (dest_dir, PATH_SEP_STR); } else { - dest_dir_ = mhl_str_dup (dest_dir); + dest_dir_ = g_strdup (dest_dir); } if (!dest_dir_) { file_op_context_destroy (ctx); diff --git a/src/utilunix.c b/src/utilunix.c index 1b72b2e40..c2afdee2b 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -41,8 +41,6 @@ #endif #include -#include - #include "global.h" #include "execute.h" #include "wtools.h" /* message() */ @@ -428,7 +426,7 @@ canonicalize_pathname (char *path) if (p[0] == PATH_SEP && p[1] == PATH_SEP) { s = p + 1; while (*(++s) == PATH_SEP); - mhl_strmove (p + 1, s); + str_move (p + 1, s); } p++; } @@ -437,7 +435,7 @@ canonicalize_pathname (char *path) p = lpath; while (*p) { if (p[0] == PATH_SEP && p[1] == '.' && p[2] == PATH_SEP) - mhl_strmove (p, p + 2); + str_move (p, p + 2); else p++; } @@ -453,7 +451,7 @@ canonicalize_pathname (char *path) lpath[1] = 0; return; } else { - mhl_strmove (lpath, lpath + 2); + str_move (lpath, lpath + 2); } } @@ -499,10 +497,10 @@ canonicalize_pathname (char *path) if (p[3] != 0) { if (s == lpath && *s == PATH_SEP) { /* "/../foo" -> "/foo" */ - mhl_strmove (s + 1, p + 4); + str_move (s + 1, p + 4); } else { /* "token/../foo" -> "foo" */ - mhl_strmove (s, p + 4); + str_move (s, p + 4); } p = (s > lpath) ? s - 1 : s; continue; diff --git a/vfs/fish.c b/vfs/fish.c index ea1d0c954..869500cd0 100644 --- a/vfs/fish.c +++ b/vfs/fish.c @@ -50,9 +50,6 @@ #include "tcputil.h" #include "../src/unixcompat.h" #include "fish.h" -#include "../mhl/memory.h" -#include "../mhl/string.h" -#include "../mhl/escape.h" int fish_directory_timeout = 900; @@ -880,7 +877,7 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c #define PREFIX \ char buf[BUF_LARGE]; \ const char *crpath; \ - char *mpath = mhl_str_dup (path); \ + char *mpath = g_strdup (path); \ SHELL_ESCAPED_STR rpath; \ struct vfs_s_super *super; \ if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \ From 0b0f8e61288682921a49e465b62a4c47585daa6c Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 15:02:51 +0100 Subject: [PATCH 13/17] Revert "introduced new type SHELL_ESCAPED_STR for more type safety" This reverts commit 90763ba82fc8fa5bc61904961f9e917eca895ada. Conflicts: ChangeLog mhl/escape.h src/complete.c vfs/fish.c Signed-off-by: Patrick Winnertz --- src/complete.c | 9 ++++--- vfs/fish.c | 69 +++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/complete.c b/src/complete.c index ee1b8ef9f..cf7fa23a4 100644 --- a/src/complete.c +++ b/src/complete.c @@ -998,17 +998,17 @@ complete_engine (WInput *in, int what_to_do) start++; in->completions = try_complete (in->buffer, &start, &end, in->completion_flags); } - if (in->completions){ if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { - char * complete = in->completions [0]; - if (insert_text (in, complete, strlen (complete))){ + complete = shell_escape(in->completions [0]); + if (insert_text (in, complete, strlen (complete))){ if (in->completions [1]) beep (); else free_completions (in); } else beep (); + g_free(complete); } if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) { int maxlen = 0, i, count = 0; @@ -1019,6 +1019,9 @@ complete_engine (WInput *in, int what_to_do) WListbox *query_list; for (p=in->completions + 1; *p; count++, p++) { + q = *p; + *p = shell_escape(*p); + g_free(q); if ((i = strlen (*p)) > maxlen) maxlen = i; } diff --git a/vfs/fish.c b/vfs/fish.c index 869500cd0..cb7e88950 100644 --- a/vfs/fish.c +++ b/vfs/fish.c @@ -355,7 +355,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) char buffer[8192]; struct vfs_s_entry *ent = NULL; FILE *logfile; - SHELL_ESCAPED_STR quoted_path; + char *quoted_path; int reply_code; #if 0 @@ -450,8 +450,8 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) "else\n" "echo '### 500'\n" "fi\n", - quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s); - g_free (quoted_path.s); + quoted_path, quoted_path, quoted_path, quoted_path, quoted_path, quoted_path); + g_free (quoted_path); ent = vfs_s_generate_entry(me, NULL, dir, 0); while (1) { int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr); @@ -606,7 +606,7 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc struct stat s; int was_error = 0; int h; - SHELL_ESCAPED_STR quoted_name; + char *quoted_name; h = open (localname, O_RDONLY); @@ -647,7 +647,7 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc */ quoted_name = shell_escape(name); - print_vfs_message(_("fish: store %s: sending command..."), quoted_name.s ); + print_vfs_message(_("fish: store %s: sending command..."), quoted_name ); /* FIXME: File size is limited to ULONG_MAX */ if (!fh->u.fish.append) @@ -671,8 +671,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc " rest=`expr $rest - $n`\n" "done\n" "}; echo '### 200'\n", - (unsigned long) s.st_size, quoted_name.s, - quoted_name.s, (unsigned long) s.st_size, + (unsigned long) s.st_size, quoted_name, + quoted_name, (unsigned long) s.st_size, (unsigned long) s.st_size); else n = fish_command (me, super, WAIT_REPLY, @@ -688,8 +688,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc " rest=`expr $rest - $n`\n" "done\n" "}; echo '### 200'\n", - (unsigned long) s.st_size, quoted_name.s, - quoted_name.s, (unsigned long) s.st_size); + (unsigned long) s.st_size, quoted_name, + quoted_name, (unsigned long) s.st_size); if (n != PRELIM) { close (h); @@ -723,14 +723,14 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc (unsigned long) s.st_size); } close(h); - g_free(quoted_name.s); + g_free(quoted_name); if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error) ERRNOR (E_REMOTE, -1); return 0; error_return: close(h); fish_get_reply(me, SUP.sockr, NULL, 0); - g_free(quoted_name.s); + g_free(quoted_name); return -1; } @@ -738,7 +738,7 @@ static int fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset) { char *name; - SHELL_ESCAPED_STR quoted_name; + char *quoted_name; if (offset) ERRNOR (E_NOTSUPP, 0); name = vfs_s_fullpath (me, fh->ino); @@ -767,8 +767,8 @@ fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset) "else\n" "echo '### 500'\n" "fi\n", - quoted_name.s, quoted_name.s, quoted_name.s, quoted_name.s ); - g_free (quoted_name.s); + quoted_name, quoted_name, quoted_name, quoted_name ); + g_free (quoted_name); if (offset != PRELIM) ERRNOR (E_REMOTE, 0); fh->linear = LS_LINEAR_OPEN; fh->u.fish.got = 0; @@ -877,8 +877,7 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c #define PREFIX \ char buf[BUF_LARGE]; \ const char *crpath; \ - char *mpath = g_strdup (path); \ - SHELL_ESCAPED_STR rpath; \ + char *rpath, *mpath = g_strdup (path); \ struct vfs_s_super *super; \ if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \ g_free (mpath); \ @@ -888,7 +887,7 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c g_free (mpath); #define POSTFIX(flags) \ - g_free (rpath.s); \ + g_free (rpath); \ return fish_send_command(me, super, buf, flags); static int @@ -898,8 +897,8 @@ fish_chmod (struct vfs_class *me, const char *path, int mode) g_snprintf(buf, sizeof(buf), "#CHMOD %4.4o /%s\n" "chmod %4.4o /%s 2>/dev/null\n" "echo '### 000'\n", - mode & 07777, rpath.s, - mode & 07777, rpath.s); + mode & 07777, rpath, + mode & 07777, rpath); POSTFIX(OPT_FLUSH); } @@ -908,7 +907,7 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat { \ char buf[BUF_LARGE]; \ const char *crpath1, *crpath2; \ - char *mpath1, *mpath2; \ + char *rpath1, *rpath2, *mpath1, *mpath2; \ struct vfs_s_super *super1, *super2; \ if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \ g_free (mpath1); \ @@ -919,13 +918,13 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat g_free (mpath2); \ return -1; \ } \ - SHELL_ESCAPED_STR rpath1 = shell_escape (crpath1); \ + rpath1 = shell_escape (crpath1); \ g_free (mpath1); \ - SHELL_ESCAPED_STR rpath2 = shell_escape (crpath2); \ + rpath2 = shell_escape (crpath2); \ g_free (mpath2); \ - g_snprintf(buf, sizeof(buf), string "\n", rpath1.s, rpath2.s, rpath1.s, rpath2.s); \ - g_free (rpath1.s); \ - g_free (rpath2.s); \ + g_snprintf(buf, sizeof(buf), string "\n", rpath1, rpath2, rpath1, rpath2); \ + g_free (rpath1); \ + g_free (rpath2); \ return fish_send_command(me, super2, buf, OPT_FLUSH); \ } @@ -938,15 +937,15 @@ FISH_OP(link, "#LINK /%s /%s\n" static int fish_symlink (struct vfs_class *me, const char *setto, const char *path) { - SHELL_ESCAPED_STR qsetto; + char *qsetto; PREFIX qsetto = shell_escape (setto); g_snprintf(buf, sizeof(buf), "#SYMLINK %s /%s\n" "ln -s %s /%s 2>/dev/null\n" "echo '### 000'\n", - qsetto.s, rpath.s, qsetto.s, rpath.s); - g_free (qsetto.s); + qsetto, rpath, qsetto, rpath); + g_free (qsetto); POSTFIX(OPT_FLUSH); } @@ -971,16 +970,16 @@ fish_chown (struct vfs_class *me, const char *path, int owner, int group) "#CHOWN %s /%s\n" "chown %s /%s 2>/dev/null\n" "echo '### 000'\n", - sowner, rpath.s, - sowner, rpath.s); + sowner, rpath, + sowner, rpath); fish_send_command (me, super, buf, OPT_FLUSH); /* FIXME: what should we report if chgrp succeeds but chown fails? */ g_snprintf (buf, sizeof(buf), "#CHGRP /%s \"/%s\"\n" "chgrp %s \"/%s\" 2>/dev/null\n" "echo '### 000'\n", - sgroup, rpath.s, - sgroup, rpath.s); + sgroup, rpath, + sgroup, rpath); /* fish_send_command(me, super, buf, OPT_FLUSH); */ POSTFIX (OPT_FLUSH) } @@ -993,7 +992,7 @@ static int fish_unlink (struct vfs_class *me, const char *path) "#DELE /%s\n" "rm -f /%s 2>/dev/null\n" "echo '### 000'\n", - rpath.s, rpath.s); + rpath, rpath); POSTFIX(OPT_FLUSH); } @@ -1007,7 +1006,7 @@ static int fish_mkdir (struct vfs_class *me, const char *path, mode_t mode) "#MKD /%s\n" "mkdir /%s 2>/dev/null\n" "echo '### 000'\n", - rpath.s, rpath.s); + rpath, rpath); POSTFIX(OPT_FLUSH); } @@ -1018,7 +1017,7 @@ static int fish_rmdir (struct vfs_class *me, const char *path) "#RMD /%s\n" "rmdir /%s 2>/dev/null\n" "echo '### 000'\n", - rpath.s, rpath.s); + rpath, rpath); POSTFIX(OPT_FLUSH); } From b10bfccfc024080145f19d7f37eabb0916f95fe7 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Fri, 13 Feb 2009 17:57:01 +0100 Subject: [PATCH 14/17] Remove some of the SHELL_ESCAPE_STR Stuff... Signed-off-by: Patrick Winnertz --- src/complete.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/complete.c b/src/complete.c index cf7fa23a4..6512fa548 100644 --- a/src/complete.c +++ b/src/complete.c @@ -39,7 +39,6 @@ #include "widget.h" #include "wtools.h" #include "main.h" -#include "util.h" #include "key.h" /* XCTRL and ALT macros */ typedef char *CompletionFunction (char * text, int state, INPUT_COMPLETE_FLAGS flags); @@ -203,9 +202,7 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) if (temp && (flags & INPUT_COMPLETE_SHELL_ESC)) { - SHELL_ESCAPED_STR e_temp = shell_escape(temp); - g_free (temp); - temp = e_temp.s; + temp = shell_escape(temp); } return temp; } @@ -483,9 +480,8 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) p = filename_completion_function (text, state, flags); if (!p) return 0; - SHELL_ESCAPED_STR e_p = shell_escape(p); - g_free(p); - return e_p.s; + p = shell_escape(p); + return p; } found = NULL; @@ -541,9 +537,9 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags) if ((p = strrchr (found, PATH_SEP)) != NULL) { p++; - SHELL_ESCAPED_STR e_p = shell_escape(p); + p = shell_escape(p); g_free(found); - return e_p.s; + return p; } return found; From ec3d3cf913a147dc00c53efb05e5147c8e63704d Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sun, 15 Feb 2009 11:52:56 +0200 Subject: [PATCH 15/17] header guard fix Signed-off-by: Sergei Trofimovich --- src/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index a81777662..e108424ed 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ #ifndef MC_UTIL_H -#define MC_UTIL_H96fc77bc3ee1f2ae2ae7c0a14d3bf08975b4cb66 +#define MC_UTIL_H #include #include From 5454c05b38e848e8013aa9edbc23feb3c27a526e Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sun, 15 Feb 2009 11:53:49 +0200 Subject: [PATCH 16/17] mismerge fix: g_concat -> g_strconcat Signed-off-by: Sergei Trofimovich --- src/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file.c b/src/file.c index efd19fd01..103930104 100644 --- a/src/file.c +++ b/src/file.c @@ -1805,7 +1805,7 @@ panel_operate (void *source_panel, FileOperation operation, else /* add trailing separator */ if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) { - dest_dir_ = g_concat (dest_dir, PATH_SEP_STR); + dest_dir_ = g_strconcat (dest_dir, PATH_SEP_STR, (char*)0); } else { dest_dir_ = g_strdup (dest_dir); } From d8d26d42fd2831be8564f535906ff2a95d4e3c97 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sun, 15 Feb 2009 11:57:26 +0200 Subject: [PATCH 17/17] fixed mismerge: completion stuff Signed-off-by: Sergei Trofimovich --- src/complete.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/complete.c b/src/complete.c index 6512fa548..32a1d1621 100644 --- a/src/complete.c +++ b/src/complete.c @@ -809,9 +809,8 @@ try_complete (char *text, int *start, int *end, INPUT_COMPLETE_FLAGS flags) *s = 0; if (*cdpath){ r = concat_dir_and_file (cdpath, word); - ignore_filenames = 1; - matches = completion_matches (r, filename_completion_function); - ignore_filenames = 0; + SHOW_C_CTX("try_complete:filename_subst_2"); + matches = completion_matches (r, filename_completion_function, flags); g_free (r); } *s = c; @@ -996,7 +995,7 @@ complete_engine (WInput *in, int what_to_do) } if (in->completions){ if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { - complete = shell_escape(in->completions [0]); + char * complete = g_strdup (in->completions [0]); if (insert_text (in, complete, strlen (complete))){ if (in->completions [1]) beep (); @@ -1015,9 +1014,6 @@ complete_engine (WInput *in, int what_to_do) WListbox *query_list; for (p=in->completions + 1; *p; count++, p++) { - q = *p; - *p = shell_escape(*p); - g_free(q); if ((i = strlen (*p)) > maxlen) maxlen = i; }