CS 3733 Operating Systems, Fall 1999 Assignment 1

Due Thursday, September 16, 1999



Warning: This is not for the current semester.


The purpose of this assignment is to make sure you are familiar with C programming, string manipulation using pointers, linkage classes, use of makefiles, and separate compilation.

General Statement of the Problem:
Characters will be coming in to your program 1 at a time. You are to gather up full lines and when you get a full line, parse and output the line. The format of the input will be similar to the input accepted by a web server.

Details:
Legal input will consist of sequences of characters which either make up short lines of printing characters or binary data.

Binary data will only come in after a line in the form
    Content-Length: 12345
followed by an arbitrary number of lines of printing characters. The binary data will start after a blank line (a line containing only 0 or more blanks) and the number of bytes will be given by the number on the Content-Length line.

Create a file myparser.c which contains only one identifier with external linkage, myparser. This will be a function with the following prototype:
    void myparser(char x);
You may put additional functions in this file, but they need to have internal linkage (static). You may use global variables, but these also must have internal linkage.

As myparser is called it will save up its characters in a string until an end of line is found. If a short line of printing characters is found, that line will be sent to standard output. If binary data is received it should output a message in the form:
    receiving n bytes of binary data before the first such byte is processed and then output a line in the form:
    binary data complete
when it receives the last byte of binary data. The first time myparser is called, it should print out a line in the form:
    This version of myparser was written by xxx

Error checking:
There are two types of errors that can occur:

  1. A line of printing characters comes in which is too long.
  2. A line which should contain printing characters contains a non-printing character.
In either of these cases, an appropriate warning message should be sent to standard error and all future input should be ignored.

Testing:
In a separate file called mytester.c, write a main program which reads characters from standard input and sends them to myparser. It should terminate when it receives and EOF.

You should make up test data for your program. You can start by using input from the keyboard. Remember that your program does not receive anything you type until you hit the RETURN key. You should also test the program by creating input files. You can use cat to combine a file containing non-printing characters (such as a GIF image) to a file created with an editor. Make sure you test for all possible error conditions including long lines and non-printing characters occurring when they are not allowed.

Turning in the assignment:
Use the cover sheet available in /usr/local/courses/cs3733/fall1999/cover1.ps or just click here. This sheet lists what needs to be turned in. You will need to include a complete description of how you tested the program including how you tested for the handling of errors. This description should be typed, rather than hand written.

Notes:

  1. Decide on how long input lines should be allowed to be. Use a symbolic constant to represent this value. If you decide to change the value of this constant, it should be possible to do it in only one place in your code. Your program must handle lines that are too long by detecting this error without the possibility of performing any illegal operations, such as writing to unallocated memory or unintentionally overwriting a variable. Most security violations on Unix systems stem from this type of programming error. Remember that just because a program works when you test it does not mean that it is correct.
  2. Make an include file which contains the prototype for your myparser.
  3. You must use separate compilation and a makefile.
  4. Lines are terminated by the newline character, '\n'. You should allow lines to contain carriage returns, '\r', and you should ignore all of these characters on input. Aside from these two characters, all characters with ASCII code below a space and above a lower case z are considered non-printing characters for this assignment.
  5. Run lint with no options. The only lint warnings you should receive have the form:
        function returns value which is always ignored
  6. I prefer that you use the Sun C compiler. To find out if this is the one you are using, execute
        which cc
    and the result should contain SUNWspro/bin/cc.
    Similarly,
        which lint
    should produce output which contains SUNWspro/bin/lint. If this is not the case you need to modify your path. Execute
        utsa path
    for more information about how your path is set up.
  7. Be prepared to demonstrate your program to me.
  8. Note that all assignments are due at the beginning of class on the due date. If you do not wish to turn it in at that time, come to class and turn it in within 12 hours for a 10 percent penalty. Do not miss class to work on an assignment.