diff --git a/mhl/escape.h b/mhl/escape.h
index 2533388..9921d52 100644
a
|
b
|
|
6 | 6 | #include <string.h> |
7 | 7 | #include <stdlib.h> |
8 | 8 | |
| 9 | #ifndef FALSE |
| 10 | # define FALSE 0 |
| 11 | #endif |
| 12 | |
| 13 | #ifndef TRUE |
| 14 | # define TRUE 1 |
| 15 | #endif |
| 16 | |
9 | 17 | #define mhl_shell_escape_toesc(x) \ |
10 | 18 | (((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \ |
11 | 19 | ((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')|| \ |
… |
… |
|
16 | 24 | #define mhl_shell_escape_nottoesc(x) \ |
17 | 25 | (((x)!=0) && (!mhl_shell_escape_toesc((x)))) |
18 | 26 | |
| 27 | /** To be compatible with the general posix command lines we have to escape |
| 28 | strings for the command line |
| 29 | |
| 30 | /params const char * in |
| 31 | string for escaping |
| 32 | /returns |
| 33 | return escaped string (later need to free) |
| 34 | */ |
19 | 35 | static inline char* mhl_shell_escape_dup(const char* src) |
20 | 36 | { |
21 | 37 | if ((src==NULL)||(!(*src))) |
… |
… |
static inline char* mhl_shell_escape_dup(const char* src) |
48 | 64 | } |
49 | 65 | } |
50 | 66 | |
51 | | /* shell-unescape within a given buffer (writing to it!) */ |
| 67 | /** Unescape paths or other strings for e.g the internal cd |
| 68 | shell-unescape within a given buffer (writing to it!) |
| 69 | |
| 70 | /params const char * in |
| 71 | string for unescaping |
| 72 | /returns |
| 73 | return unescaped string |
| 74 | */ |
52 | 75 | static inline char* mhl_shell_unescape_buf(char* text) |
53 | 76 | { |
54 | 77 | if (!text) |
… |
… |
static inline char* mhl_shell_unescape_buf(char* text) |
109 | 132 | return text; |
110 | 133 | } |
111 | 134 | |
| 135 | /** Check if char in pointer contain escape'd chars |
| 136 | |
| 137 | /params const char * in |
| 138 | string for checking |
| 139 | /returns |
| 140 | return TRUE if string contain escaped chars |
| 141 | otherwise return FALSE |
| 142 | */ |
| 143 | static inline int |
| 144 | mhl_shell_is_char_escaped ( const char *in ) { |
| 145 | if (in == NULL || !*in || in[0] != '\\') return FALSE; |
| 146 | if (mhl_shell_escape_toesc(in[1])){ |
| 147 | return TRUE; |
| 148 | } |
| 149 | return FALSE; |
| 150 | } |
| 151 | |
112 | 152 | #endif |
diff --git a/src/command.c b/src/command.c
index 3141f8d..baa0e6e 100644
a
|
b
|
|
28 | 28 | #include <string.h> |
29 | 29 | |
30 | 30 | #include "mhl/memory.h" |
| 31 | #include "mhl/escape.h" |
31 | 32 | |
32 | 33 | #include "global.h" /* home_dir */ |
33 | 34 | #include "tty.h" |
… |
… |
examine_cd (char *path) |
66 | 67 | const char *t; |
67 | 68 | |
68 | 69 | /* Tilde expansion */ |
69 | | path = unescape_string(path); |
| 70 | path = mhl_shell_unescape_buf(path); |
70 | 71 | path_tilde = tilde_expand (path); |
71 | 72 | |
72 | 73 | /* Leave space for further expansion */ |
… |
… |
examine_cd (char *path) |
138 | 139 | } |
139 | 140 | g_free (q); |
140 | 141 | g_free (path_tilde); |
141 | | mhl_mem_free(path); |
| 142 | // mhl_mem_free(path); |
142 | 143 | return result; |
143 | 144 | } |
144 | 145 | |
diff --git a/src/complete.c b/src/complete.c
index 294f263..b350307 100644
a
|
b
|
|
32 | 32 | #include <unistd.h> |
33 | 33 | |
34 | 34 | #include "mhl/memory.h" |
| 35 | #include "mhl/escape.h" |
35 | 36 | |
36 | 37 | #include "global.h" |
37 | 38 | #include "tty.h" |
… |
… |
filename_completion_function (char *text, int state) |
74 | 75 | g_free (filename); |
75 | 76 | g_free (users_dirname); |
76 | 77 | |
77 | | text = unescape_string(text); |
| 78 | text = mhl_shell_unescape_buf(text); |
78 | 79 | if ((*text) && (temp = strrchr (text, PATH_SEP))){ |
79 | 80 | filename = g_strdup (++temp); |
80 | 81 | dirname = g_strndup (text, temp - text); |
… |
… |
filename_completion_function (char *text, int state) |
82 | 83 | dirname = g_strdup ("."); |
83 | 84 | filename = g_strdup (text); |
84 | 85 | } |
85 | | mhl_mem_free(text); |
86 | 86 | |
87 | 87 | /* We aren't done yet. We also support the "~user" syntax. */ |
88 | 88 | |
… |
… |
complete_engine (WInput *in, int what_to_do) |
956 | 956 | } |
957 | 957 | if (in->completions){ |
958 | 958 | if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { |
959 | | complete = escape_string(in->completions [0]); |
| 959 | complete = mhl_shell_escape_dup(in->completions [0]); |
960 | 960 | if (insert_text (in, complete, strlen (complete))){ |
961 | 961 | if (in->completions [1]) |
962 | 962 | beep (); |
… |
… |
complete_engine (WInput *in, int what_to_do) |
976 | 976 | |
977 | 977 | for (p=in->completions + 1; *p; count++, p++) { |
978 | 978 | q = *p; |
979 | | *p = escape_string(*p); |
| 979 | *p = mhl_shell_escape_dup(*p); |
980 | 980 | mhl_mem_free(q); |
981 | 981 | if ((i = strlen (*p)) > maxlen) |
982 | 982 | maxlen = i; |
diff --git a/src/file.c b/src/file.c
index d2a80b0..dad06dd 100644
a
|
b
|
|
51 | 51 | #include <unistd.h> |
52 | 52 | |
53 | 53 | #include "mhl/memory.h" |
| 54 | #include "mhl/escape.h" |
54 | 55 | |
55 | 56 | #include "global.h" |
56 | 57 | #include "tty.h" |
… |
… |
do_transform_source (FileOpContext *ctx, const char *source) |
179 | 180 | for (next_reg = 1, j = 0, k = 0; j < strlen (ctx->dest_mask); j++) { |
180 | 181 | switch (ctx->dest_mask[j]) { |
181 | 182 | case '\\': |
182 | | if (is_escaped_string (&ctx->dest_mask[j])){ |
| 183 | if (mhl_shell_is_char_escaped (&ctx->dest_mask[j])){ |
183 | 184 | fntarget[k++] = ctx->dest_mask[j++]; |
184 | 185 | fntarget[k++] = ctx->dest_mask[j]; |
185 | 186 | break; |
… |
… |
panel_operate (void *source_panel, FileOperation operation, |
1973 | 1974 | char *temp2 = concat_dir_and_file (dest, temp); |
1974 | 1975 | char *temp3; |
1975 | 1976 | |
1976 | | temp3 = source_with_path; |
1977 | | source_with_path = unescape_string(source_with_path); |
1978 | | mhl_mem_free(temp3); |
1979 | | temp3 = temp2; |
1980 | | temp2 = unescape_string(temp2); |
1981 | | mhl_mem_free(temp3); |
| 1977 | source_with_path = mhl_shell_unescape_buf(source_with_path); |
| 1978 | temp2 = mhl_shell_unescape_buf(temp2); |
1982 | 1979 | |
1983 | 1980 | switch (operation) { |
1984 | 1981 | case OP_COPY: |
diff --git a/src/util.c b/src/util.c
index c5612cf..1f97e85 100644
a
|
b
|
|
35 | 35 | #include <sys/stat.h> |
36 | 36 | #include <unistd.h> |
37 | 37 | |
| 38 | #include "mhl/escape.h" |
| 39 | |
38 | 40 | #include "global.h" |
39 | 41 | #include "profile.h" |
40 | 42 | #include "main.h" /* mc_home */ |
diff --git a/src/util.h b/src/util.h
index 706a892..4e9a113 100644
a
|
b
|
extern char *str_unconst (const char *); |
14 | 14 | extern const char *cstrcasestr (const char *haystack, const char *needle); |
15 | 15 | extern const char *cstrstr (const char *haystack, const char *needle); |
16 | 16 | |
17 | | char *unescape_string ( const char * ); |
18 | | char *escape_string ( const char * ); |
19 | | int is_escaped_string ( const char * ); |
20 | | |
21 | 17 | void str_replace(char *s, char from, char to); |
22 | 18 | int is_printable (int c); |
23 | 19 | void msglen (const char *text, /*@out@*/ int *lines, /*@out@*/ int *columns); |