diff -u -w -r1.141 util.c
|
|
|
1525 | 1525 | return (sep != NULL) ? sep + 1 : result; |
1526 | 1526 | } |
1527 | 1527 | |
| 1528 | /* Unescape paths or other strings for e.g the internal cd */ |
| 1529 | char * |
| 1530 | unescape_string ( const char * in ) { |
| 1531 | char * local = NULL; |
| 1532 | int i = 0; |
| 1533 | int j = 20; |
| 1534 | int k = 0; |
| 1535 | |
| 1536 | local = g_malloc(j); |
| 1537 | |
| 1538 | for (i=0;i<=strlen(in);i++) { |
| 1539 | if (i-k+1 >= j ) { |
| 1540 | j = j + 20; |
| 1541 | local = g_realloc(local,j); |
| 1542 | } |
| 1543 | if ( (strchr(" \t*|;<>~#()?[]{}&",in[i])) && ( strchr("\\",in[i-1])) ) { |
| 1544 | k++; |
| 1545 | local[i-k] = in[i]; |
| 1546 | } else { |
| 1547 | local[i-k] = in[i]; |
| 1548 | } |
| 1549 | } |
| 1550 | local[i-k] = '\0'; |
| 1551 | |
| 1552 | return local; |
| 1553 | } |
| 1554 | |
| 1555 | /* To be compatible with the general posix command lines we have to escape * |
| 1556 | * strings for the command line */ |
| 1557 | char * |
| 1558 | escape_string ( const char * in ) { |
| 1559 | char * local = NULL; |
| 1560 | int i = 0; |
| 1561 | int j = 20; |
| 1562 | int k = 0; |
| 1563 | |
| 1564 | local = g_malloc(j); |
| 1565 | |
| 1566 | for (i=0;i<strlen(in);i++) { |
| 1567 | if (i+k+1 >= j ) { //If 20 chars is too low for the path |
| 1568 | j = j + 20; |
| 1569 | local = g_realloc(local,j); |
| 1570 | } |
| 1571 | if ( (strchr(" \t*|;<>~#()?[]{}&",in[i])) && (! strchr("\\",in[i-1])) ) { |
| 1572 | local[i+k] = 92; // Ascii for "\" |
| 1573 | k = k+1; |
| 1574 | local[i+k] = in[i]; |
| 1575 | } else { |
| 1576 | local[i+k] = in[i]; |
| 1577 | } |
| 1578 | } |
| 1579 | local[i+k] = '\0'; |
| 1580 | |
| 1581 | return local; |
| 1582 | } |
diff -u -w -r1.61 complete.c
|
|
|
40 | 40 | #include "wtools.h" |
41 | 41 | #include "complete.h" |
42 | 42 | #include "main.h" |
| 43 | #include "util.h" |
43 | 44 | #include "key.h" /* XCTRL and ALT macros */ |
44 | 45 | |
45 | 46 | typedef char *CompletionFunction (char *, int); |
… |
… |
|
911 | 912 | static int |
912 | 913 | complete_engine (WInput *in, int what_to_do) |
913 | 914 | { |
| 915 | char *complete = NULL; |
914 | 916 | if (in->completions && in->point != end) |
915 | 917 | free_completions (in); |
916 | 918 | if (!in->completions){ |
… |
… |
|
924 | 926 | } |
925 | 927 | if (in->completions){ |
926 | 928 | if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { |
927 | | if (insert_text (in, in->completions [0], strlen (in->completions [0]))){ |
| 929 | complete = escape_string(in->completions [0]); |
| 930 | if (insert_text (in, complete, strlen (complete))){ |
928 | 931 | if (in->completions [1]) |
929 | 932 | beep (); |
930 | 933 | else |
… |
… |
|
940 | 943 | Dlg_head *query_dlg; |
941 | 944 | WListbox *query_list; |
942 | 945 | |
943 | | for (p=in->completions + 1; *p; count++, p++) |
| 946 | for (p=in->completions + 1; *p; count++, p++) { |
| 947 | *p = escape_string(*p); |
944 | 948 | if ((i = strlen (*p)) > maxlen) |
945 | 949 | maxlen = i; |
| 950 | } |
946 | 951 | start_x = in->widget.x; |
947 | 952 | start_y = in->widget.y; |
948 | 953 | if (start_y - 2 >= count) { |
diff -u -w -r1.34 command.c
|
|
|
64 | 64 | const char *t; |
65 | 65 | |
66 | 66 | /* Tilde expansion */ |
| 67 | path = unescape_string(path); |
67 | 68 | path_tilde = tilde_expand (path); |
68 | 69 | |
69 | 70 | /* Leave space for further expansion */ |
diff -u -w -r1.151 file.c
|
|
|
63 | 63 | #include "widget.h" |
64 | 64 | #include "wtools.h" |
65 | 65 | #include "background.h" /* we_are_background */ |
| 66 | #include "util.h" |
66 | 67 | |
67 | 68 | /* Needed for current_panel, other_panel and WTree */ |
68 | 69 | #include "dir.h" |
… |
… |
|
791 | 807 | } |
792 | 808 | } |
793 | 809 | |
794 | | if (!appending) { |
| 810 | if (!appending && ctx->preserve) { |
795 | 811 | while (mc_chmod (dst_path, (src_mode & ctx->umask_kill))) { |
796 | 812 | temp_status = file_error ( |
797 | 813 | _(" Cannot chmod target file \"%s\" \n %s "), dst_path); |
… |
… |
|
1872 | 1890 | dest = temp2; |
1873 | 1891 | temp = NULL; |
1874 | 1892 | |
| 1893 | source_with_path = unescape_string(source_with_path); |
| 1894 | dest = unescape_string(dest); |
1875 | 1895 | switch (operation) { |
1876 | 1896 | case OP_COPY: |
1877 | 1897 | /* |
… |
… |
|
1963 | 1983 | else { |
1964 | 1984 | char *temp2 = concat_dir_and_file (dest, temp); |
1965 | 1985 | |
| 1986 | source_with_path = unescape_string(source_with_path); |
| 1987 | temp2 = unescape_string(temp2); |
| 1988 | |
1966 | 1989 | switch (operation) { |
1967 | 1990 | case OP_COPY: |
1968 | 1991 | /* |