BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C++代写 | CSE-111 Function pointers, a shell

C++代写 | CSE-111 Function pointers, a shell

CSE-111 • Fall 2019 • Program 2 • Function pointers, a shell  
1 of 7  
$
Id: asg2-shell-fnptrs-oop.mm,v 1.49 2019-10-08 15:40:49-07 – – $  
PWD: /afs/cats.ucsc.edu/courses/cse111-wm/Assignments/asg2-shell-fnptrs-oop  
URL: http://www2.ucsc.edu/courses/cse111-wm/:/Assignments/asg2-shell-fnptrs-oop/  
1
. Overview  
You will maintain a tree structure with a simple hierarchy, maintained by a map of  
functions. The program will involve object-oriented programming using virtual  
functions, and displatching functions from a table of functions.  
Programming will be done C++ style, not C style, as shown in the following table.  
Do not use :  
Instead, use :  
raw char*strings  
raw C arrays  
<string>  
<vector>  
<
raw pointers  
stdio.h>  
,
<cstdio>  
<iostream>, <iomanip>  
<shared_ptr>or <unique_ptr>  
inheritance  
union  
<
header.h>  
<cheader>  
Header files: Include only C++11/14/17 header files and facilities where feasable,  
and use namespace std. Include <cheader files only when C++-style files are  
>
unavailable. Include <header.h> files from C only when an appropriate <cheader  
>
files is unavailable. Use the script cpplint.py.perl (a wrapper for cpplint.py) to  
check style, and checksourceto check some formatting considerations.  
2
. Program specification  
The program specification is given in terms of a Unix man(1) page.  
NAME  
yshell — in memory simulated tree shell  
SYNOPSIS  
yshell  
[
-@flags]  
DESCRIPTION  
This shell reads commands from the standard input and write output to the  
standard output, with errors being written to the standard error. Each line  
read by the shell is parsed into words by splitting using space characters, with  
any number of spaces between words. There may also be leading and trailing  
spaces. The first word on any line is a command to be simulated, and the rest  
are operands to that command. If either the standard input or the standard  
output is not a tty, each line from the standard input is echoed to the standard  
output.  
The commands modify an inode tree, where each inode is either a file or a  
directory. Files contain data and directories contain inodes. An inode is speci-  
fied by means of a pathname. A pathname consists of a sequence of characters  
separated by slash (  
The inode tree has a root, which is a special node, and also a current inode as  
well. Whenever a pathname is decoded, if the first character is a slash ( ),  
decoding begins at the root, otherwise it begins with the current directory.  
Whenever a pathname component is a dot ( ), it refers to the current directory.  
/) characters.  
/
.
CSE-111 • Fall 2019 • Program 2 • Function pointers, a shell  
2 of 7  
If a component is a double dot (..) it refers to the parent of the current direc-  
tory. Every directory has both of these entries, with the root being its own par-  
ent. Multiple adjacent slashes are treated as a single slash. Trailing slashes  
are permitted only on directories.  
Every inode has three attributes: an inode number, which is uniquely  
assigned, starting from 1 for the root; contents, which is a map from file-  
names to inodes for a directory, and text for a file; and a size, which is the  
byte count for text, and the number of sub-inodes for a directory.  
OPERANDS  
None. All input comes from the standard input.  
OPTIONS  
The -@option is followed by a sequence of flags to enable debug output, written  
to the standard error.  
COMMANDS  
The following commands are interpreted. Error messages are printed and  
nothing is done in the case of invalid operands.  
#
string  
If the first non-space character on a line is a hash, the line is a comment  
and is ignored.  
cat pathname…  
The contents of each file is copied to the standard output. An error is  
reported if no files are specified, a file does not exist, or is a directory.  
cd [pathname]  
The current directory is set the the pathname given. If no pathname is  
specified, the root directory ( ) is used. It is an error if the pathname  
does not exist or is a plain file, or if more than one operand is given.  
/
echo [words…]  
The string, which may be empty, is echoed to the standard output on a  
line by itself.  
exit [status]  
Exit the program with the given status. If the status is missing, exit  
with status 0. If a non-numeric argument is given, exit with status 127.  
ls [pathname…]  
A description of the files or directories are printed to the standard out-  
put. It is an error if any of the file or directory does not exist. If no path-  
name is specified, the current working directory is used. If a pathname  
specified is a directory, then the contents of the directory are listed. A  
directory listed within a directory is shown by a terminating slash. Ele-  
ments of a directory are listed lexicographically.  
For each file listed, output consists of the inode number, then the size,  
then the filename. Output is lined up into columns and each column is  
separated from the next by two spaces. The numeric fields are exactly 6  
characters wide and the units position in a column must be aligned.  
CSE-111 • Fall 2019 • Program 2 • Function pointers, a shell  
3 of 7  
lsr [pathname…]  
As for ls, but a recursive depth-first preorder traversal is done for subdi-  
rectories.  
make pathname [words…]  
The file specified is created and the rest of the words are put in that file.  
If the file already exists, a new one is not created, but its contents are  
replaced. It is an error to specify a directory. If there are no words, the  
file is empty.  
mkdir pathname  
A new directory is created. It is an error if a file or directory of the same  
name already exists, or if the complete pathname to the parent of this  
new directory does not already exist. Two entries are added to the direc-  
tory, namely dot (.) and dotdot (..). Directory entries are always kept in  
sorted lexicographic order.  
prompt string  
Set the prompt to the words specified on the command line. Each word is  
separated from the next by one space and the prompt itself is terminated  
by an extra space. The default prompt is a single percent sign and a  
space (% ).  
pwd  
Prints the current working directory.  
rm pathname  
The specified file or directory is deleted (removed from its parent’s list of  
files and subdirectories). It is an error for the pathname not to exist. If  
the pathname is a directory, it must be empty.  
rmr pathname  
A recursive removal is done, using a depth-first postorder traversal.  
EXIT STATUS  
0
1
No errors were detected.  
Error messages were printed to the standard error.  
3
. A sample run  
The following table shows a sample run. Each interaction with the shell is listed in  
a separate box with shell output in Courier Roman and user input in Courier Bold  
typeface. A commentary about what is happening is opposite in the right column.  
%
/
pwd  
Initially the cwd is the root directory.  
CSE-111 • Fall 2019 • Program 2 • Function pointers, a shell  
4 of 7  
%
/
ls  
:
The absence of an operand to ls means  
that dot is used as its operand, which  
is currently the root. Directories  
always contain at least two items,  
namely dot and dotdot. The inode  
number of the root is always inode #1.  
The parent of dotdot is itself.  
1
1
2 .  
2 ..  
%
%
make foo this is a test  
Make a file called foo which contains  
the string ‘‘this is a test’’, which is  
14 characters. An inode is allocated,  
namely inode #2.  
make bar test a is this  
ls  
Another file, similarly created, with  
inode #3.  
%
/
Same as the previous output of ls,  
except with two more files. Note that  
:
1
1
3
2
4 .  
files are kept in lexicographic order, so  
baris listed before foo.  
4 ..  
14 bar  
14 foo  
%
cat food  
An error message is printed, causing  
the return code from the shell eventu-  
ally to be 1 rather than 0. Note the  
error format: command followed by  
object causing the problem followed by  
the reason for the failure.  
cat: food: No such file or directory  
%
cat foo  
this is a test  
echo O for a muse of fire  
O for a muse of fire  
Files can consist of only one line,  
namely a string.  
%
Arguments to echo are simply written  
to the standard output.  
%
prompt =>  
The prompt is changed to the charac-  
ters ‘‘=>’’ followed by a space. Multiple  
words would have been permitted.  
=
> rm bar  
The file bar is deleted and the size of  
the root directory is reduced by 1.  
=
=
> make baz foo bar baz  
> mkdir test  
A new file is created with inode #4.  
Inode #5 is created as a directory  
called test. This directory is a child of  
the root and contains the two usual  
entries, dot and dotdot.  
=
> prompt %  
The prompt is changed back to a % fol-  
lowed by a space.  
CSE-111 • Fall 2019 • Program 2 • Function pointers, a shell  
5 of 7  
%
/
ls /  
:
Just checking the contents of the root.  
1
1
4
2
5
5 .  
5 ..  
11 baz  
14 foo  
2 test/  
%
cd test  
pwd  
The cwd is now test.  
Yes, it is.  
%
/
test  
%
cd  
Without arguments cd goes back to the  
root directory.  
%
/
pwd  
OK.  
%
cd test  
Go to a directory called test which is a  
subdirectory of the cwd, whose alias  
name is always dot.  
%
/
pwd  
test  
%
cd ..  
pwd  
Dotdot is always an alias for the par-  
ent of the cwd.  
%
/
%
%
cd test  
make me me me me  
This would have errored out if test  
were not a directory or did not exist.  
The next available inode is #6.  
%
cat me  
me me me  
%
%
cd ..  
cd test  
%
cat me  
me me me  
%
cd  
%
/
lsr /  
:
Recursive directory listing. This is  
done using a preorder traversal. With-  
ing a given level, lexicographic order-  
ing is used. Recursion will go through  
all subdirectories at all levels.  
1
1
4
2
5
5 .  
5 ..  
11 baz  
14 foo  
3 test/  
/
test:  
5
1
6
3 .  
5 ..  
8 me  
%
cd test  
bestdaixie