diff options
Diffstat (limited to 'src/eval.zig')
-rw-r--r-- | src/eval.zig | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/eval.zig b/src/eval.zig index daf2d38..0fe0fde 100644 --- a/src/eval.zig +++ b/src/eval.zig @@ -788,6 +788,130 @@ fn executeCommandWithOutput(command: Command, allocator: Allocator, output_captu // No output for successful creation (DOS style) return CommandStatus{ .Code = 0 }; }, + .Rmdir => |rmdir| { + const dir_path = rmdir.path; + + std.fs.cwd().deleteDir(dir_path) catch |err| { + const error_msg = switch (err) { + error.FileNotFound => "The system cannot find the path specified\n", + error.AccessDenied => "Access denied\n", + error.DirNotEmpty => "The directory is not empty\n", + error.FileBusy => "The directory is in use\n", + error.NotDir => "The system cannot find the path specified\n", + else => "Unable to remove directory\n", + }; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }; + + // No output for successful removal (DOS style) + return CommandStatus{ .Code = 0 }; + }, + .Rename => |rename| { + const from_path = switch (rename.from) { + .Con, .Lpt1, .Lpt2, .Lpt3, .Prn => { + const error_msg = "Cannot rename device\n"; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }, + .Path => |path| path, + }; + + const to_path = switch (rename.to) { + .Con, .Lpt1, .Lpt2, .Lpt3, .Prn => { + const error_msg = "Cannot rename to device\n"; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }, + .Path => |path| path, + }; + + std.fs.cwd().rename(from_path, to_path) catch |err| { + const error_msg = switch (err) { + error.FileNotFound => "The system cannot find the file specified\n", + error.AccessDenied => "Access denied\n", + error.PathAlreadyExists => "A duplicate file name exists, or the file cannot be found\n", + error.RenameAcrossMountPoints => "Cannot rename across different drives\n", + else => "Cannot rename file\n", + }; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }; + + // No output for successful rename (DOS style) + return CommandStatus{ .Code = 0 }; + }, + .Move => { + const error_msg = "MOVE command not yet implemented\n"; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }, + .PathGet => { + const current_path = std.process.getEnvVarOwned(allocator, "PATH") catch |err| switch (err) { + error.EnvironmentVariableNotFound => { + // PATH not set, show empty + const output = "PATH=(not set)\n"; + if (output_capture) |capture| { + try capture.write(output); + } else { + print("{s}", .{output}); + } + return CommandStatus{ .Code = 0 }; + }, + else => { + const error_msg = "Cannot access PATH environment variable\n"; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }, + }; + defer allocator.free(current_path); + + const output = try std.fmt.allocPrint(allocator, "PATH={s}\n", .{current_path}); + defer allocator.free(output); + if (output_capture) |capture| { + try capture.write(output); + } else { + print("{s}", .{output}); + } + return CommandStatus{ .Code = 0 }; + }, + .PathSet => |pathset| { + // Note: In a real DOS system, this would persist for the session + // Here we just show what would be set but don't actually set it + // since Zig's std.process doesn't provide a simple way to set env vars + const output = try std.fmt.allocPrint(allocator, "PATH would be set to: {s}\n(Note: Environment variable setting not implemented in this shell)\n", .{pathset.value}); + defer allocator.free(output); + if (output_capture) |capture| { + try capture.write(output); + } else { + print("{s}", .{output}); + } + return CommandStatus{ .Code = 0 }; + }, else => { const error_msg = try std.fmt.allocPrint(allocator, "Command not implemented: {any}\n", .{builtin_cmd}); defer allocator.free(error_msg); |