CS253: Software Development with C++

Fall 2019

HW 3

CS253 HW3: Options!

Description

For this assignment, you will improve upon your previous work, adding command-line options, and changing a few things.                 

Arguments

The first argument is no longer a keyword file. Instead, the first command-line arguments should be options:                 

-k keywordfile
Specify the keyword file. The keyword file contains a list of valid keywords, one per line.
-n
Display lines with Name keys. That is, keys that are exactly the string Name.
-l
Display lines with Link… keys. These are the string Link, followed by an arbitrary alphanumeric string of at least one character, e.g., LinkDog, Link7012351, Linkqq42sv, etc.
-o
Display lines with other keys. That is, keys that aren’t Name or Link… keys.

If any of -n, -o, or -l are given, then display only lines with those keys. If not, then display all keys.                 

Any remaining arguments are files containing lists of enemies. If no remaining arguments are given, read enemies from standard input, as in the previous assignment.                 

Input Format

Same as previous assignment, except that a Name key is mandatory, and keys can now be alphanumeric.                 

As you may have realized, there is no need for an explicit check for alphabetic keys, since the -k keyfile controls which keys are valid.                 

Output Format

Same as previous assignment, except that within a given enemy, keys & values are displayed in this order:

  1. Name
  2. anything but Name and Link
  3. Link
    Multiple Link… lines are displayed in the input order.

Except as specified above, the output order is the same as the input order.                 

Sample Runs

Here are sample runs, where % is my prompt.                 

% cat keys
Name
Linkage
LinkIs
bonehead
motivation
RealName
Motif
% cat in1
RealName Victor Von Doom
Linkage College Acquaintance
Name Doctor Doom
motivation Rule the world!



Name Silver Surfer
Motif         Really into            
 the whole            
                silver thing        
% cat in2
Name Super-Skrull
LinkIs Just wants to kill the FF
RealName Kl'rt
% cat in3
Name
    Annihilus
ActualName unknown
Origin Negative Zone
% cmake .
… cmake output appears here …
% make
… make output appears here …
% ./hw3 -k keys in1 in2
Name       Doctor Doom
RealName   Victor Von Doom
motivation Rule the world!
Linkage    College Acquaintance

Name  Silver Surfer
Motif Really into the whole silver thing

Name     Super-Skrull
RealName Kl'rt
LinkIs   Just wants to kill the FF
% ./hw3 -k keys <in3
./hw3: key “ActualName” not in keyfile
% ./hw3 -n -k keys in1 in2
Name Doctor Doom

Name Silver Surfer

Name Super-Skrull
% ./hw3 -k keys -ln in1 in2
Name    Doctor Doom
Linkage College Acquaintance

Name Silver Surfer

Name   Super-Skrull
LinkIs Just wants to kill the FF
% ./hw3 -lkkeys in1 in2
Linkage College Acquaintance


LinkIs Just wants to kill the FF
%

Debugging

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements

If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.                 

Hint

Use getopt. Seriously, use it. Don’t do this yourself.                 

Tar file

    cmake .
    make

How to submit your homework:

    ~cs253/bin/checkin HW3 hw3.tar

How to receive negative points:

Turn in someone else’s work.