Assignment 3

Due date

This assignment is due at midnight on Sunday 8 Oct, at the end of week 12.

General

This assignment continues the work of translating Assignment 1 into C. The concentration this time is on concurrent processes and communication between them.

The concepts that are used in this assignment are

Supplied functions

This assignment use functions that are not in the standard C or Unix libraries. The functions is char *fetch_sound(char *filename) char **list_sounds(void) You will need to add these functions at link time. They are stored in the library ~ostutes/libA3.a. If your source is a3.c that you are compiling to a3, use this command line: gcc -o a3 a3.c -L/student1/os/ostutes -lA3

The function fetch_sound is as described earlier. The function list_sounds takes no parameters and returns an array of strings. This array is dynamically allocated by list_sounds. Your program is responsible for freeing the memory when it is no longer needed. Note that the strings are dynamically allocated, and so is the array of strings.

Each string consists of a filename, followed by a colon `:' and the file description. Each string is null-terminated, as usual. The number of elements of the array is not specified. However, it is terminated by a NULL pointer. For example, if there are two sounds, then the function would return an array such as

{ "clapton.au:Eric Clapton ``Cocaine''", "holst.au:``The Planets''", NULL } That is, given char **sounds; sounds = list_sounds(); then sounds[0] == "clapton.au:Eric Clapton ``Cocaine''" sounds[1] == "holst.au:``The Planets''" sounds[2] == NULL Use this to find the number of sounds.

(An alternative to this is to return the number of elements in a separate argument. I prefer the given way because it effectively encodes the length within the data structure, using a good C sentinel - NULL -for this. Another alternative would be to return a structure with length and array fields. Early versions of C would not return a structure. Returning a pointer to a structure would be portable and quite good practice. However, a sentinel value is still a good idea even in this situation, so I have opted for simplicity and common C style. On the other hand, in an O/O language like C++ one would rely on a length method rather than a sentinel value.)

Specification Error

Because I was unable to find a specification of .au files, I assumed that they would be ordinary strings. It turns out that they can contain the null character '\0' as components, rather than only being terminated by '\0'. Rather than change the specs at this late stage, I will leave it as it is. In practice, this means that some sound files will play for a shorter period than expected, as the fetch_sound() function will return an array of longer length than it would interpreted as a string.

Specification

This program uses the external program xselect and xwarn to give a graphical display of data. It uses the functions list_sounds and fetch_sounds to return data.

This program uses the function list_sounds to get a list of sound files and their descriptions. It passes the descriptions to xselect for display and reads the selected descriptions. It determines the corresponding filename.

For each filename, if the file does not exist in the directory .sounds then a file of that name must be created in the cache directory. The contents of the file should be from a call to fetch_sound.

The file should be copied to /dev/audio.

When EOF is reached on xselect, the cache directory and all its contents should be removed, and the program should terminate normally.

Other comments

If you want to use dialin access to work then some programs will need to be replaced. See here for more information.

If you are running Linux, then you will need binary copies of some programs. See here for more information.



Creative Commons License Copyright © Jan Newmarch under the terms of the Creative Commons Attribution 2.1 Australia License.