Question: in C Add support for compound commands that use pipes to communicate two or more processes. Follow these steps: a) (2 pt.) Modify functions get_args

in C
in C Add support for compound commands that use pipes to communicate
two or more processes. Follow these steps: a) (2 pt.) Modify functions

Add support for compound commands that use pipes to communicate two or more processes. Follow these steps: a) (2 pt.) Modify functions get_args and print_args implemented in the previous homework assignment to work with null-terminated arrays, where the size of the array is defined by its first element set to NULL. The new prototype for these functions 1. will be the following: void ReadArgs(char*in, char **argv, int size) Argument size represents the number of elements allocated for argv by the caller. The function should guarantee that the array is null terminated under any circumstances, even if the number of tokens in string in exceeds size. Notice that this function does not return the number of arguments extracted from in anymore. void PrintArgs(char **argv) This function does not need the number of arguments to be passed to the function anymore. Instead, the function will stop printing arguments as soon as the NULL element is found. b) (4 pt.) The following data structures represent a command line, composed of multiple sub-commands separated by pipes ("1" character). Each command has an array of at most, MAX_SUB_COMMANDS sub- commands. Another field named num_sub_commands indicates how 2. many sub-commands are present. Each sub-command contains a field called line containing the entire sub-command as a C string, as well as a null-terminated array of at most MAX_ARGS - 1 arguments (one array element is reserved for NULL). #define MAX_SUB_COMMANDS 5 #define MAX_ARGS 10 struct SubCommand { char *line; char *argv[MAX_ARGS); struct Command { struct SubCommand sub_commands (MAX_SUB_COMMANDS); int num_sub_commands; }; Write the following two functions: void ReadCommand(char *line, struct Command command) This function takes an entire command line (first argument), and populates the Command data structure, passed by reference in the second argument. The function body has two parts: First, the line is split into sub-strings with strtok using the "1" character delimiter, and each sub-string is duplicated and stored into the sub- command's line field. Second, all sub-commands are processed, and their argv fields are populated (use calls to ReadArgs). - void PrintCommand(struct Command *command) This function prints all arguments for each sub- command of the command passed by reference. The function can invoke PrintArgs internally. Write a main() function that asks the user for an input string, and dumps all sub-commands and their arguments, by invoking the two functions above. Add support for compound commands that use pipes to communicate two or more processes. Follow these steps: a) (2 pt.) Modify functions get_args and print_args implemented in the previous homework assignment to work with null-terminated arrays, where the size of the array is defined by its first element set to NULL. The new prototype for these functions 1. will be the following: void ReadArgs(char*in, char **argv, int size) Argument size represents the number of elements allocated for argv by the caller. The function should guarantee that the array is null terminated under any circumstances, even if the number of tokens in string in exceeds size. Notice that this function does not return the number of arguments extracted from in anymore. void PrintArgs(char **argv) This function does not need the number of arguments to be passed to the function anymore. Instead, the function will stop printing arguments as soon as the NULL element is found. b) (4 pt.) The following data structures represent a command line, composed of multiple sub-commands separated by pipes ("1" character). Each command has an array of at most, MAX_SUB_COMMANDS sub- commands. Another field named num_sub_commands indicates how 2. many sub-commands are present. Each sub-command contains a field called line containing the entire sub-command as a C string, as well as a null-terminated array of at most MAX_ARGS - 1 arguments (one array element is reserved for NULL). #define MAX_SUB_COMMANDS 5 #define MAX_ARGS 10 struct SubCommand { char *line; char *argv[MAX_ARGS); struct Command { struct SubCommand sub_commands (MAX_SUB_COMMANDS); int num_sub_commands; }; Write the following two functions: void ReadCommand(char *line, struct Command command) This function takes an entire command line (first argument), and populates the Command data structure, passed by reference in the second argument. The function body has two parts: First, the line is split into sub-strings with strtok using the "1" character delimiter, and each sub-string is duplicated and stored into the sub- command's line field. Second, all sub-commands are processed, and their argv fields are populated (use calls to ReadArgs). - void PrintCommand(struct Command *command) This function prints all arguments for each sub- command of the command passed by reference. The function can invoke PrintArgs internally. Write a main() function that asks the user for an input string, and dumps all sub-commands and their arguments, by invoking the two functions above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!