Ticket #147: 147_escape_use_MHL.patch

File 147_escape_use_MHL.patch, 5.9 KB (added by slavazanko, 15 years ago)
  • mhl/escape.h

    diff --git a/mhl/escape.h b/mhl/escape.h
    index 2533388..9921d52 100644
    a b  
    66#include <string.h> 
    77#include <stdlib.h> 
    88 
     9#ifndef FALSE 
     10#       define FALSE 0 
     11#endif 
     12 
     13#ifndef TRUE 
     14#       define TRUE 1 
     15#endif 
     16 
    917#define mhl_shell_escape_toesc(x)       \ 
    1018    (((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')||       \ 
    1119     ((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')||      \ 
     
    1624#define mhl_shell_escape_nottoesc(x)    \ 
    1725    (((x)!=0) && (!mhl_shell_escape_toesc((x)))) 
    1826 
     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 */ 
    1935static inline char* mhl_shell_escape_dup(const char* src) 
    2036{ 
    2137    if ((src==NULL)||(!(*src))) 
    static inline char* mhl_shell_escape_dup(const char* src) 
    4864    } 
    4965} 
    5066 
    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*/ 
    5275static inline char* mhl_shell_unescape_buf(char* text) 
    5376{ 
    5477    if (!text) 
    static inline char* mhl_shell_unescape_buf(char* text) 
    109132    return text; 
    110133} 
    111134 
     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 */ 
     143static inline int 
     144mhl_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 
    112152#endif 
  • src/command.c

    diff --git a/src/command.c b/src/command.c
    index 3141f8d..baa0e6e 100644
    a b  
    2828#include <string.h> 
    2929 
    3030#include "mhl/memory.h" 
     31#include "mhl/escape.h" 
    3132 
    3233#include "global.h"             /* home_dir */ 
    3334#include "tty.h" 
    examine_cd (char *path) 
    6667    const char *t; 
    6768 
    6869    /* Tilde expansion */ 
    69     path = unescape_string(path); 
     70    path = mhl_shell_unescape_buf(path); 
    7071    path_tilde = tilde_expand (path); 
    7172 
    7273    /* Leave space for further expansion */ 
    examine_cd (char *path) 
    138139    } 
    139140    g_free (q); 
    140141    g_free (path_tilde); 
    141     mhl_mem_free(path); 
     142//    mhl_mem_free(path); 
    142143    return result; 
    143144} 
    144145 
  • src/complete.c

    diff --git a/src/complete.c b/src/complete.c
    index 294f263..b350307 100644
    a b  
    3232#include <unistd.h> 
    3333 
    3434#include "mhl/memory.h" 
     35#include "mhl/escape.h" 
    3536 
    3637#include "global.h" 
    3738#include "tty.h" 
    filename_completion_function (char *text, int state) 
    7475        g_free (filename); 
    7576        g_free (users_dirname); 
    7677 
    77         text = unescape_string(text); 
     78        text = mhl_shell_unescape_buf(text); 
    7879        if ((*text) && (temp = strrchr (text, PATH_SEP))){ 
    7980            filename = g_strdup (++temp); 
    8081            dirname = g_strndup (text, temp - text); 
    filename_completion_function (char *text, int state) 
    8283            dirname = g_strdup ("."); 
    8384            filename = g_strdup (text); 
    8485        } 
    85         mhl_mem_free(text); 
    8686 
    8787        /* We aren't done yet.  We also support the "~user" syntax. */ 
    8888 
    complete_engine (WInput *in, int what_to_do) 
    956956    } 
    957957    if (in->completions){ 
    958958        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]); 
    960960            if (insert_text (in, complete, strlen (complete))){ 
    961961                if (in->completions [1]) 
    962962                    beep (); 
    complete_engine (WInput *in, int what_to_do) 
    976976 
    977977            for (p=in->completions + 1; *p; count++, p++) { 
    978978                q = *p; 
    979                 *p = escape_string(*p); 
     979                *p = mhl_shell_escape_dup(*p); 
    980980                mhl_mem_free(q); 
    981981                if ((i = strlen (*p)) > maxlen) 
    982982                    maxlen = i; 
  • src/file.c

    diff --git a/src/file.c b/src/file.c
    index d2a80b0..dad06dd 100644
    a b  
    5151#include <unistd.h> 
    5252 
    5353#include "mhl/memory.h" 
     54#include "mhl/escape.h" 
    5455 
    5556#include "global.h" 
    5657#include "tty.h" 
    do_transform_source (FileOpContext *ctx, const char *source) 
    179180    for (next_reg = 1, j = 0, k = 0; j < strlen (ctx->dest_mask); j++) { 
    180181        switch (ctx->dest_mask[j]) { 
    181182        case '\\': 
    182             if (is_escaped_string (&ctx->dest_mask[j])){ 
     183            if (mhl_shell_is_char_escaped (&ctx->dest_mask[j])){ 
    183184                fntarget[k++] = ctx->dest_mask[j++]; 
    184185                fntarget[k++] = ctx->dest_mask[j]; 
    185186                break; 
    panel_operate (void *source_panel, FileOperation operation, 
    19731974                    char *temp2 = concat_dir_and_file (dest, temp); 
    19741975                    char *temp3; 
    19751976 
    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); 
    19821979 
    19831980                    switch (operation) { 
    19841981                    case OP_COPY: 
  • src/util.c

    diff --git a/src/util.c b/src/util.c
    index c5612cf..1f97e85 100644
    a b  
    3535#include <sys/stat.h> 
    3636#include <unistd.h> 
    3737 
     38#include "mhl/escape.h" 
     39 
    3840#include "global.h" 
    3941#include "profile.h" 
    4042#include "main.h"               /* mc_home */ 
  • src/util.h

    diff --git a/src/util.h b/src/util.h
    index 706a892..4e9a113 100644
    a b extern char *str_unconst (const char *); 
    1414extern const char *cstrcasestr (const char *haystack, const char *needle); 
    1515extern const char *cstrstr (const char *haystack, const char *needle); 
    1616 
    17 char *unescape_string ( const char * ); 
    18 char *escape_string ( const char * ); 
    19 int is_escaped_string ( const char * ); 
    20  
    2117void str_replace(char *s, char from, char to); 
    2218int  is_printable (int c); 
    2319void msglen (const char *text, /*@out@*/ int *lines, /*@out@*/ int *columns);