gifsicle  1.92
About: Gifsicle is a UNIX command-line tool for creating, editing, and getting information about GIF images and animations.
  Fossies Dox: gifsicle-1.92.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

clp.h
Go to the documentation of this file.
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-2017 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 
31 typedef struct Clp_Option Clp_Option;
32 typedef struct Clp_Parser Clp_Parser;
34 
35 
41 struct Clp_Option {
42  const char *long_name;
44  int short_name;
46  int option_id;
48  int val_type;
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_ValFirstUser 10
99 #define Clp_Mandatory (1<<0)
105 #define Clp_Optional (1<<1)
107 #define Clp_Negate (1<<2)
111 #define Clp_OnlyNegated (1<<3)
117 #define Clp_PreferredMatch (1<<4)
127 /* Clp_NotOption 0 */
128 #define Clp_Short (1<<0)
130 #define Clp_Long (1<<1)
132 #define Clp_ShortNegated (1<<2)
134 #define Clp_LongNegated (1<<3)
136 #define Clp_LongImplicit (1<<4)
141 #define Clp_NotOption 0
143 #define Clp_Done -1
145 #define Clp_BadOption -2
147 #define Clp_Error -3
150 #define Clp_ValSize 40
152 #define Clp_ValIntSize 10
163 typedef int (*Clp_ValParseFunc)(Clp_Parser *clp, const char *vstr,
164  int complain, void *user_data);
165 
170 typedef void (*Clp_ErrorHandler)(Clp_Parser *clp, const char *message);
171 
172 
178 struct Clp_Parser {
179  const Clp_Option *option;
181  int negated;
183  int have_val;
184  const char *vstr;
187  union {
188  int i;
189  unsigned u;
190  long l;
191  unsigned long ul;
192  double d;
193  const char *s;
194  void *pv;
195 #ifdef HAVE_INT64_TYPES
196  int64_t i64;
197  uint64_t u64;
198 #endif
199  char cs[Clp_ValSize];
200  unsigned char ucs[Clp_ValSize];
201  int is[Clp_ValIntSize];
202  unsigned us[Clp_ValIntSize];
203  } val;
206  void *user_data;
209  struct Clp_Internal *internal;
210 };
211 
213 #if __GNUC__ >= 4
214 # define CLP_SENTINEL __attribute__((sentinel))
215 #else
216 # define CLP_SENTINEL /* nothing */
217 #endif
218 
222 Clp_Parser *Clp_NewParser(int argc, const char * const *argv,
223  int nopt, const Clp_Option *opt);
224 
227 
228 
230 const char *Clp_ProgramName(Clp_Parser *clp);
231 
233 const char *Clp_SetProgramName(Clp_Parser *clp, const char *name);
234 
235 
238 
241 
243 int Clp_OptionChar(Clp_Parser *clp, int c);
244 
246 int Clp_SetOptionChar(Clp_Parser *clp, int c, int type);
247 
250 
252 void Clp_SetArguments(Clp_Parser *clp, int argc, const char * const *argv);
253 
256 
257 
258 #define Clp_DisallowOptions (1<<0)
264 int Clp_AddType(Clp_Parser *clp, int val_type, int flags,
265  Clp_ValParseFunc parser, void *user_data);
266 
267 
268 #define Clp_AllowNumbers (1<<0)
272 #define Clp_StringListLong (1<<1)
276 int Clp_AddStringListTypeVec(Clp_Parser *clp, int val_type, int flags,
277  int nstrs, const char * const *strs,
278  const int *vals);
279 
281 int Clp_AddStringListType(Clp_Parser *clp, int val_type, int flags, ...)
282  CLP_SENTINEL;
283 
284 
286 int Clp_Next(Clp_Parser *clp);
287 
289 const char *Clp_Shift(Clp_Parser *clp, int allow_options);
290 
291 
294 
297 
299 void Clp_SaveParser(const Clp_Parser *clp, Clp_ParserState *state);
300 
302 void Clp_RestoreParser(Clp_Parser *clp, const Clp_ParserState *state);
303 
304 
306 int Clp_OptionError(Clp_Parser *clp, const char *format, ...);
307 
309 int Clp_vsnprintf(Clp_Parser* clp, char* str, size_t size,
310  const char* format, va_list val);
311 
313 int Clp_fprintf(Clp_Parser* clp, FILE* f, const char* format, ...);
314 
316 int Clp_vfprintf(Clp_Parser* clp, FILE* f, const char* format, va_list val);
317 
319 int Clp_CurOptionNameBuf(Clp_Parser *clp, char *buf, int len);
320 
322 const char *Clp_CurOptionName(Clp_Parser *clp);
323 
325 int Clp_IsLong(Clp_Parser *clp, const char *long_name);
326 
328 int Clp_IsShort(Clp_Parser *clp, int short_name);
329 
330 #undef CLP_SENTINEL
331 #ifdef __cplusplus
332 }
333 #endif
334 #endif
Clp_Parser::ucs
unsigned char ucs[40]
Definition: clp.h:256
Clp_OptionError
int Clp_OptionError(Clp_Parser *clp, const char *format,...)
Report a parser error.
Definition: clp.c:2261
Clp_ValParseFunc
int(* Clp_ValParseFunc)(Clp_Parser *clp, const char *vstr, int complain, void *user_data)
A value parsing function.
Definition: clp.h:219
Clp_ValIntSize
#define Clp_ValIntSize
Minimum size of the Clp_Parser val.is field.
Definition: clp.h:207
Clp_fprintf
int Clp_fprintf(Clp_Parser *clp, FILE *f, const char *format,...)
Print a message.
Definition: clp.c:2285
Clp_Shift
const char * Clp_Shift(Clp_Parser *clp, int allow_options)
Return the next argument from clp without option parsing.
Definition: clp.c:1983
Clp_Internal::utf8
int utf8
Definition: clp.c:200
Clp_Option::option_id
int option_id
Definition: clp.h:46
Clp_NewParser
Clp_Parser * Clp_NewParser(int argc, const char *const *argv, int nopt, const Clp_Option *opt)
Create a new Clp_Parser.
Definition: clp.c:503
Clp_AddStringListType
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:1285
Clp_SetErrorHandler
Clp_ErrorHandler Clp_SetErrorHandler(Clp_Parser *clp, Clp_ErrorHandler errh)
Set clp's error handler function.
Clp_Internal::argc
int argc
Definition: clp.c:194
Clp_Parser::pv
void * pv
Definition: clp.h:250
Clp_Parser
Command line parser.
Definition: clp.h:234
Clp_Option::long_name
const char * long_name
Definition: clp.h:42
Clp_Internal
Definition: clp.c:184
Clp_Parser::option
const Clp_Option * option
Definition: clp.h:235
Clp_DeleteParserState
void Clp_DeleteParserState(Clp_ParserState *state)
Destroy a Clp_ParserState object.
Definition: clp.c:1470
Clp_Parser::s
const char * s
Definition: clp.h:249
clp
static Clp_Parser * clp
Definition: gifdiff.c:58
Clp_SetUTF8
int Clp_SetUTF8(Clp_Parser *clp, int utf8)
Set clp's UTF-8 mode.
Definition: clp.c:635
Clp_IsShort
int Clp_IsShort(Clp_Parser *clp, int short_name)
Test if the current option had short name name.
Definition: clp.c:2476
Clp_Parser::negated
int negated
Definition: clp.h:237
Clp_RestoreParser
void Clp_RestoreParser(Clp_Parser *clp, const Clp_ParserState *state)
Restore parser state from state into clp.
Definition: clp.c:1513
Clp_Parser::l
long l
Definition: clp.h:246
Clp_IsLong
int Clp_IsLong(Clp_Parser *clp, const char *long_name)
Test if the current option had long name name.
Definition: clp.c:2468
Clp_SetOptions
int Clp_SetOptions(Clp_Parser *clp, int nopt, const Clp_Option *opt)
Set clp's option definitions.
Definition: clp.c:785
Clp_Parser::u
unsigned u
Definition: clp.h:245
Clp_Parser::us
unsigned us[10]
Definition: clp.h:258
Clp_NewParserState
Clp_ParserState * Clp_NewParserState(void)
Create a new Clp_ParserState.
Definition: clp.c:1446
Clp_Parser::is
int is[10]
Definition: clp.h:257
Clp_Parser::user_data
void * user_data
Definition: clp.h:262
Clp_SetArguments
void Clp_SetArguments(Clp_Parser *clp, int argc, const char *const *argv)
Set clp's arguments.
Definition: clp.c:871
Clp_Next
int Clp_Next(Clp_Parser *clp)
Parse and return the next argument from clp.
Definition: clp.c:1835
Clp_Option
Option description.
Definition: clp.h:41
Clp_Parser::ul
unsigned long ul
Definition: clp.h:247
Clp_ParserState
Definition: clp.c:222
Clp_OptionChar
int Clp_OptionChar(Clp_Parser *clp, int c)
Return clp's treatment of character c.
Definition: clp.c:652
Clp_Internal::argv
const char *const * argv
Definition: clp.c:193
Clp_CurOptionNameBuf
int Clp_CurOptionNameBuf(Clp_Parser *clp, char *buf, int len)
Extract the current option as a string.
Definition: clp.c:2422
Clp_Parser::have_val
int have_val
Definition: clp.h:239
Clp_Parser::vstr
const char * vstr
Definition: clp.h:240
Clp_Internal::nopt
int nopt
Definition: clp.c:187
Clp_SetOptionProcessing
int Clp_SetOptionProcessing(Clp_Parser *clp, int on)
Set whether clp is searching for options.
Definition: clp.c:894
Clp_Parser::cs
char cs[40]
Definition: clp.h:255
Clp_vsnprintf
int Clp_vsnprintf(Clp_Parser *clp, char *str, size_t size, const char *format, va_list val)
Format a message.
Definition: clp.c:2336
Clp_Option::val_type
int val_type
Definition: clp.h:48
Clp_Option::flags
int flags
Definition: clp.h:50
Clp_DeleteParser
void Clp_DeleteParser(Clp_Parser *clp)
Destroy a Clp_Parser object.
Definition: clp.c:579
Clp_SetProgramName
const char * Clp_SetProgramName(Clp_Parser *clp, const char *name)
Set clp's program name.
Definition: clp.c:1419
Clp_Parser::val
union Clp_Parser::@0 val
Clp_Internal::opt
const Clp_Option * opt
Definition: clp.c:185
Clp_ProgramName
const char * Clp_ProgramName(Clp_Parser *clp)
Return clp's program name.
Definition: clp.c:1407
Clp_ErrorHandler
void(* Clp_ErrorHandler)(Clp_Parser *clp, const char *message)
A function for reporting option errors.
Definition: clp.h:226
Clp_SetOptionChar
int Clp_SetOptionChar(Clp_Parser *clp, int c, int type)
Set clp's treatment of character c.
Definition: clp.c:710
Clp_Parser::i
int i
Definition: clp.h:244
Clp_CurOptionName
const char * Clp_CurOptionName(Clp_Parser *clp)
Extract the current option as a string.
Definition: clp.c:2460
Clp_ValSize
#define Clp_ValSize
Minimum size of the Clp_Parser val.cs field.
Definition: clp.h:204
Clp_Parser::d
double d
Definition: clp.h:248
Clp_vfprintf
int Clp_vfprintf(Clp_Parser *clp, FILE *f, const char *format, va_list val)
Print a message.
Definition: clp.c:2310
Clp_SaveParser
void Clp_SaveParser(const Clp_Parser *clp, Clp_ParserState *state)
Save clp's current state in state.
Definition: clp.c:1480
Clp_Option::short_name
int short_name
Definition: clp.h:44