bool pushLine(bool firstline = false) { char buf[OS_MAXINPUT]; if(!readLine(buf, getPrompt(firstline))){ return false; /* no input */ } int len = OS_STRLEN(buf); for(; len > 0 && OS_IS_SPACE(buf[len-1]); len--){ buf[len-1] = '\0'; } if(firstline && buf[0] == '='){ /* first line starts with `=' ? */ OS::String str = OS::String(this, buf+1); if(str.isEmpty()){ return false; } pushString(OS::String(this, "return ") + str); /* change it to `return' */ }else{ OS::String str = OS::String(this, buf); if(str.isEmpty()){ return false; } pushString(str); } // freeLine(b); return true; }
bool inComplete() { OS::String str = toString(-1); int lmsg = str.getLen(); const char *msg = str; if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) { pop(); return true; } return false; }
static int __glutBitmapCharacter(OS * os, int params, int, int, void*) { if(params >= 2) { if(os->getType(-params + 0) == OS_VALUE_TYPE_NUMBER) { int std_font = os->toInt(-params + 0); glutBitmapCharacter((void*)std_font, os->toInt(-params + 1)); return 0; } OS::String str = os->toString(-params + 0); glutBitmapCharacter((void*)str.toChar(), os->toInt(-params + 1)); } return 0; }
/** Set default video output. * \par Description: * Sets the default video output. * \par Note: * Applications will probably never call this. * * \param zIdentifier - Identifier of the output. * * \author Arno Klenke *****************************************************************************/ void MediaManager::SetDefaultVideoOutput( os::String zIdentifier ) { if( !m->m_bValid ) return; Message cMsg( MEDIA_SERVER_SET_DEFAULT_VIDEO_OUTPUT ); cMsg.AddString( "output", zIdentifier.str() ); m->m_cMediaServerLink.SendMessage( &cMsg ); }
bool my_isdigit(const OS::String& str) { int len = str.getLen(); for(int i = 0; i < len; i++){ if(!isdigit(str[i])){ return false; } } return len > 0; }
/* Convert the RFC822 date to time_t */ time_t convert_date( os::String cDate ) { struct tm sTime; time_t nEpoch = 0; const char *pStart; char *pEnd; pStart = cDate.c_str(); pEnd = strptime( pStart, "%a, %d %b %Y %H:%M:%S %z", &sTime ); if( pEnd > pStart ) nEpoch = mktime( &sTime ); return nEpoch; }
status_t DbxPlugin::CheckFile( const os::String cFilename ) { status_t nError = EINVAL; DBX *hDbx; hDbx = dbx_open( cFilename.c_str() ); if( hDbx != NULL ) { if( hDbx->type == DBX_TYPE_FOLDER || hDbx->type == DBX_TYPE_EMAIL ) nError = EOK; dbx_close( hDbx ); } return nError; }
uint Format_Ruby::GetNextWordLimit(const os::String &line, uint chr) { uint max=line.size(); if(chr>=max) return max; if(canContinueIdentifier(line[chr])){//in identifier while(chr<=max && canContinueIdentifier(line[chr])) ++chr; }else{//outside identifier while(chr<=max && !canContinueIdentifier(line[chr])) ++chr; } return chr; }
status_t MboxPlugin::CheckFile( const os::String cFilename ) { status_t nError = EINVAL; FILE *hMbox = fopen( cFilename.c_str(), "r" ); if( NULL == hMbox ) return EIO; char pHead[15]; const char pFromSeq[] = "\nFrom "; const char pEudoraSeq[] = { 0xa, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x53 }; fgets( pHead, 15, hMbox ); if( memcmp( pHead, &pFromSeq[1], 5 ) == 0 || memcmp( pHead, &pEudoraSeq[1], 14 ) == 0 ) nError = EOK; fclose( hMbox ); return nError; }
//TODO: this method is slightly wrong. Fix it void Format_Ruby::FindWords( const os::String &line, os::String &format ) { uint start=0, end; while(start<line.size() && (format[start]!=F_DEFAULT || !canStartIdentifier(line[start]))) ++start; end=start+1; while(end<line.size() && format[end]==F_DEFAULT && canContinueIdentifier(line[end])) ++end; while(start<line.size()){ os::String tmp=line.const_str().substr(start, end-start); int max=sizeof(keywords)/sizeof(keywords[0]); int min=0; int test=max/2; //binary search while(max-min>1){ if(!strcmp(keywords[test], tmp.c_str())) break; if(tmp<keywords[test]) max=test; else min=test; test=(max+min)/2; } if(!strcmp(keywords[test], tmp.c_str())){ for(;start<end;++start) format[start]=F_KEYWORD; } start=end+1; while(start<line.size() && (format[start]!=F_DEFAULT || !canStartIdentifier(line[start]))) ++start; end=start+1; while(end<line.size() && format[end]==F_DEFAULT && canContinueIdentifier(line[end])) ++end; } }
os::String Format_Ruby::GetIndentString( const os::String &line, bool useTabs, uint tabSize ) { if(line.size()==0) return ""; uint white; for(white=0;white<line.size();++white) if(line[white]!=' ' && line[white]!='\t') break; //TODO: ignore trailing whitespace if(line[line.size()-1]=='{' || line[line.size()-1]==':'){ os::String pad; if(useTabs) pad="\t"; else pad.resize(tabSize, ' '); return os::String(line.const_str().substr(0, white))+pad; }else return line.const_str().substr(0, white); }
status_t MboxImporter::AddMessage( os::String &cMessage ) { if( cMessage != "" ) { if( m_bDoCrLf ) { /* Convert linefeeds to CRLF pairs */ const char *pStart, *pEnd; int nLf = 0; pStart = cMessage.c_str(); while( ( pEnd = strchr( pStart, '\n' ) ) != NULL ) { nLf++; pStart = pEnd + 1; } char *pMessage = (char*)calloc( 1, cMessage.size() + nLf + 1 ); if( NULL == pMessage ) return ENOMEM; const char *pIn; char *pOut; pIn = cMessage.c_str(); pOut = pMessage; while( '\0' != *pIn ) { if( '\n' == *pIn ) *pOut++ = '\r'; *pOut++ = *pIn++; } cMessage = pMessage; free( pMessage ); } /* Add an RFC2822 terminating sequence */ cMessage += "\r\n.\r\n"; /* Create a Mailmessage and send it back down to the application along with the relevent data */ Mailmessage *pcImport = new Mailmessage( cMessage.c_str(), cMessage.size() ); Message *pcImportMessage = new Message( M_IMPORT_NEW ); pcImportMessage->AddPointer( "message", pcImport ); pcImportMessage->AddString( "folder", m_cFolder ); m_pcMessenger->SendMessage( pcImportMessage ); /* Update the progress dialog & check if the user canceled */ float vProgress = ( (double)m_nBytes / (double)m_nSize ); char zMessage[64] = { '\0' }; snprintf( zMessage, 64, "Importing message #%Ld", m_nCount++ ); m_pcDialog->Lock(); m_pcDialog->SetMessage( zMessage ); m_pcDialog->SetProgress( vProgress ); m_bRun = !m_pcDialog->IsCancelled(); m_pcDialog->Unlock(); } cMessage = ""; return EOK; }
/* This detects changes in the title, and also draws the title when appropriate. * It should be called once for each frame. */ static guchar *show_info(guchar *img, gint height, gint bpl) { gint pos, length; gchar *title; time_t now; static int prevpos; static gchar *prevtitle; static char buf[200]; static time_t start, then; static gboolean persistent = FALSE; char showinfo; /* Once per second, check for any changes in the title. Note that we * do this even for the "Never show title" setting, because a change * in the title should trigger "quiet" actions even if the title isn't * shown. */ time(&now); if (now != then) { then = now; pos = cf_position; title = (gchar*)cf_title.c_str(); /* pos = xmms_remote_get_playlist_pos(0); title = xmms_remote_get_playlist_title(0, pos);*/ if (!title) { title = "Unknown"; } if (pos != prevpos || !prevtitle || strcmp(title, prevtitle)) { /* Yes, it changed. Regenerate the info string */ prevpos = pos; if (prevtitle) free(prevtitle); prevtitle = strdup(title); sprintf(buf, "{%d} %s", pos + 1, title); start = now; /* Trigger "quiet" acctions. */ beatquiet = TRUE; } } /* If the user pressed 'i' recently, then show info for 4 seconds */ showinfo = *config.show_info; if (blurskinfo || persistent) { if (showinfo == 'A') { config.show_info = config_default_show_info; showinfo = 'N'; } else { showinfo = '4'; if (blurskinfo) { start = now; persistent = TRUE; } } blurskinfo = FALSE; } /* If not supposed to show text, then we're done */ switch (showinfo) { case 'N': /* Never show info */ return img; case '4': /* 4 second info */ if (now - start > 4) { persistent = FALSE; return img; } case 'A': /* Always show info */ break; } /* We don't want to draw onto the main image, because then the text * would leave blur trails. Most combinations of cpu_speed and * overall_effect copy the image data into a temporary buffer, but * the specific combination of cpu_speed=Fast and overall_effect=Normal * (which is very common!) normally leaves the image in the main buffer. * We need to detect this, and copy the image before we draw the text. */ if (img != img_tmp) { memcpy(img_tmp, img, img_chunks * 8); img = img_tmp; } /* draw the text */ textdraw(img, height, bpl, "Center", buf); return img; }
int main(int argc, char * argv[]) #endif { initStartTime(); printf("ObjectScript FastCGI Process Manager %s\n", OS_FCGI_VERSION); printf("%s\n", OS_COPYRIGHT); printf("%s\n", OS_OPENSOURCE); if(FCGX_Init()){ // #ifdef _MSC_VER printf("Error: initialization is failed\n"); // #endif exit(1); } int threads; { OS * os = OS::create(); #ifdef _MSC_VER const char * config_flename = "conf\\etc\\os-fcgi\\conf.os"; if(!os->isFileExist(config_flename)){ config_flename = "..\\..\\conf\\etc\\os-fcgi\\conf.os"; // os->isFileExist(config_flename); } #else const char * config_flename = "/etc/os-fcgi/conf.os"; #endif os->require(config_flename, false, 1); threads = (os->getProperty(-1, "threads"), os->popInt()); OS::String listen = (os->getProperty(-1, "listen"), os->popString(":9000")); os->release(); int listen_queue_backlog = 400; listen_socket = FCGX_OpenSocket(listen, listen_queue_backlog); if(listen_socket < 0){ printf("Error: listen address is incorrect %s\n", listen.toChar()); // log("listen_socket < 0 \n"); exit(1); } // #ifdef _MSC_VER printf("listen: %s\n", listen.toChar()); // #endif } #ifndef _MSC_VER const int MAX_THREAD_COUNT = 64; if(threads < 1){ threads = 1; }else if(threads > MAX_THREAD_COUNT){ threads = MAX_THREAD_COUNT; } printf("threads: %d\n", threads); demonize(); pthread_t id[MAX_THREAD_COUNT]; for(int i = 1; i < threads; i++){ pthread_create(&id[i], NULL, doit, NULL); } #else threads = 1; printf("threads: %d\n", threads); #endif doit(NULL); return 0; }
/* Unregister an event */ void SrvEvents::UnregisterEvent( os::String zID, int64 nProcess, int64 nTargetPort ) { /* Find parent node */ m_cLock.Lock(); SrvEventNode_s* psParent; os::String zEventName; psParent = GetParentNode( zID, zEventName ); if( psParent == NULL ) { dbprintf( "SrvEvents::UnregisterCall(): Call %s by %i not present\n", zID.c_str(), (int)nProcess ); m_cLock.Unlock(); return; } /* Find node */ SrvEventNode_s* psNode = GetNode( psParent, zEventName ); if( psNode == NULL ) { dbprintf( "SrvEvents::UnregisterCall(): Call %s by %i not present\n", zID.c_str(), (int)nProcess ); m_cLock.Unlock(); return; } /* Find event */ psNode->AddRef(); std::vector<SrvEvent_s*>::iterator i = psNode->m_cEvents.begin(); while( i != psNode->m_cEvents.end() ) { SrvEvent_s* psEvent = (*i); if( psEvent->m_nProcess == nProcess && ( nTargetPort == -1 || ( psEvent->m_nTargetPort == nTargetPort ) ) ) { /* Send notifications to the monitors */ os::Message cReply; cReply.AddBool( "event_unregistered", true ); cReply.AddString( "id", zID ); cReply.AddInt64( "target", psEvent->m_nTargetPort ); cReply.AddInt64( "token", psEvent->m_nHandlerToken ); cReply.AddInt64( "message_code", psEvent->m_nMessageCode ); cReply.AddInt64( "process", psEvent->m_nProcess ); psParent = psNode; while( psParent != NULL ) { std::vector<SrvEventMonitor_s*>::iterator j = psParent->m_cMonitors.begin(); for( ; j != psParent->m_cMonitors.end(); j++ ) { cReply.SetCode( (*j)->m_nMessageCode ); os::Messenger cLink( (*j)->m_nTargetPort, (*j)->m_nHandlerToken, -1 ); cLink.SendMessage( &cReply ); //dbprintf( "Notification %s about unregistration sent to %i\n", zID.c_str(), (int)(*j)->m_nTargetPort ); } psParent = psParent->m_psParent; } i = psNode->m_cEvents.erase( i ); delete( psEvent ); psNode->Release(); //dbprintf( "Event %s unregistered by %i\n", zID.c_str(), (int)nProcess ); } else i++; } /* Release the node */ psNode->Release(); m_cLock.Unlock(); //dbprintf( "SrvEvents::UnregisterCall(): Call %s by %i unregistered\n", zID.c_str(), (int)nProcess ); }
CodeViewContext Format_Ruby::Parse(const os::String &line, os::String &format, CodeViewContext cookie){ int oldcntx=cookie.nContext, newcntx=cookie.nContext; char c; format.resize(line.size()); for(uint a=0;a<line.size();++a){ newcntx = oldcntx & ( C_COMMENT | C_CONST ); c = line[a]; switch(line[a]){ //if found '\'' -> // if context is comment or string: ignore // if context is charconst and escape: ignore // if context is charconst and !escape: end charconst // if context is !charconst and !escape: begin charconst case '\'': if(oldcntx & (C_COMMENT | C_STRINGCONST)) break; if(oldcntx & C_CHARCONST){ if(oldcntx & C_ESCAPE){ break; }else{ newcntx &= ~C_CHARCONST; } }else{ if(!(oldcntx & C_ESCAPE)){ newcntx |= C_CHARCONST; } } break; //if found '"' -> // if context is comment or charconst: ignore // if context is string and escape; ignore // if context is string and !escape: end string // if context is !string and !escape: begin string case '"': if(oldcntx & (C_COMMENT | C_CHARCONST)) break; if(!(oldcntx & C_ESCAPE)){ if(oldcntx & C_STRINGCONST){ newcntx &= ~C_STRINGCONST; }else{ newcntx |= C_STRINGCONST; } } break; //if found '\\' -> // if context is !escape: set escape case '\\': if(!(oldcntx & C_ESCAPE)) newcntx |= C_ESCAPE; break; case '#': if(!(oldcntx & C_ESCAPE)) newcntx |= C_LINECOMMENT; break; //if found '/' -> // if context is !slash: set slash case '/': if( oldcntx & (C_COMMENT | C_CONST) ) break; newcntx |= C_SLASH; break; } if(newcntx & C_CHARCONST) format[a] = F_STRING; else if(newcntx & C_STRINGCONST) format[a] = F_STRING; else if(newcntx & C_COMMENT) format[a] = F_COMMENT; else format[a] = F_DEFAULT; //special handling of closing quotes if((oldcntx & C_STRINGCONST) && !(newcntx & C_STRINGCONST)) format[a] = F_STRING; else if((oldcntx & C_CHARCONST) && !(newcntx & C_CHARCONST)) format[a] = F_STRING; oldcntx = newcntx; } //now look for words... FindWords(line, format); if(newcntx&C_ESCAPE) return newcntx & ( C_COMMENT | C_CONST ); else return newcntx & ( C_SPANCOMMENT ); }