CSC209S L0101 Spring 00

Assignment 1

Jan 10th, 2000 Due February 4th, 2000

Question 1 (10 Marks)

Write a csh script name "treeList" to (recursively) print the names of all directories in a tree, and summarize the number of bytes used by the files in each. The script is invoked as

% treeList {<dir>}

where <dir> is an optional parameter naming the directory to use as the root of the tree. If no parameter is supplied, then use the current working directory as the starting point. You may use recursion (i.e. have your script call itself), but if you do, do it carefully! You may not make any assumptions about where the script file is located, or that it is located in a directory listed by the PATH environment variable. You may not make use of "du" (or any similar UNIX utility).

Hand in a printed version of your csh script, as well as submitting it electronically on CDF using "submit -N a1 csc209h treeList". You can overwrite a previous submission by adding the "-f " switch to the submit command.

Question 2 (5 marks)

Write a csh script named "three" which takes 3 command line parameters, each of which is the name of some program to run. Have your script run each program as a background process, and wait until each has terminated before printing a simple message indicating that all processes have completed. Make your script invulnerable to "control-C". Hint: You may find the shell commands onintr and wait helpful.

Hand in a printed version of your csh script, as well as submitting it electronically on CDF using "submit -N a1 csc209h three". You can overwrite a previous submission by adding the "-f " switch to the submit command.

Question 3 (5 Marks)

From the course website, download the file Broken.c. This C program has both compile-time and run-time errors in it. Make a copy of the file named Fixed.c, and find and correct the errors (be sure to read the instructions included at the start of Broken.c).

Submit the corrected program using the command "submit -N a1 csc209h Fixed.c". Also, hand in a printed version of the corrected program.

Question 4 (15 Marks)

Write a csh script named "install". The script is called as

% install <fileName>

where <fileName> is a (non-optional) parameter naming a file containing files to be installed. The file named by <fileName> is a "tar" file that you must first unpack (if <fileName> ends in .gz, assume it is gzip'd and start by unzipping it first). The tar file will contain a file named contents, which will tell you where each unpacked file is to go. Read contents line by line. Each line will contain the name of an unpacked file, and its destination directory separated by a space. Move each file to its desired destination. An example tar file can be found on the course website.

You are responsible for handling errors that may arise while doing the "installation". Your script should warn when an error occurs, but should only shut down when it is truly impossible to continue. The following is a (non-exhaustive) list of errors you might consider:

Hand in a printed version of your csh script, as well as submitting it electronically on CDF using "submit -N a1 csc209h install". You can overwrite a previous submission by adding the "-f " switch to the submit command.