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@132: errorString=""; insilmaril@132: noErr=true; insilmaril@132: } insilmaril@132: insilmaril@132: void API::parseCommand (const QString &s) insilmaril@132: { insilmaril@132: initCommand(); 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 paramList.count()) insilmaril@132: { insilmaril@132: errorString =QString("Parameter index %1 is outside of parameter list").arg(index); insilmaril@138: noErr=false; insilmaril@132: } else insilmaril@132: { insilmaril@132: paramList[index].toInt (&ok, 10); insilmaril@132: if (!ok) insilmaril@132: { insilmaril@132: errorString=QString("Parameter %1 is not an integer").arg(index); insilmaril@138: noErr=false; insilmaril@138: } else insilmaril@138: noErr=true; insilmaril@132: } insilmaril@138: return noErr; insilmaril@132: } insilmaril@132: insilmaril@132: int API::parInt (bool &ok,const uint &index) insilmaril@132: { insilmaril@132: if (checkParamIsInt (index)) insilmaril@132: { insilmaril@132: return paramList[index].toInt (&ok, 10); insilmaril@132: } insilmaril@132: ok=false; insilmaril@132: return 0; insilmaril@132: } insilmaril@132: insilmaril@132: QString API::parString (bool &ok,const uint &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: }