Skip to content
Snippets Groups Projects
Commit 98275dfb authored by Vanshika Mohan Bongade's avatar Vanshika Mohan Bongade
Browse files

Upload New File

parent b0467730
Branches
No related tags found
No related merge requests found
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment