Click
Loading...
Searching...
No Matches
clp.h
Go to the documentation of this file.
1/* -*- related-file-name: "../../lib/clp.c" -*- */
2#ifndef LCDF_CLP_H
3#define LCDF_CLP_H
4#ifdef __cplusplus
5extern "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-2014 Eddie Kohler, ekohler@gmail.com
12 *
13 * CLP is free software. It is distributed under the GNU General Public
14 * License, Version 2, or, alternatively and at your discretion, under the
15 * more permissive (BSD-like) Click LICENSE file as described below.
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining a
18 * copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, subject to the
20 * conditions listed in the Click LICENSE file, which is available in full at
21 * http://github.com/kohler/click/blob/master/LICENSE. The conditions
22 * include: you must preserve this copyright notice, and you cannot mention
23 * the copyright holders in advertising related to the Software without
24 * their permission. The Software is provided WITHOUT ANY WARRANTY, EXPRESS
25 * OR IMPLIED. This notice is a summary of the Click LICENSE file; the
26 * license in that file is binding. */
27
28#include <stdio.h>
29#include <stdarg.h>
30
31typedef struct Clp_Option Clp_Option;
32typedef struct Clp_Parser Clp_Parser;
33typedef struct Clp_ParserState Clp_ParserState;
34
35
41struct Clp_Option {
42 const char *long_name;
50 int flags;
51};
52
58#define Clp_NoVal 0
59#define Clp_ValString 1
61#define Clp_ValStringNotOption 2
65#define Clp_ValBool 3
70#define Clp_ValInt 4
77#define Clp_ValUnsigned 5
84#define Clp_ValLong 6
86#define Clp_ValUnsignedLong 7
88#define Clp_ValDouble 8
91#define Clp_ValStringDashTerimnated 9
93#define Clp_ValFirstUser 10
101#define Clp_Mandatory (1<<0)
107#define Clp_Optional (1<<1)
109#define Clp_Negate (1<<2)
113#define Clp_OnlyNegated (1<<3)
119#define Clp_PreferredMatch (1<<4)
129/* Clp_NotOption 0 */
130#define Clp_Short (1<<0)
132#define Clp_Long (1<<1)
134#define Clp_ShortNegated (1<<2)
136#define Clp_LongNegated (1<<3)
138#define Clp_LongImplicit (1<<4)
143#define Clp_NotOption 0
145#define Clp_Done -1
147#define Clp_BadOption -2
149#define Clp_Error -3
152#define Clp_ValSize 40
154#define Clp_ValIntSize 10
165typedef int (*Clp_ValParseFunc)(Clp_Parser *clp, const char *vstr,
166 int complain, void *user_data);
167
172typedef void (*Clp_ErrorHandler)(Clp_Parser *clp, const char *message);
173
174
186 const char *vstr;
189 union {
190 int i;
191 unsigned u;
192 long l;
193 unsigned long ul;
194 double d;
195 const char *s;
196 void *pv;
197#ifdef HAVE_INT64_TYPES
198 int64_t i64;
199 uint64_t u64;
200#endif
201 char cs[Clp_ValSize];
202 unsigned char ucs[Clp_ValSize];
203 int is[Clp_ValIntSize];
204 unsigned us[Clp_ValIntSize];
205 char** ps;
206 } val;
209 void *user_data;
212 struct Clp_Internal *internal;
213};
214
216#if __GNUC__ >= 4
217# define CLP_SENTINEL __attribute__((sentinel))
218#else
219# define CLP_SENTINEL /* nothing */
220#endif
225Clp_Parser *Clp_NewParser(int argc, const char * const *argv,
226 int nopt, const Clp_Option *opt);
227
230
231
233const char *Clp_ProgramName(Clp_Parser *clp);
234
236const char *Clp_SetProgramName(Clp_Parser *clp, const char *name);
237
238
241
243int Clp_SetUTF8(Clp_Parser *clp, int utf8);
244
246int Clp_OptionChar(Clp_Parser *clp, int c);
247
249int Clp_SetOptionChar(Clp_Parser *clp, int c, int type);
250
252int Clp_SetOptions(Clp_Parser *clp, int nopt, const Clp_Option *opt);
253
255void Clp_SetArguments(Clp_Parser *clp, int argc, const char * const *argv);
256
258int Clp_SetOptionProcessing(Clp_Parser *clp, int on);
259
260
261#define Clp_DisallowOptions (1<<0)
265#define Clp_DashTerminated (1<<1)
266
268int Clp_AddType(Clp_Parser *clp, int val_type, int flags,
269 Clp_ValParseFunc parser, void *user_data);
270
271
272#define Clp_AllowNumbers (1<<0)
276#define Clp_StringListLong (1<<1)
280int Clp_AddStringListTypeVec(Clp_Parser *clp, int val_type, int flags,
281 int nstrs, const char * const *strs,
282 const int *vals);
283
285int Clp_AddStringListType(Clp_Parser *clp, int val_type, int flags, ...)
286 CLP_SENTINEL;
287
288
290int Clp_Next(Clp_Parser *clp);
291
293const char *Clp_Shift(Clp_Parser *clp, int allow_options);
294
295
297Clp_ParserState *Clp_NewParserState(void);
298
300void Clp_DeleteParserState(Clp_ParserState *state);
301
303void Clp_SaveParser(const Clp_Parser *clp, Clp_ParserState *state);
304
306void Clp_RestoreParser(Clp_Parser *clp, const Clp_ParserState *state);
307
308
310int Clp_OptionError(Clp_Parser *clp, const char *format, ...);
311
313int Clp_vsnprintf(Clp_Parser* clp, char* str, size_t size,
314 const char* format, va_list val);
315
317int Clp_fprintf(Clp_Parser* clp, FILE* f, const char* format, ...);
318
320int Clp_vfprintf(Clp_Parser* clp, FILE* f, const char* format, va_list val);
321
323int Clp_CurOptionNameBuf(Clp_Parser *clp, char *buf, int len);
324
326const char *Clp_CurOptionName(Clp_Parser *clp);
327
329int Clp_IsLong(Clp_Parser *clp, const char *long_name);
330
332int Clp_IsShort(Clp_Parser *clp, int short_name);
333
334#undef CLP_SENTINEL
335#ifdef __cplusplus
336}
337#endif
338#endif
#define Clp_ValIntSize
Minimum size of the Clp_Parser val.is field.
Definition clp.h:154
int Clp_SetOptions(Clp_Parser *clp, int nopt, const Clp_Option *opt)
Set clp's option definitions.
Definition clp.c:783
void Clp_SetArguments(Clp_Parser *clp, int argc, const char *const *argv)
Set clp's arguments.
Definition clp.c:869
int Clp_OptionChar(Clp_Parser *clp, int c)
Return clp's treatment of character c.
Definition clp.c:650
int Clp_vfprintf(Clp_Parser *clp, FILE *f, const char *format, va_list val)
Print a message.
Definition clp.c:2318
Clp_Parser * Clp_NewParser(int argc, const char *const *argv, int nopt, const Clp_Option *opt)
Create a new Clp_Parser.
Definition clp.c:501
void Clp_RestoreParser(Clp_Parser *clp, const Clp_ParserState *state)
Restore parser state from state into clp.
Definition clp.c:1517
int Clp_AddStringListType(Clp_Parser *clp, int val_type, int flags,...) CLP_SENTINEL
Define a new string list value type for clp.
Definition clp.c:1287
void(* Clp_ErrorHandler)(Clp_Parser *clp, const char *message)
A function for reporting option errors.
Definition clp.h:172
int Clp_SetOptionProcessing(Clp_Parser *clp, int on)
Set whether clp is searching for options.
Definition clp.c:892
#define Clp_ValSize
Minimum size of the Clp_Parser val.cs field.
Definition clp.h:152
const char * Clp_SetProgramName(Clp_Parser *clp, const char *name)
Set clp's program name.
Definition clp.c:1422
int Clp_SetOptionChar(Clp_Parser *clp, int c, int type)
Set clp's treatment of character c.
Definition clp.c:708
int Clp_OptionError(Clp_Parser *clp, const char *format,...)
Report a parser error.
Definition clp.c:2269
int Clp_AddStringListTypeVec(Clp_Parser *clp, int val_type, int flags, int nstrs, const char *const *strs, const int *vals)
Define a new string list value type for clp.
Definition clp.c:1376
const char * Clp_CurOptionName(Clp_Parser *clp)
Extract the current option as a string.
Definition clp.c:2468
const char * Clp_Shift(Clp_Parser *clp, int allow_options)
Return the next argument from clp without option parsing.
Definition clp.c:1988
int Clp_CurOptionNameBuf(Clp_Parser *clp, char *buf, int len)
Extract the current option as a string.
Definition clp.c:2430
void Clp_SaveParser(const Clp_Parser *clp, Clp_ParserState *state)
Save clp's current state in state.
Definition clp.c:1484
int Clp_IsShort(Clp_Parser *clp, int short_name)
Test if the current option had short name name.
Definition clp.c:2484
int Clp_AddType(Clp_Parser *clp, int val_type, int flags, Clp_ValParseFunc parser, void *user_data)
Define a new value type for clp.
Definition clp.c:1041
const char * Clp_ProgramName(Clp_Parser *clp)
Return clp's program name.
Definition clp.c:1410
int(* Clp_ValParseFunc)(Clp_Parser *clp, const char *vstr, int complain, void *user_data)
A value parsing function.
Definition clp.h:165
int Clp_Next(Clp_Parser *clp)
Parse and return the next argument from clp.
Definition clp.c:1840
Clp_ParserState * Clp_NewParserState(void)
Create a new Clp_ParserState.
Definition clp.c:1450
int Clp_fprintf(Clp_Parser *clp, FILE *f, const char *format,...)
Print a message.
Definition clp.c:2293
void Clp_DeleteParserState(Clp_ParserState *state)
Destroy a Clp_ParserState object.
Definition clp.c:1474
int Clp_vsnprintf(Clp_Parser *clp, char *str, size_t size, const char *format, va_list val)
Format a message.
Definition clp.c:2344
Clp_ErrorHandler Clp_SetErrorHandler(Clp_Parser *clp, Clp_ErrorHandler errh)
Set clp's error handler function.
int Clp_IsLong(Clp_Parser *clp, const char *long_name)
Test if the current option had long name name.
Definition clp.c:2476
void Clp_DeleteParser(Clp_Parser *clp)
Destroy a Clp_Parser object.
Definition clp.c:577
int Clp_SetUTF8(Clp_Parser *clp, int utf8)
Set clp's UTF-8 mode.
Definition clp.c:633
Option description.
Definition clp.h:41
int val_type
Definition clp.h:48
int flags
Definition clp.h:50
int option_id
Definition clp.h:46
int short_name
Definition clp.h:44
const char * long_name
Definition clp.h:42
Command line parser.
Definition clp.h:180
int have_val
Definition clp.h:185
const char * vstr
Definition clp.h:186
union Clp_Parser::@7 val
void * user_data
Definition clp.h:209
const Clp_Option * option
Definition clp.h:181
int negated
Definition clp.h:183