Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

printquoted() and CSH_JUNKIE_QUOTES



-----BEGIN PGP SIGNED MESSAGE-----

As I suggested in my previous patch, here's a patch to make
printquoted() handle CSH_JUNKIE_QUOTES properly.  After the patch,
try:

% unsetopt cshjunkiequotes rcquotes
% alias foo="'a
> b'c'"
% alias foo
foo=\''a
b'\''c'\'
% setopt cshjunkiequotes
% alias foo
foo=\''a\
b'\''c'\'
% setopt rcquotes
% alias foo
foo='''a\
b''c'''
% unsetopt cshjunkiequotes
% alias foo
foo='''a
b''c'''

 -zefram

      *** 1.3	1996/01/07 02:09:24
      --- Src/builtin.c	1996/01/07 03:05:54
      ***************
      *** 5407,5413 ****
        printquoted(char *str)
        {
            char *ptr;
      !     int special = 0, inquote = 0;
        
            /* check for empty string */
            if(!*str) {
      --- 5407,5413 ----
        printquoted(char *str)
        {
            char *ptr;
      !     int inquote = 0;
        
            /* check for empty string */
            if(!*str) {
      ***************
      *** 5416,5459 ****
            }
        
            /* check for special characters in the string */
      !     for (ptr = str; *ptr; ptr++) {
      ! 	if (ispecial(*ptr)) {
      ! 	    special = 1;
      ! 	    break;
      ! 	}
      !     }
      !     if (!special) {
      ! 	/* no special characters at all */
      ! 	printf("%s", str);
      ! 	return;
      !     }
        
            if (isset(RCQUOTES)) {
        	/* use rc-style quotes-within-quotes for the whole string */
        	putchar('\'');
        	for (ptr = str; *ptr; ptr++) {
        	    if (*ptr == '\'')
      ! 		printf("''");
      ! 	    else
      ! 		putchar(*ptr);
        	}
        	putchar('\'');
            } else {
        	/* use Bourne-style quoting, avoiding empty quoted strings */
        	for (ptr = str; *ptr; ptr++) {
      ! 	    if (*ptr == '\'' && inquote) {
      ! 		printf("'\\'");
      ! 		inquote = 0;
      ! 	    } else if (*ptr == '\'')
      ! 		printf("\\'");
      ! 	    else if (!inquote) {
      ! 		printf("'%c",*ptr);
      ! 		inquote = 1;
      ! 	    } else
        		putchar(*ptr);
        	}
        	if (inquote)
        	    putchar('\'');
            }
        }
      - 
      --- 5416,5462 ----
            }
        
            /* check for special characters in the string */
      !     for (ptr = str; *ptr; ptr++)
      ! 	if (ispecial(*ptr))
      ! 	    goto hasspecial;
        
      +     /* no special characters at all */
      +     fputs(str, stdout);
      +     return;
      + 
      +     hasspecial:
            if (isset(RCQUOTES)) {
        	/* use rc-style quotes-within-quotes for the whole string */
        	putchar('\'');
        	for (ptr = str; *ptr; ptr++) {
        	    if (*ptr == '\'')
      ! 		putchar('\'');
      ! 	    else if(*ptr == '\n' && isset(CSHJUNKIEQUOTES))
      ! 		putchar('\\');
      ! 	    putchar(*ptr);
        	}
        	putchar('\'');
            } else {
        	/* use Bourne-style quoting, avoiding empty quoted strings */
        	for (ptr = str; *ptr; ptr++) {
      ! 	    if (*ptr == '\'') {
      ! 		if(inquote) {
      ! 		    putchar('\'');
      ! 		    inquote=0;
      ! 		}
      ! 		putchar('\\');
      ! 		putchar('\'');
      ! 	    } else {
      ! 		if (!inquote) {
      ! 		    putchar('\'');
      ! 		    inquote=1;
      ! 		}
      ! 	        if(*ptr == '\n' && isset(CSHJUNKIEQUOTES))
      ! 		    putchar('\\');
        		putchar(*ptr);
      + 	    }
        	}
        	if (inquote)
        	    putchar('\'');
            }
        }

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQCVAgUBMO89z3D/+HJTpU/hAQHuSAQAnYF1vTWMf44XIQ1BdYrhN4D4fv60S0O6
979n9ujFbeIEMS5q6dkKWojZTd3vvkcZTuStiV2iJfPP5H5LOcvyHV85ovdFyxz2
xXJEkeM2LW9CRcMt6Apo4VhDcvwA/CuNf/RtAfk7usHyzOtFcdOr86Tzw6nvL3EF
0LCVg9iof90=
=Kp/V
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author