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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/************************** Fraunhofer IIS FDK SysLib **********************
(C) Copyright Fraunhofer IIS (1999)
All Rights Reserved
Please be advised that this software and/or program delivery is
Confidential Information of Fraunhofer and subject to and covered by the
Fraunhofer IIS Software Evaluation Agreement
between Google Inc. and Fraunhofer
effective and in full force since March 1, 2012.
You may use this software and/or program only under the terms and
conditions described in the above mentioned Fraunhofer IIS Software
Evaluation Agreement. Any other and/or further use requires a separate agreement.
$Id$
Author(s):
Description: command line parser
This software and/or program is protected by copyright law and international
treaties. Any reproduction or distribution of this software and/or program,
or any portion of it, may result in severe civil and criminal penalties, and
will be prosecuted to the maximum extent possible under law.
******************************************************************************/
/** \file cmdl_parser.h
* \brief Command line parser.
*
* The command line parser can extract certain data fields out of a character
* string and assign values to variables. It has 2 main functions. One to parse
* a command line in the form of standard C runtime "argc" and "argv" parameters,
* and the other to assemble these parameters reading text lines from a file in
* case the C runtime does not provide them.
*/
#ifndef __PARSER_H
#define __PARSER_H
#include "machine_type.h"
#define CMDL_MAX_STRLEN 255
#define CMDL_MAX_ARGC 30
/* \cond */
/* Type definition for text */
#ifdef WIN32
#include <tchar.h>
#ifndef _tstof /* For Visual Studio 6 */
#ifdef _UNICODE
#include <wchar.h>
#define _tstof(x) (float) wcstod(x, NULL) /* For Visual Studio 6 */
#else
#define _tstof atof
#endif
#endif
#ifndef _tstol /* For Visual Studio 6 */
#ifdef _UNICODE
#define _tstol _wtol
#else
#define _tstol atol
#endif
#endif
#ifndef _tstoi /* For Visual Studio 6 */
#ifdef _UNICODE
#define _tstoi _wtoi
#else
#define _tstoi atoi
#endif
#endif
#ifndef TEXTCHAR
#define TEXTCHAR char
#endif
#ifndef _TEXT
#define _TEXT
#endif
#else /* WIN32 */
#define TEXTCHAR char
#define _tcslen(a) FDKstrlen(a)
#define _tcscpy strcpy
#define _tcscmp FDKstrcmp
#define _tcsncmp FDKstrncmp
#define _tscanf scanf
#define _TEXT(x) x
#define _tfopen fopen
#define _ftprintf fprintf
#define _tcsncpy FDKstrncpy
#define _tstof FDKatof
#define _tstol FDKatol
#define _tstoi FDKatoi
#define _tcstol strtol
#define _istdigit isdigit
#endif /* WIN32 */
/* \endcond */
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Scans argc, argv and a scanf style format string for parameters and stores the
* values in the variable number of pointers passed to the function.
For example:
\code
#define ARG_PARAM "(-a %d) (-v %1)"
#define ARG_VALUE &config->aot, &verbose
int nFoundArgs = IIS_ScanCmdl(argc, argv, ARG_PARAM, ARG_VALUE);
\endcode
wheras the wild-cards (\%d, \%1, ..) define the data type of the argument:
- \%1 boolean (e. g. -x)
- \%d integer (e. g. -x 23)
- \%f float (e. g. -x 3.4)
- \%y double (e. g. -x 31415926535897932384626433832795028841971693993751)
- \%s string (e. g. -x "file.dat")
- \%u unsigned character (e. g. -x 3)
- \%c signed character (e. g. -x -3)
More examples on how to use it are located in every (encoder/decoder) example framework.
* \param argc Number of arguments.
* \param argv Complete character string of the command line arguments.
* \param pReqArgs A list of parameters and a corresponding list of memory addresses to
* assign each parameter to.
*
* \return Number of found arguments.
*/
INT IIS_ScanCmdl(INT argc, TEXTCHAR* argv[], const TEXTCHAR* pReqArgs, ...);
#ifdef __cplusplus
}
#endif
/**
* Reads a text file, assembles argc and argv parameters for each text line
* and calls the given function for each set of argc, argv parameters.
*
* \param param_filename Name of text file that should be parsed.
* \param pFunction Pointer to function that should be called for every text line found.
*
* \return 0 on success, 1 on failure.
*/
INT IIS_ProcessCmdlList(const TEXTCHAR* param_filename, int (*pFunction)(int, TEXTCHAR**));
#endif /* __PARSER_H */
|