/usr/include/visp/vpParseArgv.h is in libvisp-dev 2.8.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /****************************************************************************
*
* $Id: vpParseArgv.h 2780 2010-09-08 08:37:15Z fspindle $
*
* Declarations for Tk-related things that are visible
* outside of the Tk module itself.
*
* Copyright 1989-1992 Regents of the University of California.
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*
* This file has been modified to be used only for argv parsing without
* reference to tk, tcl or X11. Base on tk.h from tk2.3
*
* Description:
* Command line argument parsing.
*
* Authors:
* Fabien Spindler (modification of the original version)
*
*****************************************************************************/
/*!
\file vpParseArgv.h
\brief Command line argument parsing.
*/
#ifndef vpParseArgv_h
#define vpParseArgv_h
#include <visp/vpConfig.h>
/*!
\class vpParseArgv
\ingroup ArgumentParser
\brief Command line argument parsing.
The code below shows a first way to parse command line arguments
using vpParseArgv class. It allows to specify an option
name with more than one character.
\code
#include <stdio.h>
#include <visp/vpParseArgv.h>
// Usage : [-int <integer value>] [-float <float value>] [-double <double value>] [-h]
int main(int argc, const char ** argv)
{
// Variables to set by command line parsing
int i_val = 0;
float f_val = 0;
double d_val = 0;
// Parse the command line to set the variables
vpParseArgv::vpArgvInfo argTable[] =
{
{"-int", vpParseArgv::ARGV_INT, (char*) NULL, (char *) &i_val,
"An integer value."},
{"-float", vpParseArgv::ARGV_FLOAT, (char*) NULL, (char *) &f_val,
"A float value."},
{"-double", vpParseArgv::ARGV_DOUBLE, (char*) NULL, (char *) &d_val,
"A double value."},
{"-h", vpParseArgv::ARGV_HELP, (char*) NULL, (char *) NULL,
"Print the help."},
{(char*) NULL, vpParseArgv::ARGV_END, (char*) NULL, (char*) NULL, (char*) NULL}
} ;
// Read the command line options
if(vpParseArgv::parse(&argc, argv, argTable,
vpParseArgv::ARGV_NO_LEFTOVERS |
vpParseArgv::ARGV_NO_ABBREV |
vpParseArgv::ARGV_NO_DEFAULTS)) {
return (false);
}
// i_val, f_val, d_val may have new values
}
\endcode
The code below shows an other way to parse command line arguments using
vpParseArgv class. Here command line options are only one character long.
\code
#include <stdio.h>
#include <stdlib.h>
#include <visp/vpParseArgv.h>
// List of allowed command line options
#define GETOPTARGS "d:f:i:h" // double point mean here that the preceding option request an argument
// Usage : [-i <integer value>] [-f <float value>] [-d <double value>] [-h]
int main(int argc, const char ** argv)
{
// Variables to set by command line parsing
int i_val = 0;
float f_val = 0;
double d_val = 0;
// Parse the command line to set the variables
const char *optarg;
int c;
while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
switch (c) {
case 'd': d_val = atof(optarg); break;
case 'f': f_val = (float) atof(optarg); break;
case 'i': i_val = atoi(optarg); break;
case 'h': printf("Usage: ...\n"); return true; break;
default:
printf("Usage: ...\n"); return true; break;
}
}
if ((c == 1) || (c == -1)) {
// standalone param or error
printf("Usage: ...\n");
return false;
}
// i_val, f_val, d_val may have new values
}
\endcode
*/
class VISP_EXPORT vpParseArgv
{
public:
/*!
Legal values for the type field of a vpArgvInfo.
*/
typedef enum {
ARGV_CONSTANT,/*!< Stand alone argument. */
ARGV_INT, /*!< Argument is associated to an int. */
ARGV_LONG, /*!< Argument is associated to a long. */
ARGV_STRING, /*!< Argument is associated to a char * string. */
ARGV_REST,
ARGV_FLOAT, /*!< Argument is associated to a float. */
ARGV_DOUBLE, /*!< Argument is associated to a double. */
ARGV_FUNC,
ARGV_GENFUNC,
ARGV_HELP, /*!< Argument is for help displaying. */
ARGV_END /*!< End of the argument list. */
} vpArgvType;
/*!
Flag bits.
*/
typedef enum {
ARGV_NO_DEFAULTS = 0x1, /*!< No default options like -help. */
ARGV_NO_LEFTOVERS = 0x2, /*!< Print an error message if an option is not in the argument list. */
ARGV_NO_ABBREV = 0x4, /*!< No abrevation. Print an error message if an option is abrevated (ie "-i" in place of "-int" which is requested). */
ARGV_DONT_SKIP_FIRST_ARG = 0x8, /*!< Don't skip first argument. */
ARGV_NO_PRINT = 0x10 /*!< No printings. */
} vpArgvFlags;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/*!
Structure used to specify how to handle argv options.
*/
typedef struct {
const char *key; /*!< The key string that flags the option in the
* argv array. */
vpArgvType type; /*!< Indicates option type; see below. */
const char *src; /*!< Value to be used in setting dst; usage
* depends on type. */
const char *dst; /*!< Address of value to be modified; usage
* depends on type. */
const char *help; /*!< Documentation message describing this option. */
} vpArgvInfo;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
public:
static vpArgvInfo defaultTable[2];
static bool parse(int *argcPtr, const char **argv,
vpArgvInfo *argTable, int flags);
static int parse(int argc, const char** argv, const char* validOpts, const char** param);
private:
static void printUsage (vpArgvInfo *argTable, int flags);
} ;
#endif
|