Programming Lab #4: Tree-structured Directories


Assigned: Mon 13 Apr 1998

Due: Mon 20 Apr 1998


General description

For this project you will write a program which:

  • implements a general tree class using the standard representation of general trees as binary trees,
  • implements a simple simulation of an operating system's directory structure by reading in user commands and making appropriate modifications to an underlying general tree.

In particular, you should use the representation of general trees discussed in the Weiss textbook (pp. ). In addition to the firstChild and leftSibling pointers discussed there, we would also like to support access from a child node to that node's parent. The natural way to do this would be to use a separate reference within each node to the node's parent. Therefore, each of your tree nodes should have three references to other nodes in addition to a data field.

The data contained in the trees should be generic, i.e., you should use Object as the corresponding type in your general tree class. For this specific use of general trees (i.e., for the directory structure simulation), you will use a specific class which describes a simple file or directory.

Your implementation should create an empty directory structure for the user when it is first started up, and then accept commands to ...

Note The sections of the textbook which describe file systems applications of general trees may be helpful, but this application is different from the one described there. Nevertheless, you will want to read the approprate sections on the implementation of general trees using binary trees.

For details on the methods you should support, the command-line interface, error reporting, etc., see below.

Commands and command syntax

Note also that, just as for the linked list iterator class given in the text on page 400, your insertion and removal methods should throw an ItemNotFound exception.

We'll use single- or double-character commands as follows (in keeping with the syle of unix, we'll use lowercase letters):

  • md command: make a directory

    one argument, the name of the directory.

    Note: creates the directory only; does not change current directory.

  • mf command: make a file

    one argument, the name of the file; also reads in a single string (terminated by end of line) which is the contents of the file.

  • cd command: change directory

    one argument, the pathname of the intended new current directory; the pathname is a list of identifiers separated by slashes. If there is an initial slash, the path starts at the top of the tree. If not, the path is relative to the current directory. In addition to identifiers, the special code "^" may be used, which indicates the parent of the current directory (relative to where we are in the path). This is like the unix "..".

  • ls command: list out directory

    no argument. Lists out the names of the files and directories in the current directory, one per line. Each name which is the name of a directory (rather than a file) should have a slash placed after the name.

  • pf command: print a file

    one argument: a filename. This command prints out the contents of the named file, without changing the current directory. A filename may be either a simple name (of a file in the current directory) or a pathname plus a filename.

  • rm command: remove a file or directory

    one argument: the name of the directory or file to be removed (may include a full pathname).

A note on errors: for each of the above operations/methods, you should give an explicit report if an error occurs, i.e., if there is no way to perform the requested operation.

Here is a sample run showing typical input/output (you should feel free to use appropriate introductory text and prompts of your own design):


Welcome to Directorium, your directory system value store!
Enter commands one per line, and input values where indicated:

> ls

  *empty directory*

> md foobar

  [created directory "foobar"]

> 

Thanks for using Directorium, come again soon!
		


Assessment

Your project will be assessed on the basis of both a "live" demonstration and a hard copy description and print-out of the project code. The printed version should specify both members of your group and should specifically mention any free late days used, remaining problems or bugs, special enhancements, etc. In addition to "raw code", you should include a brief introduction describing anything that is special in your approach to the problem (bugs, enhancements, etc., should also be mentioned here).

Your grade will be determined in part by the correctness of your code, but also by virtue of the techniques you use to implement it.

I will be available in lab on Monday mornings from 10:00 - 11:30 for demonstrations. You may also demonstrate at other times (Thursday morning office hours will likely be popular), including by appointment, but you must demonstrate your project and hand in your hard copy by the due date unless you receive a specific provision otherwise (see also the information about free late days on the syllabus).