X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fsh%2Fshquote.c;h=e992a66323134e723dd30a5ceb94853d20323fe6;hb=95732b497d12c98613bb3c5db16b61f377501a59;hp=aac2d3494721c9a0642e7ef7e33f5f90e126f2b9;hpb=eb87367179effbe5f430236db8259006d71438b7;p=platform%2Fupstream%2Fbash.git diff --git a/lib/sh/shquote.c b/lib/sh/shquote.c index aac2d34..e992a66 100644 --- a/lib/sh/shquote.c +++ b/lib/sh/shquote.c @@ -81,7 +81,8 @@ sh_double_quote (string) for (s = string; s && (c = *s); s++) { - if (sh_syntaxtab[c] & CBSDQUOTE) + /* Backslash-newline disappears within double quotes, so don't add one. */ + if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n') *r++ = '\\'; else if (c == CTLESC || c == CTLNUL) *r++ = CTLESC; /* could be '\\'? */ @@ -95,6 +96,32 @@ sh_double_quote (string) return (result); } +/* Turn S into a simple double-quoted string. If FLAGS is non-zero, quote + double quote characters in S with backslashes. */ +char * +sh_mkdoublequoted (s, slen, flags) + const char *s; + int slen, flags; +{ + char *r, *ret; + int rlen; + + rlen = (flags == 0) ? slen + 3 : (2 * slen) + 1; + ret = r = (char *)xmalloc (rlen); + + *r++ = '"'; + while (*s) + { + if (flags && *s == '"') + *r++ = '\\'; + *r++ = *s++; + } + *r++ = '"'; + *r = '\0'; + + return ret; +} + /* Remove backslashes that are quoting characters that are special between double quotes. Return a new string. XXX - should this handle CTLESC and CTLNUL? */ @@ -128,7 +155,11 @@ sh_un_double_quote (string) } /* Quote special characters in STRING using backslashes. Return a new - string. */ + string. NOTE: if the string is to be further expanded, we need a + way to protect the CTLESC and CTLNUL characters. As I write this, + the current callers will never cause the string to be expanded without + going through the shell parser, which will protect the internal + quoting characters. */ char * sh_backslash_quote (string) char *string; @@ -160,11 +191,12 @@ sh_backslash_quote (string) *r++ = '\\'; *r++ = c; break; -#endif + case CTLESC: case CTLNUL: /* internal quoting characters */ *r++ = CTLESC; /* could be '\\'? */ *r++ = c; break; +#endif case '#': /* comment char */ if (s == string)