diff --git a/WEEK-7/dshlib.h b/WEEK-7/dshlib.h new file mode 100644 index 0000000000000000000000000000000000000000..139d6933a1808b83192ce9936f3af8202079b0b5 --- /dev/null +++ b/WEEK-7/dshlib.h @@ -0,0 +1,45 @@ +#ifndef DSHLIB_H +#define DSHLIB_H + +#include <stdbool.h> + +#define SH_CMD_MAX 512 // Max length of a command line +#define CMD_MAX 10 // Max number of piped commands +#define CMD_ARG_MAX 20 // Max arguments per command +#define OK 0 +#define OK_EXIT -1 +#define ERR_TOO_MANY_COMMANDS -2 +#define ERR_MEMORY -3 +#define ERR_EXEC_CMD -4 +#define WARN_NO_CMDS -5 +#define CMD_WARN_NO_CMD "Warning: No command entered.\n" +#define CMD_ERR_PIPE_LIMIT "Error: Too many commands. Max is %d.\n" +#define EXIT_CMD "exit" +#define SH_PROMPT "dsh3> " + +/** + * Structure to store a single command with arguments. + */ +typedef struct { + char *_cmd_buffer; // The full command string + char *argv[CMD_ARG_MAX]; // Array of command arguments + char *infile; // Input redirection file (for `<`) + char *outfile; // Output redirection file (for `>` and `>>`) + bool append; // True if `>>` (append mode), false if `>` (overwrite mode) +} cmd_buff_t; + +/** + * Structure to store a list of commands, e.g., for pipelines. + */ +typedef struct { + cmd_buff_t commands[CMD_MAX]; // Array of commands + int num; // Number of commands in the pipeline +} command_list_t; + +// Function Declarations +int exec_local_cmd_loop(); +int build_cmd_list(char *cmd_line, command_list_t *clist); +int execute_pipeline(command_list_t *clist); +int free_cmd_list(command_list_t *cmd_lst); + +#endif // DSHLIB_H