// ----------------------------------------------------------------------- bool ParseMasks(const char *Masks_, QSet<QString> &Patterns_, TExcludePatterns &ExcludePatterns_) { QStringList MasksList = QString::fromLocal8Bit(Masks_).split(';', QString::SkipEmptyParts); for(QStringList::Iterator it = MasksList.begin(); it != MasksList.end(); ++it) { *it = it->trimmed(); if(it->isEmpty()) return false; } // for(QStringList::Iterator it = MasksList.begin(); it != MasksList.end(); ++it) { if(Patterns_.contains(*it)) continue; // ExcludePatterns_.push_back(QRegExp(*it, #ifdef Q_OS_WIN Qt::CaseInsensitive, QRegExp::Wildcard)); #else Qt::CaseSensitive, QRegExp::WildcardUnix)); #endif Patterns_.insert(*it); } return true; }
void ReduxWidget::open() { QStringList files = QFileDialog::getOpenFileNames( this, tr( "Open File" ), "", tr( "Log Files (*_lg*)" ) ); int sz = PATH_MAX + 1; // N.B. It is possible to construct a path longer than PATH_MAX on most systems, // so this is really not fool-proof... char* buf = new char[sz]; QStringList::Iterator it = files.begin(); while( it != files.end() ) { memset( buf, 0, sz * sizeof( char ) ); if( ( ! it->isEmpty() ) && realpath( it->toStdString().c_str(), buf ) ) { dumpMsg( QString( "Opening LogFile : " ) + *it ); /*LogFile* tmpLog = new LogFile ( buf ); bool skip = false; for ( unsigned int i=0; i<myLogs.size(); ++i) if ( !(*(myLogs[i]) != *tmpLog) ) skip = true; cout << *tmpLog << endl; if ( ! skip ) myLogs.push_back( tmpLog ); else delete tmpLog; //myLog.load(); */ } ++it; } delete[] buf; //emit setsChanged(); //logTree->reset(); //emit jobsChanged(); //jobTree->reset(); //for (int i=0; i<myJobs.size(); ++i) cout << *myJobs[i]; //cout << myNet; //cout << dumpXML(true) << endl; }
ConversionStatus GettextImportPlugin::readEntryRaw(QTextStream& stream) { //kDebug() << " START"; enum {Begin,Comment,Msgctxt,Msgid,Msgstr} part=Begin; _trailingNewLines=0; bool error=false; bool recoverableError=false; bool seenMsgctxt=false; _msgstr.clear(); _msgstr.append(QString()); _msgid.clear(); _msgid.append(QString()); _msgctxt.clear(); _comment.clear(); _gettextPluralForm=false; _obsolete=false; QStringList::Iterator msgstrIt=_msgstr.begin(); QString line; while( !stream.atEnd() ) { _errorLine++; //line=stream.readLine(); if (!_bufferedLine.isEmpty()) { line=_bufferedLine; _bufferedLine.clear(); } else line=stream.readLine(); kDebug() << "Parsing line: " << line; static const QString lesslessless="<<<<<<<"; static const QString isisis="======="; static const QString moremoremore=">>>>>>>"; if (KDE_ISUNLIKELY( line.startsWith( lesslessless ) || line.startsWith( isisis ) || line.startsWith( moremoremore ) )) { // We have found a CVS/SVN conflict marker. Abort. // (It cannot be any useful data of the PO file, as otherwise the line would start with at least a quote) kError() << "CVS/SVN conflict marker found! Aborting!" << endl << line << endl; return PARSE_ERROR; } // remove whitespaces from beginning and end of line line = line.trimmed(); // remember wrapping state to save file nicely int len=line.length(); if (len) { _trailingNewLines=0; if (_maxLineLength<len && line.at(0)!='#') _maxLineLength=len; } else ++_trailingNewLines; if(part==Begin) { // ignore trailing newlines if(!len) continue; if(line.startsWith(_obsoleteStart)) { _obsolete=true; part=Comment; _comment=line; } else if(line.startsWith('#')) { part=Comment; _comment=line; } else if( line.startsWith(_msgctxtStart) && line.contains( _rxMsgCtxt ) ) { part=Msgctxt; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgctxt\\s*\"")); line.remove(_rxMsgLineRemEndQuote); _msgctxt=line; seenMsgctxt=true; } else if( line.contains( _rxMsgId ) ) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(_rxMsgIdRemQuotes); line.remove(_rxMsgLineRemEndQuote); (*(_msgid).begin())=line; } // one of the quotation marks is missing else if(KDE_ISUNLIKELY( /*_testBorked&&*/ line.contains( _rxMsgIdBorked ) )) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); (*(_msgid).begin())=line; if(!line.isEmpty()) recoverableError=true; } else { kDebug() << "no comment, msgctxt or msgid found after a comment: " << line; error=true; break; } } else if(part==Comment) { if(!len && _obsolete ) return OK; if(!len) continue; else if(line.startsWith(_obsoleteStart)) { _comment+=('\n'+line); _obsolete=true; } else if(line.startsWith('#')) { _comment+=('\n'+line); } else if( line.startsWith(_msgctxtStart) &&line.contains( _rxMsgCtxt ) ) { part=Msgctxt; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgctxt\\s*\"")); line.remove(_rxMsgLineRemEndQuote); _msgctxt=line; seenMsgctxt=true; } else if( line.contains( _rxMsgId ) ) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(_rxMsgIdRemQuotes); line.remove(_rxMsgLineRemEndQuote); (*(_msgid).begin())=line; } // one of the quotation marks is missing else if(KDE_ISUNLIKELY( /*_testBorked&&*/line.contains( _rxMsgIdBorked ) )) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); (*(_msgid).begin())=line; if(!line.isEmpty()) recoverableError=true; } else { kDebug() << "no comment or msgid found after a comment while parsing: " << _comment; error=true; break; } } else if(part==Msgctxt) { if(!len) continue; else if( line.contains( _rxMsgLine ) ) { // remove quotes at beginning and the end of the lines line.remove(_rxMsgLineRemStartQuote); line.remove(_rxMsgLineRemEndQuote); // add Msgctxt line to item if(_msgctxt.isEmpty()) _msgctxt=line; else _msgctxt+=('\n'+line); } else if( line.contains( _rxMsgId ) ) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(_rxMsgIdRemQuotes); line.remove(_rxMsgLineRemEndQuote); _msgidMultiline=line.isEmpty(); (*(_msgid).begin())=line; } // one of the quotation marks is missing else if(KDE_ISUNLIKELY(/*_testBorked&&*/ line.contains ( _rxMsgIdBorked ) )) { part=Msgid; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); (*(_msgid).begin())=line; if(!line.isEmpty()) recoverableError=true; } else { kDebug() << "no msgid found after a msgctxt while parsing: " << _msgctxt; error=true; break; } } else if(part==Msgid) { if(!len) continue; else if( line.contains( _rxMsgLine ) ) { // remove quotes at beginning and the end of the lines line.remove(_rxMsgLineRemStartQuote); line.remove(_rxMsgLineRemEndQuote); QStringList::Iterator it; if(_gettextPluralForm) { it=_msgid.end(); --it; } else it = _msgid.begin(); // add Msgid line to item if(it->isEmpty()) (*it)=line; else (*it)+=('\n'+line); } else if( line.contains( _rxMsgIdPlural) ) { part=Msgid; _gettextPluralForm = true; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid_plural\\s*\"")); line.remove(_rxMsgLineRemEndQuote); _msgid.append(line); } // one of the quotation marks is missing else if(KDE_ISUNLIKELY(/*_testBorked&&*/ line.contains( _rxMsgIdPluralBorked ) )) { part=Msgid; _gettextPluralForm = true; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgid_plural\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); _msgid.append(line); if(!line.isEmpty()) recoverableError=true; } else if( !_gettextPluralForm && ( line.contains( _rxMsgStr ) ) ) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(_rxMsgStrRemQuotes); line.remove(_rxMsgLineRemEndQuote); _msgstrMultiline=line.isEmpty(); (*msgstrIt)=line; } else if( !_gettextPluralForm && ( line.contains( _rxMsgStrOther )) ) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(_rxMsgStrRemQuotes); line.remove(_rxMsgLineRemEndQuote); (*msgstrIt)=line; if(!line.isEmpty()) recoverableError=true; } else if( _gettextPluralForm && ( line.contains( _rxMsgStrPluralStart ) ) ) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[0\\]\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); (*msgstrIt)=line; } else if(KDE_ISUNLIKELY( /*_testBorked&&*/ _gettextPluralForm && line.contains( _rxMsgStrPluralStartBorked ) )) { part=Msgstr; // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[0\\]\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); (*msgstrIt)=line; if(!line.isEmpty()) recoverableError=true; } else if ( line.startsWith( '#' ) ) { // ### TODO: could this be considered recoverable? kDebug() << "comment found after a msgid while parsing: " << _msgid.first(); error=true; break; } else if ( line.startsWith( "msgid" ) ) { kDebug() << "Another msgid found after a msgid while parsing: " << _msgid.first(); error=true; break; } // a line of the msgid with a missing quotation mark else if(KDE_ISUNLIKELY( /*_testBorked&&*/line.contains( _rxMsgLineBorked ) )) { recoverableError=true; // remove quotes at beginning and the end of the lines line.remove(_rxMsgLineRemStartQuote); line.remove(_rxMsgLineRemEndQuote); QStringList::Iterator it; if( _gettextPluralForm ) { it=_msgid.end(); --it; } else it = _msgid.begin(); // add Msgid line to item if(it->isEmpty()) (*it)=line; else (*it)+=('\n'+line); } else { kDebug() << "no msgstr found after a msgid while parsing: " << _msgid.first(); error=true; break; } } else if(part==Msgstr) { if(!len) break; // another line of the msgstr else if( line.contains( _rxMsgLine ) ) { // remove quotes at beginning and the end of the lines line.remove(_rxMsgLineRemStartQuote); line.remove(_rxMsgLineRemEndQuote); if(!(*msgstrIt).isEmpty()) (*msgstrIt)+='\n'; (*msgstrIt)+=line; } else if( _gettextPluralForm && ( line.contains( _rxMsgStrPlural ) ) ) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[[0-9]+\\]\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); _msgstr.append(line); msgstrIt=_msgstr.end(); --msgstrIt; } else if ( line.startsWith( '#' ) || line.startsWith( "msgid" ) ) { _errorLine--; _bufferedLine=line; break; } else if(KDE_ISUNLIKELY(/*_testBorked&&*/ _gettextPluralForm && ( line.contains( _rxMsgStrPluralBorked ) ) )) { // remove quotes at beginning and the end of the lines line.remove(QRegExp("^msgstr\\[[0-9]\\]\\s*\"?")); line.remove(_rxMsgLineRemEndQuote); _msgstr.append(line); msgstrIt=_msgstr.end(); --msgstrIt; if(!line.isEmpty()) recoverableError=true; } else if(line.startsWith("msgstr")) { kDebug() << "Another msgstr found after a msgstr while parsing: " << line << _msgstr.last(); error=true; break; } // another line of the msgstr with a missing quotation mark else if(KDE_ISUNLIKELY( /*_testBorked&&*/line.contains( _rxMsgLineBorked ) )) { recoverableError=true; // remove quotes at beginning and the end of the lines line.remove(_rxMsgLineRemStartQuote); line.remove(_rxMsgLineRemEndQuote); if(!(*msgstrIt).isEmpty()) (*msgstrIt)+='\n'; (*msgstrIt)+=line; } else { kDebug() << "no msgid or comment found after a msgstr while parsing: " << _msgstr.last(); error=true; break; } } } /* if(_gettextPluralForm) { kDebug() << "gettext plural form:\n" << "msgid:\n" << _msgid.first() << "\n" << "msgid_plural:\n" << _msgid.last() << "\n" << endl; int counter=0; for(QStringList::Iterator it = _msgstr.begin(); it != _msgstr.end(); ++it) { kDebug() << "msgstr[" << counter << "]:\n" << (*it) << endl; counter++; } } */ //kDebug() << " NEAR RETURN"; if(KDE_ISUNLIKELY(error)) return PARSE_ERROR; else if(KDE_ISUNLIKELY(recoverableError)) return RECOVERED_PARSE_ERROR; else return OK; }