insilmaril@105: #include "api.h" insilmaril@105: insilmaril@105: #include insilmaril@105: insilmaril@132: API::API() insilmaril@105: { insilmaril@132: initCommand(); insilmaril@132: } insilmaril@132: insilmaril@132: void API::initCommand() insilmaril@132: { insilmaril@132: com=""; insilmaril@132: paramList.clear(); insilmaril@394: resetError(); insilmaril@132: } insilmaril@132: insilmaril@394: void API::parseInput (const QString &s) insilmaril@132: { insilmaril@132: initCommand(); insilmaril@394: input=s; insilmaril@105: QRegExp re; insilmaril@105: int pos; insilmaril@105: insilmaril@105: // Get command insilmaril@105: re.setPattern ("(.*)\\s"); insilmaril@106: re.setMinimal (true); insilmaril@105: pos=re.search (s); insilmaril@105: if (pos>=0) insilmaril@132: com=re.cap(1); insilmaril@105: insilmaril@105: // Get parameters insilmaril@138: paramList.clear(); insilmaril@105: re.setPattern ("\\((.*)\\)"); insilmaril@105: pos=re.search (s); insilmaril@105: if (pos>=0) insilmaril@132: { insilmaril@132: QString s=re.cap(1); insilmaril@138: QString a; insilmaril@138: bool inquote=false; insilmaril@138: pos=0; insilmaril@138: if (!s.isEmpty()) insilmaril@138: { insilmaril@138: while (pos plist) insilmaril@394: { insilmaril@394: QStringList expList; insilmaril@394: QString expected; insilmaril@394: for (int i=0; i paramList.count()) insilmaril@132: { insilmaril@394: errLevel=Aborted; insilmaril@394: errDescription=QString("Parameter index %1 is outside of parameter list").arg(index); insilmaril@394: return false; insilmaril@132: } else insilmaril@132: { insilmaril@132: paramList[index].toInt (&ok, 10); insilmaril@132: if (!ok) insilmaril@132: { insilmaril@394: errLevel=Aborted; insilmaril@394: errDescription=QString("Parameter %1 is not an integer").arg(index); insilmaril@394: return false; insilmaril@394: } insilmaril@132: } insilmaril@394: return true; insilmaril@132: } insilmaril@132: insilmaril@132: int API::parInt (bool &ok,const uint &index) insilmaril@132: { insilmaril@132: if (checkParamIsInt (index)) insilmaril@132: return paramList[index].toInt (&ok, 10); insilmaril@132: ok=false; insilmaril@132: return 0; insilmaril@132: } insilmaril@132: insilmaril@377: QString API::parString (bool &ok,const int &index) insilmaril@132: { insilmaril@132: // return the string at index, this could be also stored in insilmaril@105: // a variable later insilmaril@132: QString r; insilmaril@105: QRegExp re("\"(.*)\""); insilmaril@132: int pos=re.search (paramList[index]); insilmaril@105: if (pos>=0) insilmaril@132: r=re.cap (1); insilmaril@105: else insilmaril@132: r=""; insilmaril@132: ok=true; insilmaril@132: return r; insilmaril@132: } insilmaril@394: insilmaril@394: bool API::parBool (bool &ok,const int &index) insilmaril@394: { insilmaril@394: // return the bool at index, this could be also stored in insilmaril@394: // a variable later insilmaril@394: QString r; insilmaril@394: ok=true; insilmaril@395: QString p=paramList[index]; insilmaril@395: if (p=="true" || p=="1") insilmaril@394: return true; insilmaril@395: else if (p=="false" || p=="0") insilmaril@394: return false; insilmaril@394: ok=false; insilmaril@394: return ok; insilmaril@394: } insilmaril@394: insilmaril@395: QColor API::parColor(bool &ok,const int &index) insilmaril@395: { insilmaril@395: // return the QColor at index insilmaril@395: ok=true; insilmaril@395: return QColor (paramList[index]); insilmaril@395: } insilmaril@395: