Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #include "parser.hpp"
10 :
11 : #include <fstream>
12 : #include <iostream>
13 :
14 : using namespace std;
15 :
16 0 : ostream & operator<< (ostream & os, parse_t & p)
17 : {
18 0 : os << "/*This is an auto-generated file generated by exporttranslations. Do not modify it.*/" << endl
19 0 : << endl
20 0 : << "#ifndef KDBERROR_TRANSLATION_H" << endl
21 0 : << "#define KDBERROR_TRANSLATION_H" << endl
22 0 : << endl
23 0 : << endl
24 0 : << "static const char *description_strings[] = {" << endl;
25 :
26 0 : for (size_t i = 1; i < p.size (); ++i)
27 : {
28 0 : if (p[i]["unused"] == "yes")
29 : {
30 : continue;
31 : }
32 :
33 0 : if (i != 1) os << "," << endl;
34 :
35 0 : os << " QT_TRANSLATE_NOOP(" << p[i]["description"] << ")";
36 : }
37 :
38 0 : os << endl << "};" << endl << endl;
39 :
40 0 : os << "#endif" << endl;
41 0 : return os;
42 : }
43 :
44 0 : int main (int argc, char ** argv) try
45 : {
46 0 : if (argc == 1 || argc > 3)
47 : {
48 0 : cerr << "Usage " << argv[0] << " infile [outfile]" << endl;
49 0 : return 1;
50 : }
51 :
52 0 : string infile = argv[1];
53 :
54 0 : parse_t result = parse (infile);
55 :
56 0 : if (argc == 3)
57 : {
58 0 : ofstream fout (argv[2]);
59 0 : if (!fout.is_open ())
60 : {
61 0 : cerr << "Could not open output file" << endl;
62 0 : return 1;
63 : }
64 0 : fout << result;
65 : }
66 : else
67 : {
68 0 : cout << result;
69 : }
70 : }
71 0 : catch (parse_error const & e)
72 : {
73 0 : cerr << "The line " << e.linenr << " caused following parse error: " << e.info << endl;
74 : return 2;
75 0 : }
|