author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <string.h> |
|
44 |
#include <errno.h> |
|
45 |
#include <stdlib.h> |
|
46 |
||
47 |
#include <qfile.h> |
|
48 |
#include <qstring.h> |
|
49 |
#include <qtextstream.h> |
|
50 |
||
51 |
#include "parser.h" |
|
52 |
||
53 |
static QTextStream qout(stdout, QIODevice::WriteOnly); |
|
54 |
static QTextStream qerr(stderr, QIODevice::WriteOnly); |
|
55 |
||
56 |
static void usage() |
|
57 |
{ |
|
58 |
qerr << "Usage: parse [-report-whitespace-only-chardata] [-report-start-end-entity] <in-file> [<out-file>]\n"; |
|
59 |
exit(1); |
|
60 |
} |
|
61 |
||
62 |
int main(int argc, const char *argv[]) |
|
63 |
{ |
|
64 |
QString file_name; |
|
65 |
QString out_file_name; |
|
66 |
bool report_start_end_entity = false; |
|
67 |
bool report_whitespace_only_chardata = false; |
|
68 |
||
69 |
for (int i = 1 ; i < argc; ++i) { |
|
70 |
QString arg = QString::fromLocal8Bit(argv[i]); |
|
71 |
if (arg == QLatin1String("-report-whitespace-only-chardata")) |
|
72 |
report_whitespace_only_chardata = true; |
|
73 |
else if (arg == QLatin1String("-report-start-end-entity")) |
|
74 |
report_start_end_entity = true; |
|
75 |
else if (file_name.isEmpty()) |
|
76 |
file_name = arg; |
|
77 |
else if (out_file_name.isEmpty()) |
|
78 |
out_file_name = arg; |
|
79 |
else |
|
80 |
usage(); |
|
81 |
} |
|
82 |
||
83 |
if (file_name.isEmpty()) |
|
84 |
usage(); |
|
85 |
||
86 |
QFile in_file(file_name); |
|
87 |
if (!in_file.open(QIODevice::ReadOnly)) { |
|
88 |
qerr << "Could not open " << file_name << ": " << strerror(errno) << endl; |
|
89 |
return 1; |
|
90 |
} |
|
91 |
||
92 |
if (out_file_name.isEmpty()) |
|
93 |
out_file_name = file_name + ".ref"; |
|
94 |
||
95 |
QFile _out_file; |
|
96 |
QTextStream _out_stream; |
|
97 |
QTextStream *out_stream; |
|
98 |
if (out_file_name == "-") { |
|
99 |
out_stream = &qout; |
|
100 |
} else { |
|
101 |
_out_file.setFileName(out_file_name); |
|
102 |
if (!_out_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { |
|
103 |
qerr << "Could not open " << out_file_name << ": " << strerror(errno) << endl; |
|
104 |
return 1; |
|
105 |
} |
|
106 |
_out_stream.setDevice(&_out_file); |
|
107 |
out_stream = &_out_stream; |
|
108 |
} |
|
109 |
||
110 |
Parser parser; |
|
111 |
if (report_start_end_entity) |
|
112 |
parser.setFeature("http://trolltech.com/xml/features/report-start-end-entity", true); |
|
113 |
if (report_whitespace_only_chardata) |
|
114 |
parser.setFeature("http://trolltech.com/xml/features/report-whitespace-only-CharData", true); |
|
115 |
||
116 |
parser.parseFile(&in_file); |
|
117 |
||
118 |
out_stream->setCodec("utf8"); |
|
119 |
||
120 |
*out_stream << parser.result(); |
|
121 |
||
122 |
return 0; |
|
123 |
} |