bump product version to 7.2.5.1
[LibreOffice.git] / solenv / gbuildtojson / gbuildtojson.cxx
blob8061b801cd769e6e818873c59e65963431ab0f2d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <algorithm>
11 #include <fstream>
12 #include <iostream>
13 #include <list>
14 #include <map>
15 #include <sstream>
16 #include <string>
17 #include <stdio.h>
19 using namespace std;
21 int main(int argc, char** argv)
23 const string optsintro("--");
24 map<string, string> vartofile;
25 for(int i=1; i < argc; ++i)
27 const string arg(argv[i]);
28 if(arg.substr(0,2) != optsintro)
30 cerr << "Only option args starting with -- allowed." << endl;
31 return 1;
33 const size_t eqpos = arg.find("=", 2);
34 if(eqpos == string::npos)
36 cerr << "Only option args assigning with = allowed." << endl;
37 return 2;
39 const string argname(arg.substr(2, eqpos-2));
40 vartofile[argname] = arg.substr(eqpos+1, string::npos);
42 cout << "{";
43 bool first(true);
44 for(const auto& varandfile : vartofile)
46 if(first)
47 first =false;
48 else
49 cout << "," << endl;
50 string varupper(varandfile.first);
51 for(auto& c : varupper)
52 if(c != '_')
53 c = c-32;
54 ifstream filestream(varandfile.second.c_str());
55 stringstream contents;
56 contents << filestream.rdbuf();
57 filestream.close();
58 (void)remove(varandfile.second.c_str());
59 string escapedcontents;
60 for(const auto& c : contents.str())
62 if(c=='\\')
63 escapedcontents += "\\\\";
64 else if(c=='"')
65 escapedcontents += "\\\"";
66 else if(c=='\n')
67 continue;
68 else
69 escapedcontents += c;
71 cout << "\"" << varupper << "\": \"" << escapedcontents << "\"";
73 cout << "}" << endl;
74 return 0;
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */