Example #1
0
WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
    : ObjectFile(Binary::ID_Wasm, Buffer) {
  ErrorAsOutParameter ErrAsOutParam(&Err);
  Header.Magic = getData().substr(0, 4);
  if (Header.Magic != StringRef("\0asm", 4)) {
    Err = make_error<StringError>("Bad magic number",
                                  object_error::parse_failed);
    return;
  }
  const uint8_t *Ptr = getPtr(4);
  Header.Version = readUint32(Ptr);
  if (Header.Version != wasm::WasmVersion) {
    Err = make_error<StringError>("Bad version number",
                                  object_error::parse_failed);
    return;
  }

  const uint8_t *Eof = getPtr(getData().size());
  wasm::WasmSection Sec;
  while (Ptr < Eof) {
    if ((Err = readSection(Sec, Ptr, getPtr(0))))
      return;
    if (Sec.Type == wasm::WASM_SEC_USER) {
      if ((Err = parseUserSection(Sec, Sec.Content.data(), Sec.Content.size())))
        return;
    }
    Sections.push_back(Sec);
  }
}
Example #2
0
File: ini.cpp Project: qrti/tosh
bool Ini::read()
{
    char line[MAXLINE];
    uint16_t lc = 1;
    
    while(fgets(line, MAXLINE, file)){
        char* p = line;
        strip(p);
        p = trim(p);        
        
        if(strlen(p)){
            if(*p == '['){
                if(allocData())
                    return true;
                
                lsc = lc;
                
                if(readSection(p))
                    return true;
            }
            else{
                if(readValues(p))
                    return true;
            }
        }
        
        lc++;
    };    
    
    if(dc)
        allocData();
    
    return false;
}
void DVBProvider::onReadSection(
	boost::asio::posix::stream_descriptor *io,
	ID pid,
	util::Buffer *buf,
	const boost::system::error_code& error,
	size_t transferred )
{
	bool tryRead=true;
	
	if (error) {
		if (error.value() == boost::system::errc::timed_out) {
			//	Timeout
			timeout( pid );
		}
		else if (error.value() != boost::system::errc::value_too_large) {
			printf( "[DVBProvider] Read section error!!!: err(%s,%d), pid=%04x, transferred=%d, capacity=%d!\n",
				error.message().c_str(), error.value(), pid, transferred, buf->capacity() );
			tryRead=false;
		}
	}
	
	if (transferred) {
		buf->resize( transferred );
		enqueue( pid, buf );
		buf = NULL;
	}

	if (tryRead) {
		readSection( io, pid, buf );
	}
	else {
		freeNetworkBuffer( buf );
	}
}
Example #4
0
bool QuickDC::Hash::CacheStorage::openForReading()
{
	if (!file.exists())
		return false;
		
	if (!file.open(Samurai::IO::File::Read))
		return false;
	
	position = 0;
	
	CacheMasterRecord master;
	if (!readSection(STORAGE_MAGIC_MASTER, &master, sizeof(master)))
	{
		reset();
		return false;
	}

	if (!(master.size_info == HEADER_SIZE_INFO && master.version == HEADER_VERSION))
	{
		QERR("Invalid header of cache file");
		reset();
		return false;
	}
	
	opened = true;
	return true;
}
Example #5
0
void FileParser::processLine(const QString &text)
{
  QStringList keyVal;
  if (intoData) {
    keyVal = readKeyVal(text);
    if (keyVal.size() <= 1)
      return;
    saveWordDic(keyVal);
    return;
  }

  QString section = readSection(text);
  if (!section.isEmpty()) {
    if (section == QString::fromUtf8("数据") || section == "Data") {
      intoData = true;
      intoRule = false;
      return;
    }
    if (section == QString::fromUtf8("组词规则") || section == "Rule") {
      intoRule = true;
    }
  }

  QStringList conf = readConf(text);
  if (!conf.isEmpty()) {
    if (intoRule == true) {
      QStringList tmp = conf.at(1).split('+');
      wordRule.append(qMakePair(conf.at(0), tmp));
    }
    if (conf.at(0) == QString::fromUtf8("键码") || conf.at(0) == "KeyCode") {
      KeyCode = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("码长") || conf.at(0) == "Length") {
      Length = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("拼音") || conf.at(0) == "Pinyin") { 
      Pinyin = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("拼音长度") || conf.at(0) == "PinyinLength") { 
      PinyinLength = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("提示") || conf.at(0) == "Prompt") { 
      Prompt = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("构词") || conf.at(0) == "ConstructPhrase") { 
      ConstructPhrase = conf.at(1);
      return;
    }
    if (conf.at(0) == QString::fromUtf8("规避字符") || conf.at(0) == "InvalidChar") { 
      InvalidChar = conf.at(1);
      return;
    }
  }
}
	SonicXNFile::SonicXNFile(string filename, XNFileMode file_mode_parameter) {
		File file(filename, LIBGENS_FILE_READ_BINARY);

		info=NULL;
		offset_table=NULL;
		footer=NULL;
		end=NULL;
		big_endian=false;

		folder = filename;
		size_t sz=folder.size();
		int last_slash=0;
		for (size_t i=0; i<sz; i++) {
			if ((folder[i] == '\\') || (folder[i] == '/')) last_slash=i;
		}
		if (last_slash) folder.erase(last_slash+1, folder.size()-last_slash-1);
		else folder="";
		
		std::transform(filename.begin(), filename.end(), filename.begin(), ::tolower);
		
		if ((filename.find(LIBGENS_XNO_EXTENSION)      != string::npos) || (filename.find(LIBGENS_XNM_EXTENSION)      != string::npos) || (file_mode_parameter == MODE_XNO)) {
			file_mode = MODE_XNO;
		}
		else if (filename.find(LIBGENS_ZNO_EXTENSION) != string::npos  || (filename.find(LIBGENS_ZNM_EXTENSION)      != string::npos) || (file_mode_parameter == MODE_ZNO)) {
			file_mode = MODE_ZNO;
		}
		else if (filename.find(LIBGENS_INO_EXTENSION) != string::npos  || (filename.find(LIBGENS_INM_EXTENSION)      != string::npos) || (file_mode_parameter == MODE_INO)) {
			file_mode = MODE_INO;
		}
		else if ((filename.find(LIBGENS_GNO_EXTENSION) != string::npos) || (filename.find(LIBGENS_GNM_EXTENSION) != string::npos) || (filename.find(LIBGENS_GNA_EXTENSION) != string::npos) || (file_mode_parameter == MODE_GNO)) {
			file_mode = MODE_GNO;
		}
		else if (filename.find(LIBGENS_ENO_EXTENSION) != string::npos || (file_mode_parameter == MODE_ENO)) {
			file_mode = MODE_ENO;
		}
		else if (file_mode_parameter == MODE_YNO) {
			file_mode = MODE_YNO;
		}

		setHeaders();

		if (file.valid()) {
			while (!end) {
				readSection(&file);
			}
			file.close();
		}

		SonicXNObject *object=getObject();
		if (object) {
			string name="Object";
			if (footer) name=footer->name;
			object->setNames(name);
		}
	}
