diff options
| -rw-r--r-- | src/parser.zig | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/parser.zig b/src/parser.zig index e0f28de..e04a4fb 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -20,13 +20,28 @@ pub fn parseCommand(input: []const u8) ParsedCommand { return .{ .name = "", .args = null, .output_redirect = null, .error_redirect = null, .append_output = null, .append_error = null }; } - if (input[i] == '\'' or input[i] == '"') { - const quote = input[i]; + if (input[i] == '\'') { i += 1; - while (i < input.len and input[i] != quote) : (i += 1) { + while (i < input.len and input[i] != '\'') : (i += 1) { _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; } if (i < input.len) i += 1; + } else if (input[i] == '"') { + i += 1; + while (i < input.len and input[i] != '"') : (i += 1) { + if (input[i] == '\\' and i + 1 < input.len) { + const next = input[i + 1]; + if (next == '"' or next == '\\') { + i += 1; + _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; + } else { + _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; + } + } else { + _ = cmd_buf.append(std.heap.page_allocator, input[i]) catch {}; + } + } + if (i < input.len) i += 1; } else { while (i < input.len and input[i] != ' ') : (i += 1) { if (input[i] == '\\' and i + 1 < input.len) { |