コード例 #1
0
ファイル: qt.cpp プロジェクト: DirtYiCE/uim
void CandidateWindow::slotStdinActivated( int fd )
{
    char buf[ 4096 ];
    char *read_buf = strdup( "" );
    int n;

    while (uim_helper_fd_readable( fd ) > 0) {
        n = read( fd, buf, 4096 - 1 );
        if ( n == 0 )
        {
            close( fd );
            exit( 1 );
        }
        if ( n == -1 )
            return ;
        buf[ n ] = '\0';
	read_buf = (char *)realloc( read_buf, strlen( read_buf ) + n + 1 );
	strcat( read_buf, buf );
    }

    QStringList msgList = QStringList::split( "\f\f", QString( read_buf ) );

    QStringList::Iterator it = msgList.begin();
    const QStringList::Iterator end = msgList.end();
    for ( ; it != end; ++it )
        strParse( ( *it ) );
    free( read_buf );
}
コード例 #2
0
ファイル: IVCfgMgr.cpp プロジェクト: fatrar/yiqiulib
bool CIVCfgMgr::GetAutoRunChannel( 
    int szChannel[_MaxAutoChannel],
    size_t& nCount )
{
    const char* pTmpStr = m_pRootEle->Attribute(_AutoRunChannel);
    if ( pTmpStr == NULL )
    {
        nCount = 0;
        return true;
    }

    StringHelp::CParseString<> strParse(pTmpStr);
    nCount = min(strParse.Count(), _MaxAutoChannel);
    for ( size_t i=0; i< nCount; ++i )
    {
        strParse.At(i, szChannel[i]);
    }
    return true;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: lalalaring/stateviewer
void load_trace_txt ( char* fname ) 
{
	std::string str, word;
	char buf[1024];

	unsigned long totalBytes = getFileSize ( fname );
	unsigned long currBytes = 0;

	FILE* fp = fopen ( fname, "rt" );
	int c;
	std::vector<std::string> changestates;
	changestates.push_back ( "x" );			// 0 = BIN_NOTUSED
	changestates.push_back ( "c" );			// 1 = BIN_CREATE
	changestates.push_back ( "u" );			// 2 = BIN_CHANGE
	changestates.push_back ( "s" );			// 3 = BIN_SWITCH
	changestates.push_back ( "-" );			// 4 = BIN_REUSE
	changestates.push_back ( "D" );

	Call cl;
	Event e;
	int lin = 0;
	int max_lin = 5000;
	std::string szstr;
	int sz;
	unsigned long cstart = 0;
	int cnum = 0;

	while (!feof(fp) && lin < max_lin) {
		
		currBytes = getFilePos ( fp );
		printf ( "%d (%.2f%%)\n", currBytes, currBytes*100.0f/totalBytes );

		fgets ( buf, 1024, fp );
		str = buf;
		int bin = 0;		
		str = strTrim ( str );

		e.name = word;
		
		if ( str.compare (0, 2, "C:") == 0 ) {
			/*word = strSplit ( str, " " );	
			word = strSplit ( str, " " );	cl.bin_id = strToI(word);
			word = strSplit ( str, " " );	cl.size = strToI(word); 
			word = strSplit ( str, " " );	cl.obj_id = strToLI(word);
			word = strSplit ( str, " " );	cl.val_id = strToLI(word);
			word = strSplit ( str, " " );	cl.name = word;
			mCalls.push_back ( cl );*/
			cnum++;			
		} else if ( str.compare ( 0, 2, "FR" ) == 0 ) {
			e.count = 1;
			for (int n=0; n < NUM_BIN; n++ ) {
				e.bin_id[n] = -1;
				e.bin_change[n] = -1;
			}			
			mEvents.push_back ( e );
		} else if ( str.compare ( 0, 2, "Dr" ) == 0 ) {
			e.count = 1;
			int bin = 0;
			word = strLeft ( str, 8 );
			str = strTrim ( str );			
			while ( str.length() > 0 ) {
				word = strSplit ( str, " " );				
				c = strExtract ( word, changestates );
				szstr = strParse ( word, "[", "]" );
				e.bin_id[bin] = strToI ( word );
				e.bin_change[bin] = c;		
				e.bin_size[bin] = strToI ( szstr );
				bin++;				
			}	
			e.call_start = cstart;
			e.call_num = cnum;
			if ( e.bin_size[BIN_DRAW] > mMaxSize ) mMaxSize = e.bin_size[BIN_DRAW];
			mEvents.push_back ( e );			
			cstart += cnum;
		}	
		
		lin++;
	}

	fclose ( fp );
}