| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2007 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | #include <QCoreApplication>
|
|---|
| 20 | #include <QProcess>
|
|---|
| 21 | #include <QFile>
|
|---|
| 22 | #include <stdio.h>
|
|---|
| 23 | #include <stdlib.h>
|
|---|
| 24 |
|
|---|
| 25 | //! Tries to get the revision by running "svn info"
|
|---|
| 26 | QString get_from_svn_info() {
|
|---|
| 27 | QString revision;
|
|---|
| 28 |
|
|---|
| 29 | QProcess p;
|
|---|
| 30 | p.setEnvironment( QStringList() << "LC_ALL=C" );
|
|---|
| 31 | p.setProcessChannelMode(QProcess::MergedChannels);
|
|---|
| 32 | p.start( "svn", QStringList() << "info" );
|
|---|
| 33 | p.waitForStarted();
|
|---|
| 34 | p.waitForFinished();
|
|---|
| 35 |
|
|---|
| 36 | QByteArray line;
|
|---|
| 37 | QRegExp rx("^Revision: (\\d+)");
|
|---|
| 38 | while (p.canReadLine()) {
|
|---|
| 39 | line = p.readLine();
|
|---|
| 40 | if (rx.indexIn(line)!=-1) {
|
|---|
| 41 | revision = rx.cap(1);
|
|---|
| 42 | break;
|
|---|
| 43 | }
|
|---|
| 44 | //qDebug( line.data() );
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | return revision;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | //! Looks for 'revision="number"' in .svn/entries
|
|---|
| 51 | QString get_from_entries_1() {
|
|---|
| 52 | QString revision;
|
|---|
| 53 |
|
|---|
| 54 | QFile f(".svn/entries");
|
|---|
| 55 | QRegExp rx("revision=\"(\\d+)\"");
|
|---|
| 56 | if ( f.open(QIODevice::ReadOnly) ) {
|
|---|
| 57 | QByteArray line;
|
|---|
| 58 | while (!f.atEnd()) {
|
|---|
| 59 | line = f.readLine();
|
|---|
| 60 | if (rx.indexIn(line)!=-1) {
|
|---|
| 61 | revision = rx.cap(1);
|
|---|
| 62 | break;
|
|---|
| 63 | }
|
|---|
| 64 | //qDebug( line.data() );
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | return revision;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | //! Looks for 'dir' in .svn/entries
|
|---|
| 72 | //! the revision is in the next line
|
|---|
| 73 | QString get_from_entries_2() {
|
|---|
| 74 | QString revision;
|
|---|
| 75 |
|
|---|
| 76 | QFile f(".svn/entries");
|
|---|
| 77 | //QFile f("/tmp/temp/entries");
|
|---|
| 78 | QRegExp rx("^dir$");
|
|---|
| 79 | if ( f.open(QIODevice::ReadOnly) ) {
|
|---|
| 80 | QByteArray line;
|
|---|
| 81 | while (!f.atEnd()) {
|
|---|
| 82 | line = f.readLine();
|
|---|
| 83 | line = line.simplified();
|
|---|
| 84 | if (rx.indexIn(line)!=-1) {
|
|---|
| 85 | // Next line
|
|---|
| 86 | line = f.readLine();
|
|---|
| 87 | revision = line.simplified();
|
|---|
| 88 | break;
|
|---|
| 89 | }
|
|---|
| 90 | //qDebug( line.data() );
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | return revision;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | int main( int argc, char ** argv )
|
|---|
| 98 | {
|
|---|
| 99 | QCoreApplication a( argc, argv );
|
|---|
| 100 |
|
|---|
| 101 | QString revision;
|
|---|
| 102 |
|
|---|
| 103 | revision = get_from_svn_info();
|
|---|
| 104 |
|
|---|
| 105 | if (revision.isEmpty()) {
|
|---|
| 106 | revision = get_from_entries_1();
|
|---|
| 107 |
|
|---|
| 108 | if (revision.isEmpty()) {
|
|---|
| 109 | revision = get_from_entries_2();
|
|---|
| 110 |
|
|---|
| 111 | if (revision.isEmpty()) {
|
|---|
| 112 | revision = "UNKNOWN";
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | printf("#define SVN_REVISION \"SVN-r%s\"\n", revision.toLatin1().data());
|
|---|
| 118 |
|
|---|
| 119 | return 0;
|
|---|
| 120 | };
|
|---|