A CLI accepts textual input from the user, and executes the commands issued. The main logic of
Question:
A CLI accepts textual input from the user, and executes the commands issued. The main logic of the CLI is given below:
main: loop
get input line
if end of input exit
break line into words
found := false
if command is builtin
then
do_builtin(line)
found:=true
else
found:=find_and_execute(line)
end if
if not found report error
end loop
Write a program that repeatedly reads a line of input from the user, the fgets() function will help you here. Your program should end when either end of the input file is encountered, or the exact word exit appears in the input as the only word on a line. Traditionally both the File System and Command Language are case sensitive, you should also implement this.
Break the line up into words, which are separated by one or more spaces. The provided function tokenize() does this, and it uses strtok() internally. You may use this function if you wish, in which case you should provide documentation on its operation, or you may write your own parser.
Implement the find_and_execute() section of the logic above, by creating a new process using fork(), and then use one of the exec() family of functions to run the program requested by the user in the text provided. If the requested program cannot be run then an appropriate error message should be displayed, perror() will help with this (as there are many reasons why this may fail), and the child process terminated.
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall