1 /*
2  * parseargs.h
3  *
4  * Command line argument parser.
5  *
6  * Copyright 1996-2003 Glyph & Cog, LLC
7  */
8 
9 #ifndef PARSEARGS_H
10 #define PARSEARGS_H
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include "gtypes.h"
17 
18 /*
19  * Argument kinds.
20  */
21 typedef enum {
22   argFlag,			/* flag (present / not-present) */
23 				/*   [val: GBool *]             */
24   argInt,			/* integer arg    */
25 				/*   [val: int *] */
26   argFP,			/* floating point arg */
27 				/*   [val: double *]  */
28   argString,			/* string arg      */
29 				/*   [val: char *] */
30   /* dummy entries -- these show up in the usage listing only; */
31   /* useful for X args, for example                            */
32   argFlagDummy,
33   argIntDummy,
34   argFPDummy,
35   argStringDummy
36 } ArgKind;
37 
38 /*
39  * Argument descriptor.
40  */
41 typedef struct {
42   char *arg;			/* the command line switch */
43   ArgKind kind;			/* kind of arg */
44   void *val;			/* place to store value */
45   int size;			/* for argString: size of string */
46   char *usage;			/* usage string */
47 } ArgDesc;
48 
49 /*
50  * Parse command line.  Removes all args which are found in the arg
51  * descriptor list <args>.  Stops parsing if "--" is found (and removes
52  * it).  Returns gFalse if there was an error.
53  */
54 extern GBool parseArgs(ArgDesc *args, int *argc, char *argv[]);
55 
56 /*
57  * Print usage message, based on arg descriptor list.
58  */
59 extern void printUsage(char *program, char *otherArgs, ArgDesc *args);
60 
61 /*
62  * Check if a string is a valid integer or floating point number.
63  */
64 extern GBool isInt(char *s);
65 extern GBool isFP(char *s);
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif
72