示例#1
0
文件: script.cpp 项目: Tellus/colobot
bool CScript::ReadStack(FILE *file)
{
    int     nb;

    fRead(&nb, sizeof(int), 1, file);
    fRead(&m_ipf, sizeof(int), 1, file);
    fRead(&m_errMode, sizeof(int), 1, file);

    if ( m_botProg == 0 )  return false;
    if ( !m_botProg->RestoreState(file) )  return false;

    m_object->SetRunScript(this);
    m_bRun = true;
    m_bContinue = false;
    return true;
}
示例#2
0
CString CHSCalculate::CreateHtml(const CString& strContent, const InfoIndex* pInfoIndex)
{
	if (pInfoIndex == NULL)
	{
		return "";
	}

	// 读格式文件
	CString strPath = CGeneralHelper::GetAppPath() + _T("face\\html\\") + HTMLFORMAT_PATH;
	CFile  fRead(strPath, CFile::modeRead); 
    long flen = (long)fRead.GetLength(); 
	if (flen <= 0)
	{
		return "";
	}
	char*  pBuffer = new char[flen]; 
	fRead.Read(pBuffer,flen); 
	CString strFotmat(pBuffer, flen);
	delete[] pBuffer;
	fRead.Close();

	//////////////////////////////////////////////////////////////////////////
	// 形成html文件
	// 标题
	strFotmat.Replace(HTML_REPLACE_TITLE, pInfoIndex->m_cTitle);
	// 正文
	// 将换行符替换成<\br>
	CString strFormatContent(strContent, strContent.GetLength());
	strFormatContent.Replace("\r\n", "</br>&nbsp&nbsp");
	strFotmat.Replace(HTML_REPLACE_CONTENT, strContent);
	// 时间
	CString strTime;
	strTime.Format("%04d-%02d-%02d ", pInfoIndex->m_lDate/10000, (pInfoIndex->m_lDate%10000)/100, pInfoIndex->m_lDate%100);
	strTime.AppendFormat("%02d:%02d:%02d", pInfoIndex->m_lTime/10000, (pInfoIndex->m_lTime%10000)/100, pInfoIndex->m_lTime%100);
	strFotmat.Replace(HTML_REPLACE_TIME, strTime);
	// 作者
	CString strAuthor = "";
	strFotmat.Replace(HTML_REPLACE_AUTHOR, strAuthor);
	// 来源
	CString strOrigin = "";
	strFotmat.Replace(HTML_REPLACE_ORIGIN, strOrigin);
	//////////////////////////////////////////////////////////////////////////

	// 写html文件
	strPath = CGeneralHelper::GetAppPath() + _T("face\\html\\") + HTMLCONTENT_PATH;
	CFile fWrite(strPath, CFile::modeCreate | CFile::modeWrite);
	fWrite.Write(strFotmat.GetBuffer(), strFotmat.GetLength());
	fWrite.Close();

	return strPath;
}
示例#3
0
void DRMReceiver::run()
{
//	QElapsedTimer Timer;
	m_run = true;
	m_stopAck = false;
	CVector<short> tmpSnd(BufferSize);
	while(m_run)
	{
		if(fromFile)
		{
//			Timer.start();
			fRead(tmpSnd);
			for(int i = 0; i < SAMPLINGSTRIPE; i++)
			{
				tempBuf[i] = tmpSnd.at(i);
			}
		}
		else
		{
//			Timer.start();
			pSoundInInterface->Read(tmpSnd);
			for(int i = 0; i < SAMPLINGSTRIPE; i++)
			{
				tempBuf[i] = tmpSnd.at(i * 2) * 2.5f;
			}
		}
//		qDebug() << "Time" << Timer.elapsed();
//		qDebug() << __FILE__ << __LINE__ << "tempBuf" << tempBuf[SAMPLINGSTRIPE / 2];
		runDRM();

		Io_Led = Qt::green;
	}
	if(fromFile)
	{
		sf_close(sfin);
		tmpSnd.clear();
		qDebug() << __FILE__ << __LINE__ << "sf_close(sfin)";
	}
	// do NOT close pSoundInInterface
//	pSoundInInterface->Close();
	m_stopAck = true;
//	qDebug() << __FILE__ << __LINE__;
}
示例#4
0
int main()
{
     FILE *pFile = NULL;
     int lineCnt = 0;
     int i = 0;
     ipList_t* ipList = NULL;

    /*thread pool 갯수 지정 */
     threadpool thpool = thpool_init(THREAD_CNT);

    /* 읽을 파일의 라인수를 체크 */
    lineCnt = lineCount(CHECKLIST_FILE_PATH);

    printf("lineCnt :[%d] \n",lineCnt);

    ipList = (ipList_t*)malloc(sizeof(ipList_t)*(lineCnt+10));
    memset(ipList,0x00, sizeof(ipList_t)*(lineCnt+10));
   
   
    pFile = fopen( CHECKLIST_FILE_PATH, "r" );
    
    if( pFile != NULL )
    {
        char strTemp[255];
        char *pStr;

        while( !feof( pFile ) )
        {
            char* ss = NULL;
            pStr = fgets( strTemp, sizeof(strTemp), pFile ); 
			
            printf( "pStr:[%s] \n", pStr );
            printf( "strTemp:[%s] \n", strTemp );

            if(pStr != NULL)
            {
                pStr = rtrim(pStr);
                char* trimStr;

                //strncpy((ipList+i)->ip, pStr, STR_LEN); //ipList+0 번째가 깨진다.
                strcpy((ipList+i)->ip, pStr);
                 i++;
                
            }
        }

        fclose( pFile );
    }

    for(i =0 ;i < lineCnt;i++)
    {
        printf("ipList[%d]:[%s] \n",i,(ipList+i)->ip);
        thpool_add_work(thpool, (void*)pingChk, (ipList+i)->ip);
    }

    

    thpool_wait(thpool);

    thpool_destroy(thpool);

    free(ipList);

#if 0
    pthread_t p_thread[THREAD_CNT]; 
    int thr_id; //쓰레드ID
    int status;

    //char p1[] = "thread_1";   // 1번 쓰레드 이름
    //char p2[] = "thread_2";   // 2번 쓰레드 이름
    //char pM[] = "thread_m";   // 메인 쓰레드 이름
 
        // 파일 읽기
        if(fRead() == ERROR)
        {
            printf("FRead Error \n");        }
        Fread();





    sleep(2);  // 2초 대기후 쓰레드 생성
 


    sys

    // ① 1번 쓰레드 생성
    // 쓰레드 생성시 함수는 t_function
    // t_function 의 매개변수로 p1 을 넘긴다.  
    thr_id = pthread_create(&p_thread[0], NULL, t_function, (void *)p1);

    // pthread_create() 으로 성공적으로 쓰레드가 생성되면 0 이 리턴됩니다
    if (thr_id < 0)
    {
        perror("thread create error : ");
        exit(0);
    }
 
    // ② 2번 쓰레드 생성
    thr_id = pthread_create(&p_thread[1], NULL, t_function, (void *)p2);
    if (thr_id < 0)
    {
        perror("thread create error : ");
        exit(0);
    }
 
    // ③ main() 함수에서도 쓰레드에서 돌아가고 있는 동일한 함수 실행
    //t_function((void *)pM);
 
    // 쓰레드 종료를 기다린다. 
    pthread_join(p_thread[0], (void **)&status);
    pthread_join(p_thread[1], (void **)&status);
 
    printf("언제 종료 될까요?\n");
 #endif

    return SUCCESS;
}