CS253 HW4: Options!
Description
For this assignment, you will improve upon your previous work in
HW2, adding command-line options.
This is a complete program, not a library.
                
Arguments
The first command-line arguments should be options:
                
-
-g
golly-rule -
Instead of the rule used in HW2, apply this rule, from the
Golly
program. It has this form:
-g B
bval/S
sval.
Both bval and sval are composed of digits 0
…8
, in
strictly ascending order.
The default is -gB3/S23
, the rule used in HW2.
bval says when a new cell is born, and sval
says when an existing cell survives.
E.g., -g B137/S257
means that iff an empty
cell has exactly one, three, or seven neighbors, a cell is born
there. Also, iff a live cell has exactly two,
five, or seven neighbors, then it survives and stays alive.
Valid examples: -gB/S -gB78/S4 -g B3/S13 -gB012345678/S012345678
Invalid examples: -g S12/B34 -g B23 -gb23/s23 -g B12S78 -g B21/S34 -g B22/S34
-
-l
live-char -
Use this character to indicate that a cell is alive. This applies
when reading & writing. The default is
O
, same as HW2.
If you use a character special to bash (space, asterisk, ampersand,
etc.), then quote it: -l'*'
-
-d
dead-char -
Use this character to indicate that a cell is dead. This applies
when reading & writing. The default is
.
, same as HW2.
If you use a character special to bash (space, asterisk, ampersand,
etc.), then quote it: -d " "
-
-i
-
Produce an infinite number of generations on output, each
separated by a blank line.
There must be, at most, one optional argument after these options.
If that argument is present, read from that file, otherwise
read from standard input.
                
Sample Runs
Here are sample runs, where %
is my prompt.
                
% cmake .
… cmake output appears here …
% make
… make output appears here …
% cat block3
''''
'**'
'*''
''''
% ./hw4 <block3
./hw4: bad input char “'”
% ./hw4 -d"'" -l '*' <block3
''''
'**'
'**'
''''
% cat blinker
....
.O..
.O..
.O..
....
% ./hw4 blinker
....
....
OOO.
....
....
% ./hw4 -i blinker | head -17
....
....
OOO.
....
....
....
.O..
.O..
.O..
....
....
....
OOO.
....
....
% ./hw4 -g B3/S23 blinker
....
....
OOO.
....
....
% ./hw4 -gB123/S2456 blinker
OOO.
O.O.
OOO.
O.O.
OOO.
% ./hw4 -gB123/S2456 -i blinker | head -17
OOO.
O.O.
OOO.
O.O.
OOO.
O.O.
O.O.
.O..
O.O.
O.O.
O.O.
O.O.
OOO.
O.O.
O.O.
Animation
For cheap animation, try this:
./hw4 -i ~cs253/pub/Life/r | sed 's/^$/sleep 0.2;clear/e'
or:
./hw4 -i ~cs253/pub/Life/ggg | sed 's/^$/sleep 0.2;clear/e'
or:
./hw4 -i ~cs253/pub/Life/lines | sed 's/^$/sleep 0.2;clear/e'
Change the 0.2
to a larger/smaller value to slow it down
or speed it up.
                
Debugging
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a
Hints
- Use getopt(). Seriously, use it. Don’t do this yourself.
You will have to actually read the manual page for
getopt(). This is a skill that you must acquire to be
a good programmer.
Requirements
All requirements from HW2 still apply, with these additions:
- If more than one problem is detected, pick one.
- Produce an error message and stop the program if:
- more than one filename is present after the options
- a bad option or bad option argument is given
(the message must contain the bad option and argument, if present)
-g
, -l
, or -d
are given multiple times.
- the argument to any option is improper
- A space after an option taking an argument (
-g
, -l
, -d
)
is optional. -lO
is valid, as is -l O
, -l "O"
,
or -l'O'
.
- Options must precede filenames.
Option processing must stop at the first argument that
isn’t an option (or an argument to an option, e.g.,
-d X
).
This command must complain about too many arguments:
./hw4 -g B12/S34 infile -i
It may not treat -i
as an option.
- Option bundling:
./hw4 -il@ kokopelli
is the same as
./hw4 -i -l@ kokopelli
- The next non-space character after an option that requires an
argument must be the argument itself, not another option flag.
./hw4 -gd B3/S2 x
will treat d
as the argument
to -g
, and treat B3/S2
and x
as filenames.
./hw4 -i-d X
is invalid.
- “This is too hard!”
Tar file
- The tar file for this assignment must be called:
hw4.tar
- It must contain:
- source files (
*.cc
)
- header files (
*.h
)
CMakeLists.txt
- This command must produce the program
hw4
(note the dot):
cmake . && make
- At least
-Wall
must be used every time g++ runs.
How to submit your work:
In Canvas, check in the
file
hw4.tar
to the assignment
“HW4”.
                
How to receive negative points:
Turn in someone else’s work.