-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargvec.h
113 lines (93 loc) · 2.99 KB
/
argvec.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* This file is part of libsysperf
*
* Copyright (C) 2001, 2004-2007 by Nokia Corporation.
*
* Contact: Eero Tamminen <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/* ========================================================================= *
* File: argvec.h
*
* Author: Simo Piiroinen
*
* -------------------------------------------------------------------------
*
* History:
*
* 21-Jun-2005 Simo Piiroinen
* - initial version
* ========================================================================= */
#ifndef ARGVEC_H_
#define ARGVEC_H_
#ifdef __cplusplus
extern "C" {
#elif 0
} /* fool JED indentation ... */
#endif
/* ------------------------------------------------------------------------- *
* manual_t
* ------------------------------------------------------------------------- */
typedef struct manual_t
{
const char *man_sect;
const char *man_text;
} manual_t;
#define MAN_ADD(s,c) { s, c },
#define MAN_END { 0, 0 }
/* ------------------------------------------------------------------------- *
* option_t
* ------------------------------------------------------------------------- */
typedef struct option_t
{
int op_tag;
const char *op_short;
const char *op_long;
const char *op_param;
const char *op_usage;
} option_t;
#define OPT_ADD(tag,sn,ln,ar,us) { tag, sn, ln, ar, us }
#define OPT_END { -1, }
/* ------------------------------------------------------------------------- *
* argvec_t
* ------------------------------------------------------------------------- */
typedef struct argvec_t
{
int av_argc; // argv from main()
char **av_argv; //
int av_iarg; // parse pos: av_argv[av_iarg][av_ichr]
int av_ichr; //
int av_done; // all args handled succesully
const
option_t *av_opt; //
const
manual_t *av_man;
} argvec_t;
/* ------------------------------------------------------------------------- *
* prototypes
* ------------------------------------------------------------------------- */
int argvec_done(argvec_t *self);
argvec_t *argvec_create(int argc, char **argv, const option_t *opt, const manual_t *man);
void argvec_delete(argvec_t *self);
void argvec_options(argvec_t *self, int verbose);
void argvec_usage(argvec_t *self);
char *argvec_pull(argvec_t *self);
int argvec_next(argvec_t *self, int *ptag, char **pstr);
#ifdef __cplusplus
};
#endif
#endif /* ARGVEC_H_ */