Question: #include csapp.h #define MAXARGS 1 2 8 void eval ( char * cmdline ) ; int parseline ( char * buf , char *
#include "csapp.h#define MAXARGSvoid evalcharcmdline;int parselinechar buf char argv;int builtincommandchar argv;int main char cmdlineMAXLINE; while printf; Fgetscmdline MAXLINE, stdin; if feofstdin exit; evalcmdline;void evalchar cmdline char argvMAXARGS; char bufMAXLINE;
int bg; pidt pid; strcpybuf cmdline; bg parselinebuf argv; if argv NULL return; if builtincommandargv if pid Fork if execveargv argv, environ printfs: Command not found.
argv; exit; if bg int status; if waitpidpid &status, unixerrorwaitfg: waitpid error"; else printfd s pid, cmdline; return;int builtincommandchar argv if strcmpargv "quit" exit; if strcmpargv& return ; return ;int parselinechar buf char argv char delim; int argc; int bg; bufstrlenbuf; while buf && buf buf; argc ; while delim strchrbuf argvargc buf;delim ; buf delim ; while buf && buf buf; argvargc NULL; if argc return ; if bg argvargc& argvargc NULL; return bg;
edit this code so that Your new version must maintain variables using a local array of strings abcxyz It should not rely on the real shell to keep these strings. Which means that at the top of it there must be a declaration like char vars to have an array that will contain up to for example strings in the form abcxyz When the user types a command like set pathhomeckprogs your shell should find an empty element in local array vars call malloc and store the string there. When the user types a command to run a program from the disk, say test arg arg your shell should use execve to find the program in the current directory. If the program in not found, execve returns error and your shell should insert the PATH value before the filename by creating a new string and concatenating and call execve with that new string. So in the above example, either program test is executed or program homeckprogstest is executed.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
