XRootD
XrdOucArgs.hh
Go to the documentation of this file.
1
#ifndef __XRDOUCARGS_HH__
2
#define __XRDOUCARGS_HH__
3
/******************************************************************************/
4
/* */
5
/* X r d O u c A r g s . h h */
6
/* */
7
/* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
8
/* All Rights Reserved */
9
/* Produced by Andrew Hanushevsky for Stanford University under contract */
10
/* DE-AC02-76-SFO0515 with the Department of Energy */
11
/* */
12
/* This file is part of the XRootD software suite. */
13
/* */
14
/* XRootD is free software: you can redistribute it and/or modify it under */
15
/* the terms of the GNU Lesser General Public License as published by the */
16
/* Free Software Foundation, either version 3 of the License, or (at your */
17
/* option) any later version. */
18
/* */
19
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22
/* License for more details. */
23
/* */
24
/* You should have received a copy of the GNU Lesser General Public License */
25
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27
/* */
28
/* The copyright holder's institutional names and contributor's names may not */
29
/* be used to endorse or promote products derived from this software without */
30
/* specific prior written permission of the institution or contributor. */
31
/******************************************************************************/
32
33
#include <cstdlib>
34
#include <cstring>
35
36
#include "
XrdOuc/XrdOucTokenizer.hh
"
37
38
class
XrdOucArgsXO
;
39
class
XrdSysError
;
40
41
class
XrdOucArgs
42
{
43
public
:
44
45
// getarg() returns arguments, if any, one at a time. It should be called after
46
// exhausting the option list via getopt() (i.e., it returns args after
47
// the last '-' option in the input). Null is returned if no more
48
// arguments remain.
49
//
50
char
*
getarg
();
51
52
// getopt() works almost exactly like the standard C-library getopt(). Some
53
// extensions have been implemented see the constructor. In short:
54
// ? -> Invalid option or missing option argument (see below).
55
// : -> Missing option arg only when StdOpts starts with a colon.
56
// -1-> End of option list (can try getarg() now if so wanted).
57
//
58
char
getopt
();
59
60
// Set() tells this XrdOucArgs where the options and arguments come from.
61
// They may come from a character string or from argument array. This
62
// simplifies having a command/interactive tool as a single program.
63
// You must call Set() prior to getxxx(). You may use the same object
64
// over again by simply calling Set() again.
65
//
66
void
Set
(
char
*arglist);
67
68
void
Set
(
int
argc,
char
**argv);
69
70
// The StdOpts (which may be null) consist repeated single letters each
71
// optionally followed by a colon (indicating an argument value is needed)
72
// or a period, indicating an argument value is optional. If neither then the
73
// single letter option does not have an argument value. The extended options
74
// map multiple character words to the single letter equivalent (as above).
75
76
// Note that this class is not an exact implementation of getopt(), as follows:
77
// 1) Single letter streams are not supported. That is, each single letter
78
// option must be preceeded by a '-' (i.e., -a -b is NOT equivalent to -ab).
79
// 2) Multi-character options may be preceeded by a single dash. Most other
80
// implementation require a double dash. You can simulate this here by just
81
// making all your multi-character options start with a dash.
82
//
83
XrdOucArgs
(
XrdSysError
*erp,
// -> Error Message Object (0->silence)
84
const
char
*etxt,
// The error text prefix
85
const
char
*StdOpts,
// List of standard 1-character options
86
const
char
*optw=0,
// Extended option name (0->end of list)
87
// int minl, // Minimum abbreviation length
88
// const char *optmap, // Equivalence with 1-character option
89
...);
// Repeat last 3 args, as desired.
90
91
// Example:
92
// XrdOucArgs myArgs(0, "", "ab:c.e",
93
// "debug", 1, "d", // -d, -de, -deb, -debu, -debug
94
// "force", 5, "F", // -force is valid only!
95
// 0); // No more extended options
96
97
// Note: getopt() returns the single letter equivalent for long options. So,
98
// 'd' is returned when -debug is encountered and 'F' for -force.
99
100
~XrdOucArgs
();
101
102
char
*
argval
;
103
104
private
:
105
106
XrdOucTokenizer
arg_stream;
107
XrdSysError
*eDest;
108
char
*epfx;
109
XrdOucArgsXO
*optp;
110
char
*vopts;
111
char
*curopt;
112
int
inStream;
113
int
endopts;
114
int
Argc;
115
int
Aloc;
116
char
**Argv;
117
char
missarg;
118
};
119
#endif
XrdOucTokenizer.hh
XrdOucArgsXO
Definition:
XrdOucArgs.cc:44
XrdOucArgs
Definition:
XrdOucArgs.hh:42
XrdOucArgs::getopt
char getopt()
Definition:
XrdOucArgs.cc:151
XrdOucArgs::getarg
char * getarg()
Definition:
XrdOucArgs.cc:136
XrdOucArgs::~XrdOucArgs
~XrdOucArgs()
Definition:
XrdOucArgs.cc:126
XrdOucArgs::XrdOucArgs
XrdOucArgs(XrdSysError *erp, const char *etxt, const char *StdOpts, const char *optw=0,...)
Definition:
XrdOucArgs.cc:86
XrdOucArgs::Set
void Set(char *arglist)
Definition:
XrdOucArgs.cc:236
XrdOucArgs::argval
char * argval
Definition:
XrdOucArgs.hh:102
XrdOucTokenizer
Definition:
XrdOucTokenizer.hh:33
XrdSysError
Definition:
XrdSysError.hh:90
XrdOuc
XrdOucArgs.hh
Generated by
1.9.1