XRootD
Loading...
Searching...
No Matches
XrdOucArgs Class Reference

#include <XrdOucArgs.hh>

+ Collaboration diagram for XrdOucArgs:

Public Member Functions

 XrdOucArgs (XrdSysError *erp, const char *etxt, const char *StdOpts, const char *optw=0,...)
 
 ~XrdOucArgs ()
 
char * getarg ()
 
char getopt ()
 
void Set (char *arglist)
 
void Set (int argc, char **argv)
 

Public Attributes

char * argval
 

Detailed Description

Definition at line 41 of file XrdOucArgs.hh.

Constructor & Destructor Documentation

◆ XrdOucArgs()

XrdOucArgs::XrdOucArgs ( XrdSysError * erp,
const char * etxt,
const char * StdOpts,
const char * optw = 0,
... )

Definition at line 86 of file XrdOucArgs.cc.

92 : arg_stream(0)
93{
94 va_list ap;
95 const char *optm;
96 int minl;
97
98// Do the standard initialization
99//
100 inStream = Argc = Aloc = 0; vopts = curopt = 0; endopts = 1;
101 optp = 0; eDest = erp;
102 epfx = strdup(etxt ? etxt : "");
103
104// Process the valid opts
105//
106 if (StdOpts && *StdOpts == ':') {missarg = ':'; StdOpts++;}
107 else missarg = '?';
108 vopts = strdup(StdOpts ? StdOpts : "");
109
110// Handle list of extended options, if any
111//
112 if (optw)
113 {va_start(ap, optw);
114 while(optw)
115 {minl = va_arg(ap, int);
116 optm = va_arg(ap, const char *);
117 optp = new XrdOucArgsXO(optp, optw, minl, optm);
118 optw = va_arg(ap, const char *);
119 }
120 va_end(ap);
121 }
122}

◆ ~XrdOucArgs()

XrdOucArgs::~XrdOucArgs ( )

Definition at line 126 of file XrdOucArgs.cc.

127 {if (vopts) free(vopts);
128 if (optp) delete optp;
129 free(epfx);
130 }

Member Function Documentation

◆ getarg()

char * XrdOucArgs::getarg ( )

Definition at line 136 of file XrdOucArgs.cc.

137{
138
139// Return argument from whatever source we have
140//
141 if (inStream) return arg_stream.GetToken();
142 if (Aloc >= Argc) return (char *)0;
143 argval = Argv[Aloc++];
144 return argval;
145}
char * argval

References argval.

Referenced by XrdFrmAdmin::Audit(), XrdFrmAdmin::Chksum(), main(), XrdFrmAdmin::MakeLF(), XrdFrmAdmin::Mark(), XrdFrmAdmin::Mmap(), XrdFrmAdmin::Pin(), and XrdFrmAdmin::Remove().

+ Here is the caller graph for this function:

◆ getopt()

char XrdOucArgs::getopt ( )

Definition at line 151 of file XrdOucArgs.cc.

152{
153 char optbuff[3] = {'-', 'x', '\0'}, *optspec, *arglist, *optname = 0;
154
155// Check if we really have any more options
156//
157 if (endopts) return -1;
158
159// Get next option from whatever source we have
160//
161 if (curopt && *curopt) curopt++;
162 else if (inStream)
163 {if ((optname = curopt = arg_stream.GetToken(&arglist)))
164 {if (*curopt != '-') {arg_stream.RetToken(); curopt = 0;}
165 else curopt++;
166 }
167 }
168 else if (Aloc >= Argc || *Argv[Aloc] != '-') curopt = 0;
169 else optname = curopt = Argv[Aloc++]+1;
170
171// Check if we really have an option here
172//
173 if (!curopt) {endopts = 1; return -1;}
174 if (!*curopt)
175 {if (eDest) eDest->Say(epfx, "Option letter missing after '-'.");
176 endopts = 1;
177 return '?';
178 }
179
180// Check for extended options or single letter option
181//
182 if (*curopt == ':' || *curopt == '.') optspec = 0;
183 else {if (optp) {optspec = *optp%curopt; curopt = 0;}
184 else {optspec = index(vopts, int(*curopt));
185 optbuff[1] = *curopt; optname = optbuff; curopt++;
186 }
187 }
188 if (!optspec)
189 {char buff[500];
190 if (eDest)
191 {sprintf(buff, "Invalid option, '%s'.", optname);
192 eDest->Say(epfx, buff);
193 }
194 endopts = 1;
195 return '?';
196 }
197
198// Check if this option requires an argument
199//
200 if (optspec[1] != ':' && optspec[1] != '.') return *optspec;
201
202// Get the argument from whatever source we have
203//
204 if (inStream) argval = arg_stream.GetToken();
205 else argval = (Aloc < Argc ? Argv[Aloc++] : 0);
206
207// If we have a valid argument, then we are all done
208//
209 if (argval)
210 {if (!*argval) argval = 0;
211 else if (*argval != '-') return *optspec;
212 }
213
214// If argument is optional, let it go
215//
216 if (optspec[1] == '.')
217 {if (argval && *argval == '-')
218 {if (inStream) arg_stream.RetToken();
219 else Aloc--;
220 }
221 argval = 0;
222 return *optspec;
223 }
224
225// Complain about a missing argument
226//
227 if (eDest) eDest->Say(epfx, "Value not specified for '", optname, "'.");
228 endopts = 1;
229 return missarg;
230}

References argval.

Referenced by main().

+ Here is the caller graph for this function:

◆ Set() [1/2]

void XrdOucArgs::Set ( char * arglist)

Definition at line 236 of file XrdOucArgs.cc.

237{
238 inStream = 1;
239 arg_stream.Attach(arglist);
240 curopt = 0;
241 endopts = !arg_stream.GetLine();
242}

Referenced by main().

+ Here is the caller graph for this function:

◆ Set() [2/2]

void XrdOucArgs::Set ( int argc,
char ** argv )

Definition at line 244 of file XrdOucArgs.cc.

245{
246 inStream = 0;
247 Argc = argc; Argv = argv; Aloc = 0;
248 curopt = 0; endopts = 0;
249 endopts = !argc;
250}

Member Data Documentation

◆ argval

char* XrdOucArgs::argval

Definition at line 102 of file XrdOucArgs.hh.

Referenced by getarg(), getopt(), and main().


The documentation for this class was generated from the following files: