71 fNDone((nskip<=size_t(objc)) ? nskip : size_t(objc)),
78 throw Rexception(
"RtclArgs::<ctor>",
"Bad args: objc must be >= 0");
85 : fpInterp(rhs.fpInterp),
89 fNOptMiss(rhs.fNOptMiss),
90 fNConfigRead(rhs.fNConfigRead),
106 if (ind >=
size_t(
fObjc))
107 throw Rexception(
"RtclArgs::Objv()",
"Bad args: index out-of-range");
117 if (!
NextArg(name, pobj))
return false;
118 if (pobj==0)
return true;
129 if (!
NextArg(name, pobj))
return false;
130 if (pobj==0)
return true;
131 val = Tcl_GetString(pobj);
141 if (!
NextArg(name, pobj))
return false;
142 if (pobj==0)
return true;
143 val = Tcl_GetString(pobj);
152 int32_t val32 = int32_t(val);
153 bool ret =
GetArg(name, val32, int32_t(min), int32_t(max));
163 uint32_t val32 = uint32_t(val);
164 bool ret =
GetArg(name, val32, uint32_t(max), uint32_t(min));
165 val = uint8_t(val32);
174 int32_t val32 = int32_t(val);
175 bool ret =
GetArg(name, val32, int32_t(min), int32_t(max));
176 val = int16_t(val32);
186 uint32_t val32 = uint32_t(val);
187 bool ret =
GetArg(name, val32, uint32_t(max), uint32_t(min));
188 val = uint16_t(val32);
198 if (!
NextArg(name, pobj))
return false;
199 if (pobj==0)
return true;
201 if (Tcl_GetIntFromObj(
fpInterp, pobj, &objval) != TCL_OK)
return false;
202 if (objval < min || objval > max) {
204 sos <<
"-E: value '" << objval <<
"' for '" << name <<
"' out of range "
205 << min <<
"..." << max;
209 val = int32_t(objval);
220 if (!
NextArg(name, pobj))
return false;
221 if (pobj==0)
return true;
223 if (Tcl_GetIntFromObj(
fpInterp, pobj, &objval) != TCL_OK)
return false;
224 unsigned int objuval = objval;
225 if (objuval < min || objuval > max) {
227 sos <<
"-E: value '" << objuval <<
"' for '" << name <<
"' out of range "
228 << min <<
"..." << max;
232 val = uint32_t(objval);
241 double vald = double(val);
242 bool ret =
GetArg(name, vald,
double(min),
double(max));
253 if (!
NextArg(name, pobj))
return false;
254 if (pobj==0)
return true;
256 if (Tcl_GetDoubleFromObj(
fpInterp, pobj, &objval) != TCL_OK)
return false;
257 if (objval < min || objval > max) {
259 sos <<
"-E: value '" << objval <<
"' for '" << name <<
"' out of range "
260 << min <<
"..." << max;
272 size_t lmin,
size_t lmax)
275 Tcl_Obj** objv =
nullptr;
276 if (!
NextArgList(name, objc, objv, lmin, lmax))
return false;
277 if (objv==0)
return true;
282 for (
int i=0; i<objc; i++) {
284 if (Tcl_GetIntFromObj(
fpInterp, objv[i], &ival) != TCL_OK)
return false;
285 int ivalmsb = ival>>8;
286 if (ivalmsb != 0 && ivalmsb != -1) {
288 sos <<
"-E: list element '" << Tcl_GetString(objv[i])
290 <<
"' out of range " <<
"0...0xff";
294 val.push_back(uint8_t(ival));
303 size_t lmin,
size_t lmax)
306 Tcl_Obj** objv =
nullptr;
307 if (!
NextArgList(name, objc, objv, lmin, lmax))
return false;
308 if (objv==0)
return true;
313 for (
int i=0; i<objc; i++) {
315 if (Tcl_GetIntFromObj(
fpInterp, objv[i], &ival) != TCL_OK)
return false;
316 int ivalmsb = ival>>16;
317 if (ivalmsb != 0 && ivalmsb != -1) {
319 sos <<
"-E: list element '" << Tcl_GetString(objv[i])
321 <<
"' out of range " <<
"0...0xffff";
325 val.push_back(uint16_t(ival));
337 if (!
GetArg(name, tmp))
return false;
342 SetResult(Tcl_NewStringObj(val.data(), val.length()));
355 if (!
GetArg(name, tmp, max, min))
return false;
378 if (str[0]==
'-' && str[1] && !isdigit(str[1])) {
381 if (str[1]==
'-' && str[2]==0) {
397 if (!
NextOpt(opt) || opt.empty())
return false;
420 if (str[0]==
'-' && str[1] && str[1]!=
'-' && !isdigit(str[1])) {
439 "Bad state: no argument processed yet");
464 if (ind < 0 || ind >=
int(
fObjc))
return "";
465 return Tcl_GetString(
fObjv[ind]);
473 Tcl_AppendResult(
fpInterp, str,
nullptr);
488 if (str.length()>0 && str[str.length()-1]==
'\n') {
489 Tcl_AppendResult(
fpInterp, str.substr(0,str.length()-1).c_str(),
nullptr);
491 Tcl_AppendResult(
fpInterp, str.c_str(),
nullptr);
503 bool isopt = name[0] ==
'?';
504 bool isoptopt = isopt && (name[1] ==
'?');
510 AppendResult(
"-E: required argument '", name,
"' missing",
nullptr);
521 if (nval[0]==
'-' && nval[1] && isalpha(nval[1])) {
536 size_t lmin,
size_t lmax)
540 Tcl_Obj* pobj =
nullptr;
541 if (!
NextArg(name, pobj))
return false;
542 if (pobj==0)
return true;
544 if (Tcl_ListObjGetElements(
fpInterp, pobj, &objc, &objv) != TCL_OK) {
548 if (
size_t(objc) < lmin ||
size_t(objc) > lmax) {
550 sos <<
"-E: list length '" << objc <<
"' for '" << name <<
"' out of range "
551 << lmin <<
"..." << lmax;
563 if (name==0 || name[0]!=
'?' || name[1]!=
'?')
564 throw Rexception(
"RtclArgs::Config()",
"Bad args: name must start with ??");
575 AppendResult(
"-E: only one config read allowed per command, '",
void ConfigNameCheck(const char *name)
FIXME_docs.
Tcl_Obj * CurrentArg() const
FIXME_docs.
bool NextOpt(std::string &val)
FIXME_docs.
const char * PeekArgString(int rind) const
FIXME_docs.
void AppendResultLines(const std::string &str)
FIXME_docs.
Tcl_Obj *const * Objv() const
FIXME_docs.
int NextSubOpt(std::string &val, const RtclNameSet &optset)
FIXME_docs.
bool fArgErr
argument processing error flag
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
RtclArgs()
Default constructor.
size_t fNOptMiss
number of missed optional args
Tcl_Obj *const * fObjv
original args vector
bool Config(const char *name, std::string &val)
FIXME_docs.
size_t fNConfigRead
number of read mode config's
void AppendResult(const char *str,...)
FIXME_docs.
bool fOptErr
option processing error flag
bool ConfigReadCheck()
FIXME_docs.
void SetResult(const std::string &str)
FIXME_docs.
size_t fNDone
number of processed args
bool NextArgList(const char *name, int &objc, Tcl_Obj **&objv, size_t lmin=0, size_t lmax=uint32_max)
FIXME_docs.
bool NextArg(const char *name, Tcl_Obj *&pobj)
FIXME_docs.
Tcl_Interp * fpInterp
pointer to tcl interpreter
bool AllDone()
FIXME_docs.
size_t fObjc
original args count
int CheckMatch(Tcl_Interp *interp, std::string &rval, const std::string &tval, bool misserr) const
FIXME_docs.
bool Check(Tcl_Interp *interp, std::string &rval, const std::string &tval) const
FIXME_docs.
void AppendResultNewLines(Tcl_Interp *interp)
Declaration of class ReventLoop.