basic-shell / shell_helper.h
shell_helper.h
Raw
#ifndef _SHELL_HELPER_H
#define _SHELL_HELPER_H

#include "tokenize.h"

/* Closes a file descriptor, and if there was an error, halts the program. */
int assert_close(int fd);
/* Free all of the data within the command array. */
void free_data(char** cmd, int* cmdlen);
/* Exits the program by printing message and frees data. */
void bye_bye(char** cmd, int* cmdlen);
/* Traverses given input and then adds each in to the cmd vector for later execution. */
void store_cmds(char* in, char** cmd, int* cmdlen);
/* Sends invalid argument message for requested command. */
void bad_data(char* cmd);
/* Updates previous command using input. */
void change_prev_cmd(char* in, char* prev);
/* In a child process, attempt to execute the commands. */
void exec_chld(int current_cmd, int last_cmd, char*** cmd_sequence, char* file_to_read, char* file_to_write, int* parent_pipe_fd);
/* Changes current working directory of the shell to the path specified. */
void change_directory(char** cmd);
/* Explains all the built-in commands available in our shell. */
void explain_cmds();
/* In the event of invalid piping or redirection, print an error message and free the memory. */
void invalid_piping_redirection(char*** cmd_sequence, int current_cmd);
/* Executes a "source" command (running a list of commands from a file). */
void execute_source_command(char** cmd);
/* Executes a system command (that is, all commands other than built-in commands). */
void execute_system_command(char** cmd, int num_args);
/* Executes the command and calls necessary helpers for further execution.
 * Also returns a value representing whether the program should exit. */
int execute_command_helper(char** cmd, int* cmdlen, char* in, char* prev);
/* Executes the given sequence of commands, by splitting the input on ";" tokens.
 * Also returns a value representing whether the program should exit. */
int execute_sequence(char** cmd, int* cmdlen, char* in, char* prev);

#endif