INGOR
ytParseArgs.h
1/*
2 util/ytParseArgs.{h,c} : Parsing command line arguments
3 Copyright (C) 2018, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Kyoto University nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#ifndef __YTLIB_PARSE_ARGS_H
37#define __YTLIB_PARSE_ARGS_H
38
39#include "lang/ytType.h"
40#include "lang/ytObject.h"
41#include "util/ytKeyValues.h"
42
43typedef struct ytParseArgs_t ytParseArgs;
44extern char * ytParseArgs_defaultStringValue;
45
46#ifdef DOXY
50#define ytParseArgs_DEFAULT_KEY
53#define ytParseArgs_OPT_ERROR
56#define ytParseArgs_OPT_WARNING
59#define ytParseArgs_OPT_IGNORE
60#else /* ifdef DOXY */
61#define ytParseArgs_DEFAULT_KEY "__ARGS_WITHOUT_KEY__"
62#define ytParseArgs_OPT_ERROR 0
63#define ytParseArgs_OPT_WARNING 1
64#define ytParseArgs_OPT_IGNORE 2
65#endif /* else of ifdef DOXY */
66
69
70void ytParseArgs_addString(ytParseArgs * this, const char * key, char ** arg);
71void ytParseArgs_addStringOpt(ytParseArgs * this, const char * key, char ** arg);
72void ytParseArgs_addInt(ytParseArgs * this, const char * key, int * arg);
73void ytParseArgs_addDouble(ytParseArgs * this, const char * key, double * arg);
74void ytParseArgs_addIntArray(ytParseArgs * this, const char * key, ytIntArray ** arg);
75void ytParseArgs_addStrArray(ytParseArgs * this, const char * key, ytStrArray ** arg);
76void ytParseArgs_addStrArrayAdd(ytParseArgs * this, const char * key, ytStrArray ** arg);
77void ytParseArgs_addDoubleArray(ytParseArgs * this, const char * key, ytDoubleArray ** arg);
78void ytParseArgs_addKeyValues(ytParseArgs * this, const char * key, ytKeyValues ** arg);
79void ytParseArgs_addKeyValuesArray(ytParseArgs * this, const char * key, ytArray ** arg);
80void ytParseArgs_addOn(ytParseArgs * this, const char * key, int * arg);
81void ytParseArgs_addOff(ytParseArgs * this, const char * key, int * arg);
82void ytParseArgs_addOnOff(ytParseArgs * this, const char * key, int * arg);
83void ytParseArgs_addFunc(ytParseArgs * this, const char * key, void (*arg)());
84void ytParseArgs_addFunc3(ytParseArgs * this, const char * key,
85 void (*f)(const char *, const char *, void *), void * arg);
86void ytParseArgs_addNone(ytParseArgs * this, const char * key);
87int ytParseArgs_set(ytParseArgs * argset, int argc, char ** argv);
88int ytParseArgs_setKV(ytParseArgs * argset, const ytKeyValues * kv, int opt);
89ytKeyValues * ytParseArgs_genKV(int argc, char ** argv, const char * defKey);
90
91void ytParseArgs_verbose(ytParseArgs * this, int e);
92int ytParseArgs_debug(int argc, char ** argv);
93
96#define ytPA_int(this,key,arg) ytParseArgs_addInt(this, key, arg)
99#define ytPA_double(this,key,arg) ytParseArgs_addDouble(this, key, arg)
102#define ytPA_str(this,key,arg) ytParseArgs_addString(this, key, arg)
103#define ytPA_IntArray(this,key,arg) ytParseArgs_addIntArray(this, key, arg)
104#define ytPA_DoubleArray(this,key,arg) ytParseArgs_addDoubleArray(this, key, arg)
105#define ytPA_StrArray(this,key,arg) ytParseArgs_addStrArray(this, key, arg)
106#define ytPA_StrArrayAdd(this,key,arg) ytParseArgs_addStrArrayAdd(this, key, arg)
107#define ytPA_KeyValues(this,key,arg) ytParseArgs_addKeyValues(this, key, arg)
108#define ytPA_KV(this,key,arg) ytParseArgs_addKeyValues(this, key, arg)
109#define ytPA_KVArray(this,key,arg) ytParseArgs_addKeyValuesArray(this, key, arg)
110#define ytPA_on(this,key,arg) ytParseArgs_addOn(this, key, arg)
111#define ytPA_OnOff(this,key,arg) ytParseArgs_addOnOff(this, key, arg)
112#define ytPA_onoff(this,key,arg) ytParseArgs_addOnOff(this, key, arg)
113#define ytPA_off(this,key,arg) ytParseArgs_addOff(this, key, arg)
114#define ytPA_StrArrayAdd(this,key,arg) ytParseArgs_addStrArrayAdd(this, key, arg)
115#define ytPA_none(this,key) ytParseArgs_addNone(this, key)
116
117#endif /* __YTLIB_PARSE_ARGS_H */
118
119/* End of file. */
Expandable array.
Expandable array.
Expandable array.
key-value pairs.
Structure for parsing command line arguments.
void ytParseArgs_addOff(ytParseArgs *this, const char *key, int *arg)
Adds a key that sets an int value of 0 if it exists.
Definition: ytParseArgs.c:325
void ytParseArgs_addIntArray(ytParseArgs *this, const char *key, ytIntArray **arg)
Adds a key that sets an integer array to a ytIntArray instance.
Definition: ytParseArgs.c:356
void ytParseArgs_addOnOff(ytParseArgs *this, const char *key, int *arg)
Adds a key that sets an int value of 0 or 1.
Definition: ytParseArgs.c:342
void ytParseArgs_addStrArrayAdd(ytParseArgs *this, const char *key, ytStrArray **arg)
Adds a key that adds a string to a ytStrArray instance.
Definition: ytParseArgs.c:385
void ytParseArgs_addOn(ytParseArgs *this, const char *key, int *arg)
Adds a key that sets an int value of 1 if it exists.
Definition: ytParseArgs.c:315
void ytParseArgs_addDouble(ytParseArgs *this, const char *key, double *arg)
Adds a key that takes a double value.
Definition: ytParseArgs.c:305
void ytParseArgs_addStrArray(ytParseArgs *this, const char *key, ytStrArray **arg)
Adds a key that sets a string array to a ytStrArray instance.
Definition: ytParseArgs.c:370
int ytParseArgs_set(ytParseArgs *parser, int argc, char **argv)
Parses command line arguments.
Definition: ytParseArgs.c:1017
ytKeyValues * ytParseArgs_genKV(int argc, char **argv, const char *defKey)
Generates ytKeyValues instance from command line arguments.
Definition: ytParseArgs.c:1190
ytParseArgs * ytParseArgs_new()
Creates a new ytParseArgs instance.
Definition: ytParseArgs.c:177
void ytParseArgs_addKeyValues(ytParseArgs *this, const char *key, ytKeyValues **arg)
Adds a key that accepts key=value style values as ytKeyValues.
Definition: ytParseArgs.c:411
void ytParseArgs_addFunc(ytParseArgs *this, const char *key, void(*f)())
Adds a key that calls the specified function.
Definition: ytParseArgs.c:435
void ytParseArgs_addNone(ytParseArgs *this, const char *key)
Adds a key to ignore.
Definition: ytParseArgs.c:463
int ytParseArgs_setKV(ytParseArgs *parser, const ytKeyValues *kv, int opt)
Sets values in the variables from the ytKeyValues instance.
Definition: ytParseArgs.c:1150
void ytParseArgs_addFunc3(ytParseArgs *this, const char *key, void(*f)(const char *, const char *, void *), void *arg)
Adds a key that calls the specified function with its argument.
Definition: ytParseArgs.c:450
void ytParseArgs_delete(ytParseArgs *this)
Deletes the ytParseArgs instance.
Definition: ytParseArgs.c:194
void ytParseArgs_addInt(ytParseArgs *this, const char *key, int *arg)
Adds a key that takes an int value.
Definition: ytParseArgs.c:295
void ytParseArgs_addDoubleArray(ytParseArgs *this, const char *key, ytDoubleArray **arg)
Adds a key that sets a double array to a ytDoubleArray instance.
Definition: ytParseArgs.c:400
void ytParseArgs_addKeyValuesArray(ytParseArgs *this, const char *key, ytArray **arg)
Adds a key that accepts key=value style values as a ytKeyValues instance and adds them to the ytArray...
Definition: ytParseArgs.c:423
void ytParseArgs_verbose(ytParseArgs *this, int e)
Sets the verbose level.
Definition: ytParseArgs.c:1232
void ytParseArgs_addStringOpt(ytParseArgs *this, const char *key, char **arg)
Adds a key that takes a string (char *) value. The value can be omitted.
Definition: ytParseArgs.c:285
void ytParseArgs_addString(ytParseArgs *this, const char *key, char **arg)
Adds a key that takes a string (char *) value.
Definition: ytParseArgs.c:277
Expandable array.