1 /* -*- related-file-name: "../../liblcdf/clp.c" -*- */
2 #ifndef LCDF_CLP_H
3 #define LCDF_CLP_H
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 /* clp.h - Public interface to CLP.
9  * This file is part of CLP, the command line parser package.
10  *
11  * Copyright (c) 1997-2003 Eddie Kohler, kohler@icir.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, subject to the conditions
16  * listed in the Click LICENSE file, which is available in full at
17  * http://www.pdos.lcs.mit.edu/click/license.html. The conditions include: you
18  * must preserve this copyright notice, and you cannot mention the copyright
19  * holders in advertising related to the Software without their permission.
20  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
21  * notice is a summary of the Click LICENSE file; the license in that file is
22  * legally binding. */
23 
24 
25 /* Argument types */
26 #define Clp_NoArg		0
27 #define Clp_ArgString		1
28 #define Clp_ArgStringNotOption	2
29 #define Clp_ArgBool		3
30 #define Clp_ArgInt		4
31 #define Clp_ArgUnsigned		5
32 #define Clp_ArgDouble		6
33 
34 #define Clp_FirstUserType	10
35 
36 /* Argument type flags */
37 #define Clp_DisallowOptions	(1<<0)	/* Argument won't resemble an option */
38 
39 /* Flags for individual Clp_Options */
40 #define Clp_Mandatory		(1<<0)	/* Has mandatory argument */
41 #define Clp_Optional		(1<<1)	/* Has optional argument */
42 #define Clp_Negate		(1<<2)	/* Allow --no-OPT */
43 #define Clp_OnlyNegated		(1<<3)	/* Allow --no-OPT, but not --OPT */
44 #define Clp_PreferredMatch	(1<<4)	/* Prefer --OPT to --OPTwhatever when
45 					   matching option prefixes */
46 
47 /* Option types for Clp_SetOptionChar */
48 /*	Clp_NotOption		0 */
49 #define Clp_Short		(1<<0)
50 #define Clp_Long		(1<<1)
51 #define Clp_ShortNegated	(1<<2)
52 #define Clp_LongNegated		(1<<3)
53 #define Clp_LongImplicit	(1<<4)
54 
55 /* Flags for Clp_AddStringListType */
56 #define Clp_AllowNumbers	(1<<0)
57 
58 /* Return values from Clp_Next */
59 #define Clp_NotOption		0
60 #define Clp_Done		-1
61 #define Clp_BadOption		-2
62 #define Clp_Error		-3
63 
64 /* Sizes of clp->val */
65 #define Clp_ValSize		40
66 #define Clp_ValIntSize		10
67 
68 
69 typedef struct Clp_Option Clp_Option;
70 typedef struct Clp_Parser Clp_Parser;
71 typedef struct Clp_Internal Clp_Internal;
72 typedef struct Clp_ParserState Clp_ParserState;
73 
74 typedef int (*Clp_ArgParseFunc)(Clp_Parser *, const char *, int, void *);
75 typedef void (*Clp_ErrorHandler)(const char *);
76 
77 
78 struct Clp_Option {
79 
80   const char *long_name;
81   int short_name;
82 
83   int option_id;
84 
85   int arg_type;
86   int flags;
87 
88 };
89 
90 
91 struct Clp_Parser {
92 
93   int negated;
94 
95   int have_arg;
96   const char *arg;
97 
98   union {
99     int i;
100     unsigned u;
101     double d;
102     const char *s;
103     void *pv;
104 #ifdef HAVE_INT64_TYPES
105     int64_t i64;
106     uint64_t u64;
107 #endif
108     char cs[Clp_ValSize];
109     unsigned char ucs[Clp_ValSize];
110     int is[Clp_ValIntSize];
111     unsigned us[Clp_ValIntSize];
112   } val;
113 
114   Clp_Internal *internal;
115 
116 };
117 
118 
119 Clp_Parser *	Clp_NewParser(int argc, const char * const *argv,
120 			      int nopt, Clp_Option *opt);
121 void		Clp_DeleteParser(Clp_Parser *);
122 
123 Clp_ErrorHandler Clp_SetErrorHandler(Clp_Parser *, Clp_ErrorHandler);
124 int		Clp_SetOptionChar(Clp_Parser *, int c, int option_type);
125 
126 int		Clp_AddType
127 			(Clp_Parser *, int type_id, int flags,
128 			 Clp_ArgParseFunc func, void *user_data);
129 int		Clp_AddStringListType
130 			(Clp_Parser *, int type_id, int flags, ...);
131 int		Clp_AddStringListTypeVec
132 			(Clp_Parser *, int type_id, int flags,
133 			 int n, char **str, int *val);
134 
135 const char *	Clp_ProgramName(Clp_Parser *);
136 
137 int		Clp_Next(Clp_Parser *);
138 const char *	Clp_Shift(Clp_Parser *, int allow_dashes);
139 int		Clp_SetOptionProcessing(Clp_Parser *, int option_processing);
140 
141 Clp_ParserState *Clp_NewParserState(void);
142 void		Clp_DeleteParserState(Clp_ParserState *);
143 void		Clp_SaveParser(Clp_Parser *, Clp_ParserState *);
144 void		Clp_RestoreParser(Clp_Parser *, Clp_ParserState *);
145 
146 int		Clp_OptionError(Clp_Parser *, const char *, ...);
147 int		Clp_CurOptionNameBuf(Clp_Parser *, char *buf, int buflen);
148 const char *	Clp_CurOptionName(Clp_Parser *); /* uses static memory */
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 #endif
154