#include <stdio.h>
#include <argp.h>

enum boolean { NO, YES };
enum boolean bool = NO;

const char * argp_program_version = "0.1";
/* mail bug reports to */
const char * argp_program_bug_address = "jbranso@fastmail.com";

//define an argp option called joke  aka "--joke" or "-j"
/* struct argp_option argp_options_joke; */
/* argp_options_joke.name = "joke"; */
/* argp_options_joke.key  = 'j'; */
/* /\* This is the value that you see when you print: */
/* ** ./argp --usage. */
/* *\/ */
/* argp_options_joke.arg  = "ARG"; //must be provided. */
/* argp_options_joke.doc  = "Print a funny joke."; */
/* argp_options_joke.flags = OPTION_ARG_OPTIONAL;  // this option does not need an argument. */

static const struct argp_option options [] =
  {
    {"joke", 'j', "ARG", OPTION_ARG_OPTIONAL, "Print a funny joke" },
    { 0 }
  };
// the above can be specified much simplier.  I could actually get rid of the argp_options_joke variable.
//struct argp_option options [2] = { "joke", "j" "STRING", 0, "Print a funny joke", { 0 } };

//define an argp parse function
error_t argp_parser (int opt, char *arg, struct argp_state *state) {
  extern enum boolean bool;
  switch (opt)
    {
      // if this parser function is called on an option that it doesn't recognize, then don't do anything.
    default:
      return ARGP_ERR_UNKNOWN;
    case 'j':
      {
        bool = YES;
        break;
      }
    }
  return 0;
}

/* struct argp argp; */
struct argp argp =
  { options, argp_parser, 0, "Just a simple test argp program" };
/* a string containing the basic usage of this program. */

/* If I try to set the argp values manually, I get a segmentation fault. */
/* argp.args_doc = "argp [options]"; */
/* argp.doc = "Just a simple test argp program!"; */
/* argp.options = options; */
/* argp.parser = argp_parser; */

int main (int argc, char **argv) {

  // I still have a bit more to learn with argp, but that's ok!
  argp_parse (&argp, argc, argv, 0, 0, 0);
  if (bool == YES) {
    printf ("What do you call a box full of ducks?\n");
    printf ("A bunch of quackers.\n");
  }

  return 0;
}