sp<Retval> MonPacket::parseLine(String& sLine){ sp<Retval> retval; Regexp b("^[\\s]*([\\S]+):[\\s]*([\\S\\s]+)"); if( DFW_RET(retval, b.regexp(sLine.toChars())) ) return DFW_RETVAL_D(retval); String sName; String sTemp; sName.set(b.getMatch(1), b.getMatchLength(1)); sTemp.set(b.getMatch(2), b.getMatchLength(2)); //face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed //eno16777736: 43582102 237978 0 495 0 0 0 0 4023838 47391 0 0 0 0 0 0 //lo: 6879295 64596 0 0 0 0 0 0 6879295 64596 0 0 0 0 0 0 if( sName.equals("lo") ) return NULL; int c = 0; String sVal; const char* p = sTemp.toChars(); do{ if( (*p) == '\0' ) break; if( ((*p)==' ') || ((*p)=='\t') ){ p++; continue; } const char* b = ::strstr(p, " "); if( !b ) { sVal.set(p); }else{ sVal.set(p, b-p); } p += sVal.length(); if( N_R_BYTES == c ) { m_rbytes += Long::parseLong(sVal); }else if( N_R_PACKETS == c ) { m_rpackets += Long::parseLong(sVal); }else if( N_R_ERRS == c ) { m_rerrs += Long::parseLong(sVal); }else if( N_T_BYTES == c ) { m_tbytes += Long::parseLong(sVal); }else if( N_T_PACKETS == c ) { m_tpackets += Long::parseLong(sVal); }else if( N_T_ERRS == c ) { m_terrs += Long::parseLong(sVal); } c++; }while(true); return NULL; }
String String::token(const char *delim, size_t offset) { char *ptr = getText(); size_t len = getLength(); size_t chars = 0; String result; bool found = false; if(offset >= len) return result; len -= offset; ptr += offset; while(chars < len) { if(strchr(delim, ptr[chars])) { found = true; break; } ++chars; } if(!chars && found) erase(offset, 1); if(!chars) return result; result.set(ptr, chars); if(found) ++chars; erase(offset, chars); return result; }
sp<Retval> MonDiskstats::readData(){ sp<Retval> retval; String sContents; String sLine; if( DFW_RET(retval, File::contents(sContents, source_path())) ) return DFW_RETVAL_D(retval); if( sContents.length()==0 ) return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0 ,"Has not contents at %s", source_path()); unsigned len; const char* lp; const char* p = sContents.toChars(); do{ if( p == NULL ) break; if( (lp = strstr(p, "\n")) == NULL ) break; if( (len = lp - p) == 0 ) break; sLine.set(p, len); p += len + 1; if( DFW_RET(retval, parseLine(sLine)) ){ // FIXME: printf("%s\n", retval->dump().toChars()); } }while(true); return NULL; }
//----------------------------------------- void HTTP::getAuthUserPass(char *user, char *pass) { if (arg) { char *s = stristr(arg,"Basic"); if (s) { while (*s) if (*s++ == ' ') break; String str; str.set(s,String::T_BASE64); str.convertTo(String::T_ASCII); s = strstr(str.cstr(),":"); if (s) { *s = 0; if (user) strcpy(user,str.cstr()); if (pass) strcpy(pass,s+1); } } } }
String String::truncate(const char* szText, int nLen, const char* szTail) { String sHead; String sText = szText; String sTail = szTail; int nBytes = UTF8_ByteLen(sText, nLen - UTF8_CharLen(sTail)); sHead.set(sText.c_str(), nBytes); sHead += sTail; return sHead; }
void ColorHSV::get(String& s) const { char temp[10]; sprintf(&temp[0], "%x%x%x", (short)hue_, (unsigned char)saturation_, (unsigned char)value_); s.set(&temp[0]); }
sp<Retval> MonPacket::parseTitle_l(sp<String>& s , int* all, int* bytes, int* packets, int* errs) { int find = 0; int c = 0; String sVal; const char* p = s->toChars(); do{ if( (*p) == '\0' ) { break; } if( ((*p)==' ') || ((*p)=='\t') ){ p++; continue; } const char* b = ::strstr(p, " "); if( !b ) { sVal.set(p); }else{ sVal.set(p, b-p); } p += sVal.length(); //bytes packets errs drop fifo frame compressed multicast //bytes packets errs drop fifo colls carrier compressed if( sVal.equals("bytes") ){ *bytes = c; find++; }else if( sVal.equals("packets") ){ *packets = c; find++; }else if( sVal.equals("errs") ){ *errs = c; find++; } c++; }while(true); if( find == 3 ){ *all = c; return NULL; } return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0 , "Not find need format (%s)", source_path()); }
static String *join(String a,String b) { String *n = new String; size_t totalChar= len(a.get())+len(b.get())+1; char d[totalChar]; concatenate(d, a.get()); concatenate(d+len(d), b.get()); n->set(d); return n; }
void SocketMessage::getPayload(String &msg) const { if (!payload) { throw NoDataAvailableException(); } if (payload_type==1 || payload_type==Variant::TYPE_STRING) { msg.set((const char*)payload,payload_size); return; } throw DataInOtherFormatException(); }
String String::operator+(const char *s) { String tmp; if(str && str->text) tmp.set(str->text); if(s && *s) tmp.add(s); return tmp; }
String String::lfill(Uint32 nlen) { if (len >= nlen) return right(nlen); String s; s.set(spaces, nlen - len); s.append(msg, len); return s; }
extern C void itoa(char *buffer, int divisor, int number) { String s; Number::Base base = Number::Dec; switch (divisor) { case 10: base = Number::Dec; break; case 16: base = Number::Hex; break; } s.set(number, base, buffer); }
Function::ReturnValue sci_inspectorGetFunctionList(typed_list &in, int _iRetCount, typed_list &out) { if (in.size() != 0) { Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "inspectorGetFunctionList", 0); return Function::Error; } symbol::Context* pC = symbol::Context::getInstance(); std::list<symbol::Symbol> funcName; int size = pC->getFunctionList(funcName, L""); String* pOut = new String(size, 4); int i = 0; for (auto it : funcName) { types::Callable* pCall = pC->get(it)->getAs<types::Callable>(); //Function name pOut->set(i, 0, pCall->getName().c_str()); pOut->set(i, 1, pCall->getModule().c_str()); pOut->set(i, 2, pCall->getTypeStr().c_str()); if (pCall->isMacroFile()) { pOut->set(i, 3, pCall->getAs<types::MacroFile>()->getMacro() == NULL ? L"false" : L"true"); } else { pOut->set(i, 3, L""); } ++i; } out.push_back(pOut); return Function::OK; }
void Token::getName(int token, String &dest, const DFA *dfa) { dest.clear(); static const char *typeNames[] = { "T_EOF", "T_UNKNOWN", }; if (token >= T_TOKEN_TYPES_START && token < T_TOKEN_TYPES_END) { dest.set(typeNames[token - T_TOKEN_TYPES_START]); } else if (dfa != 0) { dfa->getTokenName(token, dest); } }
mxArray *mxCreateCharArray(int ndim, const int *dims) { if (ndim == 0 || ndim == 1) { ndim = 2; } String *ptr = new String(ndim, (int *)dims); int size = ptr->getSize(); for (int i = 0; i < size; ++i) { ptr->set(i, L""); } return (mxArray *)ptr; }
static String UnitTest_GetWindowText(HWND hWnd) { String text; int len= ::GetWindowTextLength(hWnd); if (len > 0) { Flexbuf<TCHAR> buf(len + 1); if (buf != 0) { len= ::GetWindowText(hWnd, buf, len+1); if (len > 0) { text.set(buf, len); } } } return text; }
String mono_to_utf16_string(MonoString *p_mono_string) { int len = mono_string_length(p_mono_string); String ret; if (len == 0) return ret; ret.resize(len + 1); ret.set(len, 0); CharType *src = (CharType *)mono_string_chars(p_mono_string); CharType *dst = &(ret.operator[](0)); for (int i = 0; i < len; i++) { dst[i] = src[i]; } return ret; }
String& String::makeTrailingSlash(const char* szAppend) { #if defined(WIN32) if (!endsWith("\\") && !endsWith("/")) { #else if (!endsWith("/")) { #endif String sAppend; if (szAppend != 0) { sAppend = szAppend; } else { sAppend = filenamePathSeparator(); } append(sAppend); } return *this; } String String::reverse(const char* szText) { String sText = szText; String sReverse; int nLength = sText.bytes(); Flexbuf<char> buf(nLength); char* p = (char*) sText.c_str(); char* q = (char*) buf + nLength; while (*p != 0) { int n = UTF8_CharSize(p); q -= n; switch (n) { case 3: *q++ = *p++; case 2: *q++ = *p++; case 1: *q++ = *p++; } q -= n; } sReverse.set((char*) buf, nLength); return sReverse; }
sp<Retval> MonPacket::readData(){ sp<Retval> retval; String sContents; String sLine; if( DFW_RET(retval, File::contents(sContents, source_path())) ) return DFW_RETVAL_D(retval); if( sContents.length()==0 ) return DFW_RETVAL_NEW_MSG(DFW_ERROR, 0 ,"Has not contents at %s", source_path()); unsigned len; const char* lp; const char* p = sContents.toChars(); int round = 0; do{ if( p == NULL ) break; if( (lp = strstr(p, "\n")) == NULL ) break; if( (len = lp - p) == 0 ) break; sLine.set(p, len); p += len + 1; if( round == 0 ){ }else if( round == 1 && DFW_RET(retval, parseTitle(sLine)) ){ return DFW_RETVAL_D(retval); }else if( round > 1 && DFW_RET(retval, parseLine(sLine)) ){ return DFW_RETVAL_D(retval); } round++; }while(true); return NULL; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char tmpURL[8192]; tmpURL[0]=0; char *chanURL=NULL; iniFileName.set(".\\peercast.ini"); // off by default now showGUI = false; if (strlen(lpCmdLine) > 0) { char *p; if ((p = strstr(lpCmdLine,"-inifile"))!=NULL) iniFileName.setFromString(p+8); if (strstr(lpCmdLine,"-zen")) showGUI = false; if (strstr(lpCmdLine,"-multi")) allowMulti = true; if (strstr(lpCmdLine,"-kill")) killMe = true; if ((p = strstr(lpCmdLine,"-url"))!=NULL) { p+=4; while (*p) { if (*p=='"') { p++; break; } if (*p != ' ') break; p++; } if (*p) strncpy(tmpURL,p,sizeof(tmpURL)-1); } } // get current path { exePath = iniFileName; char *s = exePath.cstr(); char *end = NULL; while (*s) { if (*s++ == '\\') end = s; } if (end) *end = 0; } if (strnicmp(tmpURL,"peercast://",11)==0) { if (strnicmp(tmpURL+11,"pls/",4)==0) chanURL = tmpURL+11+4; else chanURL = tmpURL+11; showGUI = false; } MSG msg; HACCEL hAccelTable; // Initialize global strings //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING); strcpy(szTitle,"PeerCast"); strcpy(szWindowClass,"PeerCast"); if (!allowMulti) { HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass); if (GetLastError() == ERROR_ALREADY_EXISTS) { HWND oldWin = FindWindow(szWindowClass,NULL); if (oldWin) { if (killMe) { SendMessage(oldWin,WM_DESTROY,0,0); return 0; } if (chanURL) { COPYDATASTRUCT copy; copy.dwData = WM_PLAYCHANNEL; copy.cbData = strlen(chanURL)+1; // plus null term copy.lpData = chanURL; SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©); }else{ if (showGUI) SendMessage(oldWin,WM_SHOWGUI,0,0); } } return 0; } } if (killMe) return 0; MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) return FALSE; peercastInst = new MyPeercastInst(); peercastApp = new MyPeercastApp(); peercastInst->init(); if (chanURL) { ChanInfo info; servMgr->procConnectArgs(chanURL,info); chanMgr->findAndPlayChannel(info,false); } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE); // setup menu notifes int mask = peercastInst->getNotifyMask(); if (mask & ServMgr::NT_PEERCAST) CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND); if (mask & ServMgr::NT_BROADCASTERS) CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND); if (mask & ServMgr::NT_TRACKINFO) CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); peercastInst->saveSettings(); peercastInst->quit(); return msg.wParam; }
void GUITextBox::setupText(int type, char Char) { GUIFont *font = GUIFontManager::getFont(label.getFontIndex()); const int *spaces = font ? font->getFontObject()->getCharHorizontalGlyphs() : NULL, length = label.getString().getLength(); String temp; int start = windowBounds.x + padding.x, index = 0; if (!spaces) return; for (int t = 0; t < length; t++) { if (blinkerPosition > start) { index++; start += spaces[label.getCharString()[t]]; } } if (type == INSERT_CHAR) { if (index != length && length) { String leftSide; leftSide.set(label.getCharString(), index); leftSide += Char; temp.set(label.getCharString() + index, length - index); label.setString(leftSide + temp); } else { temp = label.getString(); temp += Char; label.setString(temp); } blinkerPosition = blinkerPosition + GUIFontManager::getCharacterWidth(Char, font); } if (type == BACKSPACE_DELETE && (blinkerPosition != windowBounds.x + padding.x)) { if (index != length) { String leftSide; setupBlinker(blinkerPosition - GUIFontManager::getCharacterWidth(label.getCharString()[index -1], label.getFontIndex())); leftSide.set(label.getCharString(), index - 1); temp.set(label.getCharString() + index, length - index); label.setString(leftSide + temp); return; } setupBlinker(blinkerPosition - GUIFontManager::getCharacterWidth(label.getCharString()[length -1], font)); temp.set(label.getCharString(), length - 1); if (temp.getLength()) label.setString(temp); else { label.clear(); blinkerPosition = windowBounds.x + padding.x; } } if (type == SIMPLE_DELETE && length) { if ((blinkerPosition == windowBounds.x + padding.x) && (length == 1)) { label.clear(); return; } if (index < length) { String leftSide; leftSide.set(label.getCharString(), index); temp.set(label.getCharString() + index + 1, length - index - 1); label.setString(leftSide + temp); } } if (type == PARSE_VISIBLE) textEndIndex = font->getFontObject()->getMaxFittingLength(label.getString(), getWidth()); }
void PFPFile::load(FileObject &ff) /*!\brief PFP-File laden * * Mit dieser Funktion wird ein PFP-File in die Klasse geladen. Dabei wird zuerst der Header geladen * und überprüft, ob es sich um ein gültiges PFP-File handelt. Dann wird die virtuelle Funktion * PFPFile::LoadRequest mit ID, Haupt- und Unterversion als Parameter aufgerufen. Liefert diese * nicht true (1) zurück, wird der Ladevorgang abgebrochen. Andernfalls wird fortgeführt * und geprüft, ob der * Datenbereich komprimiert ist und gegebenenfalls dekomprimiert. Erst danach werden die * einzelnen Chunks eingelesen. Kommt es dabei zu Fehlern durch ungültige Chunks, werden diese * ignoriert und die Funktion gibt den Fehlercode 434 zurück. * * \param ff Pointer auf eine CFile-Klasse, mit der die einzulesende Datei geöffnet wurde. * \returns Konnte die Datei fehlerfrei eingelesen werden, gibt die Funktion true (1) zurück, * im Fehlerfall false (0). Ein entsprechender Fehlercode wird gesetzt. * * \remarks * Vor dem Laden der Datei wird die Funktion PFPFile::Clear aufgerufen, so dass eventuell vorher * vorhandene Daten verloren gehen. * * \since Version 6.1.0 */ { const char *p; try { p=ff.map(0,24); } catch (OverflowException &) { throw InvalidFormatException(); } if (strncmp(p,"PFP-File",8)!=0) throw InvalidFormatException(); if (Peek8(p+8)!=3) throw InvalidFormatException(); size_t z,fsize; // Wir haben ein gültiges PFP-File, aber dürfen wir es auch laden? char tmpid[5]; tmpid[4]=0; strncpy(tmpid,p+10,4); int t1,t2; t1=Peek8(p+15); t2=Peek8(p+14); if (!loadRequest(tmpid,t1,t2)) { throw AccessDeniedByInstanceException(); } clear(); id.set(p+10,4); mainversion=Peek8(p+15); subversion=Peek8(p+14); comp=(Compression::Algorithm)Peek8(p+16); size_t hsize=Peek8(p+9); char *u=NULL; if (comp) { p=(char*)ff.map(hsize,8); if (!p) throw ReadException(); size_t sizeunk=Peek32(p); size_t sizecomp=Peek32(p+4); p=ff.map(hsize+8,sizecomp); if (!p) throw ReadException(); u=(char*)malloc(sizeunk+1); if (!u) throw OutOfMemoryException(); size_t dstlen=sizeunk; Compression c; try { c.init(comp); c.uncompress(u,&dstlen,p,sizecomp); } catch (...) { free(u); clear(); throw; } if (dstlen!=sizeunk) { free(u); clear(); throw DecompressionFailedException(); } u[dstlen]=0; p=u; fsize=dstlen; } else { p=ff.map(); p+=hsize; fsize=ff.size()-hsize; } // Wir haben nun den ersten Chunk ab Pointer p z=0; String Chunkname; try { size_t size=0; while ((z+=size)<fsize) { size=Peek32(p+z+4); if (strncmp(p+z,"ENDF",4)==0) break; if (!size) break; // Falls z+size über das Ende der Datei geht, stimmt mit diesem Chunk was nicht if (z+size>fsize) break; PFPChunk *chunk=new PFPChunk; if (!chunk) throw OutOfMemoryException(); Chunkname.set(p+z,4); chunk->setName(Chunkname); chunk->setData(p+z+8,size-8); addChunk(chunk); } } catch (...) { if (u) free(u); clear(); throw; } if (u) free(u); }
String* String::clone() { String *pstClone = new String(getDims(), getDimsArray()); pstClone->set(m_pRealData); return pstClone; }
/*--------------------------------------------------------------------------*/ Function::ReturnValue sci_basename(typed_list &in, int _iRetCount, typed_list &out) { int iExpand = 1; int iConvert = 1; if (in.size() < 1 || in.size() > 3) { Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "basename", 1, 3); return Function::Error; } if (_iRetCount != 1) { Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "basename", 1); return Function::Error; } if (in.size() > 2) { if (in[2]->isBool() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 3); return Function::Error; } if (in[2]->getAs<types::Bool>()->getSize() != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 3); return Function::Error; } iExpand = in[2]->getAs<types::Bool>()->get()[0]; } if (in.size() > 1) { if (in[1]->isBool() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 2); return Function::Error; } if (in[1]->getAs<types::Bool>()->getSize() != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 2); return Function::Error; } iConvert = in[1]->getAs<types::Bool>()->get()[0]; } if (in[0]->isDouble() && in[0]->getAs<Double>()->isEmpty()) { out.push_back(Double::Empty()); return Function::OK; } if (in[0]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: A string matrix expected.\n"), "basename", 1); return Function::Error; } String* pS = in[0]->getAs<types::String>(); String* pOut = new String(pS->getRows(), pS->getCols()); for (int i = 0 ; i < pS->getSize() ; i++) { wchar_t* base = basenameW(pS->get(i), (BOOL)iExpand); pOut->set(i, base); FREE(base); } out.push_back(pOut); return Function::OK; //SciErr sciErr; //BOOL flag = TRUE; /* default */ //BOOL flagexpand = TRUE; /* default */ //int *piAddressVarOne = NULL; //wchar_t **pStVarOne = NULL; //int *lenStVarOne = NULL; //int iType1 = 0; //int m1 = 0, n1 = 0; //wchar_t **pStResult = NULL; //int i = 0; ///* Check Input & Output parameters */ //CheckRhs(1,3); //CheckLhs(1,1); //if (Rhs > 2) //{ // int *piAddressVarThree = NULL; // int *piData = NULL; // int iType3 = 0; // int m3 = 0, n3 = 0; // sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType3); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if (iType3 != sci_boolean) // { // Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3); // return 0; // } // sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarThree, &m3, &n3, &piData); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // sciErr = getVarDimension(pvApiCtx, piAddressVarThree, &m3, &n3); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if ( (m3 != n3) && (n3 != 1) ) // { // Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3); // return 0; // } // flagexpand = piData[0]; //} //if (Rhs > 1) //{ // int *piAddressVarTwo = NULL; // int *piData = NULL; // int iType2 = 0; // int m2 = 0, n2 = 0; // sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if (iType2 != sci_boolean) // { // Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2); // return 0; // } // sciErr = getVarDimension(pvApiCtx, piAddressVarTwo, &m2, &n2); // if ( (m2 != n2) && (n2 != 1) ) // { // Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2); // return 0; // } // sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarTwo, &m2, &n2, &piData); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // flag = piData[0]; //} //sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); //if(sciErr.iErr) //{ // printError(&sciErr, 0); // return 0; //} //sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); //if(sciErr.iErr) //{ // printError(&sciErr, 0); // return 0; //} //if (iType1 == sci_matrix) //{ // sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // if ( (m1 == n1) && (m1 == 0) ) // { // sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, NULL); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // LhsVar(1) = Rhs + 1; // C2F(putlhsvar)(); // } // else // { // Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1); // } //} //else if (iType1 == sci_strings) //{ // int i = 0; // sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1)); // if (lenStVarOne == NULL) // { // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // // get lenStVarOne value // sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); // if(sciErr.iErr) // { // freeArrayOfWideString(pStVarOne, m1 * n1); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // printError(&sciErr, 0); // return 0; // } // pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1)); // if (pStVarOne == NULL) // { // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // for (i = 0; i < (m1 * n1); i++) // { // pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1)); // if (pStVarOne[i] == NULL) // { // freeArrayOfWideString(pStVarOne, m1 * n1); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // } // // get pStVarOne // sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne); // if(sciErr.iErr) // { // freeArrayOfWideString(pStVarOne, m1 * n1); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // printError(&sciErr, 0); // return 0; // } // pStResult = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1)); // if (pStResult == NULL) // { // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // Scierror(999,_("%s: Memory allocation error.\n"),fname); // return 0; // } // for (i=0;i< m1 * n1; i++) // { // pStResult[i] = basenameW(pStVarOne[i], flagexpand); // } // sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1, m1, n1, pStResult); // if(sciErr.iErr) // { // printError(&sciErr, 0); // return 0; // } // LhsVar(1) = Rhs + 1; // C2F(putlhsvar)(); // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;} // freeArrayOfWideString(pStResult, m1 * n1); // freeArrayOfWideString(pStVarOne, m1 * n1); //} //else //{ // Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1); //} //return 0; }
bool TestCppBase::TestString() { // constructors { VS(String(15).c_str(), "15"); VS(String(-15).c_str(), "-15"); VS(String(int64_t(12345678912345678LL)).c_str(), "12345678912345678"); VS(String(int64_t(-12345678912345678LL)).c_str(), "-12345678912345678"); VS(String(5.603).c_str(), "5.603"); VS(String("test").c_str(), "test"); VS(String(String("test")).c_str(), "test"); } // informational { VERIFY(String().isNull()); VERIFY(!String("").isNull()); VERIFY(String().empty()); VERIFY(String("").empty()); VERIFY(!String("test").empty()); VERIFY(String().size() == 0); VERIFY(String().length() == 0); VERIFY(String("").size() == 0); VERIFY(String("").length() == 0); VERIFY(String("test").size() == 4); VERIFY(String("test").length() == 4); VERIFY(!String("2test").isNumeric()); VERIFY(!String("2test").isInteger()); VERIFY(!String("2test").isValidVariableName()); VERIFY(!String("test").isNumeric()); VERIFY(!String("test").isInteger()); VERIFY(String("test").isValidVariableName()); VERIFY(String("23").isNumeric()); VERIFY(String("23").isInteger()); VERIFY(String("23.3").isNumeric()); VERIFY(!String("23.3").isInteger()); } // operators { String s; s = "test1"; VS(s.c_str(), "test1"); s = String("test2"); VS(s.c_str(), "test2"); s = Variant("test3"); VS(s.c_str(), "test3"); s = String("a") + "b"; VS(s.c_str(), "ab"); s = String("c") + String("d"); VS(s.c_str(), "cd"); s += "efg"; VS(s.c_str(), "cdefg"); s += String("hij"); VS(s.c_str(), "cdefghij"); s = String("\x50\x51") | "\x51\x51"; VS(s.c_str(), "\x51\x51"); s = String("\x50\x51") & "\x51\x51"; VS(s.c_str(), "\x50\x51"); s = String("\x50\x51") ^ "\x51\x51"; VS(s.c_str(), "\x01"); s = "\x50\x51"; s |= "\x51\x51"; VS(s.c_str(), "\x51\x51"); s = "\x50\x51"; s &= "\x51\x51"; VS(s.c_str(), "\x50\x51"); s = "\x50\x51"; s ^= "\x51\x51"; VS(s.c_str(), "\x01"); s = "\x50\x51"; s = ~s; VS(s.c_str(), "\xAF\xAE"); } // manipulations { String s = StringUtil::ToLower("Test"); VS(s.c_str(), "test"); } // conversions { VERIFY(!String().toBoolean()); VERIFY(String("123").toBoolean()); VERIFY(String("123").toByte() == 123); VERIFY(String("32767").toInt16() == 32767); VERIFY(String("1234567890").toInt32() == 1234567890); VERIFY(String("123456789012345678").toInt64() == 123456789012345678LL); VERIFY(String("123.45").toDouble() == 123.45); } // offset { VS(String("test").rvalAt(2).c_str(), "s"); String s = "test"; s.set(2, String("")); VS(s, String("te\0t", 4, AttachLiteral)); s.set(2, String("zz")); VS(s, "tezt"); s.set(5, String("q")); VS(s, "tezt q"); String s2 = s; // test copy-on-write s.set(1, String("3")); VS(s, "t3zt q"); VS(s2, "tezt q"); } return Count(true); }
/*--------------------------------------------------------------------------*/ Function::ReturnValue sci_mgetl(typed_list &in, int _iRetCount, typed_list &out) { int iFileID = 0; int iErr = 0; bool bCloseFile = false; int iLinesExcepted = -1; int iLinesRead = -1; wchar_t** wcReadedStrings = NULL; if (in.size() < 1 || in.size() > 2) { Scierror(77, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mgetl" , 1, 2); return Function::OK; } if (in.size() == 2) { //number of lines if (in[1]->isDouble() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), "mgetl", 2); return Function::Error; } if (in[1]->getAs<Double>()->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: An integer value expected.\n"), "mgetl", 2); return Function::Error; } if (in[1]->getAs<Double>()->get(0) != (int)in[1]->getAs<Double>()->get(0)) { Scierror(999, _("%s: Wrong value for input argument #%d: An integer value expected.\n"), "mgetl", 2); return Function::Error; } iLinesExcepted = static_cast<int>(in[1]->getAs<Double>()->get(0)); } if (in[0]->isDouble() && in[0]->getAs<Double>()->getSize() == 1) { iFileID = static_cast<int>(in[0]->getAs<Double>()->get(0)); } else if (in[0]->isString() && in[0]->getAs<types::String>()->getSize() == 1) { wchar_t *expandedFileName = expandPathVariableW(in[0]->getAs<types::String>()->get(0)); iErr = mopen(expandedFileName, L"rt", 0, &iFileID); if (iErr) { char* pst = wide_string_to_UTF8(expandedFileName); switch (iErr) { case MOPEN_NO_MORE_LOGICAL_UNIT: Scierror(66, _("%s: Too many files opened!\n"), "mgetl"); break; case MOPEN_CAN_NOT_OPEN_FILE: Scierror(999, _("%s: Cannot open file %s.\n"), "mgetl", pst); break; case MOPEN_NO_MORE_MEMORY: Scierror(999, _("%s: No more memory.\n"), "mgetl"); break; case MOPEN_INVALID_FILENAME: Scierror(999, _("%s: invalid filename %s.\n"), "mgetl", pst); break; default: //MOPEN_INVALID_STATUS Scierror(999, _("%s: invalid status.\n"), "mgetl"); break; } FREE(pst); return Function::Error; } FREE(expandedFileName); bCloseFile = true; } else { //Error Scierror(999, _("%s: Wrong type for input argument #%d: a String or Integer expected.\n"), "mgetl", 1); return Function::Error; } switch (iFileID) { case 0: // stderr case 6: // stdout Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mgetl", iFileID); return types::Function::Error; default : { types::File* pFile = FileManager::getFile(iFileID); // file opened with fortran open function if (pFile == NULL || pFile->getFileType() == 1) { Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mgetl", iFileID); return types::Function::Error; } wcReadedStrings = mgetl(iFileID, iLinesExcepted, &iLinesRead, &iErr); switch (iErr) { case MGETL_MEMORY_ALLOCATION_ERROR : break; } } } if (wcReadedStrings && iLinesRead > 0) { String *pS = new String(iLinesRead, 1); pS->set(wcReadedStrings); out.push_back(pS); freeArrayOfWideString(wcReadedStrings, iLinesRead); } else { out.push_back(types::Double::Empty()); if (wcReadedStrings) { FREE(wcReadedStrings); } } if (bCloseFile) { mclose(iFileID); } return Function::OK; }
ProcessStatus::ProcessStatus(pid_t processId) { #ifdef __linux String path = Format("/proc/%%/stat") << processId; Ref<File, Owner> file = new File(path); file->open(File::Read); Ref<LineSource, Owner> source = new LineSource(file); String line = source->readLine(); { // extract command name first, because it may contain whitespace int i0 = line->find('(') + 1, i1 = line->find(')'); commandName_ = line->copy(i0, i1); for (int i = i0; i < i1; ++i) line->set(i, 'x'); } Ref<StringList, Owner> parts = line.split(" "); processId_ = parts->at(0).toInt(); parentProcessId_ = parts->at(3).toInt(); processGroupId_ = parts->at(4).toInt(); foregroundProcessGroupId_ = parts->at(7).toInt(); /*{ int code = parts->get(6).toInt(); int major = (code >> 8) & 0xFF; int minor = (code & 0xFF) | ((code >> 20) << 8); // interpretation according to lanana.org if (major == 4) terminalName_ = Format("tty%%") << minor; else if ((136 <= major) && (major <= 143)) terminalName_ = Format("pts/%%") << minor; else if (major == 3) terminalName_ = Format("ttyp%%") << minor; }*/ loginName_ = User(FileStatus(path).ownerId()).loginName(); processStatus_ = parts->at(2)->get(0); file->close(); #else // def __linux #ifdef KERN_PROC2 // e.g. on OpenBSD size_t sz = sizeof(kinfo_proc2); struct kinfo_proc2* proc = (kinfo_proc2*)ftl::malloc(sz); mem::clr(proc, sz); int mib[] = { CTL_KERN, KERN_PROC2, KERN_PROC_PID, processId, sz, 1 }; if (::sysctl(mib, sizeof(mib)/sizeof(mib[0]), proc, &sz, NULL, 0) == -1) FTL_SYSTEM_EXCEPTION; processId_ = proc->p_pid; parentProcessId_ = proc->p_ppid; processGroupId_ = proc->p__pgid; foregroundProcessGroupId_ = proc->p_tpgid; /*const int ttyNameSize = 256; char ttyName[ttyNameSize]; terminalName_ = devname_r(proc->kp_eproc.e_tdev, S_IFCHR, ttyName, ttyNameSize);*/ loginName_ = User(proc->p_ruid).loginName(); commandName_ = proc->p_comm; processStatus_ = proc->p_stat; if (processStatus_ == SIDL) processStatus_ = 'W'; else if (processStatus_ == SRUN) processStatus_ = 'R'; #ifdef SONPROC else if (processStatus_ == SONPROC) processStatus_ = 'R'; #endif else if (processStatus_ == SSLEEP) processStatus_ = 'S'; else if (processStatus_ == SSTOP) processStatus_ = 'T'; else if (processStatus_ == SZOMB) processStatus_ = 'Z'; #ifdef SDEAD else if (processStatus_ == SDEAD) processStatus_ = 'Z'; #endif else processStatus_ = '?'; ftl::free(proc); #else // def KERN_PROC2 struct kinfo_proc* proc; int mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = processId; size_t sz = 0; if (::sysctl(mib, 4, NULL, &sz, NULL, 0) == -1) FTL_SYSTEM_EXCEPTION; proc = (kinfo_proc*)ftl::malloc(sz); mem::clr(proc, sz); if (::sysctl(mib, 4, proc, &sz, NULL, 0) == -1) FTL_SYSTEM_EXCEPTION; processId_ = proc->kp_proc.p_pid; parentProcessId_ = proc->kp_eproc.e_ppid; processGroupId_ = proc->kp_eproc.e_pgid; foregroundProcessGroupId_ = proc->kp_eproc.e_tpgid; /*const int ttyNameSize = 256; char ttyName[ttyNameSize]; terminalName_ = devname_r(proc->kp_eproc.e_tdev, S_IFCHR, ttyName, ttyNameSize);*/ loginName_ = User(proc->kp_eproc.e_pcred.p_ruid).loginName(); commandName_ = proc->kp_proc.p_comm; processStatus_ = proc->kp_proc.p_stat; if (processStatus_ == SIDL) processStatus_ = 'W'; else if (processStatus_ == SRUN) processStatus_ = 'R'; #ifdef SONPROC else if (processStatus_ == SONPROC) processStatus_ = 'R'; #endif #ifdef __MACH__ else if (processStatus_ == SSLEEP) processStatus_ = (proc->kp_proc.sigwait) ? 'S' : 'D'; #else else if (processStatus_ == SSLEEP) processStatus_ = 'S'; #endif else if (processStatus_ == SSTOP) processStatus_ = 'T'; else if (processStatus_ == SZOMB) processStatus_ = 'Z'; #ifdef SDEAD else if (processStatus_ == SDEAD) processStatus_ = 'Z'; #endif else processStatus_ = '?'; ftl::free(proc); #endif // def KERN_PROC2 #endif // def __linux }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #ifdef _DEBUG // memory leak check ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif char tmpURL[8192]; tmpURL[0]=0; char *chanURL=NULL; //VERSION_EX = 0; iniFileName.set(".\\peercast.ini"); WIN32_FIND_DATA fd; //JP-EX HANDLE hFind; //JP-EX OSVERSIONINFO osInfo; //JP-EX osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX GetVersionEx(&osInfo); if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) winDistinctionNT = true; else winDistinctionNT = false; // off by default now showGUI = false; if (strlen(lpCmdLine) > 0) { char *p; if ((p = strstr(lpCmdLine,"-inifile"))!=NULL) iniFileName.setFromString(p+8); if (strstr(lpCmdLine,"-zen")) showGUI = false; if (strstr(lpCmdLine,"-multi")) allowMulti = true; if (strstr(lpCmdLine,"-kill")) killMe = true; if ((p = strstr(lpCmdLine,"-url"))!=NULL) { p+=4; while (*p) { if (*p=='"') { p++; break; } if (*p != ' ') break; p++; } if (*p) strncpy(tmpURL,p,sizeof(tmpURL)-1); } } // get current path { exePath = iniFileName; char *s = exePath.cstr(); char *end = NULL; while (*s) { if (*s++ == '\\') end = s; } if (end) *end = 0; } if (strnicmp(tmpURL,"peercast://",11)==0) { if (strnicmp(tmpURL+11,"pls/",4)==0) chanURL = tmpURL+11+4; else chanURL = tmpURL+11; showGUI = false; } MSG msg; HACCEL hAccelTable; // Initialize global strings //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING); strcpy(szTitle,"PeerCast"); strcpy(szWindowClass,"PeerCast"); if (!allowMulti) { HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass); if (GetLastError() == ERROR_ALREADY_EXISTS) { HWND oldWin = FindWindow(szWindowClass,NULL); if (oldWin) { if (killMe) { SendMessage(oldWin,WM_DESTROY,0,0); return 0; } if (chanURL) { COPYDATASTRUCT copy; copy.dwData = WM_PLAYCHANNEL; copy.cbData = strlen(chanURL)+1; // plus null term copy.lpData = chanURL; SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)©); } else { if (showGUI) SendMessage(oldWin,WM_SHOWGUI,0,0); } } return 0; } } if (killMe) return 0; MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) return FALSE; peercastInst = new MyPeercastInst(); peercastApp = new MyPeercastApp(); peercastInst->init(); LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x"); if (peercastApp->clearTemp()) //JP-EX { DeleteFile("play.pls"); hFind = FindFirstFile("*.asx",&fd); if (hFind != INVALID_HANDLE_VALUE) { do { DeleteFile((char *)&fd.cFileName); } while (FindNextFile(hFind,&fd)); FindClose(hFind); } } if (chanURL) { ChanInfo info; servMgr->procConnectArgs(chanURL,info); chanMgr->findAndPlayChannel(info,false); } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE); // setup menu notifes int mask = peercastInst->getNotifyMask(); if (mask & ServMgr::NT_PEERCAST) CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND); if (mask & ServMgr::NT_BROADCASTERS) CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND); if (mask & ServMgr::NT_TRACKINFO) CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon); peercastInst->saveSettings(); peercastInst->quit(); return msg.wParam; }