Skip to content

Commit 01c6089

Browse files
committed
Fix compilation errors on MSVC.
1 parent c333c22 commit 01c6089

File tree

9 files changed

+38
-23
lines changed

9 files changed

+38
-23
lines changed

lib/iconv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545
#include "generated/aliases.h"
4646

47-
const size_t TEMP_BUFFER_SIZE = 4096;
47+
#define TEMP_BUFFER_SIZE 4096
4848

4949
_CPPP_API struct VersionInfo version = {VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
5050

tests/buffer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Buffer
7878
std::ofstream output_file{output_file_path, std::ios::binary | std::ios::trunc};
7979
if (!output_file.good())
8080
{
81-
error(output_file_path, "Unable to open output file.");
81+
error(output_file_path.string(), "Unable to open output file.");
8282
}
8383

8484
output_file.write(buffer, size);
@@ -156,9 +156,9 @@ class Buffer
156156
{
157157
if (*this != other)
158158
{
159-
error("compare_data", "The data is different.");
159+
error("compare_assert", "The data is different.");
160160
}
161-
success("compare_data", "The data is the same.");
161+
success("compare_assert", "The data is the same.");
162162
}
163163

164164
void write_stream(std::ostream &stream, bool newline = false, bool flush = true) const
@@ -199,7 +199,7 @@ class Buffer
199199
std::ifstream input_file{input_file_path, binary ? std::ios::binary : std::ios::in};
200200
if (!input_file.good())
201201
{
202-
error(input_file_path, "Unable to open file " + input_file_path.string());
202+
error(input_file_path.string(), "Unable to open file " + input_file_path.string());
203203
}
204204

205205
std::size_t size = std::filesystem::file_size(input_file_path);

tests/check-stateless.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ void check2_pre_process(const std::filesystem::path &input_file_path, const std:
3939
std::ifstream input_file {input_file_path};
4040
if (!input_file.good())
4141
{
42-
error(input_file_path, "Unable to open input file.");
42+
error(input_file_path.string(), "Unable to open input file.");
4343
}
4444
std::ofstream output_file {output_file_path, std::ios::trunc};
4545
if (!output_file.good())
4646
{
47-
error(output_file_path, "Unable to open output file.");
47+
error(output_file_path.string(), "Unable to open output file.");
4848
}
4949

5050
std::string line;
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
7070
print_stderr("Usage: check-stateless DATADIR CHARSET [--debug]\n");
7171
return EXIT_FAILURE;
7272
}
73-
bool debug;
73+
bool debug = false;
7474
if (argc == 4)
7575
{
7676
debug = true;

tests/sort.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626

2727
#include <algorithm>
2828
#include <fstream>
29+
#include <filesystem>
2930
#include <string>
3031
#include <vector>
3132

3233
#include "output.hpp"
3334
#include "utils.hpp"
3435

35-
inline void sort_file(const std::string &file_name, const std::string &output_file_name)
36+
inline void sort_file(const std::filesystem::path &file_name, const std::filesystem::path &output_file_name)
3637
{
3738
std::vector<std::string> lines;
3839

tests/table-from.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ inline void table_from(const std::filesystem::path &save_file_path, const std::s
199199
std::ofstream save_file{save_file_path, std::ios::out | std::ios::trunc};
200200
if (!save_file.good())
201201
{
202-
error(save_file_path, "Cannot open save file.");
202+
error(save_file_path.string(), "Cannot open save file.");
203203
}
204204

205205
iconv_t cd = iconv_open("UCS-4-INTERNAL", charset.c_str());
@@ -211,7 +211,7 @@ inline void table_from(const std::filesystem::path &save_file_path, const std::s
211211
unsigned int out[3];
212212
unsigned char buf[4];
213213
unsigned int i[4];
214-
int result;
214+
215215
run_table_from_test(cd, i, 0, out, buf, bmp_only, save_file);
216216

217217
iconv_close(cd);

tests/table-to.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ inline void table_to(const std::filesystem::path &save_file_path, const std::str
4444
std::ofstream save_file{save_file_path, std::ios::out | std::ios::trunc};
4545
if (!save_file.good())
4646
{
47-
error(save_file_path, "Cannot open save file.");
47+
error(save_file_path.string(), "Cannot open save file.");
4848
}
4949

5050
iconv_t cd = iconv_open(charset.c_str(), "UCS-4-INTERNAL");

tests/tests.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ set_target_properties(check-stateful PROPERTIES RUNTIME_OUTPUT_DIRECTORY
2626
set_target_properties(check-stateless PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${output_testsdir}" )
2727
set_target_properties(sort PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${output_testsdir}" )
2828

29+
macro(convert_to_crlf input_file output_file)
30+
file(READ ${input_file} file_content)
31+
file(WRITE ${output_file} "${file_content}")
32+
endmacro()
2933

3034
# Test macro
3135
macro(test state encoding)
@@ -39,14 +43,19 @@ endmacro(test)
3943
set(TEST_DATA_DIR "${output_testsdir}/data")
4044

4145
# Copy data directory.
42-
if (NOT EXISTS "${TEST_DATA_DIR}")
46+
if (NOT EXISTS "${TEST_DATA_DIR}" OR TRUE)
4347
file(MAKE_DIRECTORY "${TEST_DATA_DIR}")
4448
file(GLOB_RECURSE TEST_DATA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tests/data/*")
4549

4650
foreach(TEST_FILE ${TEST_DATA_FILES})
4751
if(NOT IS_DIRECTORY "${TEST_FILE}")
4852
get_filename_component(TEST_FILE_NAME "${TEST_FILE}" NAME)
49-
file(COPY_FILE "${TEST_FILE}" "${TEST_DATA_DIR}/${TEST_FILE_NAME}")
53+
if ("${TEST_FILE_NAME}" MATCHES "\\.TXT$" AND (WIN32 OR WINCE OR WINDOWS_PHONE OR WINDOWS_STORE))
54+
# On Windows, copy the text-only file as CR LF.
55+
convert_to_crlf("${TEST_FILE}" "${TEST_DATA_DIR}/${TEST_FILE_NAME}")
56+
else()
57+
file(COPY_FILE "${TEST_FILE}" "${TEST_DATA_DIR}/${TEST_FILE_NAME}")
58+
endif()
5059
endif()
5160
endforeach()
5261
unset(TEST_DATA_FILES)

tests/uniq-u.hpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,21 @@ static void uniq_u(const std::filesystem::path& infile, std::filesystem::path& o
188188
char *prevfield, *thisfield;
189189
size_t prevlen, thislen;
190190
int match_count = 0;
191+
std::string tmp;
191192

192-
FILE *istream = std::fopen(infile.c_str(), "r");
193+
tmp = infile.string();
194+
FILE *istream = std::fopen(tmp.c_str(), "r");
193195
if (istream == nullptr)
194196
{
195-
print_stderr("uniq-u: Error while opening {}\n", infile);
197+
print_stderr("uniq-u: Error while opening {}\n", tmp);
196198
error("fopen", "File open error.");
197199
}
198200

199-
FILE *ostream = std::fopen(outfile.c_str(), "w");
201+
tmp = outfile.string();
202+
FILE *ostream = std::fopen(tmp.c_str(), "w");
200203
if (ostream == nullptr)
201204
{
202-
print_stderr("uniq-u: Error while opening {}\n", outfile);
205+
print_stderr("uniq-u: Error while opening {}\n", tmp);
203206
error("fopen", "File open error.");
204207
}
205208

@@ -254,13 +257,15 @@ static void uniq_u(const std::filesystem::path& infile, std::filesystem::path& o
254257
closefiles:
255258
if (std::ferror(istream) || std::fclose(istream) == EOF)
256259
{
257-
print_stderr("uniq-u: Error while reading {}\n", infile);
260+
tmp = infile.string();
261+
print_stderr("uniq-u: Error while reading {}\n", tmp);
258262
error("fclose", "I/O Error.");
259263
}
260264

261265
if (ferror(ostream) || fclose(ostream) == EOF)
262266
{
263-
print_stderr("uniq-u: Error while writing {}\n", outfile);
267+
tmp = outfile.string();
268+
print_stderr("uniq-u: Error while writing {}\n", tmp);
264269
error("fclose", "I/O Error.");
265270
}
266271

tests/utils.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ inline void write_all(const std::filesystem::path &output_file_path, const std::
6666
std::ios::binary | std::ios::ate | (append ? std::ios::app : std::ios::trunc)};
6767
if (!output_file.good())
6868
{
69-
error(output_file_path, "Unable to open output file.");
69+
error(output_file_path.string(), "Unable to open output file.");
7070
}
7171

7272
output_file.write(buffer.data(), buffer.size());
@@ -86,7 +86,7 @@ inline void write_all(const std::filesystem::path &output_file_path, const Buffe
8686
std::ios::binary | std::ios::ate | (append ? std::ios::app : std::ios::trunc)};
8787
if (!output_file.good())
8888
{
89-
error(output_file_path, "Unable to open output file.");
89+
error(output_file_path.string(), "Unable to open output file.");
9090
}
9191

9292
output_file.write(buffer.data(), buffer.size);
@@ -103,7 +103,7 @@ inline void merge_files(const std::vector<std::filesystem::path> &files, const s
103103
std::ofstream output_file{output_file_path, std::ios::binary | std::ios::trunc};
104104
if (!output_file.good())
105105
{
106-
error(output_file_path, "Unable to open output file.");
106+
error(output_file_path.string(), "Unable to open output file.");
107107
}
108108

109109
for (const auto &file : files)

0 commit comments

Comments
 (0)