SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
5.0KB

  1. /**********************************************************************
  2. ** Copyright (C) 2002 Detlev Offenbach <detlev@die-offenbachs.de>
  3. **
  4. ** This is a modified version of lupdate. The original is part of TQt-Linguist.
  5. ** The copyright of the original file can be found below.
  6. **
  7. ** This version is modified to handle python sources.
  8. **
  9. ** The file is provided AS IS with NO WARRANTY OF ANY KIND,
  10. ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
  11. ** A PARTICULAR PURPOSE.
  12. **
  13. **********************************************************************/
  14. /**********************************************************************
  15. ** Copyright (C) 2000 Trolltech AS. All rights reserved.
  16. **
  17. ** main.cpp
  18. **
  19. ** This file is part of TQt Linguist.
  20. **
  21. ** See the file LICENSE included in the distribution for the usage
  22. ** and distribution terms.
  23. **
  24. ** The file is provided AS IS with NO WARRANTY OF ANY KIND,
  25. ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
  26. ** A PARTICULAR PURPOSE.
  27. **
  28. **********************************************************************/
  29. #include <qfile.h>
  30. #include <qstring.h>
  31. #include <qstringlist.h>
  32. #include <qtextstream.h>
  33. #include <errno.h>
  34. #include <metatranslator.h>
  35. #include <proparser.h>
  36. #include <string.h>
  37. // defined in fetchtr.cpp
  38. extern void fetchtr_py( const char *fileName, MetaTranslator *tor,
  39. const char *defaultContext, bool mustExist );
  40. // defined in merge.cpp
  41. extern void merge( MetaTranslator *tor, const MetaTranslator *virginTor,
  42. bool verbose );
  43. typedef TQValueList<MetaTranslatorMessage> TML;
  44. static void printUsage()
  45. {
  46. qWarning( "Usage: pylupdate [options] file.pro...\n"
  47. "Options:\n"
  48. " -help Display this information and exits\n"
  49. " -noobsolete\n"
  50. " Drop all obsolete strings\n"
  51. " -verbose\n"
  52. " Explain what is being done\n"
  53. " -version\n"
  54. " Display the version of pylupdate and exits" );
  55. }
  56. int main( int argc, char **argv )
  57. {
  58. bool verbose = FALSE;
  59. bool noObsolete = FALSE;
  60. bool metSomething = FALSE;
  61. int numProFiles = 0;
  62. for ( int i = 1; i < argc; i++ ) {
  63. if ( qstrcmp(argv[i], "-help") == 0 ) {
  64. printUsage();
  65. return 0;
  66. } else if ( qstrcmp(argv[i], "-noobsolete") == 0 ) {
  67. noObsolete = TRUE;
  68. continue;
  69. } else if ( qstrcmp(argv[i], "-verbose") == 0 ) {
  70. verbose = TRUE;
  71. continue;
  72. } else if ( qstrcmp(argv[i], "-version") == 0 ) {
  73. qWarning( "pylupdate version %s", QT_VERSION_STR );
  74. return 0;
  75. }
  76. numProFiles++;
  77. TQFile f( argv[i] );
  78. if ( !f.open(IO_ReadOnly) ) {
  79. qWarning( "pylupdate error: Cannot open project file '%s': %s",
  80. argv[i], strerror(errno) );
  81. return 1;
  82. }
  83. TQTextStream t( &f );
  84. TQString fullText = t.read();
  85. f.close();
  86. MetaTranslator fetchedTor;
  87. TQString defaultContext = "@default";
  88. TQCString codec;
  89. TQStringList translatorFiles;
  90. TQStringList::Iterator tf;
  91. TQMap<TQString, TQString> tagMap = proFileTagMap( fullText );
  92. TQMap<TQString, TQString>::Iterator it;
  93. for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
  94. TQStringList toks = TQStringList::split( TQChar(' '), it.data() );
  95. TQStringList::Iterator t;
  96. for ( t = toks.begin(); t != toks.end(); ++t ) {
  97. if ( it.key() == TQString("SOURCES") ) {
  98. fetchtr_py( *t, &fetchedTor,
  99. defaultContext, TRUE );
  100. metSomething = TRUE;
  101. } else if ( it.key() == TQString("TRANSLATIONS") ) {
  102. translatorFiles.append( *t );
  103. metSomething = TRUE;
  104. } else if ( it.key() == TQString("CODEC") ) {
  105. codec = (*t).latin1();
  106. }
  107. }
  108. }
  109. for ( tf = translatorFiles.begin(); tf != translatorFiles.end(); ++tf ) {
  110. MetaTranslator tor;
  111. tor.load( *tf );
  112. if ( !codec.isEmpty() )
  113. tor.setCodec( codec );
  114. if ( verbose )
  115. qWarning( "Updating '%s'...", (*tf).latin1() );
  116. merge( &tor, &fetchedTor, verbose );
  117. if ( noObsolete )
  118. tor.stripObsoleteMessages();
  119. tor.stripEmptyContexts();
  120. if ( !tor.save(*tf) )
  121. qWarning( "pylupdate error: Cannot save '%s': %s", (*tf).latin1(),
  122. strerror(errno) );
  123. }
  124. if ( !metSomething ) {
  125. qWarning( "pylupdate warning: File '%s' does not look like a project"
  126. " file", argv[i] );
  127. } else if ( translatorFiles.isEmpty() ) {
  128. qWarning( "pylupdate warning: Met no 'TRANSLATIONS' entry in project"
  129. " file '%s'", argv[i] );
  130. }
  131. }
  132. if ( numProFiles == 0 ) {
  133. printUsage();
  134. return 1;
  135. }
  136. return 0;
  137. }