Question
Your shell program must provide services to support the following commands and features: Note: The commands are shown in uppercase font, but dont have to
Your shell program must provide services to support the following commands and features:
Note: The commands are shown in uppercase font, but don’t have to be programmed that way. The parameters to the commands are enclosed between the symbols < and >, but the symbols are not actually part of the parameters.
STOP: Terminates execution of the current toyshell session.
SETSHELLNAME <shell_name>: Sets the shell name in the toyshell command prompt to <shell_name>. For example, a sample command prompt is shown below:
tsh[10]:
In this command prompt, there are three parts. The first part, tsh, is the shell name. The second part, [10], is the number of commands that have been entered in the current session (i.e., since the last time toyshell was run). And the third part, :, is the terminator. If no shell name is defined, toyshell should be the default shell name.
SETTERMINATOR <terminator>: Sets the terminator in the toyshell command prompt to <terminator>. If no terminator is defined, toyshell should use -> as the default terminator.
HISTORY: Lists the commands that have been entered in the current session (i.e., since the last time toyshell was run). The maximum number of commands in the history list should be set to 10 as the default.
! <n>: Re-executes a command that has been previously executed in the current session. The command will execute the n-th command in the history list. For example, the command ! 6 will cause the 6-th command to be executed again.
NEWNAME <new_name> | <new_name> <old_name>: Manages the alias list. The first option deletes a previously defined alias. The second option defines an alias for another command. For example, the command NEWNAME mymove deletes the alias for mymove, and the command NEWNAME mycopy cp defines mycopy as the alias for the cp command. If an alias for a command already exists, then the new alias replaces the old alias. The maximum number of aliases in the alias list should be set to 10 as the default.
Alias Substitution: When an alias is detected in a command, the old name should be substituted into the command before the command is executed. For example, assume the following aliases are defined as shown below:
aa ls –l
bb grep toyshell
cc grep .cpp
dd aa | bb
Then, for the following sequence of commands at the command prompt:
aa
aa | bb
aa | bb | cc
dd | cc
alias substitutions should result in the following sequence of commands being executed:
ls –l
ls –l | grep toyshell
ls –l | grep toyshell | grep .cpp
ls –l | grep toyshell | grep .cpp
NEWNAMES: Outputs all the aliases that have been defined. Each pair of names should be shown on one line. For example, the possible aliases for a few commands are shown below:
mymove mv
mycopy cp
chkshell ls –l | grep toyshell.cpp
SAVENEWNAMES <file_name>: Stores all currently defined a in the file <file_name>.
READNEWNAMES <file_name>: Reads all aliases in the file <file_name> and adds them to the aliases defined in the current session. If a duplicate is found in the file <file_name>, it should be ignored.
<UNIX_command>: Executes the UNIX command <UNIX_command>, corresponding to any valid UNIX command. One approach to implementing this is to use the system function. If the first token on a command line is not a built-in command, assume that it is a UNIX command.
Error handling: Your approach should effectively identify and recover from errors. For example, bad input and/or the inability to execute a command should not cause toyshell to crash.
Note: You must handle all the built-in commands with exactly the same syntax as shown above. Thus, an important part of the toyshell program will be to parse commands entered at the command prompt to break them down into their component parts. Once a command has been parsed, the component parts can be checked to ensure that a valid command has been entered and that it adheres to the required syntax. One approach to effective parsing is to use the C-string strtok function (to be covered in detail in the second lecture and the first lab).
Step by Step Solution
3.49 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
include include include include include include include using namespace std define MAXALIASNUM 10 de...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