Line 1... |
Line 1... |
// $Id: RtclArgs.cpp 374 2011-03-27 17:02:47Z mueller $
|
// $Id: RtclArgs.cpp 492 2013-02-24 22:14:47Z mueller $
|
//
|
//
|
// Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
// Software Foundation, either version 2, or at your option any later version.
|
// Software Foundation, either version 2, or at your option any later version.
|
//
|
//
|
Line 11... |
Line 11... |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for complete details.
|
// for complete details.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
// Date Rev Version Comment
|
// Date Rev Version Comment
|
|
// 2013-02-12 487 1.0.6 add CurrentArg() method
|
|
// 2013-02-03 481 1.0.5 use Rexception
|
// 2011-03-26 373 1.0.4 add GetArg(float/double)
|
// 2011-03-26 373 1.0.4 add GetArg(float/double)
|
// 2011-03-13 369 1.0.3 add GetArg(vector<unit8_t>); NextOpt clear NOptMiss
|
// 2011-03-13 369 1.0.3 add GetArg(vector<unit8_t>); NextOpt clear NOptMiss
|
// 2011-03-06 367 1.0.2 add Config() methods;
|
// 2011-03-06 367 1.0.2 add Config() methods;
|
// 2011-03-05 366 1.0.1 fObjc,fNDone now size_t; add NDone(), SetResult();
|
// 2011-03-05 366 1.0.1 fObjc,fNDone now size_t; add NDone(), SetResult();
|
// add GetArg(Tcl_Obj), PeekArgString();
|
// add GetArg(Tcl_Obj), PeekArgString();
|
Line 22... |
Line 24... |
// 2011-02-11 360 0.1 First draft
|
// 2011-02-11 360 0.1 First draft
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: RtclArgs.cpp 374 2011-03-27 17:02:47Z mueller $
|
\version $Id: RtclArgs.cpp 492 2013-02-24 22:14:47Z mueller $
|
\brief Implemenation of RtclArgs.
|
\brief Implemenation of RtclArgs.
|
*/
|
*/
|
|
|
//debug
|
//debug
|
#include <iostream>
|
#include <iostream>
|
|
|
#include <ctype.h>
|
#include <ctype.h>
|
#include <stdarg.h>
|
#include <stdarg.h>
|
|
|
#include <stdexcept>
|
|
|
|
#include "RtclArgs.hpp"
|
#include "RtclArgs.hpp"
|
|
|
#include "Rtcl.hpp"
|
#include "Rtcl.hpp"
|
|
#include "librtools/Rexception.hpp"
|
|
|
using namespace std;
|
using namespace std;
|
using namespace Retro;
|
|
|
|
/*!
|
/*!
|
\class Retro::RtclArgs
|
\class Retro::RtclArgs
|
\brief FIXME_docs
|
\brief FIXME_docs
|
*/
|
*/
|
|
|
|
// all method definitions in namespace Retro
|
|
namespace Retro {
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! Default constructor
|
//! Default constructor
|
|
|
RtclArgs::RtclArgs()
|
RtclArgs::RtclArgs()
|
: fpInterp(0),
|
: fpInterp(0),
|
Line 74... |
Line 78... |
fNConfigRead(0),
|
fNConfigRead(0),
|
fOptErr(false),
|
fOptErr(false),
|
fArgErr(false)
|
fArgErr(false)
|
{
|
{
|
if (objc < 0)
|
if (objc < 0)
|
throw invalid_argument("RtclArgs::ctor: objc must be >= 0");
|
throw Rexception("RtclArgs::<ctor>","Bad args: objc must be >= 0");
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
Line 102... |
Line 106... |
//! FIXME_docs
|
//! FIXME_docs
|
|
|
Tcl_Obj* RtclArgs::Objv(size_t ind) const
|
Tcl_Obj* RtclArgs::Objv(size_t ind) const
|
{
|
{
|
if (ind >= (size_t)fObjc)
|
if (ind >= (size_t)fObjc)
|
throw out_of_range("RtclArgs::Objv: index out-of-range");
|
throw Rexception("RtclArgs::Objv()","Bad args: index out-of-range");
|
return fObjv[ind];
|
return fObjv[ind];
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
Line 401... |
Line 405... |
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
|
Tcl_Obj* RtclArgs::CurrentArg() const
|
|
{
|
|
if (fNDone == 0)
|
|
throw Rexception("RtclArgs::CurrentArg()",
|
|
"Bad state: no argument processed yet");
|
|
|
|
return fObjv[fNDone-1];
|
|
}
|
|
|
|
//------------------------------------------+-----------------------------------
|
|
//! FIXME_docs
|
|
|
bool RtclArgs::AllDone()
|
bool RtclArgs::AllDone()
|
{
|
{
|
if (fArgErr || fOptErr) return false;
|
if (fArgErr || fOptErr) return false;
|
if (fNDone < fObjc) {
|
if (fNDone < fObjc) {
|
AppendResult("-E: superfluous arguments, first one \"",
|
AppendResult("-E: superfluous arguments, first one '",
|
Tcl_GetString(fObjv[fNDone]), "\"", NULL);
|
Tcl_GetString(fObjv[fNDone]), "'", NULL);
|
return false;
|
return false;
|
}
|
}
|
return true;
|
return true;
|
}
|
}
|
|
|
Line 464... |
Line 480... |
|
|
if (!isopt) fNOptMiss = 0;
|
if (!isopt) fNOptMiss = 0;
|
|
|
if (fNDone == fObjc) {
|
if (fNDone == fObjc) {
|
if (!isopt) {
|
if (!isopt) {
|
AppendResult("-E: required argument \"", name, "\" missing", NULL);
|
AppendResult("-E: required argument '", name, "' missing", NULL);
|
fArgErr = true;
|
fArgErr = true;
|
return false;
|
return false;
|
}
|
}
|
fNOptMiss += 1;
|
fNOptMiss += 1;
|
return true;
|
return true;
|
Line 518... |
Line 534... |
//! FIXME_docs
|
//! FIXME_docs
|
|
|
void RtclArgs::ConfigNameCheck(const char* name)
|
void RtclArgs::ConfigNameCheck(const char* name)
|
{
|
{
|
if (name==0 || name[0]!='?' || name[1]!='?')
|
if (name==0 || name[0]!='?' || name[1]!='?')
|
throw invalid_argument("RtclArgs::Config(): name must start with ??");
|
throw Rexception("RtclArgs::Config()","Bad args: name must start with ??");
|
return;
|
return;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
bool RtclArgs::ConfigReadCheck()
|
bool RtclArgs::ConfigReadCheck()
|
{
|
{
|
if (fNConfigRead != 0) {
|
if (fNConfigRead != 0) {
|
SetResult(Tcl_NewObj());
|
SetResult(Tcl_NewObj());
|
AppendResult("-E: only one config read allowed per command, \"",
|
AppendResult("-E: only one config read allowed per command, '",
|
PeekArgString(-1), "\" is second", NULL);
|
PeekArgString(-1), "' is second", NULL);
|
return false;
|
return false;
|
}
|
}
|
fNConfigRead += 1;
|
fNConfigRead += 1;
|
return true;
|
return true;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
} // end namespace Retro
|
#if (defined(Retro_NoInline) || defined(Retro_RtclArgs_NoInline))
|
|
#define inline
|
|
#include "RtclArgs.ipp"
|
|
#undef inline
|
|
#endif
|
|
|
|
No newline at end of file
|
No newline at end of file
|