Back to index

tetex-bin  3.0
parseargs.h
Go to the documentation of this file.
00001 /*
00002  * parseargs.h
00003  *
00004  * Command line argument parser.
00005  *
00006  * Copyright 1996-2003 Glyph & Cog, LLC
00007  */
00008 
00009 #ifndef PARSEARGS_H
00010 #define PARSEARGS_H
00011 
00012 #ifdef __cplusplus
00013 extern "C" {
00014 #endif
00015 
00016 #include "gtypes.h"
00017 
00018 /*
00019  * Argument kinds.
00020  */
00021 typedef enum {
00022   argFlag,                  /* flag (present / not-present) */
00023                             /*   [val: GBool *]             */
00024   argInt,                   /* integer arg    */
00025                             /*   [val: int *] */
00026   argFP,                    /* floating point arg */
00027                             /*   [val: double *]  */
00028   argString,                /* string arg      */
00029                             /*   [val: char *] */
00030   /* dummy entries -- these show up in the usage listing only; */
00031   /* useful for X args, for example                            */
00032   argFlagDummy,
00033   argIntDummy,
00034   argFPDummy,
00035   argStringDummy
00036 } ArgKind;
00037 
00038 /*
00039  * Argument descriptor.
00040  */
00041 typedef struct {
00042   char *arg;                /* the command line switch */
00043   ArgKind kind;                    /* kind of arg */
00044   void *val;                /* place to store value */
00045   int size;                 /* for argString: size of string */
00046   char *usage;                     /* usage string */
00047 } ArgDesc;
00048 
00049 /*
00050  * Parse command line.  Removes all args which are found in the arg
00051  * descriptor list <args>.  Stops parsing if "--" is found (and removes
00052  * it).  Returns gFalse if there was an error.
00053  */
00054 extern GBool parseArgs(ArgDesc *args, int *argc, char *argv[]);
00055 
00056 /*
00057  * Print usage message, based on arg descriptor list.
00058  */
00059 extern void printUsage(char *program, char *otherArgs, ArgDesc *args);
00060 
00061 /*
00062  * Check if a string is a valid integer or floating point number.
00063  */
00064 extern GBool isInt(char *s);
00065 extern GBool isFP(char *s);
00066 
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070 
00071 #endif