annotate Deprecated/Resources/CodeGeneration/testCppHandler/main.cpp @ 1458:828a9b4ee1b7

added missing copyright
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 21:23:02 +0200
parents f6a2d46d2b76
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
1 /**
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
2 * Stone of Orthanc
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
4 * Department, University Hospital of Liege, Belgium
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
6 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
7 * This program is free software: you can redistribute it and/or
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
10 * the License, or (at your option) any later version.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
11 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
12 * This program is distributed in the hope that it will be useful, but
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
15 * Affero General Public License for more details.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
16 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
19 **/
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
20
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
21
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
22 #include <string>
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
23 #include <fstream>
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
24 #include <filesystem>
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
25 #include <regex>
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
26 using namespace std;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
27 namespace fs = std::filesystem;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
28
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
29 #include <boost/program_options.hpp>
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
30 using namespace boost::program_options;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
31
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
32 #include "TestStoneCodeGen_generated.hpp"
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
33
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
34 /**
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
35 Transforms `str` by replacing occurrences of `oldStr` with `newStr`, using
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
36 plain text (*not* regular expressions.)
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
37 */
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
38 static inline void ReplaceInString(
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
39 string& str,
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
40 const std::string& oldStr,
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
41 const std::string& newStr)
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
42 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
43 std::string::size_type pos = 0u;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
44 while ((pos = str.find(oldStr, pos)) != std::string::npos) {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
45 str.replace(pos, oldStr.length(), newStr);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
46 pos += newStr.length();
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
47 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
48 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
49
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
50 string SlurpFile(const string& fileName)
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
51 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
52 ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
53
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
54 ifstream::pos_type fileSize = ifs.tellg();
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
55 ifs.seekg(0, ios::beg);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
56
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
57 vector<char> bytes(fileSize);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
58 ifs.read(bytes.data(), fileSize);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
59
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
60 return string(bytes.data(), fileSize);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
61 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
62
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
63 class MyHandler : public TestStoneCodeGen::IHandler
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
64 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
65 public:
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
66 virtual bool Handle(const TestStoneCodeGen::A& value) override
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
67 {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
68 TestStoneCodeGen::StoneDumpValue(cout, value);
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
69 return true;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
70 }
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
71 virtual bool Handle(const TestStoneCodeGen::B& value) override
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
72 {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
73 TestStoneCodeGen::StoneDumpValue(cout, value);
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
74 return true;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
75 }
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
76 virtual bool Handle(const TestStoneCodeGen::C& value) override
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
77 {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
78 TestStoneCodeGen::StoneDumpValue(cout, value);
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
79 return true;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
80 }
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
81 virtual bool Handle(const TestStoneCodeGen::Message1& value) override
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
82 {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
83 TestStoneCodeGen::StoneDumpValue(cout, value);
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
84 return true;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
85 }
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
86 virtual bool Handle(const TestStoneCodeGen::Message2& value) override
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
87 {
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
88 TestStoneCodeGen::StoneDumpValue(cout, value);
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
89 return true;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
90 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
91 };
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
92
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
93 template<typename T>
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
94 void ProcessPath(T filePath)
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
95 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
96 cout << "+--------------------------------------------+\n";
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
97 cout << "| Processing: " << filePath.path().string() << "\n";
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
98 cout << "+--------------------------------------------+\n";
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
99 MyHandler handler;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
100 auto contents = SlurpFile(filePath.path().string());
687
342f3e04bfa9 CodeGen: test cleanup + all working again + using same yaml and stimuli files
Alain Mazy <alain@mazy.be>
parents: 653
diff changeset
101 TestStoneCodeGen::StoneDispatchToHandler(contents, &handler);
653
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
102 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
103
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
104 int main(int argc, char** argv)
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
105 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
106 try
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
107 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
108
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
109 options_description desc("Allowed options");
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
110 desc.add_options()
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
111 // First parameter describes option name/short name
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
112 // The second is parameter to option
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
113 // The third is description
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
114 ("help,h", "print usage message")
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
115 ("pattern,p", value<string>(), "pattern for input")
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
116 ;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
117
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
118 variables_map vm;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
119 store(parse_command_line(argc, argv, desc), vm);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
120
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
121 if (vm.count("help"))
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
122 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
123 cout << desc << "\n";
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
124 return 0;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
125 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
126
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
127 notify(vm);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
128
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
129 string pattern = vm["pattern"].as<string>();
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
130
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
131 // tranform globbing pattern into regex
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
132 // we should deal with -, ., *...
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
133 string regexPatternStr = pattern;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
134 cout << "Pattern is: " << regexPatternStr << endl;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
135 ReplaceInString(regexPatternStr, "\\", "\\\\");
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
136 ReplaceInString(regexPatternStr, "-", "\\-");
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
137 ReplaceInString(regexPatternStr, ".", "\\.");
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
138 ReplaceInString(regexPatternStr, "*", ".*");
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
139 ReplaceInString(regexPatternStr, "?", ".");
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
140 cout << "Corresponding regex is: " << regexPatternStr << endl;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
141
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
142 regex regexPattern(regexPatternStr);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
143
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
144 for (auto& p : fs::directory_iterator("."))
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
145 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
146 auto fileName = p.path().filename().string();
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
147 if (regex_match(fileName, regexPattern))
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
148 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
149 ProcessPath(p);
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
150 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
151 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
152 return 0;
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
153
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
154
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
155 }
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
156 catch (exception& e)
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
157 {
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
158 cerr << e.what() << "\n";
4eccf698e52f Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents: 495
diff changeset
159 }
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1401
diff changeset
160 }