| 1158 | #define HA_BASH_TOK_SZ 256 |
| 1159 | |
| 1160 | static int ha_tokenize(const char *cmd, char toks[][HA_BASH_TOK_SZ], int max) { |
| 1161 | int n = 0; |
| 1162 | const char *p = cmd; |
| 1163 | while (*p && n < max) { |
| 1164 | while (*p && isspace((unsigned char)*p)) |
| 1165 | p++; |
| 1166 | if (!*p) |
| 1167 | break; |
| 1168 | char *d = toks[n]; |
| 1169 | int dlen = 0; |
| 1170 | while (*p && !isspace((unsigned char)*p)) { |
| 1171 | if (*p == '\'') { |
| 1172 | for (p++; *p && *p != '\''; p++) |
| 1173 | if (dlen < HA_BASH_TOK_SZ - 1) |
| 1174 | d[dlen++] = *p; |
| 1175 | if (*p == '\'') |
| 1176 | p++; |
| 1177 | } else if (*p == '"') { |
| 1178 | for (p++; *p && *p != '"'; p++) { |
| 1179 | if (*p == '\\' && p[1] && strchr("\\\"$`", p[1])) |
| 1180 | p++; |
| 1181 | if (dlen < HA_BASH_TOK_SZ - 1) |
| 1182 | d[dlen++] = *p; |
| 1183 | } |
| 1184 | if (*p == '"') |
| 1185 | p++; |
| 1186 | } else if (*p == '\\' && p[1]) { |
| 1187 | p++; |
| 1188 | if (dlen < HA_BASH_TOK_SZ - 1) |
| 1189 | d[dlen++] = *p++; |
| 1190 | } else { |
| 1191 | if (dlen < HA_BASH_TOK_SZ - 1) |
| 1192 | d[dlen++] = *p++; |
| 1193 | } |
| 1194 | } |
| 1195 | d[dlen] = '\0'; |
| 1196 | if (dlen > 0) |
| 1197 | n++; |
| 1198 | } |
| 1199 | return n; |
| 1200 | } |
| 1201 | |
| 1202 | static bool ha_is_env_assign(const char *t) { |
| 1203 | if (!t || !t[0]) |
no outgoing calls
no test coverage detected