Match Assignment for u0000000

The goal of this assignment is to give you some practice with C on a problem that is algorithmically straightforward but difficult to get right on a first try. With any luck, you'll have a bug along the way, and then you get to practice using GDB.

Your task is to implement a program that takes command-line arguments and checks whether each argument matches a particular pattern. The pattern to check is determined by a command-line flag: -a, -b, or -c, where the default mode is -a. The patterns for each flag are described below.

By default, your program should print “yes” (always lowercase, no extra space) for each matching argument and “no” (always lowercase, no extra space) for each non-matching argument, each on a separate line. If the -t flag is provided, then your program should instead print nothing for non-matching argument and it should print a converted value for each matching argument. Each pattern mode has an associated conversion, as described below.

At most one of -a, -b, or -c will be provided. A -t flag can be provided before or after any of -a, -b, and -c. All flags (i.e,. up to two of them) precede other command-line arguments. A non-flag argument never starts with -. All arguments are in ASCII.

See the end of this page for example command-line uses of your program. Neither the examples there nor the examples for indvidual patterns are meant to be exhaustive.

Constraints: Your implementation must be in ANSI C, so that it compiles without errors or extra flags on the CADE lab1-n.eng.utah.edu machines using the default gcc. Your implementation must not depend on any libraries other than the standard C library; please note that while "regex.h" and its associated functions are POSIX-standard, they are not part of ANSI C and therefore not allowed in this assignment. Also, yor implementation must not use multiplication, division, or modulo operators. (Bitwise operations offer alternatives to those operations.) You should hand in one matchlab.c file so that gcc -o matchlab matchlab.c on a CADE lab machine builds your program as matchlab; your program should work the same with and without debugging and optimization options such as -g or -O2. Hand in via Canvas.

Important! Make sure the uID listed at the top of the page is correct, because this assignment (and its correct answer) is uID-specific.

Where the descriptions below say “even position” or “odd position”, counting is from 0, as in C. So, a first character is in an even position.

-a mode

Match a sequence of the following, with nothing else before, after, or in between: For matches, perform the following conversion: Example arguments that match, followed by their conversions: Example arguments that do not match:

-b mode

Match a sequence of the following, with nothing else before, after, or in between: For matches, perform the following conversion: Example arguments that match, followed by their conversions: Example arguments that do not match:

-c mode

Match a sequence of the following, with nothing else before, after, or in between: For matches, perform the following conversion: Example arguments that match, followed by their conversions: Example arguments that do not match:

Examples

Assuming that your program is created as ./matchlab, here are some example command-line uses (where “$” is a command-line prompt). We expect your program to match this output exactly.

  $ ./matchlab ccccccc=rrrr,GHG
  yes
  $ ./matchlab ccc=ppppppp:DAH
  no
  $ ./matchlab ccccccc=rrrr,GHG ccc=ppppppp:DAH
  yes
  no
  $ ./matchlab -t ccccccc=rrrr,GHG
  GGGGGGGGGGGGGGGG
  $ ./matchlab -t ccc=ppppppp:DAH ccccccc=rrrr,GHG
  GGGGGGGGGGGGGGGG
  $ ./matchlab -t ccccccc=rrrr,GHG ccccc=rrrr,C
  GGGGGGGGGGGGGGGG
  CCCCCCCCCCCC
  $ ./matchlab -t -b gg,Cwwwwwwwww_C606
  g0g1,2C3w4w5w6w7w0w1w2w3w4_5C6670061
  $ ./matchlab -c -t jjjjjjjjj_GEHuuuuuuu_E914
  jjjjjjjjj_Huuuuuuu_914
  $ ./matchlab -c jjjjjjjjj_GEHuuuuuuu_E914
  yes