Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The goal of this assignment is to write a C++ program that provides a basic directory maintenance simulator to process UNIX/Linux-style commands.
- we could use a binary tree structure where one branchis essentially a linked list of sibling nodes at a given level, and the other branch is a pointer to the contents of the given directory. Pictorially,the data structure would look like this:
- For simplicity, we will use the same type of node for a file or a directory.
- Requirements for this assignment:
- We will simulate several of the UNIX command-line operating system commandsfor a directory system in order to add directories, add files, list directory contents, etc.
- We will implement the following commands:
- ls // lists all filesand directories in the current directory, indicating which (file or directory)it is
- mkdir <dirname> // creates a new directory if it does not alreadyexist
- cd <dirname> // changes into specified directory ifit exists
- cd .. // changes to the parentdirectory
- pwd // specifies the current directory as: <yourname>/root/nextdir/etc/
- addf <filename> // adds a file to the current directory
- mv <fname1> <fname2> // change the name of the file or directory to the new name
- cp <fname1> <fname2> // copy file or folder to the new name
- rm <filename> // locate and remove the file or directory
- bye // ends the session
- whereis <filename> // show path to first occurrence of file or directory if it exists
- A technical note:
- Think of the structure for a Node in this system. The cd .. command suggests that it will be really critical to be able to navigate from a given node to that node's parent. Does it appear that the second picture above would make such a process efficient? One other thought. You will REALLY want to practice drawing how your pointers get set as you develop this program!!
- Program execution:
- This assignment will simulate an interactive program by reading the commands from a file. Commands will be in the file, one per line. You will NOT have to construct commands from multiple lines and SHOULD NOT code your progam to work that way. We will adopt the approach of running an interactive program non-interactively for two reasons:
- •It will illustrate that you can test interactive programs without having to do all the typing (most important)
- •It will simplify life for the person grading the assignment (me in this case)
- Error Checking:
- This assignment will require quite a bit of error checking. For instance, you should not be able to make a file or directory in a directory that already has a file or directory by that name. You obviously cannot switch into a directory that is not there, and you cannot switch to the parent directory of your root directory (although UNIX might permit you to do this if the System Administrator is not too picky). The data structure will be available in the background and will grow as we add subdirectories and files, or shrink as we remove them. Note the use of the $ as the command prompt - just like a typical command-line system!!
- Here is a typical output of a program run:
- $ pwd
- coffey/root/
- $ mkdir abc
- abc
- $ cd abc
- coffey/root/abc/
- $ addf f3
- $ addf f2
- $ addf f1
- $ ls
- F f1
- F f2
- F f3
- $ mkdir def
- def
- $ ls
- D def
- F f1
- F f2
- F f3
- $ cd cdf
- cdf is not located in abc
- $ cd def
- coffey/root/abc/def/
- $ pwd
- coffey/root/abc/def/
- $ whereis f3
- coffey/root/abc/
- $ whereis qwerty
- qwerty not found
- $ cd ..
- coffey/root/abc/
- $ ls
- D def
- F f1
- F f2
- F f3
- $ cd ..
- coffey/root/
- $ pwd
- coffey/root/
- $ ls
- D abc
- $ cd abc
- coffey/root/abc/
- $ pwd
- coffey/root/abc/
- $ ls
- D def
- F f1
- F f2
- F f3
- $ rm f5
- f5 is not in coffey/root/abc/
- $ rm f2
- $ ls
- D def
- F f1
- F f3
- $ mv f3 file3
- $ ls
- D def
- F f1
- F file3
- $ bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement