| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/shquote.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* shquote - functions to quote and dequote strings */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | /* Copyright (C) 1999-2015 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | This file is part of GNU Bash, the Bourne Again SHell. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | Bash is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | Bash is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #include <config.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # ifdef _MINIX | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # include <unistd.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #include <stdc.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | #include "syntax.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | #include <xmalloc.h> | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | #include "shmbchar.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | #include "shmbutil.h" | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | extern char *ansic_quote __P((char *, int, int *)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | extern int ansic_shouldquote __P((const char *)); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | /* Default set of characters that should be backslash-quoted in strings */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | static const char bstab[256] = | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0, 1, 1, 0, 0, 0, 0, 0, /* TAB, NL */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1, 1, 1, 0, 1, 0, 1, 1, /* SPACE, !, DQUOTE, DOL, AMP, SQUOTE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1, 1, 1, 0, 1, 0, 0, 0, /* LPAR, RPAR, STAR, COMMA */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0, 0, 0, 1, 1, 0, 1, 1, /* SEMI, LESSTHAN, GREATERTHAN, QUEST */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0, 0, 0, 1, 1, 1, 1, 0, /* LBRACK, BS, RBRACK, CARAT */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1, 0, 0, 0, 0, 0, 0, 0, /* BACKQ */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0, 0, 0, 1, 1, 1, 0, 0, /* LBRACE, BAR, RBRACE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | }; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | /* **************************************************************** */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | /* */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | /* Functions for quoting strings to be re-read as input */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | /* */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | /* **************************************************************** */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | /* Return a new string which is the single-quoted version of STRING. | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | Used by alias and trap, among others. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | sh_single_quote (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | const char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | register int c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | char *result, *r; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | result = (char *)xmalloc (3 + (4 * strlen (string))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | r = result; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | if (string[0] == '\'' && string[1] == 0)
| 7-2948 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | *r++ = '\\'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | *r++ = '\''; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | *r++ = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | return result; executed 15 times by 1 test: return result;Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | *r++ = '\''; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | for (s = string; s && (c = *s); s++)
| 0-13989 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | if (c == '\'')
| 23-11011 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | *r++ = '\\'; /* insert escaped single quote */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | *r++ = '\''; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | *r++ = '\''; /* start new quoted string */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } executed 11034 times by 1 test: end of blockExecuted by:
| 11034 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | *r++ = '\''; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | *r = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | return (result); executed 2955 times by 1 test: return (result);Executed by:
| 2955 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | /* Quote STRING using double quotes. Return a new string. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | sh_double_quote (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | const char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | register unsigned char c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | char *result, *r; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | result = (char *)xmalloc (3 + (2 * strlen (string))); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | r = result; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | *r++ = '"'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | for (s = string; s && (c = *s); s++)
| 0-4669 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | /* Backslash-newline disappears within double quotes, so don't add one. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n')
| 0-3618 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | *r++ = '\\'; executed 83 times by 1 test: *r++ = '\\';Executed by:
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | #if 0 | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | /* Assume that the string will not be further expanded. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | else if (c == CTLESC || c == CTLNUL) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | *r++ = CTLESC; /* could be '\\'? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } executed 3701 times by 1 test: end of blockExecuted by:
| 3701 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | *r++ = '"'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | *r = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | return (result); executed 968 times by 1 test: return (result);Executed by:
| 968 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | /* Turn S into a simple double-quoted string. If FLAGS is non-zero, quote | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | double quote characters in S with backslashes. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | sh_mkdoublequoted (s, slen, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | int slen, flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | char *r, *ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | int rlen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | rlen = (flags == 0) ? slen + 3 : (2 * slen) + 1;
| 0-35 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ret = r = (char *)xmalloc (rlen); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | *r++ = '"'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | while (*s)
| 35-290 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | if (flags && *s == '"')
| 0-290 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | *r++ = '\\'; never executed: *r++ = '\\'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | *r++ = *s++; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } executed 290 times by 1 test: end of blockExecuted by:
| 290 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | *r++ = '"'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | *r = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | return ret; executed 35 times by 1 test: return ret;Executed by:
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | /* Remove backslashes that are quoting characters that are special between | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | double quotes. Return a new string. XXX - should this handle CTLESC | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | and CTLNUL? */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sh_un_double_quote (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | register int c, pass_next; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | char *result, *r, *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | r = result = (char *)xmalloc (strlen (string) + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | for (pass_next = 0, s = string; s && (c = *s); s++)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | if (pass_next)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | pass_next = 0; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | if (c == '\\' && (sh_syntaxtab[(unsigned char) s[1]] & CBSDQUOTE))
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | pass_next = 1; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | *r = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | /* Quote special characters in STRING using backslashes. Return a new | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | string. NOTE: if the string is to be further expanded, we need a | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | way to protect the CTLESC and CTLNUL characters. As I write this, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | the current callers will never cause the string to be expanded without | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | going through the shell parser, which will protect the internal | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | quoting characters. TABLE, if set, points to a map of the ascii code | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | set with char needing to be backslash-quoted if table[char]==1. FLAGS, | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | if 1, causes tildes to be quoted as well. If FLAGS&2, backslash-quote | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | other shell blank characters. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | sh_backslash_quote (string, table, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | char *table; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | int c, mb_cur_max; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | size_t slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | char *result, *r, *s, *backslash_table, *send; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | DECLARE_MBSTATE; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | slen = strlen (string); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | send = string + slen; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | result = (char *)xmalloc (2 * slen + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | backslash_table = table ? table : (char *)bstab;
| 0-541 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | mb_cur_max = MB_CUR_MAX; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | for (r = result, s = string; s && (c = *s); s++)
| 0-3221 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | #if defined (HANDLE_MULTIBYTE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | /* XXX - isascii, even if is_basic(c) == 0 - works in most cases. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | if (c >= 0 && c <= 127 && backslash_table[(unsigned char)c] == 1)
| 0-2586 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | *r++ = '\\'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | continue; executed 7 times by 1 test: continue;Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | if (mb_cur_max > 1 && is_basic (c) == 0)
| 1-2578 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | COPY_CHAR_P (r, s, send); never executed: mblength = 1;never executed: mblength = 1;executed 94 times by 1 test: end of blockExecuted by:
never executed: end of blockexecuted 94 times by 1 test: mblength = (mblength < 1) ? 1 : mblength;Executed by:
executed 188 times by 1 test: *(r)++ = *(s)++;Executed by:
executed 94 times by 1 test: end of blockExecuted by:
never executed: *(r)++ = *(s)++;
| 0-188 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | s--; /* compensate for auto-increment in loop above */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | continue; executed 94 times by 1 test: continue;Executed by:
| 94 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | if (backslash_table[(unsigned char)c] == 1)
| 0-2579 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | *r++ = '\\'; never executed: *r++ = '\\'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | else if (c == '#' && s == string) /* comment char */
| 0-2579 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | *r++ = '\\'; never executed: *r++ = '\\'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | else if ((flags&1) && c == '~' && (s == string || s[-1] == ':' || s[-1] == '='))
| 0-2579 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | /* Tildes are special at the start of a word or after a `:' or `=' | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | (technically unquoted, but it doesn't make a difference in practice) */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | *r++ = '\\'; executed 1 time by 1 test: *r++ = '\\';Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | else if ((flags&2) && shellblank((unsigned char)c))
| 0-2578 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | *r++ = '\\'; never executed: *r++ = '\\'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } executed 2579 times by 1 test: end of blockExecuted by:
| 2579 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | *r = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | return (result); executed 541 times by 1 test: return (result);Executed by:
| 541 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | #if defined (PROMPT_STRING_DECODE) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | /* Quote characters that get special treatment when in double quotes in STRING | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | using backslashes. Return a new string. */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | sh_backslash_quote_for_double_quotes (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | unsigned char c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | char *result, *r, *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | result = (char *)xmalloc (2 * strlen (string) + 1); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | for (r = result, s = string; s && (c = *s); s++)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | if (sh_syntaxtab[c] & CBSDQUOTE)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | *r++ = '\\'; never executed: *r++ = '\\'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | /* I should probably add flags for these to sh_syntaxtab[] */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | else if (c == CTLESC || c == CTLNUL)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | *r++ = CTLESC; /* could be '\\'? */ never executed: *r++ = '\001'; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | *r++ = c; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | *r = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | return (result); never executed: return (result); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | #endif /* PROMPT_STRING_DECODE */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | char * | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | sh_quote_reusable (s, flags) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | int flags; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | char *ret; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | if (s == 0)
| 0-49 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | return s; never executed: return s; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | else if (*s == 0)
| 5-44 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ret = (char *)xmalloc (3); | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ret[0] = ret[1] = '\''; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | ret[2] = '\0'; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | else if (ansic_shouldquote (s))
| 3-41 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ret = ansic_quote (s, 0, (int *)0); executed 3 times by 1 test: ret = ansic_quote (s, 0, (int *)0);Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | else if (flags)
| 0-41 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ret = sh_backslash_quote (s, 0, 1); never executed: ret = sh_backslash_quote (s, 0, 1); | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | else | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ret = sh_single_quote (s); executed 41 times by 1 test: ret = sh_single_quote (s);Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | return ret; executed 49 times by 1 test: return ret;Executed by:
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | sh_contains_shell_metas (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | const char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | for (s = string; s && *s; s++)
| 0-6077 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | switch (*s) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | case ' ': case '\t': case '\n': /* IFS white space */ executed 27 times by 1 test: case ' ':Executed by:
never executed: case '\t':never executed: case '\n': | 0-27 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | case '\'': case '"': case '\\': /* quoting chars */ executed 16 times by 1 test: case '\'':Executed by:
executed 12 times by 1 test: case '"':Executed by:
executed 6 times by 1 test: case '\\':Executed by:
| 6-16 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | case '|': case '&': case ';': /* shell metacharacters */ never executed: case '|':never executed: case '&':never executed: case ';': | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | case '(': case ')': case '<': case '>': executed 6 times by 1 test: case '(':Executed by:
executed 1 time by 1 test: case ')':Executed by:
never executed: case '<':never executed: case '>': | 0-6 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | case '!': case '{': case '}': /* reserved words */ never executed: case '!':never executed: case '{':never executed: case '}': | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | case '*': case '[': case '?': case ']': /* globbing chars */ never executed: case '*':executed 2 times by 1 test: case '[':Executed by:
never executed: case '?':executed 11 times by 1 test: case ']':Executed by:
| 0-11 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | case '^': never executed: case '^': | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | case '$': case '`': /* expansion chars */ executed 3 times by 1 test: case '$':Executed by:
executed 6 times by 1 test: case '`':Executed by:
| 3-6 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | return (1); executed 90 times by 1 test: return (1);Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | case '~': /* tilde expansion */ executed 3 times by 1 test: case '~':Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | if (s == string || s[-1] == '=' || s[-1] == ':')
| 0-3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | return (1); executed 3 times by 1 test: return (1);Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | case '#': executed 4 times by 1 test: case '#':Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | if (s == string) /* comment char */
| 1-3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | return (1); executed 1 time by 1 test: return (1);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | /* FALLTHROUGH */ | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | default: code before this statement executed 3 times by 1 test: default:Executed by:
executed 5542 times by 1 test: default:Executed by:
| 3-5542 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | break; executed 5542 times by 1 test: break;Executed by:
| 5542 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | return (0); executed 441 times by 1 test: return (0);Executed by:
| 441 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | int | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | sh_contains_quotes (string) | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | const char *string; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | for (s = string; s && *s; s++)
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | { | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | if (*s == '\'' || *s == '"' || *s == '\\')
| 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | - | ||||||||||||||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |