summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/builtins.zig9
-rw-r--r--src/parser.zig21
2 files changed, 27 insertions, 3 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 409b57d..2a1eed7 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -40,6 +40,15 @@ pub fn executeEcho(stdout: anytype, args: ?[]const u8) !void {
} else if (in_quote and a[i] == quote_char) {
in_quote = false;
last_was_space = false;
+ } else if (in_quote and quote_char == '"' and a[i] == '\\' and i + 1 < a.len) {
+ const next = a[i + 1];
+ if (next == '"' or next == '\\') {
+ i += 1;
+ _ = unquoted.append(std.heap.page_allocator, a[i]) catch {};
+ } else {
+ _ = unquoted.append(std.heap.page_allocator, a[i]) catch {};
+ }
+ last_was_space = false;
} else if (!in_quote and a[i] == ' ') {
if (!last_was_space) {
_ = unquoted.append(std.heap.page_allocator, ' ') catch {};
diff --git a/src/parser.zig b/src/parser.zig
index de42f31..7289057 100644
--- a/src/parser.zig
+++ b/src/parser.zig
@@ -26,13 +26,28 @@ pub fn parseArgs(allocator: std.mem.Allocator, cmd_name: []const u8, args_str: ?
defer arg_buf.deinit(allocator);
while (i < args.len) {
- if (args[i] == '\'' or args[i] == '"') {
- const quote = args[i];
+ if (args[i] == '\'') {
i += 1;
- while (i < args.len and args[i] != quote) : (i += 1) {
+ while (i < args.len and args[i] != '\'') : (i += 1) {
try arg_buf.append(allocator, args[i]);
}
if (i < args.len) i += 1;
+ } else if (args[i] == '"') {
+ i += 1;
+ while (i < args.len and args[i] != '"') : (i += 1) {
+ if (args[i] == '\\' and i + 1 < args.len) {
+ const next = args[i + 1];
+ if (next == '"' or next == '\\') {
+ i += 1;
+ try arg_buf.append(allocator, args[i]);
+ } else {
+ try arg_buf.append(allocator, args[i]);
+ }
+ } else {
+ try arg_buf.append(allocator, args[i]);
+ }
+ }
+ if (i < args.len) i += 1;
} else if (args[i] == '\\' and i + 1 < args.len) {
i += 1;
try arg_buf.append(allocator, args[i]);