Assignment 1, CS-701, Fall 1997

Hexadecimal Dump Program

Due Date:
October 14, 1997
Deliverables:
The project directory is to contain an RCS subdirectory, and nothing else. The RCS database for the project is to include entries for the files main.cc, hexline.cc, Makefile, hexdump.1, and hexline.3. These files are described below. Consult "Using RCS" for information on how to set up your project directory and use RCS for project management.

Your ~/man directory tree is to contain man pages for hexdump(1) and hexline(3). See "How to Write a Man Page" for information on how to prepare your man pages.

You may also leave a README file in the project directory if you think that one is needed, but I neither expect nor require you to do so.

When the assignment is complete, send me an email message telling me the path to the project directory.

Requirements:
In addition to the information given here, be sure to consult the Grading Form for this assignment, which includes additional information about the requirements for this project.

Project Description

You are to write a utility program that can be used to print the contents of files in hexadecimal. The name of the command is hexdump, and it must be built from three source files, which are named main.cc, hexline.cc, and hexline.h. The header file must be #included in both the .cc files.

I will provide a Makefile, the hexline.h header file, and a library file named libhex.so. The Makefile has been emailed to you, the header file is installed in your ~/include directory, and the library file is installed in your ~/lib directory. Create a directory just for this project, and copy the Makefile into it before you start work on the project. Always use the make(1) command to compile and link your program. (There is an alias for "make" to save you all that typing: "mk".)

You are to do the project in two steps. For the first step you are to write main.cc and build hexdump by linking main.o with libhex.so, which contains a single object module with the function definition for hexline(). Once you have the code for this step tested and debugged, you are to write your own version of hexline.cc, create a new libhex.so, and link your main program to it. The Makefile supplied to you has two lines that will build the new libhex.so for you, but you have to remove the comment markers ('#' characters) from them. Read the Makefile to find them.

Write man pages for hexline(3) and hexdump(1). Check all .cc, .h, .1, .3, and Manpage files into RCS using the ci command. Delete all other files from your project directory, and make sure the command "mk" builds the program using both your .cc files. Check out copies of the man pages and copy them to the proper directories, clean up the project directory, and send me mail with the pathname of the project directory.

hexdump

As described in class, hexdump takes two optional command line options:
-s <n>
Specifies a starting offset for the dump. The default value is zero, which means to begin the dump with the first byte of the file.
-e <n>
Specifies the offset of the last byte of the file to be dumped. The default value is -1, which means "the last byte of the file."
After the options, the user may enter any number of file names. Each file will be dumped from its starting offset to its ending offset. If no file names are given, the program dumps stdin.

For this assignment, you must do all input and output by using the read() and write() system calls. Exception: you may use perror() and/or fprintf() for writing error messages to stderr.

hexline()

The hexline() function generates the character representation of one line of a file dump. The first argument is a pointer to an 81-byte "output" buffer where the formatted line is returned; the second argument is a pointer to a 16-byte "input" buffer containing the data to be formatted; the third argument is an integer that will be formatted to print in the first 8 bytes of the output buffer; the fourth and fifth arguments are starting and ending offsets for limiting how much of the input buffer is to be formatted. If either buffer argument is NULL, or if the starting and ending offsets are not between 0 and 15, or the ending offset is less than the starting offset, hexline() returns a value of -1 without changing the contents of the output buffer. Otherwise, it formats the output buffer and returns a value of zero.

There is a working version of hexdump in ~vickery/bin, which you may use to see what the program is supposed to do.



Christopher Vickery
Queens College of CUNY