Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started