Network Programming Project 1 - NPShellDeadline: Wednesday, 2024/3/27 23:551 IntroductionIn this project, you are asked to design a shell named npshell. The npshell should support the following features:1. Execution of commands2. Ordinary Pipe3. Numbered Pipe4. File RedirectionMore details will be defined in Section 3.2 Scenario of using npshell2.1 Structure of Working DirectoryExample:working_dir| -- bin# Executables may be added to or removed from bin/| | -- cat| | -- ls| |-- noop# A program that does nothing| | -- number# Add a number to each line of input| | -- removetag# Remove HTML tags and output to STDOUT| | -- removetag0| -- test. html# Same as removetag, but outputs error messages to STDERR| -- npshell2.2 ScenarioThe following is a scenario of using the npshell.bash ./npshell # execute your npshell% printenv PATH # initial PATH is bin/ and ./bin: .% setenv PATH bin # set PATH to bin/ only% printenv PATHbin% lsbin npshell test. html% ls bincat ls noop number removetag removetag0% cat test. html > test1. txt% cat test1. txtTestThis is a test programfor ras .% removetag test. htmlTestThis is a test programfor ras .% removetag test. html > test2. txt% cat test2. txtTestThis is a test programfor ras .% removetag0 test. htmlError: illegal tag "! test. html"TestThis is a test programfor ras .% removetag0 test. html > test2. txtError: illegal tag "! test. html"% cat test2. txtTestThis is a test programfor ras .% removetag test. html | number12 Test3 This is a test program4 for ras .5% removetag test. html |1 # pipe STDOUT to the first command of next line% number # STDIN is from the previous pipe (removetag)12 Test3 This is a test program4 for ras .5% removetag test. html |2 # pipe STDOUT to the first command of next next line% lsbin npshell test1.txt test2. txt test. html% number # STDIN is from the previous pipe (removetag) 12 Test3 This is a test program4 for ras .5% removetag test. html |2 # pipe STDOUT to the first command of next next line% removetag test. html |1 # pipe STDOUT to the first command of next line# (merge with the previous one)% number # STDIN is from the previous pipe (both two removetag)12 Test3 This is a test program4 for ras .567 Test8 This is a test program9 for ras .10% removetag test. html |2% removetag test. html |1% number |1% number1 12 2 Test3 3 This is a test program4 4 for ras .5 56 67 7 Test8 8 This is a test program9 9 for ras .10 10% removetag test. html | number |1% number1 12 2 Test3 3 This is a test program4 4 for ras .5 5% removetag test. html |2 removetag test. html |1 # number pipe may occur in middle % number |1 number1 12 2 Test3 3 This is a test program4 4 for ras .5 56 67 7 Test8 8 This is a test program9 9 for ras .10 10% ls |2% lsbin npshell test1.txt test2. txt test. html% number > test3. txt% cat test3. txt1 bin2 npshell3 test1. txt4 test2. txt5 test. html% removetag0 test. html |1Error: illegal tag "! test. html" # output error message to STDERR % number12 Test3 This is a test program4 for ras .5% removetag0 test. html !1 代 写Network Programming Project 1 - NPShellC/C++ # pipe both STDOUT and STDERR# to the first command of the next line% number1 Error: illegal tag "! test. html"23 Test4 This is a test program5 for ras .6% dateUnknown command: [date] .# TA manually moves the executable "date" into working_dir/bin/% dateWed Mar 13 10:44:39 PM CST 2024% exitbash$3 Specification3.1 NPShell Behavior1. Use ”% ” as the command line prompt. Notice that there is one space character after %.2. The npshell parses the inputs and executes commands.3. The npshell terminates after receiving the exit command or EOF.4. There will NOT exist the test case that commands need to read from STDIN.3.2 Input1. The length of a single-line input will not exceed 15000 characters.2. The length of each command will not exceed 256 characters.3. There must be one or more spaces between commands, arguments, pipe symbol (|),rection symbol (>), but no spaces between pipe and numbers for numbered-pipe.Examples:% ls -l | cat% ls > hello. txt% cat hello. txt |4 # no space between "| " and "4"% cat hello. txt !4 # no space between "!" and "4"4. Only English alphabets (uppercase and lowercase), digits, space, newline, ”:” , ” >” , ” | ” , and ”!” may appear in test cases.3.3 Built-in Commands1. Format. setenv [var] [value]Change or add an environment variable.If var does not exist in the environment, add var to the environment with value.If var already exists in the environment, change the value of var to value.Examples:% setenv PATH bin # set PATH to bin% setenv PATH bin:npbin # set PATH to bin:npbin. printenv [var]Print the value of an environment variable.If var does not exist in the environment, show nothing.Examples:% printenv LANGen_US. UTF-8% printenv VAR1 # show nothing if the variable does not exist% setenv VAR1 test% printenv VAR1test. exitTerminate npshell.2. Built-in commands will appear solely in a line.3. Built-in commands will not pipe to other commands, and no commands will pipe to built-in commands.3.4 Unknown Command1. If there is an unknown command, print error message to STDERR with the following format: Unknown command: [command].Examples:% cttUnknown command: [ctt] .2. You do not need to print the arguments of unknown commands.Examples:% ctt -nUnknown command: [ctt] .3. The commands after unknown commands will still be executed.Examples:% ctt | lsUnknown command: [ctt] .bin npshell test. html4. Messages piped to unknown commands will disappear.Examples:% ls | cttUnknown command: [ctt] .3.5 Ordinary Pipe and Numbered Pipe1. You need to implement pipe (cmd1 | cmd2), which means the STDOUT of the left hand sidecommand will be piped to the right hand side command.Examples:% ls | cat # The output of command "ls" acts as the input of command "cat"binnpshelltest. html2. You need implement a special piping mechanism, called numbered pipe. There are two types of numbered pipe (cmd |N and cmd !N).3. |N means the STDOUT of the left hand side command will be piped to the first command of the next N-th line, where 1 ≤ N ≤ 1000.4. !N means both STDOUT and STDERR of the left hand side command will be piped to the first command of the next N-th line, where 1 ≤ N ≤ 1000.5. If |N and !N occur in the middle, then the number starts counting from the same line.6. The line with build-in command or unknown command also counts as one line for numbered pipe, but the empty line does not.Examples:% ls |2% cttUnknown command: [ctt] .% cat # The output of command "ls" acts as the input of command "cat"binnpshelltest WX:codehelp