Back to index

glibc  2.9
Classes | Functions | Variables
argp-ex3.c File Reference
#include <argp.h>

Go to the source code of this file.

Classes

struct  arguments

Functions

static error_t parse_opt (int key, char *arg, struct argp_state *state)
int main (int argc, char **argv)

Variables

const char * argp_program_version = "argp-ex3 1.0"
const char * argp_program_bug_address = "<bug-gnu-utils@@gnu.org>"
static char doc [] = "Argp example #3 -- a program with options and arguments using argp"
static char args_doc [] = "ARG1 ARG2"
static struct argp_option []
static struct argp = { options, parse_opt, args_doc, doc }

Class Documentation

struct arguments

Definition at line 80 of file argp-ex3.c.

Class Members
int abort
char * arg1
char * args
char * output_file
int repeat_count
int silent
char ** strings
int verbose

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 131 of file argp-ex3.c.

{
  struct arguments arguments;

  /* Default values.  */
  arguments.silent = 0;
  arguments.verbose = 0;
  arguments.output_file = "-";

  /* Parse our arguments; every option seen by @code{parse_opt} will
     be reflected in @code{arguments}.  */
  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  printf ("ARG1 = %s\nARG2 = %s\nOUTPUT_FILE = %s\n"
         "VERBOSE = %s\nSILENT = %s\n",
         arguments.args[0], arguments.args[1],
         arguments.output_file,
         arguments.verbose ? "yes" : "no",
         arguments.silent ? "yes" : "no");

  exit (0);
}

Here is the call graph for this function:

static error_t parse_opt ( int  key,
char *  arg,
struct argp_state state 
) [static]

Definition at line 89 of file argp-ex3.c.

{
  /* Get the @var{input} argument from @code{argp_parse}, which we
     know is a pointer to our arguments structure.  */
  struct arguments *arguments = state->input;

  switch (key)
    {
    case 'q': case 's':
      arguments->silent = 1;
      break;
    case 'v':
      arguments->verbose = 1;
      break;
    case 'o':
      arguments->output_file = arg;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 2)
       /* Too many arguments.  */
       argp_usage (state);

      arguments->args[state->arg_num] = arg;

      break;

    case ARGP_KEY_END:
      if (state->arg_num < 2)
       /* Not enough arguments.  */
       argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

Here is the call graph for this function:


Variable Documentation

struct argp = { options, parse_opt, args_doc, doc } [static]

Definition at line 129 of file argp-ex3.c.

struct argp_option[] [static]
Initial value:
 {
  {"verbose",  'v', 0,      0,  "Produce verbose output" },
  {"quiet",    'q', 0,      0,  "Don't produce any output" },
  {"silent",   's', 0,      OPTION_ALIAS },
  {"output",   'o', "FILE", 0,
   "Output to FILE instead of standard output" },
  { 0 }
}

Definition at line 70 of file argp-ex3.c.

const char* argp_program_bug_address = "<bug-gnu-utils@@gnu.org>"

Definition at line 59 of file argp-ex3.c.

const char* argp_program_version = "argp-ex3 1.0"

Definition at line 57 of file argp-ex3.c.

char args_doc[] = "ARG1 ARG2" [static]

Definition at line 67 of file argp-ex3.c.

char doc[] = "Argp example #3 -- a program with options and arguments using argp" [static]

Definition at line 63 of file argp-ex3.c.