Back to index

glibc  2.9
Classes | Defines | Functions | Variables
argp-test.c File Reference
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <argp.h>

Go to the source code of this file.

Classes

struct  params

Defines

#define OPT_PGRP   1
#define OPT_SESS   2

Functions

static error_t sub_parse_opt (int key, char *arg, struct argp_state *state)
static char * sub_help_filter (int key, const char *text, void *input)
static void popt (int key, char *arg)
static error_t parse_opt (int key, char *arg, struct argp_state *state)
static char * help_filter (int key, const char *text, void *input)
int main (int argc, char **argv)

Variables

const char * argp_program_version = "argp-test 1.0"
static const char sub_args_doc [] = "STRING...\n-"
static const char sub_doc [] = "\vThis is the doc string from the sub-arg-parser."
static struct argp
static const char args_doc [] = "STRING"
static const char doc [] = "\nThe current time is: %s"
static struct argp_child [] = { { &sub_argp }, { 0 } }

Class Documentation

struct params

Definition at line 85 of file argp-test.c.

Class Members
unsigned foonly
unsigned foonly_default

Define Documentation

#define OPT_PGRP   1

Definition at line 91 of file argp-test.c.

#define OPT_SESS   2

Definition at line 92 of file argp-test.c.


Function Documentation

static char* help_filter ( int  key,
const char *  text,
void *  input 
) [static]

Definition at line 175 of file argp-test.c.

{
  char *new_text;
  struct params *params = input;

  if (key == ARGP_KEY_HELP_POST_DOC && text)
    {
      time_t now = time (0);
      asprintf (&new_text, text, ctime (&now));
    }
  else if (key == 'f')
    /* Show the default for the --foonly option.  */
    asprintf (&new_text, "%s (ZOT defaults to %x)",
             text, params->foonly_default);
  else
    new_text = (char *)text;

  return new_text;
}

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 201 of file argp-test.c.

{
  struct params params;
  params.foonly = 0;
  params.foonly_default = random ();
  argp_parse (&argp, argc, argv, 0, 0, &params);
  printf ("After parsing: foonly = %x\n", params.foonly);
  return 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 139 of file argp-test.c.

{
  struct params *params = state->input;

  switch (key)
    {
    case ARGP_KEY_NO_ARGS:
      printf ("NO ARGS\n");
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num > 0)
       return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser.  */
      printf ("ARG: %s\n", arg);
      break;

    case 'f':
      if (arg)
       params->foonly = atoi (arg);
      else
       params->foonly = params->foonly_default;
      popt (key, arg);
      break;

    case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q':
    case 'r': case OPT_SESS: case 'z':
      popt (key, arg);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

Here is the call graph for this function:

static void popt ( int  key,
char *  arg 
) [static]

Definition at line 125 of file argp-test.c.

{
  char buf[10];
  if (isprint (key))
    sprintf (buf, "%c", key);
  else
    sprintf (buf, "%d", key);
  if (arg)
    printf ("KEY %s: %s\n", buf, arg);
  else
    printf ("KEY %s\n", buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* sub_help_filter ( int  key,
const char *  text,
void *  input 
) [static]

Definition at line 71 of file argp-test.c.

{
  if (key == ARGP_KEY_HELP_EXTRA)
    return strdup ("This is some extra text from the sub parser (note that it \
is preceded by a blank line).");
  else
    return (char *)text;
}
static error_t sub_parse_opt ( int  key,
char *  arg,
struct argp_state state 
) [static]

Definition at line 49 of file argp-test.c.

{
  switch (key)
    {
    case ARGP_KEY_NO_ARGS:
      printf ("NO SUB ARGS\n");
      break;
    case ARGP_KEY_ARG:
      printf ("SUB ARG: %s\n", arg);
      break;

    case 's' : case 'S': case 'p': case 'q':
      printf ("SUB KEY %c\n", key);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

Here is the call graph for this function:


Variable Documentation

static struct argp [static]
Initial value:

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

struct argp_child[] = { { &sub_argp }, { 0 } } [static]

Definition at line 195 of file argp-test.c.

const char* argp_program_version = "argp-test 1.0"

Definition at line 30 of file argp-test.c.

const char args_doc[] = "STRING" [static]

Definition at line 118 of file argp-test.c.

const char doc[] = "\nThe current time is: %s" [static]

Definition at line 119 of file argp-test.c.

const char sub_args_doc[] = "STRING...\n-" [static]

Definition at line 45 of file argp-test.c.

const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser." [static]

Definition at line 46 of file argp-test.c.