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 
13 // $Id$
14 
15 #include <stdlib.h>
16 #include <string.h>
17 
19 
20 class XrdOucArgsXO;
21 class XrdSysError;
22 
24 {
25 public:
26 
27 // getarg() returns arguments, if any, one at a time. It should be called after
28 // exhausting the option list via getopt() (i.e., it returns args after
29 // the last '-' option in the input). Null is returned if no more
30 // arguments remain.
31 //
32 char *getarg();
33 
34 // getopt() works almost exactly like the standard C-library getopt(). Some
35 // extensions have been implemented see the constructor. In short:
36 // ? -> Invalid option or missing option argument (see below).
37 // : -> Missing option arg only when StdOpts starts with a colon.
38 // -1-> End of option list (can try getarg() now if so wanted).
39 //
40 char getopt();
41 
42 // Set() tells this XrdOucArgs where the options and arguments come from.
43 // They may come from a character string or from argument array. This
44 // simplifies having a command/interactive tool as a single program.
45 // You must call Set() prior to getxxx(). You may use the same object
46 // over again by simply calling Set() again.
47 //
48 void Set(char *arglist);
49 
50 void Set(int argc, char **argv);
51 
52 // The StdOpts (which may be null) consist repeated single letters each
53 // optionally followed by a colon (indicating an argument value is needed)
54 // or a period, indicating an argument value is optional. If neither then the
55 // single letter option does not have an argument value. The extended options
56 // map multiple character words to the single letter equivalent (as above).
57 
58 // Note that this class is not an exact implementation of getopt(), as follows:
59 // 1) Single letter streams are not supported. That is, each single letter
60 // option must be preceeded by a '-' (i.e., -a -b is NOT equivalent to -ab).
61 // 2) Multi-character options may be preceeded by a single dash. Most other
62 // implementation require a double dash. You can simulate this here by just
63 // making all your multi-character options start with a dash.
64 //
65  XrdOucArgs(XrdSysError *erp, // -> Error Message Object (0->silence)
66  const char *etxt, // The error text prefix
67  const char *StdOpts, // List of standard 1-character options
68  const char *optw=0, // Extended option name (0->end of list)
69  // int minl, // Minimum abbreviation length
70  // const char *optmap, // Equivalence with 1-character option
71  ...); // Repeat last 3 args, as desired.
72 
73 // Example:
74 // XrdOucArgs myArgs(0, "", "ab:c.e",
75 // "debug", 1, "d", // -d, -de, -deb, -debu, -debug
76 // "force", 5, "F", // -force is valid only!
77 // 0); // No more extended options
78 
79 // Note: getopt() returns the single letter equivalent for long options. So,
80 // 'd' is returned when -debug is encountered and 'F' for -force.
81 
82  ~XrdOucArgs();
83 
84 char *argval;
85 
86 private:
87 
90 char *epfx;
92 char *vopts;
93 char *curopt;
95 int endopts;
96 int Argc;
97 int Aloc;
98 char **Argv;
99 char missarg;
100 };
101 #endif