Debian Codegraph @

tools/HogMaker/HogMaker.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Descent Developers
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <iostream>
19 #include <algorithm>
20 #include <chrono>
21 #include <filesystem>
22 #include <fstream>
23 #include <string>
24
25 #include "d3_version.h"cxx . . $ `<file>/build/lib/d3_version.h`/
26 #include "HogFormat.h"cxx . . $ `<file>/tools/HogMaker/HogFormat.h`/
27
28 // TODO: To our descendants from the future: remove it when code will support C++20
29 template <typename TP> stdcxx . . $ std/::time_tcxx . . $ std/time_t# to_time_tcxx . . $ to_time_t(5acf241e44d4ac27).(TP tp) {
30 auto sctp = stdcxx . . $ std/::chronocxx . . $ std/chrono/::duration_castcxx . . $ std/chrono/duration_cast(b7f67bf9c2f19806).<stdcxx . . $ std/::chronocxx . . $ std/chrono/::system_clockcxx . . $ std/chrono/_V2/system_clock#::durationcxx . . $ std/chrono/_V2/system_clock#duration#>(tp - TP::clock::now()) +
31 stdcxx . . $ std/::chronocxx . . $ std/chrono/::system_clockcxx . . $ std/chrono/_V2/system_clock#::nowcxx . . $ std/chrono/_V2/system_clock#now(3657dacbd9b4f607).();
32 return stdcxx . . $ std/::chronocxx . . $ std/chrono/::system_clockcxx . . $ std/chrono/_V2/system_clock#::to_time_tcxx . . $ std/chrono/_V2/system_clock#to_time_t(88d50d0742db4f1).(sctp);
33 }
34
35 // Find requested file in search paths
36 stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# resolve_pathcxx . . $ resolve_path(57149233d7f951b5).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#> &search_path,
37 const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &file) {
38 for (const auto &i : search_path) {
39 if (is_regular_filecxx . . $ std/filesystem/is_regular_file(c53a6ef3278968b1).((i /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). file))) {
40 return (i /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). file);
41 }
42 }
43 // Return empty path
44 return stdcxx . . $ std/filesystem/__cxx11/path#path(ced63f7c635d850d).::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#{};
45 }
46
47 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) {
48 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#> input_filescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
49
50 if (argc < 3) {
51 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "HogMaker v" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). D3_MAJORVERcxx . . $ `build/lib/d3_version.h:23:9`! <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "." <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). D3_MINORVERcxx . . $ `build/lib/d3_version.h:24:9`! <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "." <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). D3_BUILDcxx . . $ `build/lib/d3_version.h:25:9`! <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "-g" <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). D3_GIT_HASHcxx . . $ `build/lib/d3_version.h:27:9`! <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"
52 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Usage:\n"
53 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). argv[0] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " <hogfile.hog> <inputfile.txt> [search_path]\n"
54 <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
55 return 1;
56 }
57
58 stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# hog_filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).{argv[1]};
59 stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# input_filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).{argv[2]};
60 // Default search path
61 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#> search_pathscxx . . $ std/vector#vector(9619226211e5a241).{input_filename.parent_pathcxx . . $ std/filesystem/__cxx11/path#parent_path(159787a050b29eb0).()};
62 // Additional search paths
63 for (int i = 3; i < argc; i++) {
64 if (is_directorycxx . . $ std/filesystem/is_directory(c53a6ef3278968b1).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#(argv[i]))) {
65 search_paths.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(argv[i]);
66 }
67 }
68
69 if (!is_regular_filecxx . . $ std/filesystem/is_regular_file(c53a6ef3278968b1).(input_filename)) {
70 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/filesystem/__cxx11/`operator<<`(bfa32d0318526b19). input_filename <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " is not a regular file!" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
71 return 1;
72 }
73
74 D3cxx . . $ D3/::HogFormatcxx . . $ D3/HogFormat# hog_table;
75
76 try {
77 create_directoriescxx . . $ std/filesystem/create_directories(c53a6ef3278968b1).(absolutecxx . . $ std/filesystem/absolute(4ac62a867fe4334a).(hog_filename).parent_pathcxx . . $ std/filesystem/__cxx11/path#parent_path(159787a050b29eb0).());
78 stdcxx . . $ std/::ifstreamcxx . . $ std/ifstream# inputcxx . . $ std/basic_ifstream#basic_ifstream(fbe7c9ddfb647a62).(input_filename, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::incxx . . $ std/ios_base#in.);
79 for (stdcxx . . $ std/::stringcxx . . $ std/string# linecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; stdcxx . . $ std/::getlinecxx . . $ std/getline(4ec722ed0b69c2ab).(input, line);) {
80 auto resolved_file = resolve_pathcxx . . $ resolve_path(57149233d7f951b5).(search_paths, linecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).);
81 if (resolved_file.emptycxx . . $ std/filesystem/__cxx11/path#empty(3482b152b9333168).()) {
82 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Warning! File " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). line <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " from " <<cxx . . $ std/filesystem/__cxx11/`operator<<`(bfa32d0318526b19). input_filename <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " not found! Skipping..." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
83 } else if (line.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() > 36) {
84 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Warning! Length of name of file " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). line <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " is more than 36 symbols! Skipping..." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
85 } else {
86 hog_table.AddEntrycxx . . $ D3/HogFormat#AddEntry(de61f79b9371789b).(D3cxx . . $ D3/::HogFileEntrycxx . . $ D3/HogFileEntry#(resolved_file));
87 }
88 }
89
90 } catch (stdcxx . . $ std/::exception &e) {
91 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Exception: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). e.what() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
92 return 1;
93 }
94
95 hog_table.SortEntriescxx . . $ D3/HogFormat#SortEntries(49f6e7a06ebc5aa8).();
96
97 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Creating " <<cxx . . $ std/filesystem/__cxx11/`operator<<`(bfa32d0318526b19). absolutecxx . . $ std/filesystem/absolute(4ac62a867fe4334a).(hog_filename) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "..." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
98 stdcxx . . $ std/::fstreamcxx . . $ std/fstream# ofscxx . . $ std/basic_fstream#basic_fstream(fbe7c9ddfb647a62).(hog_filename, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::outcxx . . $ std/ios_base#out. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::binarycxx . . $ std/ios_base#binary.);
99
100 ofs <<cxx . . $ D3/`operator<<`(ddf1f55e3333f4c5). hog_table;
101 for (const auto& i : hog_table.GetEntriescxx . . $ D3/HogFormat#GetEntries(36904b49bbb244ed).()) {
102 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Adding " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). i.GetNamecxx . . $ D3/HogFileEntry#GetName(219584694fe2b248).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "... ";
103 try {
104 stdcxx . . $ std/::fstreamcxx . . $ std/fstream# ifscxx . . $ std/basic_fstream#basic_fstream(fbe7c9ddfb647a62).(i.GetRealPathcxx . . $ D3/HogFileEntry#GetRealPath(159787a050b29eb0).(), stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::incxx . . $ std/ios_base#in. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::binarycxx . . $ std/ios_base#binary.);
105 stdcxx . . $ std/::copycxx . . $ std/copy(89f2925a29cd2615).((stdcxx . . $ std/::istreambuf_iteratorcxx . . $ std/istreambuf_iterator#<char>(ifs)), stdcxx . . $ std/istreambuf_iterator#istreambuf_iterator(ced63f7c635d850d).::istreambuf_iteratorcxx . . $ std/istreambuf_iterator#<char>(),
106 stdcxx . . $ std/::ostreambuf_iteratorcxx . . $ std/ostreambuf_iterator#<char>(ofs));
107 } catch (stdcxx . . $ std/::exception &e) {
108 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Exception: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). e.what() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
109 return 1;
110 }
111 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[ok]" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
112 }
113 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Done!" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
114
115 return 0;
116 }