Example #7
0
bool QuickDC::Hash::CacheStorage::read(QuickDC::Hash::CacheEntry*& ptr)
{
	QDBG("QuickDC::Hash::CacheStorage::read()");
	ptr = 0;
	size_t size = 0;
	CacheEntryHeader file_header;
	
	size = readSection(STORAGE_MAGIC_RECORD, &file_header, sizeof(file_header));
	if (!size)
		return false;
	
	buffer.clear();
	off_t storedPosition = (position + sizeof(CacheRecordHeader));
	size = readSection(STORAGE_MAGIC_DATA, buffer);
	if (size)
	{
		 ptr = CacheEntry::create(file_header, buffer);
		 if (ptr)
		 {
			 ptr->setCacheFileOffset(storedPosition);
		 }
	}
	return true;
}
	SonicXNSection *SonicXNFile::readSection(File *file) {
		string identifier="";
		file->readString(&identifier, 4);

		if (identifier == header_info) {
			info = new SonicXNInfo();
			info->setHeader(header_info);
			info->setFileMode(file_mode);
			info->setBigEndian(big_endian);
			info->read(file);
			info->goToEnd(file);
			
			for (size_t i=0; i<info->getSectionCount(); i++) {
				SonicXNSection *section=readSection(file);
				if (section) {
					section->goToEnd(file);
					sections.push_back(section);
				}
			}
		}
		else if (identifier == LIBGENS_XNSECTION_HEADER_OFFSET_TABLE) {
			offset_table = new SonicXNOffsetTable();
			offset_table->setHeader(LIBGENS_XNSECTION_HEADER_OFFSET_TABLE);
			offset_table->setFileMode(file_mode);
			offset_table->setBigEndian(big_endian);
			offset_table->read(file);
			offset_table->goToEnd(file);
		}
		else if (identifier == header_texture) {
			SonicXNTexture *section=new SonicXNTexture();
			section->setHeader(header_texture);
			section->setFileMode(file_mode);
			section->setBigEndian(big_endian);
			section->read(file);
			return section;
		}
		else if (identifier == header_effect) {
			SonicXNEffect *section=new SonicXNEffect();
			section->setHeader(header_effect);
			section->setFileMode(file_mode);
			section->setBigEndian(big_endian);
			section->read(file);
			return section;
		}
		else if (identifier == header_object) {
			SonicXNObject *section=new SonicXNObject(getTexture(), getEffect(), getBones());
			section->setHeader(header_object);
			section->setFileMode(file_mode);
			section->setBigEndian(big_endian);
			section->read(file);

			return section;
		}
		else if (identifier == header_bones) {
			SonicXNBones *section=new SonicXNBones();
			section->setHeader(header_bones);
			section->setFileMode(file_mode);
			section->setBigEndian(big_endian);
			section->read(file);
			return section;
		}
		else if (identifier == header_motion) {
			SonicXNMotion *section=new SonicXNMotion();
			section->setHeader(header_motion);
			section->setFileMode(file_mode);
			section->setBigEndian(big_endian);
			section->read(file);
			return section;
		}
		else if (identifier == LIBGENS_XNSECTION_HEADER_FOOTER) {
			footer=new SonicXNFooter();
			footer->setHeader(LIBGENS_XNSECTION_HEADER_FOOTER);
			footer->setFileMode(file_mode);
			footer->setBigEndian(big_endian);
			footer->read(file);
			footer->goToEnd(file);
			return footer;
		}
		else if (identifier == LIBGENS_XNSECTION_HEADER_END) {
			end=new SonicXNEnd();
			end->setHeader(LIBGENS_XNSECTION_HEADER_END);
			end->setFileMode(file_mode);
			end->setBigEndian(big_endian);
			end->read(file);
			end->goToEnd(file);
			return end;
		}

		return NULL;
	}
Example #9
0
void Reader::skipSection()
{
  readSection();
}
Example #10
0
void Reader::skipSection(DECFILELINE)
{
  readSection(ARGFILELINE);
}
// -----------------------------------------------------------------------------
// DMFotaView::addFotaView
// Creates and adds the Fota Portrait and Landscape View
// -----------------------------------------------------------------------------
//
bool DMFotaView::addFotaView()
    {
    qDebug("DMFotaView::addFotaView >>");
    connect( mMainWindow, SIGNAL( orientationChanged(Qt::Orientation) ), this, SLOT( readSection(Qt::Orientation) ) );
        
    bool ok = false;
    QString val,val2;
    loader.load(":/xml/devman.docml", &ok);
    ok = false;
    loader2.load(":/xml/devman.docml", &ok);
    // Exit if the file format is invalid
    Q_ASSERT_X(ok, "Device Manager", "Invalid docml file");
    
    ok=false;
    loader.load(":/xml/devman.docml","Portrait", &ok);
    ok=false;
    loader2.load(":/xml/devman.docml","Landscape", &ok);
   
    // Load the view by name from the xml file
    fotaPortraitView = qobject_cast<HbView*>(loader.findWidget("p:view"));
    fotaLandscapeView = qobject_cast<HbView*>(loader2.findWidget("l:view"));


    HbAction *help = qobject_cast<HbAction*> (loader.findObject("help")); 
    help->setText(QString("txt_common_menu_help"));
    QObject::connect(help, SIGNAL(triggered()), this, SLOT(OnHelp()));
    HbAction *exit = qobject_cast<HbAction*> (loader.findObject("exit"));
    exit->setText(QString("txt_common_menu_exit"));
    QObject::connect(exit, SIGNAL(triggered()), this, SLOT(OnExit()));

    help = qobject_cast<HbAction*>(loader2.findObject("help"));
    help->setText(QString("txt_common_menu_help"));
    QObject::connect(help, SIGNAL(triggered()), this, SLOT(OnHelp()));
    exit = qobject_cast<HbAction*>( loader2.findObject("exit"));
    exit->setText(QString("txt_common_menu_exit"));
    QObject::connect(exit, SIGNAL(triggered()), this, SLOT(OnExit()));
    
    mSoftKeyBackAction = new HbAction(Hb::BackNaviAction ,this);
    mSoftKeyBackAction->setText("Back");
    fotaPortraitView->setNavigationAction(mSoftKeyBackAction);
	fotaLandscapeView->setNavigationAction(mSoftKeyBackAction);
    connect(mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(backtoMainWindow()));
        
    
    i=0;
    QString str;
    //Setting title text
    label = qobject_cast<HbLabel*> (loader.findWidget("p:title"));
    label2 = qobject_cast<HbLabel*> (loader2.findWidget("l:title"));
    val = hbTrId("txt_device_update_subhead_device_updates");
    label->setPlainText(val);
    label2->setPlainText(val);
    
    
    
    HbScrollArea* area = qobject_cast<HbScrollArea*> (loader.findWidget("scrollArea"));
    area->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOn);
    
    
    list1 << "label" << "label_1" << "label_2" << "label_3" << "label_4" << "label_5" << "label_6"<<"label_7"<<"label_8"<<"label_9"<<"label_10"<<"label_11";
    list2 << "label_13" << "label_14" << "label_15" << "label_16" << "label_17" << "label_18" << "label_19"<<"label_20"<<"label_21"<<"label_22"<<"label_23"<<"label_24";


    //Product Release
    TBuf< KSysUtilVersionTextLength > prodrelease;
    prodrelease.Zero();
    if(SysUtil::GetPRInformation(prodrelease)==KErrNone)
        {
        val = hbTrId("txt_device_update_dblist_product_release");
        str = QString::fromUtf16(prodrelease.Ptr(), prodrelease.Length());
        FormatList(val,str);
        }
    
    //Software version
    
    TBuf< KSysUtilVersionTextLength > swversion;
    TBuf< KSysUtilVersionTextLength > swversiondate;
    TBuf< KSysUtilVersionTextLength > typedesignator;
    TBuf< KSysUtilVersionTextLength > version;
    swversion.Zero();
    version.Zero();
    typedesignator.Zero();
    swversiondate.Zero();
    if( SysUtil::GetSWVersion(version)==KErrNone)
        {
        TInt len= version.Length();
        TInt pos1 = version.Find(KSmlEOL);
             if( pos1 != KErrNotFound && len > pos1 )
                {
                 TBuf<KSysUtilVersionTextLength> version1;
                 version1.Zero();
                 swversion.Append( version.Left(pos1));
                 version1.Append( version.Right( len-pos1-1 ));
                 len= version1.Length();
                 pos1 = version1.Find(KSmlEOL);
                 if( pos1 != KErrNotFound  && len > pos1 )
                     {
                     swversiondate.Append(version1.Left( pos1 ));
                     version.Zero();
                     version.Append( version1.Right( len-pos1-1 ));
                     len= version.Length();
                     pos1 = version.Find(KSmlEOL);
                     if( pos1 != KErrNotFound  && len > pos1 )
                         {
                         typedesignator.Append(version.Left(pos1));         
                         }
                     }
                }
            val = hbTrId("txt_device_update_dblist_software_version");
            str = QString::fromUtf16(swversion.Ptr(), swversion.Length());
            FormatList(val,str);
            }

    //Model
    TBuf<100> phoneName;
    TInt error = SysVersionInfo::GetVersionInfo(SysVersionInfo::EModelVersion, phoneName);
    if (error==KErrNone)
    {
    
    //phoneName.Copy( telid.iModel );
    //imei.Copy(telid.iSerialNumber);
    if( phoneName.Length()>0 )
        {
        val = hbTrId("txt_device_update_dblist_model");
        str = QString::fromUtf16(phoneName.Ptr(), phoneName.Length());
        FormatList(val,str);
        }
    }
    RTelServer telServer;
    User::LeaveIfError( telServer.Connect() );
    RTelServer::TPhoneInfo teleinfo;
    User::LeaveIfError( telServer.GetPhoneInfo( 0, teleinfo ) );
    RMobilePhone phone;
    User::LeaveIfError( phone.Open( telServer, teleinfo.iName ) );
    User::LeaveIfError(phone.Initialise()); 
    TUint32 teleidentityCaps;
    phone.GetIdentityCaps( teleidentityCaps );
    RMobilePhone::TMobilePhoneIdentityV1 telid;
    TRequestStatus status;
    phone.GetPhoneId( status, telid );
    User::WaitForRequest( status );
    TBuf <50> imei;
    if (status==KErrNone)
    {
    TBuf<100> phoneName;
    imei.Copy(telid.iSerialNumber);
    }
    phone.Close();
    telServer.Close();

    //type
    if(typedesignator.Length()>0)
        {
        val = hbTrId("txt_device_update_dblist_type");
        str = QString::fromUtf16(typedesignator.Ptr(), typedesignator.Length());
        FormatList(val,str);
        }
      
    //Product Code
       /* TInt runtimesupport(0);
        CRepository* cenrep = NULL;
        TRAPD( error, cenrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );  
        if(error)
            {
            runtimesupport=1;
            }
        if ( cenrep )
                {
                cenrep->Get( KNsmlDmRuntimeVerSupport, runtimesupport );
                delete cenrep; cenrep = NULL;
                }
          if(runtimesupport)
          { */
         TBuf<KSysUtilVersionTextLength> productcode;
         productcode.Zero();
         error = SysVersionInfo::GetVersionInfo(SysVersionInfo::EProductCode, productcode);
         if(error ==KErrNone )
         {            
             if( productcode.Length()>0 )
             {        
             val = hbTrId("txt_device_update_dblist_product_code");
             str = QString::fromUtf16(productcode.Ptr(), productcode.Length());  
             FormatList(val,str);
             }                    
        }

    //IMEI   
    if(imei.Length()>0)
        {
        val = hbTrId("txt_device_update_dblist_imei");
        str = QString::fromUtf16(imei.Ptr(), imei.Length()); 
        FormatList(val,str);
        }

   
    iFotaState = FotaEngineL().GetState(-1);
    
    TBuf8<80> Name;
    TBuf8<80> Version;
    TInt Size;
    
    if(iFotaState == RFotaEngineSession::EDownloadComplete || iFotaState == RFotaEngineSession::EStartingUpdate
            || iFotaState == RFotaEngineSession::EStartingDownload || iFotaState == RFotaEngineSession::EDownloadProgressing)
        {
        label = qobject_cast<HbLabel*> (loader.findWidget("p:updatelabel"));
        label2 = qobject_cast<HbLabel*> (loader2.findWidget("l:updatelabel"));
        FotaEngineL().GetCurrentFirmwareDetailsL(Name, Version, Size);
        
        const QString
        name =
                QString::fromUtf8(
                        reinterpret_cast<const char*> (Name.Ptr()),
                                Name.Length());
        const QString
        ver =
                QString::fromUtf8(
                        reinterpret_cast<const char*> (Version.Ptr()),
                                Version.Length());
        
        TInt sizeKB = Size / 1024;
        if(sizeKB < 1024)
            {
            val = hbTrId("txt_device_update_setlabel_the_last_update_1_2_kb").arg(name)
                    .arg(ver).arg(sizeKB);
            }
        else
            {
            TInt sizeMB = sizeKB / 1024;
            val = hbTrId("txt_device_update_setlabel_the_last_update_1_2_mb").arg(name)
                    .arg(ver).arg(sizeMB);
            }
        label->setPlainText(val);
        label2->setPlainText(val);
		
		val = hbTrId("txt_device_update_button_resume_update");
    
        updateButton = qobject_cast<HbPushButton*>(loader.findWidget("p:update"));
        updateButton->setText(val);
        QObject::connect(updateButton, SIGNAL(clicked()), this, SLOT(ResumeUpdate()));
        updateButtonLandscape = qobject_cast<HbPushButton*>(loader2.findWidget("l:update"));
        updateButtonLandscape->setText(val);
		QObject::connect(updateButtonLandscape, SIGNAL(clicked()), this, SLOT(ResumeUpdate()));
		Connected = ETrue;
        }
    else
        {
        //Setting help text for update button
        label = qobject_cast<HbLabel*> (loader.findWidget("p:updatelabel"));
        label2 = qobject_cast<HbLabel*> (loader2.findWidget("l:updatelabel"));
        val = hbTrId("txt_device_update_setlabel_to_update_your_device_s");
        label->setPlainText(val);
        label2->setPlainText(val);
        
        val = hbTrId("txt_device_update_button_update");
        updateButton = qobject_cast<HbPushButton*>(loader.findWidget("p:update"));
        updateButton->setText(val);
        QObject::connect(updateButton, SIGNAL(clicked()), this, SLOT(CheckforUpdate()));
        updateButtonLandscape = qobject_cast<HbPushButton*>(loader2.findWidget("l:update"));
        updateButtonLandscape->setText(val);
        QObject::connect(updateButtonLandscape, SIGNAL(clicked()), this, SLOT(CheckforUpdate()));
        Connected = ETrue;
        }
    
    val = hbTrId("txt_device_update_button_advanced");
    advancedButton = qobject_cast<HbPushButton*>(loader.findWidget("p:advanced")); 
    advancedButton->setText(val);
    QObject::connect(advancedButton, SIGNAL(clicked()), this, SLOT(AdvancedDeviceManager()));
    advancedButtonLandscape = qobject_cast<HbPushButton*>(loader2.findWidget("l:advanced"));
    advancedButtonLandscape->setText(val);
    QObject::connect(advancedButtonLandscape, SIGNAL(clicked()), this, SLOT(AdvancedDeviceManager()));
    fotaSupportEnabled();
    mMainWindow->addView(fotaPortraitView);
    mMainWindow->addView(fotaLandscapeView);
    
    if(mMainWindow->orientation()==Qt::Vertical)
            mMainWindow->setCurrentView(fotaPortraitView);
        else
            mMainWindow->setCurrentView(fotaLandscapeView);
    
    iMoniter = CDeviceUpdateMoniter::NewL(this);
    //iMoniter->StartMoniter();
    emit applicationReady();
    qDebug("DMFotaView::addFotaView <<");
    return ETrue;
    }