----------------------- Exercise #5 for DAT2330 due December 7, 2004 ----------------------- -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Global weight: 5% of your total mark this term Due date: 10h00 (10am) Tuesday December 7, 2004. The deliverables for this exercise are to be submitted online on the Course Linux Server using the "datsubmit" method described in the exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty exercises that are submitted late but before 10h00 (10am) on Thursday, December 9. After that late-submission date, the exercise is worth zero marks; but, it must still be completed and submitted successfully to earn credit in the course. Exercises submitted by the *due date* will be marked online and your marks will be sent to you by email after the late-submission date. A sample answer will be posted online after the late-submission date. This exercise is due on or before 10h00 Tuesday December 7, 2004. Exercise Synopsis: Marks: 5% This exercise is based on the Hangman game from this site: http://www.funet.fi/pub/Linux/util/games/ You will download a modified version of this game, build it, and execute it. Do not download the original game; follow directions. Exercise Details (to be done on the Course Linux Server): 1) Remember the actions you do in this step. Fetch this hangman mystery file from the web site using wget: http://teaching.idallen.com/dat2330/04f/notes/.hangman This file has been compressed several times using different programs. Uncompress it over and over using the right programs and file extensions until you find a tar archive. Extract all the files from the tar archive. Remove the tar archive. Hint: A Unix command from Week 2 will tell you what type of information is in a file. Use that command to know what kind of decompression is needed. Some decompression programs need the file to have the correct file extension. See week14notes.txt 2) Write a shell script named gethangman.sh that will automatically fetch the above mystery file and do the steps needed to decompress it several times and then extract all the files and remove the archive. (This does what you just did in the previous step.) Things to check in your executable shell script: - Make sure that the current directory has write and execute permissions at the beginning of the script. - If there is already an existing pathname named ".hangman" in the current directory, print an error message and exit. Do not overwrite an existing ".hangman" pathname. - If there is already an existing pathname named "hangman" in the current directory, print an error message and exit. Do not overwrite an existing "hangman" pathname. - Make sure that the wget downloaded .hangman file is not empty. - Exit the script non-zero on all errors or if any programs fail. Use the full script_style.txt format for DAT2330 scripts. 3) Enter the hangman directory created by the tar file. Try to build the hangman binary executable using the "make" command. You may have to fix permissions on some files and/or directories to allow the compiler to create object files in the current directory. During the linking phase, you may get an error message about a missing -ltermcap library. If you get an error about -ltermcap: a) Edit the Makefile to remove the word "-ltermcap" from the file. (Remove only the word -ltermcap; do not remove anything else.) b) Put a comment in the Makefile explaining what you did and why Use the "make" command (which will re-read the new Makefile) to build the hangman executable. The compiling and linking should proceed without errors, and the result should be an executable file named hangman in the current directory. 4) Read the manual page that comes with the hangman program: $ man ./hangman.6 According to the man page, when was this program distributed? 5) Run the working hangman program. It should look like this: ______ | | | Guessed: | | Word #: 1 | Current Average: 0.000 __|_____ Overall Average: 0.000 | |___ |_________| Word: ---------------- Guess: 5) At the end of the Makefile create a "clean" target that executes: rm -f ${OBJS} hangman The item ${OBJS} is a Makefile variable, defined earlier in the Makefile. The braces around the name are required in a Makefile. Verify that your new "make clean" Makefile target works, removing all the object files and the hangman executable. Add a comment above your new target in the Makefile explaining what "make clean" does. 6) Find out how to change the hangman dictionary from /usr/dict/words to be the file "mywords" in the current directory. Make the change. Insert a comment in the appropriate source file explaining what the old name was and why you changed it to be the new name. Note that typing "make" after making the above program change doesn't recompile the hangman program. The Makefile is incomplete. Add this line, left-justified (no blanks), to the end of the Makefile: setup.o: pathnames.h Now, "make" will rebuild the setup.o file whenever pathnames.h changes. Add a comment to the Makefile explaining why you added the above line. Type "make" and ensure that it rebuilds the setup.o file and then the hangman program executable. The hangman program should now try to open the file "mywords" when you run it. We must put some words in this file: Put some of your own words, one per line, in your "mywords" file and run the hangman program. Note: the program ignores the first word in the file; you must have at least two words in the "mywords" file. Verify that your hangman program is now using your own words instead of the /usr/dict/words list of words. 7) The game currently exits if the user types ^D (control-D) in response to a prompt for the next letter. Modify the game to *also* exit when the user pushes the ESC key in response to a prompt for a letter. (The octal, decimal, and hexadecimal character numbers for all the ASCII characters are available by typing "man ascii". Look for the ESC character.) Re-make the program and verify that it works. Insert a comment in the source file above your change, explaining why you made the change and what it does. ------------- Documentation ------------- You are asked to insert source file comments explaining all the above changes. Files without comments will not be marked. A gethangman.sh script file without comments will not be marked. You must have comments even for steps that you do not implement. ---------- Submission ---------- Submit the following files for marking on the Course Linux Server, using the following *single* datsubmit command line: $ datsubmit 05 gethangman.sh Makefile pathnames.h getguess.c This "datsubmit" program will copy all the selected files to me for marking. Always submit all your files at the same time. Do not delete your copies; keep them. Verify that you submitted all your files. P.S. Did you spell all the label fields and file names correctly?