From dcf0bb9ce906dc0973b0a715009ccb487174f704 Mon Sep 17 00:00:00 2001 From: Ziheng Chen <zc328@dragons.drexel.edu> Date: Mon, 3 Mar 2025 04:02:08 +0000 Subject: [PATCH] Upload New File --- w8/dshlib.h | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 w8/dshlib.h diff --git a/w8/dshlib.h b/w8/dshlib.h new file mode 100644 index 0000000..0725b48 --- /dev/null +++ b/w8/dshlib.h @@ -0,0 +1,93 @@ +#ifndef __DSHLIB_H__ + #define __DSHLIB_H__ + + +//Constants for command structure sizes +#define EXE_MAX 64 +#define ARG_MAX 256 +#define CMD_MAX 8 +#define CMD_ARGV_MAX (CMD_MAX + 1) +// Longest command that can be read from the shell +#define SH_CMD_MAX EXE_MAX + ARG_MAX + +typedef struct command +{ + char exe[EXE_MAX]; + char args[ARG_MAX]; +} command_t; + +#include <stdbool.h> + +typedef struct cmd_buff +{ + int argc; + char *argv[CMD_ARGV_MAX]; + char *_cmd_buffer; + char *input_file; // extra credit, stores input redirection file (for `<`) + char *output_file; // extra credit, stores output redirection file (for `>`) + bool append_mode; // extra credit, sets append mode fomr output_file +} cmd_buff_t; + +typedef struct command_list{ + int num; + cmd_buff_t commands[CMD_MAX]; +}command_list_t; + +//Special character #defines +#define SPACE_CHAR ' ' +#define PIPE_CHAR '|' +#define PIPE_STRING "|" + +#define SH_PROMPT "dsh4> " +#define EXIT_CMD "exit" +#define RC_SC 99 +#define EXIT_SC 100 + +//Standard Return Codes +#define OK 0 +#define WARN_NO_CMDS -1 +#define ERR_TOO_MANY_COMMANDS -2 +#define ERR_CMD_OR_ARGS_TOO_BIG -3 +#define ERR_CMD_ARGS_BAD -4 //for extra credit +#define ERR_MEMORY -5 +#define ERR_EXEC_CMD -6 +#define OK_EXIT -7 + + + +//prototypes +int alloc_cmd_buff(cmd_buff_t *cmd_buff); +int free_cmd_buff(cmd_buff_t *cmd_buff); +int clear_cmd_buff(cmd_buff_t *cmd_buff); +int build_cmd_buff(char *cmd_line, cmd_buff_t *cmd_buff); +int close_cmd_buff(cmd_buff_t *cmd_buff); +int build_cmd_list(char *cmd_line, command_list_t *clist); +int free_cmd_list(command_list_t *cmd_lst); + +//built in command stuff +typedef enum { + BI_CMD_EXIT, + BI_CMD_DRAGON, + BI_CMD_CD, + BI_CMD_RC, //extra credit command + BI_CMD_STOP_SVR, //new command "stop-server" + BI_NOT_BI, + BI_EXECUTED, + BI_NOT_IMPLEMENTED, +} Built_In_Cmds; +Built_In_Cmds match_command(const char *input); +Built_In_Cmds exec_built_in_cmd(cmd_buff_t *cmd); + +//main execution context +int exec_local_cmd_loop(); +int exec_cmd(cmd_buff_t *cmd); +int execute_pipeline(command_list_t *clist); + + +//output constants +#define CMD_OK_HEADER "PARSED COMMAND LINE - TOTAL COMMANDS %d\n" +#define CMD_WARN_NO_CMD "warning: no commands provided\n" +#define CMD_ERR_PIPE_LIMIT "error: piping limited to %d commands\n" + + +#endif \ No newline at end of file -- GitLab