Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / solenv / gbuildtojson / gbuildtojson.cxx
blob4d60ac787a4bea364fa36b3612716e8318c8dc31
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 int main(int argc, char** argv)
21 const std::string optsintro("--");
22 std::map<std::string, std::string> vartofile;
23 for(int i=1; i < argc; ++i)
25 const std::string arg(argv[i]);
26 if(arg.substr(0,2) != optsintro)
28 std::cerr << "Only option args starting with -- allowed." << std::endl;
29 return 1;
31 const size_t eqpos = arg.find("=", 2);
32 if(eqpos == std::string::npos)
34 std::cerr << "Only option args assigning with = allowed." << std::endl;
35 return 2;
37 const std::string argname(arg.substr(2, eqpos-2));
38 vartofile[argname] = arg.substr(eqpos+1, std::string::npos);
40 std::cout << "{";
41 bool first(true);
42 for(const auto& varandfile : vartofile)
44 if(first)
45 first =false;
46 else
47 std::cout << "," << std::endl;
48 std::string varupper(varandfile.first);
49 for(auto& c : varupper)
50 if(c != '_')
51 c = c-32;
52 std::ifstream filestream(varandfile.second.c_str());
53 std::stringstream contents;
54 contents << filestream.rdbuf();
55 filestream.close();
56 (void)remove(varandfile.second.c_str());
57 std::string escapedcontents;
58 for(const auto& c : contents.str())
60 if(c=='\\')
61 escapedcontents += "\\\\";
62 else if(c=='"')
63 escapedcontents += "\\\"";
64 else if(c=='\n')
65 continue;
66 else
67 escapedcontents += c;
69 std::cout << "\"" << varupper << "\": \"" << escapedcontents << "\"";
71 std::cout << "}" << std::endl;
72 return 0;
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */