Beispiel #1
0
int main(void)
{
    fprintf(stdout, "Type math expession:\n");
    Lexer *exp = (Lexer *) malloc(sizeof(Lexer));
    initMathExpression(exp);
    MathResult result = calcExpression(exp);
    if (result.err != NOTHING)
    {
        // show place of error
        showErr(result.err, experrorPointer, stderr);
        clearMathExpression(exp);
        return 1;
    }
    printf("Result = %g\n", result.value);
    clearMathExpression(exp);
    free(exp);
    return 0;
}
Beispiel #2
0
bool QDictWidget::ensureDictFile()
{
    if(dictFile.exists())
    {
        return true;
    }
    QDir baseDir("/media/card");
    if(!baseDir.exists())
    {
        baseDir = QDir::home();
    }
    QDir dictDir(baseDir.path() + "/.qgcide");
    if(!dictDir.exists())
    {
        if(!baseDir.mkdir(".qgcide"))
        {
            showErr(tr("Unable to create dictionary dir ") + dictDir.absolutePath());
            return false;
        }
    }
    dictFile.setFileName(dictDir.absolutePath() + "/gcide-entries.xml");
    if(dictFile.exists())
    {
        return true;
    }
    if(QMessageBox::question(this, tr("English dictionary"),
                          tr("Dictionary must be downloaded. Please make sure you have internet connection and press yes to confirm download (14MB)."),
                          QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
    {
        return false;
    }
    progress->setVisible(true);
    QString gzFile = dictFile.fileName() + ".gz";
    if(!download("http://dl.linuxphone.ru/openmoko/qtmoko/packages/gcide-entries.xml.gz", gzFile, "gcide-entries.xml.gz"))
    {
        return false;
    }
    if(!ungzip(gzFile))
    {
        return false;
    }
    progress->setVisible(false);
    return true;
}
Beispiel #3
0
bool QDictWidget::ungzip(QString file)
{
    browser->setText(tr("Unpacking") + " " + file);
    progress->setMaximum(640);
    progress->setValue(0);

    QProcess gzip;
    gzip.start("gzip", QStringList() << "-d" << file);
    if(!gzip.waitForStarted())
    {
        showErr(tr("Unable to start gzip"));
        return false;
    }
    while(gzip.state() == QProcess::Running)
    {
        progress->setValue((progress->value() + 1) % 640);
        QApplication::processEvents();
        gzip.waitForFinished(100);
    }
    return true;
}
UINT8 main(void)
{ 
	volatile UINT8 	errflag = 0;
	volatile UINT32 nFlashID = 0;
	volatile UINT8  nRetLoadSts = 0;

	//Disable the L1D and L1P cache before loading the sections
	#ifdef DEBUG
	printf("L1D and L1P cache disabled\n");
	#endif
	CACHE_setL1pSize(CACHE_L1_0KCACHE);
	CACHE_setL1dSize(CACHE_L1_0KCACHE);
		
	//Initialize the swPLL Controller 
	Loader_InitPLL();

	Gpo_Init(&oBootGreenLED, BOOT_GREEN_LED);
	Gpo_Init(&oBootRedLED, BOOT_RED_LED);

	Gpo_Clear(&oBootRedLED);
	Gpo_Clear(&oBootGreenLED);

	#ifdef DEBUG
	printf("Boot Loader program running...\n");
	#endif

	//Initialize the DDR2
	#ifdef DEBUG
	printf("Initializing the DDR2...\n");
	#endif
	Loader_InitDDR2();
	
	//Init the 16 Mbyte Flash
	SpiFlash_Init(&oFlash, NUMONYX_16MB);

    //FlashImage_check();

	nFlashID = SpiFlash_GetFlashID( &oFlash );

	while(nFlashID != FLASH_ID )
	{
		volatile UINT32	nCounter = 0;
		while((nCounter++) <= 0x1000 );

		nFlashID = SpiFlash_GetFlashID( &oFlash );
		nFlashReadCount++;

		if(nFlashReadCount > 10 ) 
			break;
	}

	if(nFlashID != FLASH_ID )
	{
		volatile UINT32	nCounter = 0;

		while(1)
		{
			while((nCounter++) <= 0xCC0000 );
			Gpo_Toggle(&oBootRedLED);
			nCounter = 0;
		}
		
	}

	#ifdef FILE_USAGE

	if(errflag = Loader_GetImage((UINT8 *)"AppC2.hex",APP_DDR_START_ADDR_CORE2 ,APP_SIZE_CORE2))
	{	
		showErr(errflag);		
	}

	if(errflag = Loader_GetImage((UINT8 *)"AppC1.hex",APP_DDR_START_ADDR_CORE1,APP_SIZE_CORE1))
	{	
		showErr(errflag);		
	}
			
	if(errflag = Loader_GetImage((UINT8 *)"AppC0.hex",APP_DDR_START_ADDR_CORE0,APP_SIZE_CORE0))
	{	
		showErr(errflag);
		return 0;		
	}

	//Write the Downloaded Images to Flash
	Loader_WriteImagesToFlash(); 

	#endif
	
	#ifdef ETHERNET_USAGE

	#ifdef DEBUG
	printf("sizeof BootPkt -> %d\n", sizeof(BootPkt));
	#endif

	//Init the Mac interface
	bInEthernetScope = TRUE;
	EVM_init();

	if(TRUE == Ethernet_Init())
	{
	  	//Download the Images to DDR
		if(TRUE == BootPkt_Download())
		{
			//Write the Downloaded Images to Flash
			Loader_WriteImagesToFlash();
		}
	}
	bInEthernetScope = FALSE;
	Gpo_Clear(&oBootGreenLED);

	#endif

	#ifdef FLASH_BOOT 
	
	#ifdef DEBUG
	printf("Reading the images from flash\n");
	#endif

	SpiFlash_Read(&oFlash, 
				  (UINT8 *)APP_DDR_START_ADDR_CORE2, 
				  APP_FLASH_START_ADDR_CORE2, 
				  APP_SIZE_CORE2); 

	SpiFlash_Read(&oFlash, 
				  (UINT8 *)APP_DDR_START_ADDR_CORE1, 
				  APP_FLASH_START_ADDR_CORE1, 
				  APP_SIZE_CORE1);
	
	SpiFlash_Read(&oFlash, 
				  (UINT8 *)APP_DDR_START_ADDR_CORE0, 
				  APP_FLASH_START_ADDR_CORE0, 
				  APP_SIZE_CORE0);	

	#endif

	nRetLoadSts = Loader_LoadApp((UINT32)APP_DDR_START_ADDR_CORE2, APP_SIZE_CORE2);
	
	if(nRetLoadSts)
	{
		Gpo_Set(&oBootRedLED);
		while(1);
	}

	nRetLoadSts = Loader_LoadApp((UINT32)APP_DDR_START_ADDR_CORE1, APP_SIZE_CORE1); 

	if(nRetLoadSts)
	{
		Gpo_Set(&oBootRedLED);
		while(1);
	}
	//it should be last ....
	nRetLoadSts = Loader_LoadApp((UINT32)APP_DDR_START_ADDR_CORE0, APP_SIZE_CORE0);

	if(nRetLoadSts)
	{
		Gpo_Set(&oBootRedLED);
		while(1);
	}

	Gpo_Set(&oBootGreenLED);
	{
		volatile UINT32	nCounter = 0;
		while(nCounter++ < (0xCC0000*4));
	}

	if(errflag = Loader_SetAppLoadCompleteFlag((UINT32 *)APPC1_LOAD_COMPLETE_FLAG_ADDR))
	{
		showErr(errflag);
	}

	if(errflag = Loader_SetAppLoadCompleteFlag((UINT32 *)APPC2_LOAD_COMPLETE_FLAG_ADDR))
	{
		showErr(errflag);
	}
	
	#ifdef DEBUG
	printf("Starting Application program ...\n");
	#endif

	Loader_ExecuteAppC0();

	return 0;  
}
Beispiel #5
0
bool QDictWidget::download(QString url, QString destPath, QString filename)
{
    browser->setText(tr("Downloading") + " " + filename);

    QString host = url;
    QString reqPath;
    int port = 80;

    if(url.startsWith("http://"))
    {
        host.remove(0, 7);
    }

    int colonIndex = host.indexOf(':');
    int slashIndex = host.indexOf('/');
    if(slashIndex < 0)
    {
        return false;
    }
    reqPath = host.right(host.length() - slashIndex).replace(" ", "%20");
    host = host.left(slashIndex);
    if(colonIndex > 0)
    {
        QString portStr = host.right(host.length() - colonIndex - 1);
        host = host.left(colonIndex);
        port = portStr.toInt(0, 10);
    }

connect:
    QTcpSocket sock(this);
    sock.setReadBufferSize(65535);
    sock.connectToHost(host, port);
    if(!sock.waitForConnected(5000))
    {
        showErr(sock.errorString());
        return false;
    }

    QByteArray req("GET ");
    req.append(reqPath);
    req.append(" HTTP/1.1\r\nHost: ");
    req.append(host);
    req.append(':');
    req.append(QByteArray::number(port));
    req.append("\r\n\r\n");

    sock.write(req);
    sock.flush();
    sock.waitForBytesWritten();

    int contentLen = 0;
    bool html = false;
    QByteArray line;
    for(;;)
    {
        line = sock.readLine();
        if(line.isEmpty())
        {
            if(sock.waitForReadyRead(5000))
            {
                continue;
            }
            break;
        }
        if(line.trimmed().isEmpty())
        {
            break;
        }
        html = html | (line.indexOf("Content-Type: text/html") == 0);
        if(line.indexOf("Content-Length: ") == 0)
        {
            contentLen = line.remove(0, 16).trimmed().toInt(0, 10);
        }
    }

    if(html)
    {
        QByteArray text = sock.readAll();
        sock.close();
        if(text.length() == 0)
        {
            QMessageBox::critical(this, tr("English dictionary"),
                                  tr("No response from ") + host);
            return false;
        }
        text.replace("</br>", "\n");
        if(QMessageBox::information(this, tr("English dictionary"), text,
                                 QMessageBox::Ok | QMessageBox::Retry) == QMessageBox::Retry)
        {
            goto connect;
        }

        return false;
    }

    QFile f(destPath);
    if(!f.open(QFile::WriteOnly))
    {
        QMessageBox::critical(this, tr("English dictionary"),
                              tr("Unable to save file:\r\n\r\n") + f.errorString());
        sock.close();
        return false;
    }

#ifdef QTOPIA
     QtopiaApplication::setPowerConstraint(QtopiaApplication::DisableSuspend);
#endif

    if(contentLen <= 0)
    {
        QMessageBox::critical(this, tr("English dictionary"), tr("Couldnt read content length"));
        contentLen = 0x7fffffff;
    }
    progress->setMaximum(contentLen);
    progress->setValue(0);
    int remains = contentLen;

    char buf[65535];
    int count;
    for(;;)
    {
        QApplication::processEvents();
        count = sock.read(buf, 65535);
        if(count < 0)
        {
            break;
        }
        f.write(buf, count);
        f.flush();
        remains -= count;
        if(remains <= 0)
        {
            break;
        }
        progress->setValue(contentLen - remains);
    }
    f.close();
    sock.close();

#ifdef QTOPIA
    QtopiaApplication::setPowerConstraint(QtopiaApplication::Enable);
#endif

    return true;
}