| 28 | } |
| 29 | |
| 30 | int cbm_split_command(const char *cmd, char **out, int max_out) { |
| 31 | if (!cmd || !out || max_out <= 0) { |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | int count = 0; |
| 36 | char current[CBM_SZ_4K]; |
| 37 | int clen = 0; |
| 38 | char in_quote = 0; |
| 39 | |
| 40 | for (int i = 0; cmd[i]; i++) { |
| 41 | char c = cmd[i]; |
| 42 | if (in_quote) { |
| 43 | if (c == in_quote) { |
| 44 | in_quote = 0; |
| 45 | } else if (clen < (int)sizeof(current) - SKIP_ONE) { |
| 46 | current[clen++] = c; |
| 47 | } |
| 48 | } else if (c == '"' || c == '\'') { |
| 49 | in_quote = c; |
| 50 | } else if (c == ' ' || c == '\t') { |
| 51 | count = emit_token(current, &clen, out, count, max_out); |
| 52 | } else if (clen < (int)sizeof(current) - SKIP_ONE) { |
| 53 | current[clen++] = c; |
| 54 | } |
| 55 | } |
| 56 | return emit_token(current, &clen, out, count, max_out); |
| 57 | } |
| 58 | |
| 59 | /* Resolve a path: if relative, join with directory. */ |
| 60 | static char *resolve_path(const char *path, const char *directory) { |
no test coverage detected