Back to index

tetex-bin  3.0
Classes | Enumerations | Functions
parseargs.h File Reference
#include "gtypes.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ArgDesc

Enumerations

enum  ArgKind {
  argFlag, argInt, argFP, argString,
  argFlagDummy, argIntDummy, argFPDummy, argStringDummy
}

Functions

GBool parseArgs (ArgDesc *args, int *argc, char *argv[])
void printUsage (char *program, char *otherArgs, ArgDesc *args)
GBool isInt (char *s)
GBool isFP (char *s)

Class Documentation

struct ArgDesc

Definition at line 41 of file parseargs.h.

Class Members
char * arg
ArgKind kind
int size
char * usage
void * val

Enumeration Type Documentation

enum ArgKind
Enumerator:
argFlag 
argInt 
argFP 
argString 
argFlagDummy 
argIntDummy 
argFPDummy 
argStringDummy 

Definition at line 21 of file parseargs.h.

             {
  argFlag,                  /* flag (present / not-present) */
                            /*   [val: GBool *]             */
  argInt,                   /* integer arg    */
                            /*   [val: int *] */
  argFP,                    /* floating point arg */
                            /*   [val: double *]  */
  argString,                /* string arg      */
                            /*   [val: char *] */
  /* dummy entries -- these show up in the usage listing only; */
  /* useful for X args, for example                            */
  argFlagDummy,
  argIntDummy,
  argFPDummy,
  argStringDummy
} ArgKind;

Function Documentation

GBool isFP ( char *  s)

Definition at line 160 of file parseargs.c.

                    {
  int n;

  if (*s == '-' || *s == '+')
    ++s;
  n = 0;
  while (isdigit(*s)) {
    ++s;
    ++n;
  }
  if (*s == '.')
    ++s;
  while (isdigit(*s)) {
    ++s;
    ++n;
  }
  if (n > 0 && (*s == 'e' || *s == 'E')) {
    ++s;
    if (*s == '-' || *s == '+')
      ++s;
    n = 0;
    if (!isdigit(*s))
      return gFalse;
    do {
      ++s;
    } while (isdigit(*s));
  }
  if (*s)
    return gFalse;
  return gTrue;
}

Here is the caller graph for this function:

GBool isInt ( char *  s)

Definition at line 150 of file parseargs.c.

                     {
  if (*s == '-' || *s == '+')
    ++s;
  while (isdigit(*s))
    ++s;
  if (*s)
    return gFalse;
  return gTrue;
}

Here is the caller graph for this function:

GBool parseArgs ( ArgDesc args,
int argc,
char *  argv[] 
)

Definition at line 19 of file parseargs.c.

                                                        {
  ArgDesc *arg;
  int i, j;
  GBool ok;

  ok = gTrue;
  i = 1;
  while (i < *argc) {
    if (!strcmp(argv[i], "--")) {
      --*argc;
      for (j = i; j < *argc; ++j)
       argv[j] = argv[j+1];
      break;
    } else if ((arg = findArg(args, argv[i]))) {
      if (!grabArg(arg, i, argc, argv))
       ok = gFalse;
    } else {
      ++i;
    }
  }
  return ok;
}

Here is the call graph for this function:

void printUsage ( char *  program,
char *  otherArgs,
ArgDesc args 
)

Definition at line 42 of file parseargs.c.

                                                               {
  ArgDesc *arg;
  char *typ;
  int w, w1;

  w = 0;
  for (arg = args; arg->arg; ++arg) {
    if ((w1 = strlen(arg->arg)) > w)
      w = w1;
  }

  fprintf(stderr, "Usage: %s [options]", program);
  if (otherArgs)
    fprintf(stderr, " %s", otherArgs);
  fprintf(stderr, "\n");

  for (arg = args; arg->arg; ++arg) {
    fprintf(stderr, "  %s", arg->arg);
    w1 = 9 + w - strlen(arg->arg);
    switch (arg->kind) {
    case argInt:
    case argIntDummy:
      typ = " <int>";
      break;
    case argFP:
    case argFPDummy:
      typ = " <fp>";
      break;
    case argString:
    case argStringDummy:
      typ = " <string>";
      break;
    case argFlag:
    case argFlagDummy:
    default:
      typ = "";
      break;
    }
    fprintf(stderr, "%-*s", w1, typ);
    if (arg->usage)
      fprintf(stderr, ": %s", arg->usage);
    fprintf(stderr, "\n");
  }
}

Here is the call graph for this function: