bool CmdOptions::Parse (int argc, char *argv[]) { try { int a(1); bool keepParsing (true); QString word; while (a < argc) { word = QString (argv[a]); if (word == "--") { keepParsing = false; } else if (keepParsing && word.startsWith("--")) { ParseLong (word, argv, a, argc+1); } else if (keepParsing && word.startsWith("-")) { ParseShort (word, argv, a, argc+1); } else { mArgs += word; } a++; } } catch (...) { bad = true; return false; } bad = false; return true; }
bool StaticTrigComponentParser::ParseTriplet(char* text, u8* dest, u32 pos, u32 end) { u32 val; bool isNegative = false; if ( text[pos] == '-' ) // isNegative { pos ++; isNegative = true; } if ( ParseLong(text, val, pos, end) ) { if ( isNegative ) val = 0x1000000 - val; dest[2] = u8(val/0x10000); val /= 0x10000; dest[1] = u8(val/0x100); val /= 0x100; dest[0] = u8(val); return true; } return false; }
void Interpreter::ProcessInstance(int argc, char *argv[]) { otError error = OT_ERROR_NONE; long value; if (argc == 0) { if (mInstance == NULL) { mServer->OutputFormat("No Instance Set\r\n"); } else { GUID aDeviceGuid = otGetDeviceGuid(mInstance); uint32_t aCompartment = otGetCompartmentId(mInstance); mServer->OutputFormat("[%d] " GUID_FORMAT " (Compartment %u)\r\n", mInstanceIndex, GUID_ARG(aDeviceGuid), aCompartment); } } else { SuccessOrExit(error = ParseLong(argv[0], value)); VerifyOrExit(value >= 0 && value < mInstancesLength, error = OT_ERROR_INVALID_ARGS); mInstanceIndex = (uint8_t)value; mInstance = mInstances[mInstanceIndex].mInstance; } exit: AppendResult(error); }
bool StaticTrigComponentParser::ParseMemoryAddress(char* text, u32& dest, u32 pos, u32 end, u32 deathTableOffset) { u32 temp = 0; if ( ParseLong(text, temp, pos, end) ) { dest = (temp/4*4-deathTableOffset)/4; return true; } return false; }
void AppArgs::Parse(int argc, const char* const* argv) { for (int i=1; i<argc; i++) { // this shouldn't occur if (argv[i] == NULL) return; if (IsOption(argv[i])) { if (IsLongOption(argv[i])) { std::string name, val; bool hasVal; if (ParseLong(argv[i], name, val, hasVal)) { AA_LONG_MAP::iterator it = s_longMap.find(name); if (it != s_longMap.end()) { AppArgOption_t* pOpt = (*it).second; pOpt->found = true; pOpt->hasVal = hasVal; pOpt->val = val; } } } else { char name; std::string val; bool hasVal; ParseShort(argv[i], name, val, hasVal); AA_SHORT_MAP::iterator it = s_shortMap.find(name); if (it != s_shortMap.end()) { AppArgOption_t* pOpt = (*it).second; pOpt->found = true; if (hasVal) { pOpt->hasVal = true; pOpt->val = val; } else { if (i+1 < argc && !IsOption(argv[i+1])) { pOpt->hasVal = true; pOpt->val = argv[i+1]; i++; } else { pOpt->hasVal = false; } } } } } else { s_valList.push_back(argv[i]); } } }
void CmdOptions::ParseShort (QString wd, char* argv[], int & pos, int posmax) { int len = wd.length(); if (len < 2) { throw -1; } QString name = wd.right(len-1); if (mLongNameOf.count(name) < 1) { throw -1; } QString lngWd ("--"); lngWd.append(mLongNameOf[name]); ParseLong (lngWd, argv, pos, posmax); }
void GraphBase::BaseLoad(wxString path, wxString tag, wxTextCtrl *textbox) { int i, index; TextFile infile; wxString readline, filename, filetag; wxString text, numstring, namestring, basestring; wxString gtag, gname; double numdat; GraphDat *graph; int version; filename = "gbase-" + tag + ".dat"; //if(!infile.Open(initpath + "/Graphs/" + filename)) return; if(!infile.Open(path + "/" + filename)) return; if(textbox) textbox->AppendText(text.Format("Loading %d graphs\n", numgraphs)); i = 0; readline = infile.ReadLine(); // Version check //fileversion = ParseLong(&vstring, 'v'); //textbox->AppendText(text.Format("Base file version %d\n", fileversion)); //if(fileversion < version) textbox->AppendText(text.Format("Create base index\n")); while(!readline.IsEmpty()) { if(readline.GetChar(0) == 'v') version = ParseLong(&readline, 'v'); // check file version for backwards compatability else version = 0; //textbox->AppendText(text.Format("Base file version %d\n", version)); //textbox->AppendText(text.Format("Readline %s\n", readline)); if(version >= 2) { // Modern, reference by tag gtag = ParseString(&readline, 'g'); graph = GetGraph(gtag); if(graph) graph->LoadDat(readline, version); } else { //GetGraphFromName(gname)->LoadDat(readline, version); // Should add code to chop off any tag first //int ndex = readline.Find("name"); //textbox->AppendText(text.Format("Base file version %d\n", version)); //textbox->AppendText(text.Format("Readline %s\n", readline)); namestring = readline.Mid(readline.Find("name")); //textbox->AppendText(text.Format("Name string %s\n", namestring)); gname = ParseString(&namestring, 'e'); gname.Replace("_", " "); if(textbox) textbox->AppendText(text.Format("gname %s\n", gname)); graph = GetGraphFromName(gname); if(graph) graph->LoadDat(readline, version); } //graphstore[i].LoadDat(readline, version); if(infile.End()) break; readline = infile.ReadLine(); i++; } infile.Close(); // Read graphbase entries /* while(!readline.IsEmpty()) { graphstore[i].diagbox = mainwin->diagbox; graphstore[i].LoadDat(readline, version); if(infile.End()) break; readline = infile.ReadLine(); i++; } infile.Close(); */ }
void GraphDat::LoadDat(wxString data, int version) // Not in use, see GraphBase::BaseLoad - now in use { wxString readline, numstring, stringdat; long numdat; long red, green, blue; //int version; //if(diagbox) diagbox->Write(data + '\n'); readline = data.AfterFirst('f'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToDouble(&xfrom); readline = readline.AfterFirst('t'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToDouble(&xto); readline = readline.AfterFirst('f'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToDouble(&yfrom); readline = readline.AfterFirst('t'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToDouble(&yto); readline = readline.AfterFirst('l'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToLong(&numdat); xlabels = numdat; readline = readline.AfterFirst('s'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToDouble(&xstep); readline = readline.AfterFirst('m'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToLong(&numdat); xtickmode = numdat; readline = readline.AfterFirst('l'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToLong(&numdat); ylabels = numdat; readline = readline.AfterFirst('s'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToDouble(&ystep); readline = readline.AfterFirst('m'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToLong(&numdat); ytickmode = numdat; readline = readline.AfterFirst('c'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToLong(&numdat); colour = numdat; readline = readline.AfterFirst('b'); readline.Trim(false); numstring = readline.BeforeFirst(' '); numstring.ToLong(&red); readline = readline.AfterFirst(' '); numstring = readline.BeforeFirst(' '); numstring.ToLong(&green); readline = readline.AfterFirst(' '); numstring = readline.BeforeFirst(' '); numstring.ToLong(&blue); strokecolour = wxColour(red, green, blue); if(version > 0) { xshift = ParseDouble(&readline, 's'); xunitscale = ParseDouble(&readline, 'u'); plotstroke = ParseDouble(&readline, 's'); //if(diagbox) diagbox->Write(readline + '\n'); gname = ParseString(&readline, 'e'); gname.Replace("_", " "); xtag = ParseString(&readline, 'g'); xtag.Replace("_", " "); ytag = ParseString(&readline, 'g'); ytag.Replace("_", " "); } if(version > 2) { xplot = ParseDouble(&readline, 'p'); yplot = ParseDouble(&readline, 'p'); labelfontsize = ParseDouble(&readline, 'f'); clipmode = ParseLong(&readline, 'm'); } if(version > 3) type = ParseLong(&readline, 'e'); if(version > 4) { xunitdscale = ParseDouble(&readline, 'd'); xsample = ParseDouble(&readline, 'm'); } }
vector<CLogModel*> CHistoryItemLogParser::ParseLog(long& lPosition, long lLength, char* pBuffer) { map<long long,string> mapHostMacDict; string strFormatLog; stringstream strErrorMess; int iZbxServerId, iValueType, iMaintenance; string strHost, strKey_, strHostName, strIfAddress, strZbIpAddress, strSerialNumber; string strTemp; string strValue; HostInfo tagHostInfo; long long lItemId, lClock, lHostId, lServerId; vector<CLogModel*> vtHistoryItemModelPtr; while (lPosition < lLength) { // ResetHostInfo(tagHostInfo); // Init database fields lClock = iZbxServerId = lHostId = lItemId = iValueType = lServerId = iMaintenance = 0; strKey_ = strValue = strHost = strHostName = strIfAddress = strZbIpAddress = strSerialNumber = ""; CLogModel* pLogModel = RegisterModel(); //Parse Clock lClock = ParseLong((const char*)pBuffer, lPosition, lLength); //Parse ServerId iZbxServerId = ParseInt((const char*)pBuffer, lPosition, lLength); //Parse HostId lHostId = ParseLong((const char*)pBuffer, lPosition, lLength); // Calculate ServerId lServerId = ((lHostId - 10000) * 256) + iZbxServerId; //Parse Hostname strTemp = GetBlock((const char*)pBuffer, lPosition, lLength); if(strTemp.compare("") != 0) { strHostName = strTemp; strHostName = CUtilities::ReplaceBlockBracket(strHostName); strHost = strHostName; } //Parse zb IP Address strTemp = GetBlock((const char*)pBuffer, lPosition, lLength); if(strTemp.compare("") != 0) { strIfAddress = strTemp; strIfAddress = CUtilities::ReplaceBlockBracket(strIfAddress); strZbIpAddress = strIfAddress; } //Parse Maintenance Status iMaintenance = ParseInt((const char*)pBuffer, lPosition, lLength); //Parse ItemId lItemId = ParseLong((const char*)pBuffer, lPosition, lLength); //Parse Key_ strKey_ = GetItemKey((const char*)pBuffer, lPosition, lLength); //Parse Value Type iValueType = ParseInt((const char*)pBuffer, lPosition, lLength); //Parse Value if (strKey_.compare(SYSTEM_INFO) == 0 || strKey_.compare(VB_SYSTEM_INFO) == 0 || strKey_.compare(OS_INFO) == 0) { try { //ParseSystemInfo((const char*)pBuffer, lPosition, lLength, lServerId, mapHostMacDict, tagHostInfo); strValue = GetValueBlock((const char*)pBuffer, lPosition, lLength); } catch(exception& ex) { strErrorMess << ex.what() << " " << __FILE__ << " " << __LINE__; strFormatLog = CUtilities::FormatLog(ERROR_MSG, "CHistoryItemLogParser", "ParseLog", strErrorMess.str()); CUtilities::WriteErrorLog(strFormatLog); } } else if (strKey_.compare(SDK_READ_TEXT) == 0 || strKey_.compare(SDK_READ_TEXT_LINUX) == 0) { strTemp = GetToken((const char*)pBuffer, lPosition, lLength); if (strTemp.compare("") != 0) { strValue = strTemp; strSerialNumber = strValue; strSerialNumber.erase(std::find_if(tagHostInfo.strSerialNumber.rbegin(), tagHostInfo.strSerialNumber.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), tagHostInfo.strSerialNumber.end()); } } else strValue = GetItemValue((const char*)pBuffer, lPosition, lLength); CHistoryItemModel *pHistoryItemModel = dynamic_cast<CHistoryItemModel*>(pLogModel); pHistoryItemModel->SetItemId(lItemId); pHistoryItemModel->SetKey_(strKey_); pHistoryItemModel->SetValueType(iValueType); pHistoryItemModel->SetValue(strValue); pHistoryItemModel->SetServerId(lServerId); pHistoryItemModel->SetZabbixServerId(iZbxServerId); pHistoryItemModel->SetHostId(lHostId); pHistoryItemModel->SetSerialNumber(strSerialNumber); pHistoryItemModel->SetHost(strHost); pHistoryItemModel->SetHostName(strHostName); pHistoryItemModel->SetZbIpAddress(strZbIpAddress); pHistoryItemModel->SetMaintenance(iMaintenance); pHistoryItemModel->SetClock(lClock); if (ExtractData(pHistoryItemModel)) { vtHistoryItemModelPtr.push_back(pHistoryItemModel); } else { delete pHistoryItemModel; } } return vtHistoryItemModelPtr; }