예제 #1
0
void ZGui::load ( const QString fileName, bool AutoCodec )
{
	toLog("load ("+fileName+")");
	QFile file ( fileName );
	if (  file.open ( IO_ReadWrite ) )//IO_ReadOnly ) )
	{
		//Block update
	    edit->blockSignals(true);
		edit->setAutoUpdate(false);	
			
		//Set def editor
		edit->clear();
		edit->setText("");
	
		//Detect codec
		if ( AutoCodec )
		{
			//Reset all checked
			for (int i=0; i<CODEC_COUNT;i++)
				CodeMenu->setItemChecked(i,false);
			//Read data for detect
			char data[10000];
			int size = file.readBlock(data, sizeof(data));
			file.reset();
			textCode = detectCodec(data, size);
			//Check codec
			CodeMenu->setItemChecked(textCode, true);
		}
		
		toLog("\tload text");
		//Load file
		char data[ file.size() ];
		file.readBlock(data, sizeof(data));
		QTextCodec* codec = codecByLocalId(textCode);
		toLog("\tset text");
		edit->setText( codec->toUnicode( data ) );
		toLog("\tclose file");
		file.close();
		
		//Unblock update
	    edit->blockSignals(false);
		edit->setAutoUpdate(true);
		
		#ifdef MDI
		setMainWidgetTitle(sFileName);
		buildDlgMenu();
		#endif
		
		toLog("end load");
	}
}
예제 #2
0
// ---------------------------------------------------------------
int PackageDialog::extractLibrary(QFile& PkgFile, Q_UINT32 Count)
{
  char *p = (char*)malloc(Count);
  PkgFile.readBlock(p, Count);
  QByteArray Content = qUncompress((unsigned char*)p, Count);
  free(p);

  p = Content.data();
  QFile File(QucsSettings.QucsHomeDir.absPath() +
             QDir::convertSeparators("/user_lib/") + QString(p));
  if(File.exists()) {
    MsgText->append(tr("ERROR: User library \"%1\" already exists!").arg(QString(p)));
    return -1;
  }

  if(!File.open(QIODevice::WriteOnly)) {
    MsgText->append(tr("ERROR: Cannot create library \"%1\"!").arg(QString(p)));
    return -1;
  }

  File.writeBlock(p+strlen(p)+1, Content.size()-strlen(p)-1);
  File.close();
  MsgText->append(tr("Create library \"%1\"").arg(QString(p)));
  return 1;
}
예제 #3
0
// ---------------------------------------------------------------
int PackageDialog::extractFile(QFile& PkgFile, Q_UINT32 Count, QDir& currDir)
{
  char *p = (char*)malloc(Count);
  PkgFile.readBlock(p, Count);
  QByteArray Content = qUncompress((unsigned char*)p, Count);
  free(p);

  p = Content.data();
  QFile File(currDir.absFilePath(QString(p)));
  if(!File.open(QIODevice::WriteOnly)) {
    MsgText->append(tr("ERROR: Cannot create file \"%1\"!").arg(QString(p)));
    return -1;
  }

  File.writeBlock(p+strlen(p)+1, Content.size()-strlen(p)-1);
  File.close();
  MsgText->append(tr("Create file \"%1\"").arg(QString(p)));
  return 1;
}
예제 #4
0
// ---------------------------------------------------------------
int PackageDialog::extractDirectory(QFile& PkgFile, Q_UINT32 Count, QDir& currDir)
{
  char *p = (char*)malloc(Count);
  PkgFile.readBlock(p, Count);

  if(currDir.cd(QString(p))) { // directory exists ?
    MsgText->append(tr("ERROR: Project directory \"%1\" already exists!").arg(QString(p)));
    return -1;
  }

  if(!currDir.mkdir(QString(p))) {
    MsgText->append(tr("ERROR: Cannot create directory \"%1\"!").arg(QString(p)));
    return -2;
  }
  currDir.cd(QString(p));
  MsgText->append(tr("Create and enter directory \"%1\"").arg(currDir.absPath()));

  free(p);
  return 1;
}
bool UtilsCode::detectFileCodec()
{
	QFile file ( mFile );
	if (  file.open ( IO_ReadWrite ) )
	{	
		//cout<<"===== file open ok ====="<<endl;
		
		char data[10000];
		int size = file.readBlock(data, sizeof(data));
		file.reset();
		int id = detectCodec(data, size);
		
		//cout<<"########## code id is "<<id<<" ########"<<endl;
		
		mTextCodec = codecByLocalId(id);
		file.close();
		return true;
	}
	return false;
}
예제 #6
0
bool XepParser::parse(QFile &f)
{
    char buf[4096];
    char XML_START[] = "<smiles>";
    XML_Parse(m_parser, XML_START, strlen(XML_START), false);
    unsigned start = 0;
    for (;;){
        char s32[] = "<32bit_Icons>";
        char e32[] = "</32bit_Icons>";
        int size = f.readBlock(&buf[start], sizeof(buf) - start);
        if (size <= 0)
            break;
        size += start;
        replace(buf, size, s32, "<AA");
        replace(buf, size, e32, "</AA");
        if (size == sizeof(buf)){
            start = strlen(e32);
            size -= start;
        }
        int res = XML_Parse(m_parser, buf, size, false);
        if (res != XML_STATUS_OK)
            return false;
        if (start)
            memmove(buf, &buf[sizeof(buf) - start], start);
    }
    if ((m_pict.size() == 0) || (m_width == 0) || (m_height == 0))
        return false;
	Buffer pict;
	pict.fromBase64(m_pict);
	if (pict.size() < 28)
		return false;
    QByteArray arr;
    arr.assign(pict.data(28), pict.size() - 28);
    QImage img(arr);
    if ((img.width() == 0) || (img.height() == 0))
        return false;
    m_image.convertFromImage(img);
    return true;
}
예제 #7
0
int PackageDialog::insertFile(const QString& FileName, QFile& File,
                              QDataStream& Stream)
{
  QByteArray FileContent;

  if(!File.open(QIODevice::ReadOnly)) {
    QMessageBox::critical(this, tr("Error"),
                    tr("Cannot open \"%1\"!").arg(FileName));
    return -1;
  }

  Q_ULONG Count = File.size();
  char *p = (char*)malloc(Count+FileName.length()+2);
  strcpy(p, FileName.latin1());
  File.readBlock(p+FileName.length()+1, Count);
  File.close();

  Count += FileName.length()+1;
  FileContent = qCompress((unsigned char*)p, Count);
  free(p);

  Stream.writeBytes(FileContent.data(), FileContent.size());
  return 0;
}
예제 #8
0
파일: cite.cpp 프로젝트: CN-Sean/doxygen
void CiteDict::generatePage() const
{
  //printf("** CiteDict::generatePage() count=%d\n",m_ordering.count());

  // do not generate an empty citations page
  if (isEmpty()) return; // nothing to cite

  // 1. generate file with markers and citations to OUTPUT_DIRECTORY
  QFile f;
  QCString outputDir = Config_getString("OUTPUT_DIRECTORY");
  QCString citeListFile = outputDir+"/citelist.doc";
  f.setName(citeListFile);
  if (!f.open(IO_WriteOnly)) 
  {
    err("could not open file %s for writing\n",citeListFile.data());
  }
  FTextStream t(&f);
  t << "<!-- BEGIN CITATIONS -->" << endl;
  t << "<!--" << endl;
  QDictIterator<CiteInfo> it(m_entries);
  CiteInfo *ci;
  for (it.toFirst();(ci=it.current());++it)
  {
    t << "\\citation{" << ci->label << "}" << endl;
  }
  t << "-->" << endl;
  t << "<!-- END CITATIONS -->" << endl;
  t << "<!-- BEGIN BIBLIOGRAPHY -->" << endl;
  t << "<!-- END BIBLIOGRAPHY -->" << endl;
  f.close();

  // 2. generate bib2xhtml
  QCString bib2xhtmlFile = outputDir+"/bib2xhtml.pl";
  f.setName(bib2xhtmlFile);
  QCString bib2xhtml = bib2xhtml_pl;
  if (!f.open(IO_WriteOnly)) 
  {
    err("could not open file %s for writing\n",bib2xhtmlFile.data());
  }
  f.writeBlock(bib2xhtml, bib2xhtml.length());
  f.close();

  // 3. generate doxygen.bst
  QCString doxygenBstFile = outputDir+"/doxygen.bst";
  QCString bstData = doxygen_bst;
  f.setName(doxygenBstFile);
  if (!f.open(IO_WriteOnly)) 
  {
    err("could not open file %s for writing\n",doxygenBstFile.data());
  }
  f.writeBlock(bstData, bstData.length());
  f.close();

  // 4. for html we just copy the bib files to the output so that
  //    bibtex can find them without path (bibtex doesn't support path's
  //    with spaces!)
  QList<QCString> tempFiles;
  tempFiles.setAutoDelete(TRUE);
  QDir thisDir;
  if (Config_getBool("GENERATE_HTML"))
  {
    // copy bib files to the latex output dir
    QStrList &citeDataList = Config_getList("CITE_BIB_FILES");
    QCString bibOutputDir = outputDir+"/";
    QFileInfo fo(bibOutputDir);
    const char *bibdata = citeDataList.first();
    while (bibdata)
    {
      QCString bibFile = bibdata;
      if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
      QFileInfo fi(bibFile);
      if (fi.exists() && fi.dirPath(TRUE)!=fo.absFilePath())
      {
        if (!bibFile.isEmpty())
        {
          QCString destFile=bibOutputDir+fi.fileName().data();
          copyFile(bibFile,destFile);
          tempFiles.append(new QCString(destFile));
        }
      }
      else if (!fi.exists())
      {
        err("bib file %s not found!\n",bibFile.data());
      }
      bibdata = citeDataList.next();
    }
  }

  QCString oldDir = QDir::currentDirPath().utf8();
  QDir::setCurrent(outputDir);

  // 5. run bib2xhtml perl script on the generated file which will insert the
  //    bibliography in citelist.doc
  portable_system("perl","\""+bib2xhtmlFile+"\" "+getListOfBibFiles(" ",FALSE)+" \""+
                         citeListFile+"\"");

  QDir::setCurrent(oldDir);

  // 6. read back the file
  f.setName(citeListFile);
  if (!f.open(IO_ReadOnly)) 
  {
    err("could not open file %s/citelist.doc for reading\n",outputDir.data());
  }
  bool insideBib=FALSE;
  
  QCString doc;
  QFileInfo fi(citeListFile);
  QCString input(fi.size()+1);
  f.readBlock(input.data(),fi.size());
  f.close();
  input.at(fi.size())='\0';
  int p=0,s;
  //printf("input=[%s]\n",input.data());
  while ((s=input.find('\n',p))!=-1)
  {
    QCString line = input.mid(p,s-p);
    //printf("p=%d s=%d line=[%s]\n",p,s,line.data());
    p=s+1;

    if      (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE;
    else if (line.find("<!-- END BIBLIOGRAPH")!=-1)    insideBib=FALSE;
    else if (insideBib) doc+=line+"\n";
    int i;
    // determine text to use at the location of the @cite command
    if (insideBib && (i=line.find("<a name=\"CITEREF_"))!=-1)
    {
      int j=line.find("\">[");
      int k=line.find("]</a>");
      if (j!=-1 && k!=-1)
      {
        QCString label = line.mid(i+17,j-i-17);
        QCString number = line.mid(j+2,k-j-1);
        CiteInfo *ci = m_entries.find(label);
        //printf("label='%s' number='%s' => %p\n",label.data(),number.data(),ci);
        if (ci)
        {
          ci->text = number;
        }
      }
    }
  }
  //printf("doc=[%s]\n",doc.data());

  // 7. add it as a page
  addRelatedPage(CiteConsts::fileName,
       theTranslator->trCiteReferences(),doc,0,CiteConsts::fileName,1,0,0,0);

  // 8. for latex we just copy the bib files to the output and let 
  //    latex do this work.
  if (Config_getBool("GENERATE_LATEX"))
  {
    // copy bib files to the latex output dir
    QStrList &citeDataList = Config_getList("CITE_BIB_FILES");
    QCString latexOutputDir = Config_getString("LATEX_OUTPUT")+"/";
    const char *bibdata = citeDataList.first();
    while (bibdata)
    {
      QCString bibFile = bibdata;
      if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
      QFileInfo fi(bibFile);
      if (fi.exists())
      {
        if (!bibFile.isEmpty())
        {
          copyFile(bibFile,latexOutputDir+fi.fileName().data());
        }
      }
      else
      {
        err("bib file %s not found!\n",bibFile.data());
      }
      bibdata = citeDataList.next();
    }
  }

  // 9. Remove temporary files
  thisDir.remove(citeListFile);
  thisDir.remove(doxygenBstFile);
  thisDir.remove(bib2xhtmlFile);
  while (!tempFiles.isEmpty()) 
  {
    QCString *s=tempFiles.take(0);
    thisDir.remove(*s);
  }
}
예제 #9
0
bool
K2sendPlayer::bluePlay (QString * filename)
{

    char buffer[buffer_size];
    int bytes_done;
    int file_len;
    int bytes_sent;
    int current_bytes_sent;
    int rc;
    int play_length;
    bool stop = FALSE;
    unsigned long long now;
    fd_set rfds, wfds;
    struct timeval tv;
    K2sendPlayerCommand *cmd = 0;
    K2sendPlayerCommand *new_cmd = 0;
    K2sendStatusEvent *se = 0;

    TagLib::MPEG::File mp3file (filename->latin1 ());
    play_length = mp3file.audioProperties ()->length ();
    QFile file (*filename);
    kdDebug (200010) << "K2sendPlayer::bluePlay name=" << *filename << " lenght=" << play_length << endl;
    setReset (0);
    setLoudness (loud_filt);
    setVolume (100 - volume);

    if (!file.open (IO_ReadOnly)) {
        QString msg = QString ("Error opening file ");
        se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg);
        //kdDebug(200010) << "post 34" << endl;
        QApplication::postEvent (m_parent, se);
        return FALSE;
    }
    se = new K2sendStatusEvent (K2sendStatusEvent::EventTitle, *filename);
    //kdDebug(200010) << "post 35" << endl;
    QApplication::postEvent (m_parent, se);

    file_len = file.size ();
    current_bytes_sent = bytes_sent = 0;
    last_ticks = start_ticks = getTime ();

    do {
        /* check if we can send(write) or receive(read) data */
        FD_ZERO (&rfds);
        FD_SET (blue_sock, &rfds);
        FD_ZERO (&wfds);
        FD_SET (blue_sock, &wfds);

        tv.tv_sec = 3;
        tv.tv_usec = 0;

        rc = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
        if (rc < 1) {
            kdDebug (200010) << "K2sendPlayer::bluePlay select()" << endl;
            QString msg = QString ("Communication error");
            se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
            //kdDebug(200010) << "post 36" << endl;
            QApplication::postEvent (m_parent, se);
            blueClose ();
            return FALSE;
        }


        /* are we allowed to write? */
        if (FD_ISSET (blue_sock, &wfds)) {
            buffer[0] = K2sendPlayerCommand::Data;

            if (!(bytes_done = file.readBlock (buffer + 1, sizeof (buffer) - 1))) {
                if (file.atEnd ()) {
                    kdDebug (200010) << "K2sendPlayer::bluePlay Error reading file " << endl;
                    QString msg = QString ("Error reading file");
                    se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
                    //kdDebug(200010) << "post 37" << endl;
                    QApplication::postEvent (m_parent, se);

                }
            }
            else {
                if (write (blue_sock, buffer, bytes_done + 1) != bytes_done + 1) {
                    kdDebug (200010) << "K2sendPlayer::bluePlay Error sending" << endl;
                    QString msg = QString ("Error sending data");
                    se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
                    //kdDebug(200010) << "post 38" << endl;
                    QApplication::postEvent (m_parent, se);
                }
            }
            bytes_sent += bytes_done;
            current_bytes_sent += bytes_done;
        }
        if (FD_ISSET (blue_sock, &rfds)) {
            rc = read (blue_sock, buffer, sizeof (buffer));
            kdDebug (200010) << "K2sendPlayer::bluePlay  got data " << rc << " " << buffer[0] << " " << buffer[1] <<
                endl;
            /* handle commands */
            switch (buffer[0]) {
            case K2sendPlayerCommand::Buttons:
                if ((buffer[1] & 1) == 1) {
                    volume += 10;
                    if (volume > 100)
                        volume = 100;
                    //setVolume(100 - volume,TRUE);
                    kdDebug (200010) << "got cmd volume" << endl;
                    new_cmd = new K2sendPlayerCommand (K2sendPlayerCommand::Volume, volume);
                    addCommand (new_cmd);
                }
                if (buffer[1] & 2) {
                    se = new K2sendStatusEvent (K2sendStatusEvent::EventSkip, NULL, 0);
                    //kdDebug(200010) << "post 39" << endl;
                    kdDebug (200010) << "got cmd skip" << endl;
                    QApplication::postEvent (m_parent, se);
                    new_cmd = new K2sendPlayerCommand (K2sendPlayerCommand::Skip, 0);
                    addCommand (new_cmd);
                }
                if (buffer[1] & 4) {
                    volume -= 10;
                    if (volume < 0)
                        volume = 0;
                    //setVolume(100 - volume,TRUE);
                    kdDebug (200010) << "got cmd volume" << endl;
                    new_cmd = new K2sendPlayerCommand (K2sendPlayerCommand::Volume, volume);
                    addCommand (new_cmd);
                }
                if (buffer[1] & 8) {
                    se = new K2sendStatusEvent (K2sendStatusEvent::EventError, "Battery low", 2000);
                    kdDebug (200010) << "battery low" << endl;
                    QApplication::postEvent (m_parent, se);
                    new_cmd = new K2sendPlayerCommand (K2sendPlayerCommand::Stop, 0);
                    addCommand (new_cmd);
                }
                if (buffer[1] & 16) {
                    new_cmd = new K2sendPlayerCommand (K2sendPlayerCommand::Loudness, 0);
                    kdDebug (200010) << "got cmd loudness" << endl;
                    addCommand (new_cmd);
                }
                break;
            default:
                QString msg = QString ("Unknown command from BlueMP3");
                se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000);
                //kdDebug(200010) << "post 41" << endl;
                QApplication::postEvent (m_parent, se);
                break;
            }
        }
        now = getTime ();

        if ((last_ticks) < now - 250) {
            updateStatus (bytes_sent, current_bytes_sent, file_len, play_length);
            last_ticks = now;
        }
        cmd = 0;
        cmd = command ();
        if (cmd) {
            switch (cmd->command ()) {
            case K2sendPlayerCommand::Loudness:
                if (++loud_filt > 8)
                    loud_filt = 0;
                setLoudness (loud_filt);
                delete cmd;
                cmd = 0;
                break;
            case K2sendPlayerCommand::Volume:
                volume = cmd->value ();
                setVolume (100 - volume, FALSE);
                delete cmd;
                cmd = 0;
                break;
            case K2sendPlayerCommand::Play:
                bytes_done = 0;
                stop = TRUE;
                addCommand (cmd);
                break;
            case K2sendPlayerCommand::Stop:
                stop = TRUE;
                /* forward to global handling */
                addCommand (cmd);
                break;
            case K2sendPlayerCommand::Skip:
                stop = TRUE;
                addCommand (cmd);
                break;

            case K2sendPlayerCommand::Length:
                start_ticks = getTime ();
                current_bytes_sent = 0;
                bytes_sent = (file_len / 100) * cmd->value ();
                file.at (bytes_sent);
                delete cmd;
                cmd = 0;
                break;
            default:
                break;
            }
        }

    } while (bytes_sent != file_len && !stop);
    file.close ();

    se = new K2sendStatusEvent (K2sendStatusEvent::EventTitle, "");
    //kdDebug(200010) << "post 42" << endl;
    QApplication::postEvent (m_parent, se);

    this->clearStatus ();
    /* keep playing */
    if (!stop) {
        kdDebug (200010) << "K2sendPlayer::bluePlay keep playing" << endl;
        se = new K2sendStatusEvent (K2sendStatusEvent::EventSkip, 0, 0);
        //kdDebug(200010) << "post 43" << endl;
        QApplication::postEvent (m_parent, se);
        new_cmd = new K2sendPlayerCommand (K2sendPlayerCommand::Play, 0);
        addCommand (new_cmd);
    }
    kdDebug (200010) << "K2sendPlayer::bluePlay done" << endl;
    return TRUE;
}
bool kfile_metadatPlugin::readInfo ( KFileMetaInfo& info, uint what )
{
    bool readTech = false;
    // add your "calculations" here
    // if something goes wrong, "return false;"

    if ( what & ( KFileMetaInfo::Fastest |
                  KFileMetaInfo::DontCare |
                  KFileMetaInfo::TechnicalInfo ) )
        readTech = true;

    if ( info.path().isEmpty() ) // remote file cannot be handled
        return false;

    if ( readTech )
    {
        KFileMetaInfoGroup group = appendGroup ( info, "Technical" );
        char buffer[112];
        QFile qf ( info.path() );
        if ( ! qf.open ( IO_ReadOnly ) ||
                ( qf.readBlock ( buffer, 112 ) != 112 ) )
            return false; // File cannot be read --> no meta info
        qf.close();

        try
        {
            comag::meta m ( ( const unsigned char * ) buffer );

            appendItem ( group, "Title", QString::fromLatin1( m.gettitle().data() ) );
            appendItem ( group, "Title Type", ( m.gettitle_type() == comag::meta::TT_TRANSMISSION ) ?
                         i18n ( "Transmission" ) :
                         ( m.gettitle_type() == comag::meta::TT_STATION ) ?
                         i18n ( "Station" ) :
                         i18n ( "Unknown" ) );
#ifdef ENABLE_DATETIMETWOLINES
            appendItem ( group, "Start Time", QTime ( m.getstart_time().hour,
                         m.getstart_time().minute,
                         m.getstart_time().second ) );
            appendItem ( group, "Start Date", QDate ( m.getstart_date().year,
                         m.getstart_date().month,
                         m.getstart_date().day ) );
#else
            appendItem ( group, "Start Time", QDateTime ( QDate ( m.getstart_date().year,
                         m.getstart_date().month,
                         m.getstart_date().day ),
                         QTime ( m.getstart_time().hour,
                                 m.getstart_time().minute,
                                 m.getstart_time().second ) ) );
#endif
            appendItem ( group, "Duration", QTime ( m.getduration().hour,
                                                    m.getduration().minute,
                                                    m.getduration().second ) );
            appendItem ( group, "Packets", m.getpackets() );
            appendItem ( group, "Service", ( m.getservice() == comag::meta::S_RADIO ) ?
                         i18n ( "Radio" ) :
                         ( m.getservice() == comag::meta::S_TV ) ?
                         i18n ( "TV" ) : i18n ( "Unknown" ) );
            appendItem ( group, "PID", m.getpid() );
            appendItem ( group, "Timer", ( unsigned long long ) ( m.gettimer() ) );
        }
        catch ( ... )
        {
            return false; // Exceptions simply means: no meta info
        }
        // and finally display it!
        return true;
    }
    return false;
}
예제 #11
0
//--------------------------------------------------------------------------
// Parse the marker stream until SOS or EOI is seen;
//--------------------------------------------------------------------------
int ExifData::ReadJpegSections (QFile & infile, ReadMode_t ReadMode)
{
    int a;

    a = infile.getch();

    if (a != 0xff || infile.getch() != M_SOI) {
        SectionsRead = 0;
        return false;
    }
    for(SectionsRead = 0; SectionsRead < MAX_SECTIONS-1; ) {
        int marker = 0;
        int got;
        unsigned int ll,lh;
        unsigned int itemlen;
        uchar * Data;

        for (a=0; a<7; a++) {
            marker = infile.getch();
            if (marker != 0xff) break;

            if (a >= 6) {

                kdDebug(7034) << "too many padding bytes\n";
                return false;

            }
        }

        if (marker == 0xff) {
            // 0xff is legal padding, but if we get that many, something's wrong.
            throw FatalError("too many padding bytes!");
        }

        Sections[SectionsRead].Type = marker;

        // Read the length of the section.
        lh = (uchar) infile.getch();
        ll = (uchar) infile.getch();

        itemlen = (lh << 8) | ll;

        if (itemlen < 2) {
            throw FatalError("invalid marker");
        }

        Sections[SectionsRead].Size = itemlen;

        Data = (uchar *)malloc(itemlen+1); // Add 1 to allow sticking a 0 at the end.
        Sections[SectionsRead].Data = Data;

        // Store first two pre-read bytes.
        Data[0] = (uchar)lh;
        Data[1] = (uchar)ll;

        got = infile.readBlock((char*)Data+2, itemlen-2); // Read the whole section.
        if (( unsigned ) got != itemlen-2) {
            throw FatalError("reading from file");
        }
        SectionsRead++;

        switch(marker) {

        case M_SOS:   // stop before hitting compressed data
            // If reading entire image is requested, read the rest of the data.
            if (ReadMode & READ_IMAGE) {
                unsigned long size;

                size = kMax( 0ul, infile.size()-infile.at() );
                Data = (uchar *)malloc(size);
                if (Data == NULL) {
                    throw FatalError("could not allocate data for entire image");
                }

                got = infile.readBlock((char*)Data,  size);
                if (( unsigned ) got != size) {
                    throw FatalError("could not read the rest of the image");
                }

                Sections[SectionsRead].Data = Data;
                Sections[SectionsRead].Size = size;
                Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER;
                SectionsRead ++;
                //HaveAll = 1;
            }
            return true;

        case M_EOI:   // in case it's a tables-only JPEG stream
            kdDebug(7034) << "No image in jpeg!\n";
            return false;

        case M_COM: // Comment section
            // pieczy 2002-02-12
            // now the User comment goes to UserComment
            // so we can store a Comment section also in READ_EXIF mode
            process_COM(Data, itemlen);
            break;

        case M_JFIF:
            // Regular jpegs always have this tag, exif images have the exif
            // marker instead, althogh ACDsee will write images with both markers.
            // this program will re-create this marker on absence of exif marker.
            // hence no need to keep the copy from the file.
            free(Sections[--SectionsRead].Data);
            break;

        case M_EXIF:
            // Seen files from some 'U-lead' software with Vivitar scanner
            // that uses marker 31 for non exif stuff.  Thus make sure
            // it says 'Exif' in the section before treating it as exif.
            if ((ReadMode & READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0) {
                process_EXIF((uchar *)Data, itemlen); // FIXME: This call
                // requires Data to be array of at least 8 bytes. Code
                // above only checks for itemlen < 2.
            } else {
                // Discard this section.
                free(Sections[--SectionsRead].Data);
            }
            break;

        case M_SOF0:
        case M_SOF1:
        case M_SOF2:
        case M_SOF3:
        case M_SOF5:
        case M_SOF6:
        case M_SOF7:
        case M_SOF9:
        case M_SOF10:
        case M_SOF11:
        case M_SOF13:
        case M_SOF14:
        case M_SOF15:
            process_SOFn(Data, marker); //FIXME: This call requires Data to
            // be array of at least 8 bytes. Code above only checks for
            // itemlen < 2.
            break;
        default:
            break;
        }
    }
    return true;
}