/* Fetches tr() calls in C++ code in UI files (inside "<function>" tag). This mechanism is obsolete. */ void fetchtr_inlined_cpp( const char *fileName, const QString& in, MetaTranslator *tor, const char *context ) { yyInStr = in; startTokenizer( fileName, getCharFromString ); parse( tor, context, 0 ); yyInStr = QString::null; }
void fetchtr_cpp( const char *fileName, MetaTranslator *tor, const char *defaultContext, bool mustExist ) { yyInFile = fopen( fileName, "r" ); if ( yyInFile == 0 ) { if ( mustExist ) fprintf( stderr, "lupdate error: Cannot open C++ source file '%s': %s\n", fileName, strerror(errno) ); return; } startTokenizer( fileName, getCharFromFile ); parse( tor, 0, defaultContext ); fclose( yyInFile ); }
void fetchtr_php( QFileInfo *fi, MetaTranslator *tor, bool mustExist ) { char *defaultContext = ""; yyInFile = fopen( fi->filePath().latin1(), "r" ); if ( yyInFile == 0 ) { if ( mustExist ) qWarning( "lupdate error: cannot open PHP source file '%s': %s", fi->filePath().latin1(), strerror(errno) ); return; } startTokenizer( fi->fileName().latin1(), getCharFromFile ); parse( tor, 0, defaultContext ); fclose( yyInFile ); }
void fetchtr_py( const char *fileName, MetaTranslator *tor, const char *defaultContext, bool mustExist, const QByteArray &codecForSource ) { #if defined(_MSC_VER) && _MSC_VER >= 1400 if (fopen_s(&yyInFile, fileName, "r")) { if ( mustExist ) { char buf[100]; strerror_s(buf, sizeof(buf), errno); fprintf( stderr, "pylupdate5 error: Cannot open Python source file '%s': %s\n", fileName, buf ); } #else yyInFile = fopen( fileName, "r" ); if ( yyInFile == 0 ) { if ( mustExist ) fprintf( stderr, "pylupdate5 error: Cannot open Python source file '%s': %s\n", fileName, strerror(errno) ); #endif return; } startTokenizer( fileName, getCharFromFile, peekCharFromFile, tor->codecForTr(), QTextCodec::codecForName(codecForSource) ); parse( tor, 0, defaultContext ); fclose( yyInFile ); } class UiHandler : public QXmlDefaultHandler { public: UiHandler( MetaTranslator *translator, const char *fileName ) : tor( translator ), fname( fileName ), comment( "" ) { } virtual bool startElement( const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts ); virtual bool endElement( const QString& namespaceURI, const QString& localName, const QString& qName ); virtual bool characters( const QString& ch ); virtual bool fatalError( const QXmlParseException& exception ); virtual void setDocumentLocator(QXmlLocator *locator) { m_locator = locator; } QXmlLocator *m_locator; private: void flush(); MetaTranslator *tor; QByteArray fname; QString context; QString source; QString comment; QString accum; int m_lineNumber; bool trString; }; bool UiHandler::startElement( const QString& /* namespaceURI */, const QString& /* localName */, const QString& qName, const QXmlAttributes& atts ) { if ( qName == QString("item") ) { flush(); if ( !atts.value(QString("text")).isEmpty() ) source = atts.value( QString("text") ); } else if ( qName == QString("string") ) { flush(); if (atts.value(QString("notr")).isEmpty() || atts.value(QString("notr")) != QString("true")) { trString = true; comment = atts.value(QString("comment")); } else { trString = false; } } if (trString) m_lineNumber = m_locator->lineNumber(); accum.truncate( 0 ); return true; } bool UiHandler::endElement( const QString& /* namespaceURI */, const QString& /* localName */, const QString& qName ) { accum.replace( QRegExp(QString("\r\n")), "\n" ); if ( qName == QString("class") ) { if ( context.isEmpty() ) context = accum; } else if ( qName == QString("string") && trString ) { source = accum; } else if ( qName == QString("comment") ) { comment = accum; flush(); } else { flush(); } return true; }