CS240 Spring 2011: LAB01


Goal

  1. Write a Makefile to compile and link GNU indent -- a utility for pretty printing C programs.

  2. Implement cal.

    $ cal 1 2011
    Su Mo Tu We Th Fr Sa
                       1
     2  3  4  5  6  7  8
     9 10 11 12 13 14 15
    16 17 18 19 20 21 22
    23 24 25 26 27 28 29
    30 31
    

Instructions

Makefile

This lab should be done on lore.cs.purdue.edu using gmake (GNU make). The supplied code may not compile on other machines. Note that lore runs Solaris operating system and thus make and gmake are not the same program unlike on many Linux machines.

Begin by creating a directory named lab01. Inside lab01, create subdirectories Makefile and cal.

Do this part of the lab on GNU indent inside the Makefile subdirectory and the next part inside the cal subdirectory.

Download GNU source provided HERE. To untar the archive, enter command: gzip -d indent.tar.gz | tar -x

Create your Makefile in the source directory (i.e. indent).

In the Makefile:

To test whether the indent binary you built is working as expected, try using it to indent one of the source files using different styles. Use the man command to find out how to use indent. Make sure that you are using the indent binary you built and not the one that is available on lore:-)

cal

Zeller's congruence is an algorithm devised by Christian Zeller to calculate the day of the week for any Julian or Gregorian calendar date.

For the Gregorian calendar, Zeller's congruence is:

where,

NOTE: In this algorithm January and February are counted as months 13 and 14 of the previous year. E.g. if it is February 2, 2010, the algorithm counts the date as the second day of the fourteenth month of 2009 (14/02/2009 in MM/DD/YYYY format)

Your next task for this lab is to write a program that when provided with a month (first argument) and an year (second argument), outputs the calender for that month as shown in the example above. Make sure that you print the correct number of days (28, 29, 30 or 31) for each month. NOTE: Feb has 29 days in leap years, when the year number is divisible by four (except for years that are divisible by 100 and not by 400 in the Gregorian calendar).

If the date is a single digit it should be right aligned and if the first day of the month is not a Sunday, print spaces for the rest of that week. Please terminate each line with a newline character and do not have any spaces between the last non-space character and the newline. Make sure to stick to these formatting guide lines.

Create a Makefile to build your code inside lab01/cal directory. Name your final executable (and the Makefile target) as lab01-cal.

Please make sure that output of your program is the same as that of reference implementation provided HERE. Use diff to compare outputs.

Submit

Type cd .. in lab01 and change working directory to the parent directory of lab01.

In the parent directory of lab01, type turnin -v -c cs240=XXX -p lab01 lab01 to turnin your work. Replace XXX with your section number-- F1130, F130, F330, F730, F930, R1130, R330, R930, T1130.

Now, you may use the command, turnin -c cs240=XXX -p lab01 -v to verify your submission.

This lab is due on Sunday 23 January 11:59PM.