The concepts that are used in this assignment are
~ostutes/libA3.a
. If your source is
a3.c
that you are compiling to a3
, use this
command line:
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
(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 sentinal - 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 sentinal 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 sentinal value.)
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.
If you are running Linux, then you will need binary copies of some programs. See here for more information.