xview
. A question raised by some
students was "how can one ensure that a file is really a GIF file?"
The command file
will give this kind of information:
file bart.gif GIF picture - version 87a 43 x 58, interlaced, 2 colors
This assignment is to write a specialised version of the
file
command that could be used in assignment one
(or in other problems) to test and handle GIF files appropriately.
/etc/magic
under Unix (see man magic
).
Examination of the byte structure of files can be done using the
command od
(see man od
).
For GIF files, the first three
bytes hold the characters "GIF" (od -c file.gif | more
shows
this). The next three bytes give the GIF version number as "87a"
or "89a" and the next byte shows how many colours are possibly present
in the image.
giftest
,
the command would be used as
giftest [-v] [-s] [-h] [file]meaning that it can be called with an option
-v
, an
option -s
, an option -h
(or any combination in any order), and an optional filename.
The normal Unix convention that the filename must be after any options
will be followed.
If called with no options, but with a filename, then the program should determine if the file is a GIF file. If it is, then it should write the name of the file to standard output. If it is not, then it should write nothing to standard output, but just terminate. In addition, the exit code should be zero if it is a GIF file, non-zero otherwise. An example use could be
giftest filename | xview -p(An extended version of
xview
will be made available which
has an option to be
permanent, and not disappear when its input terminates.)
If no filename is given, then the command should read a filename from standard input. If the file is a GIF file the filename should be copied to standard output, otherwise no output should be written. The exit code should be zero for a GIF file, non-zero otherwise. An example use could be
echo filename | giftest | xview -p
If the -s
option is given, no output should be written
to standard output. Only the exit code should be given
An example use could be
if giftest filename then echo filename | xview -p fi
If the -v
option is given, then information about the
file should be written to standard error. This should include
whether or not it is a GIF file, and if so what version of GIF it is.
If the -h
option is given, a help message telling the
way to use the command should be written to standard error.
errno
or use the library function strerror()
to phrase these error messages and exit codes.
emacs
is to look for lines
``-*- language -*-'' as a clue.
So if you include a line
// -*- C++ -*-in your source, it would help me to invoke the right compiler.
give
.
This command runs with two parameters.
The first parameter should be the string ``a2'' and the second should be the
name of the file containing the source of your shell program. For example,
give a2 myass2.c
You may run give
any number of times.
Each time you run give
it replaces any
earlier submission of the assignment.
Submit only the source code. Do NOT give the executable file!!! I can't extract the source code from an executable, so it can't be marked. If you give an executable, then it will not be tested or marked and you will have to resubmit it.