xrootd
Loading...
Searching...
No Matches
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
37
38class XrdOucArgsXO;
39class XrdSysError;
40
42{
43public:
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//
50char *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//
58char 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//
66void Set(char *arglist);
67
68void 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
101
102char *argval;
103
104private:
105
108char *epfx;
109XrdOucArgsXO *optp;
110char *vopts;
111char *curopt;
116char **Argv;
118};
119#endif
Definition XrdOucArgs.hh:42
int Aloc
Definition XrdOucArgs.hh:115
char getopt()
void Set(int argc, char **argv)
char * curopt
Definition XrdOucArgs.hh:111
char * getarg()
XrdOucArgs(XrdSysError *erp, const char *etxt, const char *StdOpts, const char *optw=0,...)
int endopts
Definition XrdOucArgs.hh:113
char * vopts
Definition XrdOucArgs.hh:110
void Set(char *arglist)
int inStream
Definition XrdOucArgs.hh:112
char * epfx
Definition XrdOucArgs.hh:108
XrdSysError * eDest
Definition XrdOucArgs.hh:107
char ** Argv
Definition XrdOucArgs.hh:116
char missarg
Definition XrdOucArgs.hh:117
XrdOucTokenizer arg_stream
Definition XrdOucArgs.hh:106
XrdOucArgsXO * optp
Definition XrdOucArgs.hh:109
int Argc
Definition XrdOucArgs.hh:114
char * argval
Definition XrdOucArgs.hh:102
Definition XrdOucTokenizer.hh:33
Definition XrdSysError.hh:90