?
2012-05-07 02:33:43 UTC
from the command line, using this syntax:
match [-OPTION]... PATTERN [FILENAME]...
The program reads words from standard input (or from each of the named files in turn) and
compares them with the pattern specified on the command line
With no options (or with the option -w), a word is matched if it matches the pattern in its
entirety. Thus match c_t (or match -w c_t) would match cat or cut but not cater
or scotch.
• The options -p and -s specify that a word is matched if the pattern occurs as either a prefix
(at the beginning) or a suffix (at the end). Thus match -p cat would match catfish or
cataclysmic, and match -s cat would match scat or bobcat.
• The option -a allows the match to occur anywhere within a word. Thus match -a cat
would match vacate and amplification.
• The option -e specifies that a word is matched if it is embedded within the pattern. Thus
match -e vacate would match cat and ate.
• Normally the letters in a word match only if they agree in case with the pattern. The option
-i makes the match ignore the case of the word. Thus match Cat would not match cat,
whereas match -i Cat or match -i CAT would match cat or CAT or even cAt.
• Normally the pattern is matched exactly. However, if the option -j (for jumble) is
specified, then the pattern is considered matched if any rearrangement of the pattern is
matched. Thus match -j cat would also match act.
• The option -v reverses the sense of the match. The output will therefore consist of all of
the words that do not match the pattern.
1
• The option -n takes an argument that specifies constraints on the length of the matching
words. By default, any length word is permitted. However match -n3,8 -p cat would
match words that begin with cat and that contain between 3 and 8 letters. As a special
case, a minimum or maximum length of 0 (or an omitted length) indicates no restriction.
Thus, -n3,0 (or -n3) specifies words of 3 or more letters, -n0,8 (or -n,8) specifies
words of 8 or fewer characters, and -n0,0 (or -n,) specifies words of any length.
1. Implement a simple version of the filter that works correctly when run with no options or file
names, and with a pattern that contains no underscores. If no word is matched by the pattern
the program should exit with status 1 (the value returned by main). If at least one word is
matched it should exit with status 0. Note that when the program begins, argv[0] contains
the command name, so the first argument (the pattern in this case) would be in argv[1].
2. Extend the program so that it correctly handles the -s, -p, and -a options.
3. Extend the program so that it correctly handles the -e option.
4. Extend the program so that it correctly handles the -i option.
5. Extend the program so that it correctly handles the -v option.
6. Extend the program so that it correctly handles the -n option. For this level, you can assume
that the option argument will not omit length values. That is, you can assume that it will
explicitly specify the minimum and maximum lengths (either of which might be 0).