@@ -609,6 +609,36 @@ char *shell_utf8_to_native(const char *ubuf, int ubytes, int *len)
609
609
610
610
#endif
611
611
612
+ char *shell_escape_backslashes (const char *str)
613
+ {
614
+ // count the backslashes
615
+ t_ptr_size ct = 0 ;
616
+ const char *c = str;
617
+ char *newstr = NULL ;
618
+ char *n;
619
+ t_bool hasslash = false ;
620
+
621
+ while (c && *c) {
622
+ if (*c++ == ' \\ ' ) {
623
+ ct++;
624
+ hasslash = true ;
625
+ }
626
+ ct++;
627
+ }
628
+ if (!hasslash) return NULL ;
629
+ newstr = (char *)sysmem_newptr (ct + 1 );
630
+ c = str;
631
+ n = newstr;
632
+ while (c && *c) {
633
+ if (*c == ' \\ ' ) {
634
+ *n++ = ' \\ ' ;
635
+ }
636
+ *n++ = *c++;
637
+ }
638
+ *n = ' \0 ' ;
639
+ return newstr;
640
+ }
641
+
612
642
Boolean shell_readline (t_shell *x)
613
643
{
614
644
char stream[MAX_MESSAGELEN];
@@ -619,7 +649,9 @@ Boolean shell_readline(t_shell *x)
619
649
t_atom a;
620
650
char *readstream = stream;
621
651
int charsize = 1 ;
622
-
652
+ char *escape;
653
+ t_string *str;
654
+
623
655
#ifdef WIN_VERSION
624
656
WCHAR *unicodestream = NULL ;
625
657
@@ -665,7 +697,14 @@ Boolean shell_readline(t_shell *x)
665
697
sysmem_copyptr (lp2, line, (long )cbytes);
666
698
line[cbytes] = ' \0 ' ;
667
699
lp2 = lp1 + 1 ;
668
- atom_setobj (&a, string_new (line));
700
+
701
+ escape = shell_escape_backslashes (line);
702
+ str = string_new (escape ? escape : line);
703
+ if (escape) {
704
+ sysmem_freeptr (escape);
705
+ escape = NULL ;
706
+ }
707
+ atom_setobj (&a, str);
669
708
defer (x, (method)shell_output, NULL , 1 , &a);
670
709
}
671
710
if (lp2 && *lp2) { // there's an incomplete line, rewrite it to the front of the
@@ -697,7 +736,13 @@ Boolean shell_readline(t_shell *x)
697
736
}
698
737
}
699
738
if (offset) {
700
- atom_setobj (&a, string_new (line));
739
+ escape = shell_escape_backslashes (line);
740
+ str = string_new (escape ? escape : line);
741
+ if (escape) {
742
+ sysmem_freeptr (escape);
743
+ escape = NULL ;
744
+ }
745
+ atom_setobj (&a, str);
701
746
defer (x, (method)shell_output, NULL , 1 , &a);
702
747
}
703
748
#ifdef WIN_VERSION
0 commit comments