aboutsummaryrefslogtreecommitdiff
path: root/src/pproc.h
blob: 31d7c029afc4303504e4af400c0da81d1edcdcfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef PPROC_H_
#define PPROC_H_

/**
 * A mask to discover what the type is even if flags are set.
 */
#define PPROC_TYPE				0x0F

#define PPROC_BOOL_TRUE			0x01
#define PPROC_BOOL_FALSE		0x02
#define PPROC_BOOL_TOGGLE		0x03
#define PPROC_CHAR				0x04
#define PPROC_SHORT				0x05
#define PPROC_LONG				0x06
#define PPREC_LONG_LONG			0x07
#define PPROC_UCHAR				0x08
#define PPROC_USHORT			0x09
#define PPROC_ULONG				0x0A
#define PPREC_ULONG_LONG		0x0B
#define PPROC_FLOAT				0x0C
#define PPROC_DOUBLE			0x0D
#define PPROC_LONG_DOUBLE		0x0E
#define PPROC_STRING			0x0F

#define PPROCF_CALLBACK			0x10
#define PPROCF_ALLOW_EQUALS		0x20
#define PPROCF_SHORT_TERMINAL	0x40
#define PPROCF_TERMINATE		0x80


/**
 * Contains all required info to handle a single program parameter.
 *@author Mike Buland
 */
typedef struct PPROC
{
	const char *lpWord;	/**< The full text-word to use as a param. */
	const char cChar;	/**< The short char version of the param. */

	const char cMode;	/**< One of the PPROC_* macros, these are not flags. */

	/**
	 * Pointer to the function to call when this param is triggered.
	 *@param argc The number of params after and including the one that
	 * triggered this call.
	 *@param argv The array of commandline tokens to use as parameters.
	 *@returns 0 for everything is ok.  A number greater than zero signals that
	 * this parameter function used n parameters and they should be skipped by
	 * the processParams function.
	 */
	int (*proc)( int argc, char *argv[] );
	void *stateVar;	/**< A pointer to a variable to set */
	const char *shortHelp;
} PPROC;

/**
 * Process command line parameters based on a null-terminated array of PPROC
 * structures.
 *@param argc Should come straight from your main function's argc.
 *@param argv Should come straight from your main function's argv.
 *@param pproc The array of params that this function can respond to.
 */
void processParams( int argc, char *argv[], PPROC *pproc );

#endif /*PPROC_H_*/