99#include < filesystem>
1010#include < map>
1111
12+ #if defined(_WIN32)
13+ #include < Windows.h>
14+ #endif
15+
1216std::regex include_reg (" ^#[ \t ]*include[ \t ]+\" ([^\" ]+)\" [ \t ]*" );
1317std::regex define_with_value_reg (" ^#[ \t ]*define[ \t ]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t ]+(.*)[ \t ]*" );
1418std::regex define_reg (" ^#[ \t ]*define[ \t ]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t ]*" );
@@ -109,7 +113,8 @@ void process_file(std::filesystem::path in_file, std::istream& in, std::ostream&
109113 std::string content_after_include = line.substr (result.position () + result.length ());
110114 // content_after_include must be empty or end with "//"
111115 if (content_after_include.empty () || content_after_include.find (" //" ) == 0 ) {
112- std::ifstream include_file (file_path);
116+ auto file_open_path = std::filesystem::absolute (file_path);
117+ std::ifstream include_file (file_open_path);
113118 if (include_file.is_open ()) {
114119 // if file_path's parent is root_path_for_skip, use NullStream
115120 // not skip the processing of the contents of the file as it may have definitions.
@@ -210,7 +215,8 @@ void process_file(std::filesystem::path in_file, std::istream& in, std::ostream&
210215}
211216
212217void process_file (std::string in_file_name, std::string out_file_name, std::filesystem::path root_path_for_skip) {
213- std::cout << " process file: " << in_file_name << std::endl;
218+ if (!arg_info::using_std_out)
219+ std::cout << " process file: " << in_file_name << std::endl;
214220 std::ifstream in_file (in_file_name);
215221 std::ofstream out_file;
216222 std::ostream* out_stream = &out_file;
@@ -220,20 +226,22 @@ void process_file(std::string in_file_name, std::string out_file_name, std::file
220226 out_file.open (out_file_name, std::ios_base::binary);
221227 std::filesystem::path include_path = std::filesystem::path (in_file_name).parent_path ();
222228 if (in_file.is_open () && (arg_info::using_std_out || out_file.is_open ())) {
223- process_file (in_file_name, in_file, out_file , " " , include_path, root_path_for_skip);
229+ process_file (in_file_name, in_file, *out_stream , " " , include_path, root_path_for_skip);
224230 in_file.close ();
225231 if (!arg_info::using_std_out)
226232 out_file.close ();
227233 }
228234 else {
229235 std::cerr << " can't open file" << std::endl;
230236 }
231- for (auto & [key, value]: define_map) {
232- std::cout << " warning: define " << key << " is not undef" << std::endl;
237+ if (!arg_info::using_std_out) {
238+ for (auto & [key, value]: define_map) {
239+ std::cout << " warning: define " << key << " is not undef" << std::endl;
240+ }
241+ std::cout << " process file: " << in_file_name << " done\n\n "
242+ << std::endl;
233243 }
234244 define_map.clear ();
235- std::cout << " process file: " << in_file_name << " done\n\n "
236- << std::endl;
237245}
238246
239247
@@ -257,6 +265,12 @@ void print_help() {
257265}
258266
259267int main (size_t argc, char * _argv[]) {
268+ #if defined(_WIN32)
269+ // Set console code page to UTF-8 so console known how to interpret string data
270+ SetConsoleOutputCP (CP_UTF8);
271+ // Enable buffering to prevent VS from chopping up UTF-8 byte sequences
272+ setvbuf (stdout, nullptr , _IOFBF, 1000 );
273+ #endif
260274 // build argv
261275 std::vector<std::string> argv;
262276 for (size_t i = 0 ; i < argc; i++) {
0 commit comments