This assignment has 5 parts. Each part builds on the previous one. For each part, create a new directory and copy the files from the previous part into this directory. Each part should have a separate makefile which can run lint on the programs for that part. In parts 3 and 4 you will use your library from Assignment 1 to write a program that can create a music database and receive queries on that database. In part 2 you will write a program that can be used to test parts 3 and 4. In part 1 you will write a utility routine that you will need.
In this assignment you will be sending strings from one process to another. For testing purposes it is sometimes easier to generate and look at lines rather than strings. You can find two useful filters, string2line and line2string in /usr/local/courses/cs3733/fall2001/assign4.
Part 0:
Make sure the datalib library you created in assignment 1
is working correctly.
If you think you are too far from
having this working, you can use my library (at a 3-point penalty)
available in /usr/local/courses/cs3733/fall2001/assign1/workinglib.
Part 1:
Write a function with the following prototype:
int read_string_from_fd(int fd, char *buf, int bufsize);
that reads a string
from the given file descriptor and puts it in buf if it fits.
This will read one character at a time until a string terminator is found,
putting the result in buf. At most bufsize bytes will
be read. If and end-of-file occurs before any input, return 0.
If no string terminator is found or an I/O error occurs,
return -1. Otherwise, return 1 to indicate success.
In this case buf should contain a valid string.
Put this function in a file called myiolib.c.
Create a file called myiolib.h containing the prototypes
of the public functions in myiolib.c. Write a separate
main program that checks to see that this function is working correctly.
One way to do this is to write a main program called iotest
that reads strings from file descriptor 0 using read_string_from_fd
and sends the corresponding line to standard output. This program should
check for the errors that can be returned by read_string_from_fd.
You can generate input strings from the command line using:
line2string | iotest
Part 2:
Write a main program called musictester that takes two named pipes
inpipe and outpipe as command line parameters.
It does the following:
Think about using fgets for user input. Be sure that your program does not have a buffer overflow problem.
Do this using three windows.
In the first window run musictester:
musictester inpipe outpipe
In the second window, look at what is going into outpipe:
cat outpipe | string2line
In the third window, generate input for inpipe:
cat > inpipe.
Part 3:
Write a main program called musicinfo
that takes two named pipes as command line parameters.
I will refer to these as inpipe and outpipe. The main
program opens outpipe for reading and writing and
performs an infinite loop that does the following:
If the command byte is '0', do the following:
Part 4
Have musicinfo handle the following additional command bytes:
Command byte '1':
Command byte '2':
This is just like command byte '1', but uses findentry.
Command byte '3':
This is like command byte '1', but uses deleteentry.
It will only send one byte to outpipe indicating success ('0') or
failure ('1').
If an invalid command byte is received, take no action.
Handing in the program
Use the cover page provided when handing in your
assignment.
The output you provide is determined what which parts of the assignment you have working. In each case, remove any unnecessary print statements that would obscure your output.
If Parts 2 and 3 are both working correctly:
Use the 2-window method of testing described above, running musicinfo
in one window and musictester in another. Use musicinfo
with command '0' to create three entries in the music database
in the following order:
If Part 4 is also working also do the following:
Entry host port key
1. myhost1 23 my first key
2. ten10.cs.utsa.edu 10034 myfile.1
3. ten24.cs.utsa.edu 10036 myfile.2
Use cut-and-paste to gather the output from the two windows and handle them
in (clearly labeled) with your assignment. The part gathered should start
with the prompt before the program is run and end with the prompt after is
has terminated.
If Part 3 is working but Part 2 is not
Do exactly the same as above, but
use the 4-window method that does not need musictester. Gather the
output for each window using cut-and-paste and turn it in with your printout.
Make sure the output of each window is clearly labeled.
If Part 2 is working, but not part 3
Use the 3-window method described in Part 2 and use musictester
to send the same information as in the above tests. Gather the results of
the three windows, label them clearly, and turn them in with your assignment.