From 6ded62b26a5482c9c926783effd424f969b5b301 Mon Sep 17 00:00:00 2001 From: piyushchavan88 <56960155+piyushchavan88@users.noreply.github.com> Date: Sun, 3 Nov 2019 21:05:19 +0530 Subject: [PATCH] Update and rename e to shell.h --- ShellBuiltins/e | 1 - ShellBuiltins/shell.h | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) delete mode 100644 ShellBuiltins/e create mode 100644 ShellBuiltins/shell.h diff --git a/ShellBuiltins/e b/ShellBuiltins/e deleted file mode 100644 index 8b13789..0000000 --- a/ShellBuiltins/e +++ /dev/null @@ -1 +0,0 @@ - diff --git a/ShellBuiltins/shell.h b/ShellBuiltins/shell.h new file mode 100644 index 0000000..cf656f8 --- /dev/null +++ b/ShellBuiltins/shell.h @@ -0,0 +1,51 @@ + +int SHa_cd(char **args); +int SHa_help(char **args); +int SHa_exit(char **args); +char *builtin_str[] = { + "cd", + "help", + "exit" +}; + +int (builtin_func[]) (char *) = { + &SHa_cd, + &SHa_help, + &SHa_exit +}; + +int SHa_num_builtins() { + return sizeof(builtin_str) / sizeof(char *); +} + +int SHa_cd(char **args) +{ + if (args[1] == NULL) { + fprintf(stderr, "SHa: expected argument to \"cd\"\n"); + } else { + if (chdir(args[1]) != 0) { + perror("SHa"); + } + } + return 1; +} + +int SHa_help(char **args) +{ + int i; + printf("Stephen Brennan'SHa\n"); + printf("Type program names and arguments, and hit enter.\n"); + printf("The following are built in:\n"); + + for (i = 0; i < SHa_num_builtins(); i++) { + printf(" %s\n", builtin_str[i]); + } + + printf("Use the man command for information on other programs.\n"); + return 1; +} + +int SHa_exit(char **args) +{ + return 0; +}