/* File for shell related functions. * * By Bryce Schroeder, 2008 */ #ifndef _SHELL_ARGS_H_ #define _SHELL_ARGS_H_ #include #include #include #include #include #include #include /* This structure describes a command to be executed. * * Possible TODO: history array of these rather than strings? */ typedef struct { int background; /* 1 if it will be executed in the background. */ int cmd_index; /* Index in argv of the command name. */ char **argv; /* Array to hold the parsed commands. */ int argc; /* Length of the argument array. */ } command_t; /* Create a new command_t by parsing a line. * * line_buffer: the command line to parse. * * returns NULL if the line is empty. All the command_* functions can * * deal with NULL gracefully. */ command_t *command_new (const char *line_buffer); /* Execute a command from a command_t struct. The function may or may * * not block. * * cmd: command_t to execute. */ void command_exec (command_t *cmd); /* Free the memory of a command_t to dispose of it properly. * * cmd: the command_t to be deleted. */ void command_free (command_t *cmd); /* Count how many words are in a string. * * str: the string. */ int word_count (const char *str); /* Split a string along spaces into an array provided. * * str: the string to be split. * * size: pointer to an integer to write argc into. (Or NULL). * * Returns a null-terminated char* array. */ char **argv_new (const char *str, int *size); /* Copy a slice from a string, from indicies begin to end inclusive. */ char *copy_slice (const char *str, int begin, int end); /* Release the memory of an argv type null terminated array. */ void argv_free (char **argv); /* Return the last character of a nonempty null-terminated string. */ char last_char (char *str); #endif /* Guard */