summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br>2025-12-05 05:06:50 +0000
committerLucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br>2025-12-05 05:06:50 +0000
commit69df1ebb0f34499afa36c0c9d76700442c8355a8 (patch)
treeef6ebb4ded910ff871e965c9121d2161a46df2e9
parent44f14045e3bb35e5935da2ae4296904dea891c8b (diff)
downloadshell-zig-69df1ebb0f34499afa36c0c9d76700442c8355a8.tar.gz
shell-zig-69df1ebb0f34499afa36c0c9d76700442c8355a8.zip
codecrafters submit [skip ci]
-rw-r--r--src/main.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index 1511740..92067a4 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -26,6 +26,16 @@ fn parseCommand(input: []const u8) struct { name: []const u8, args: ?[]const u8
};
}
+fn isBuiltin(cmd_name: []const u8) bool {
+ const builtins = [_][]const u8{ "exit", "echo", "type" };
+ for (builtins) |builtin| {
+ if (std.mem.eql(u8, cmd_name, builtin)) {
+ return true;
+ }
+ }
+ return false;
+}
+
fn executeCommand(cmd_name: []const u8, args: ?[]const u8) !CommandResult {
if (std.mem.eql(u8, cmd_name, "exit")) {
return .exit_shell;
@@ -40,6 +50,17 @@ fn executeCommand(cmd_name: []const u8, args: ?[]const u8) !CommandResult {
return .continue_loop;
}
+ if (std.mem.eql(u8, cmd_name, "type")) {
+ if (args) |a| {
+ if (isBuiltin(a)) {
+ try stdout.print("{s} is a shell builtin\n", .{a});
+ } else {
+ try stdout.print("{s}: not found\n", .{a});
+ }
+ }
+ return .continue_loop;
+ }
+
// Command not found
try stdout.print("{s}: command not found\n", .{cmd_name});
return .continue_loop;