00001 #ifndef __XRDOUCARGS_HH__ 00002 #define __XRDOUCARGS_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c A r g s . h h */ 00006 /* */ 00007 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <stdlib.h> 00034 #include <string.h> 00035 00036 #include "XrdOuc/XrdOucTokenizer.hh" 00037 00038 class XrdOucArgsXO; 00039 class XrdSysError; 00040 00041 class XrdOucArgs 00042 { 00043 public: 00044 00045 // getarg() returns arguments, if any, one at a time. It should be called after 00046 // exhausting the option list via getopt() (i.e., it returns args after 00047 // the last '-' option in the input). Null is returned if no more 00048 // arguments remain. 00049 // 00050 char *getarg(); 00051 00052 // getopt() works almost exactly like the standard C-library getopt(). Some 00053 // extensions have been implemented see the constructor. In short: 00054 // ? -> Invalid option or missing option argument (see below). 00055 // : -> Missing option arg only when StdOpts starts with a colon. 00056 // -1-> End of option list (can try getarg() now if so wanted). 00057 // 00058 char getopt(); 00059 00060 // Set() tells this XrdOucArgs where the options and arguments come from. 00061 // They may come from a character string or from argument array. This 00062 // simplifies having a command/interactive tool as a single program. 00063 // You must call Set() prior to getxxx(). You may use the same object 00064 // over again by simply calling Set() again. 00065 // 00066 void Set(char *arglist); 00067 00068 void Set(int argc, char **argv); 00069 00070 // The StdOpts (which may be null) consist repeated single letters each 00071 // optionally followed by a colon (indicating an argument value is needed) 00072 // or a period, indicating an argument value is optional. If neither then the 00073 // single letter option does not have an argument value. The extended options 00074 // map multiple character words to the single letter equivalent (as above). 00075 00076 // Note that this class is not an exact implementation of getopt(), as follows: 00077 // 1) Single letter streams are not supported. That is, each single letter 00078 // option must be preceeded by a '-' (i.e., -a -b is NOT equivalent to -ab). 00079 // 2) Multi-character options may be preceeded by a single dash. Most other 00080 // implementation require a double dash. You can simulate this here by just 00081 // making all your multi-character options start with a dash. 00082 // 00083 XrdOucArgs(XrdSysError *erp, // -> Error Message Object (0->silence) 00084 const char *etxt, // The error text prefix 00085 const char *StdOpts, // List of standard 1-character options 00086 const char *optw=0, // Extended option name (0->end of list) 00087 // int minl, // Minimum abbreviation length 00088 // const char *optmap, // Equivalence with 1-character option 00089 ...); // Repeat last 3 args, as desired. 00090 00091 // Example: 00092 // XrdOucArgs myArgs(0, "", "ab:c.e", 00093 // "debug", 1, "d", // -d, -de, -deb, -debu, -debug 00094 // "force", 5, "F", // -force is valid only! 00095 // 0); // No more extended options 00096 00097 // Note: getopt() returns the single letter equivalent for long options. So, 00098 // 'd' is returned when -debug is encountered and 'F' for -force. 00099 00100 ~XrdOucArgs(); 00101 00102 char *argval; 00103 00104 private: 00105 00106 XrdOucTokenizer arg_stream; 00107 XrdSysError *eDest; 00108 char *epfx; 00109 XrdOucArgsXO *optp; 00110 char *vopts; 00111 char *curopt; 00112 int inStream; 00113 int endopts; 00114 int Argc; 00115 int Aloc; 00116 char **Argv; 00117 char missarg; 00118 }; 00119 #endif