CSCB09S Assignment 2

Due: Fri. Feb 16, 2001 (at noon)

Your employer just bought a broken Unix system off the street, and much to your dismay you discover that the ls command is missing. You decide to write a replacement called mydir which will do some of what ls does. You design the program as follows:

A partial example output is shown below:

drwx------     harper    users        512 Oct 27  2000 HOWTO
-rw-------     harper    users        4426 Sep 21  2000 HelloWorld.class
-rwx------     harper    other        1113 Sep 21  2000 HelloWorld.java
drwx------     harper    users       2048 Jan 31 11:15 Mail
drwxr-x---     harper    other        512 Jan  5 14:59 NEW
drwx------     harper    users        512 Nov 26  1999 News
-rw-------     harper    users       13354 Oct 23  2000 PW.C
drwx------     harper    users       1024 Dec 22 11:01 System

Observe the changing date format: for files more than about 90 days old, only the day and year are shown, for newer files, the year is suppressed and the time is shown. In either case the date occupies the same amount of space in the output. You will have to extract the required pieces from the ctime() output.

What to do

This is a program about command-line processing and system calls. You will have to read the man-pages on a number of library functions as noted below and determine how to use them. Pay particular attention to the include files listed, since these provide the function prototypes and structure definitions that you require.

Here are some of the library functions and man pages that will be of use in writing this program:

getopt(), chdir(), stat(), opendir(), readdir(), rewinddir(), qsort(), getpwuid(), getgrgid(). ctime(), strcmp(), time(), mknod.

What to hand in

Submit the code and the output of your program when run on the /etc directory on fissure using the -a, -t, and -r flags together.

Notes and Hints

As always, start NOW.

This program is easily built-up in stages, each of which is largely independent of the others. Thus, testing and development are straightforward. The final program, if well written, shouldn't be more than about 200 lines, in one file (not including comments).



Footnotes

... this)1
Just because you're not using all the info now doesn't mean the program might not need it in the future. Plan ahead and keep most of the data.


John Harper
2001-01-31