MHash-384 development repository
Revision | 5b49e10eff83cc69a352fada7d77f1e74a40b07d (tree) |
---|---|
Time | 2020-02-07 05:04:39 |
Author | LoRd_MuldeR <mulder2@gmx....> |
Commiter | LoRd_MuldeR |
Small Makefile improvement + support for legacy MinGW.
@@ -9,8 +9,7 @@ DEBUG ?= 0 | ||
9 | 9 | # ----------------------------------------------- |
10 | 10 | |
11 | 11 | ISODATE := $(shell date +%Y-%m-%d) |
12 | -OS_ARCH := $(shell $(CXX) -v 2>&1 | grep -Po 'Target:\s*\K\w+') | |
13 | -OS_TYPE := $(shell uname -s | tr '[:upper:]' '[:lower:]') | |
12 | +OS_TYPE := $(shell $(CXX) -dumpmachine) | |
14 | 13 | |
15 | 14 | # ----------------------------------------------- |
16 | 15 | # DIRECTORIES |
@@ -32,14 +31,14 @@ else | ||
32 | 31 | APPNAME = mhash384g |
33 | 32 | endif |
34 | 33 | |
35 | -ifeq ($(words $(filter mingw% cygwin%,$(OS_TYPE))),0) | |
34 | +ifeq ($(words $(filter %mingw32 %windows-gnu %cygwin %cygnus,$(OS_TYPE))),0) | |
36 | 35 | SUFFIX = run |
37 | 36 | else |
38 | 37 | SUFFIX = exe |
39 | 38 | endif |
40 | 39 | |
41 | 40 | EXEFILE = $(APPNAME).$(SUFFIX) |
42 | -TARFILE = $(OUTDIR)/$(APPNAME).$(ISODATE).$(firstword $(subst _, ,$(OS_TYPE)))-$(OS_ARCH).tgz | |
41 | +TARFILE = $(OUTDIR)/$(APPNAME).$(ISODATE).$(OS_TYPE).tgz | |
43 | 42 | |
44 | 43 | # ----------------------------------------------- |
45 | 44 | # MAKE RULES |
@@ -18,7 +18,7 @@ WNDRS ?= windres | ||
18 | 18 | # SYSTEM DETECTION |
19 | 19 | # ----------------------------------------------- |
20 | 20 | |
21 | -OS_TYPE := $(shell uname -s | tr '[:upper:]' '[:lower:]') | |
21 | +OS_TYPE := $(shell $(CXX) -dumpmachine) | |
22 | 22 | |
23 | 23 | # ----------------------------------------------- |
24 | 24 | # FILES |
@@ -40,7 +40,7 @@ else | ||
40 | 40 | EXENAME = mhash384g |
41 | 41 | endif |
42 | 42 | |
43 | -ifeq ($(words $(filter mingw% cygwin%,$(OS_TYPE))),0) | |
43 | +ifeq ($(words $(filter %mingw32 %windows-gnu %cygwin %cygnus,$(OS_TYPE))),0) | |
44 | 44 | SUFFIX = run |
45 | 45 | else |
46 | 46 | SUFFIX = exe |
@@ -63,7 +63,7 @@ ifeq ($(STATIC),1) | ||
63 | 63 | LDFLAGS += -static |
64 | 64 | endif |
65 | 65 | |
66 | -ifneq ($(words $(filter mingw%,$(OS_TYPE))),0) | |
66 | +ifneq ($(words $(filter %w64-mingw32 %w64-windows-gnu,$(OS_TYPE))),0) | |
67 | 67 | LDFLAGS += -municode |
68 | 68 | endif |
69 | 69 |
@@ -30,15 +30,14 @@ | ||
30 | 30 | #ifdef _WIN32 |
31 | 31 | #include <fcntl.h> |
32 | 32 | #include <io.h> |
33 | -#define fstat _fstat | |
34 | -#define stat _stat | |
33 | +#ifdef _MSC_VER | |
34 | +#define fstat _fstat | |
35 | +#define stat _stat | |
35 | 36 | #define fileno _fileno |
36 | 37 | #endif |
37 | - | |
38 | -/* fstat(2) macros */ | |
39 | -#if !defined(S_IFMT) && !defined(S_IFDIR) && defined(_S_IFMT) && defined(_S_IFDIR) | |
40 | -#define S_IFMT _S_IFMT | |
41 | -#define S_IFDIR _S_IFDIR | |
38 | +#ifndef _O_U8TEXT | |
39 | +#define _O_U8TEXT 0x40000 | |
40 | +#endif | |
42 | 41 | #endif |
43 | 42 | |
44 | 43 | /* System type */ |
@@ -386,3 +385,18 @@ int EXTRY_POINT(int argc, CHAR_T* argv[]) | ||
386 | 385 | return _main_(argc, argv); |
387 | 386 | #endif |
388 | 387 | } |
388 | + | |
389 | +/* | |
390 | + * For legacy MinGW (not required for Mingw-w64, use '-municode' instead) | |
391 | + */ | |
392 | +#if defined(_WIN32) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) | |
393 | +extern "C" | |
394 | +void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*); | |
395 | +int main() | |
396 | +{ | |
397 | + wchar_t **enpv, **argv; | |
398 | + int argc, si = 0; | |
399 | + __wgetmainargs(&argc, &argv, &enpv, 1, &si); | |
400 | + return wmain(argc, argv); | |
401 | +} | |
402 | +#endif |
@@ -25,8 +25,6 @@ | ||
25 | 25 | #include <cstring> |
26 | 26 | #include <unordered_set> |
27 | 27 | #include <array> |
28 | -#include <iostream> | |
29 | -#include <fstream> | |
30 | 28 | #include <algorithm> |
31 | 29 | |
32 | 30 | /* |
@@ -126,6 +124,35 @@ typedef std::unordered_set<std::array<std::uint8_t,MHASH384_SIZE>, KeyHasher, Ke | ||
126 | 124 | typedef UnorderedHashSet::iterator HashSetIter; |
127 | 125 | |
128 | 126 | /* |
127 | + * Read the next input line | |
128 | + */ | |
129 | +static bool read_line(FILE *const input, char *const line, const int max_count, bool &flag) | |
130 | +{ | |
131 | + for(;;) | |
132 | + { | |
133 | + const bool discard = flag; | |
134 | + flag = true; | |
135 | + if(fgets(line, max_count, input) != NULL) | |
136 | + { | |
137 | + size_t len = strlen(line); | |
138 | + while((len > 0) && (line[len - 1U] == '\n')) | |
139 | + { | |
140 | + flag = false; /*line not truncated*/ | |
141 | + line[--len] = '\0'; | |
142 | + } | |
143 | + if(!discard) | |
144 | + { | |
145 | + return true; | |
146 | + } | |
147 | + } | |
148 | + else | |
149 | + { | |
150 | + return false; | |
151 | + } | |
152 | + } | |
153 | +} | |
154 | + | |
155 | +/* | |
129 | 156 | * Compute hash and compare against reference |
130 | 157 | */ |
131 | 158 | static bool test_string(const uint32_t count, const char *const text, const uint8_t *const expected, const options_t &options) |
@@ -212,16 +239,11 @@ bool self_test(const options_t &options) | ||
212 | 239 | */ |
213 | 240 | bool stress_test(const CHAR_T *const file_name, const options_t &options) |
214 | 241 | { |
215 | - std::ifstream infile; | |
216 | - if(file_name) | |
242 | + errno = 0; | |
243 | + FILE *const input = file_name ? FOPEN(file_name, STR("r")) : stdin; | |
244 | + if(!input) | |
217 | 245 | { |
218 | - infile.open(file_name); | |
219 | - } | |
220 | - | |
221 | - std::istream &instream = file_name ? infile : std::cin; | |
222 | - if(!instream.good()) | |
223 | - { | |
224 | - FPUTS(STR("Error: Failed to open input file for reading!\n"), stderr); | |
246 | + FPUTS(STR("Error: Failed to open specified input file for reading!\n"), stderr); | |
225 | 247 | return false; |
226 | 248 | } |
227 | 249 |
@@ -231,16 +253,16 @@ bool stress_test(const CHAR_T *const file_name, const options_t &options) | ||
231 | 253 | stats[i].fill(0U); |
232 | 254 | } |
233 | 255 | |
234 | - bool success = true; | |
235 | 256 | UnorderedHashSet hash_set; |
236 | - std::string line; | |
257 | + char line[1024U]; | |
258 | + bool success = true, flag = false; | |
237 | 259 | |
238 | - while(instream.good()) | |
260 | + while(read_line(input, line, 1024U, flag)) | |
239 | 261 | { |
240 | - std::getline(instream, line); | |
241 | - if(!instream.fail()) | |
262 | + /*FPRINTF(stderr, STR("\"%") PRI_char STR("\"\n"), line);*/ | |
263 | + if(line[0U]) | |
242 | 264 | { |
243 | - if(!append_string(hash_set, stats, line.c_str(), options.base64, options.lower_case)) | |
265 | + if(!append_string(hash_set, stats, line, options.base64, options.lower_case)) | |
244 | 266 | { |
245 | 267 | success = false; |
246 | 268 | if(!options.keep_going) |
@@ -268,7 +290,7 @@ bool stress_test(const CHAR_T *const file_name, const options_t &options) | ||
268 | 290 | |
269 | 291 | if(success) |
270 | 292 | { |
271 | - if(instream.eof() && (!instream.bad())) | |
293 | + if(!ferror(input)) | |
272 | 294 | { |
273 | 295 | FPRINTF(stderr, STR("\nStress-test completed successfully. [%") STR(PRIu64) STR("]\n"), static_cast<uint64_t>(hash_set.size())); |
274 | 296 | } |
@@ -283,9 +305,9 @@ bool stress_test(const CHAR_T *const file_name, const options_t &options) | ||
283 | 305 | FPRINTF(stderr, STR("\nStress-test ended *with* collision! [%") STR(PRIu64) STR("]\n"), static_cast<uint64_t>(hash_set.size())); |
284 | 306 | } |
285 | 307 | |
286 | - if(file_name && infile.is_open()) | |
308 | + if(file_name) | |
287 | 309 | { |
288 | - infile.close(); | |
310 | + fclose(input); | |
289 | 311 | } |
290 | 312 | |
291 | 313 | return success; |