• R/O
  • HTTP
  • SSH
  • HTTPS

mhash384: Commit

MHash-384 development repository


Commit MetaInfo

Revision5b49e10eff83cc69a352fada7d77f1e74a40b07d (tree)
Time2020-02-07 05:04:39
AuthorLoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Small Makefile improvement + support for legacy MinGW.

Change Summary

Incremental Difference

--- a/Makefile
+++ b/Makefile
@@ -9,8 +9,7 @@ DEBUG ?= 0
99 # -----------------------------------------------
1010
1111 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)
1413
1514 # -----------------------------------------------
1615 # DIRECTORIES
@@ -32,14 +31,14 @@ else
3231 APPNAME = mhash384g
3332 endif
3433
35-ifeq ($(words $(filter mingw% cygwin%,$(OS_TYPE))),0)
34+ifeq ($(words $(filter %mingw32 %windows-gnu %cygwin %cygnus,$(OS_TYPE))),0)
3635 SUFFIX = run
3736 else
3837 SUFFIX = exe
3938 endif
4039
4140 EXEFILE = $(APPNAME).$(SUFFIX)
42-TARFILE = $(OUTDIR)/$(APPNAME).$(ISODATE).$(firstword $(subst _, ,$(OS_TYPE)))-$(OS_ARCH).tgz
41+TARFILE = $(OUTDIR)/$(APPNAME).$(ISODATE).$(OS_TYPE).tgz
4342
4443 # -----------------------------------------------
4544 # MAKE RULES
--- a/frontend/Makefile
+++ b/frontend/Makefile
@@ -18,7 +18,7 @@ WNDRS ?= windres
1818 # SYSTEM DETECTION
1919 # -----------------------------------------------
2020
21-OS_TYPE := $(shell uname -s | tr '[:upper:]' '[:lower:]')
21+OS_TYPE := $(shell $(CXX) -dumpmachine)
2222
2323 # -----------------------------------------------
2424 # FILES
@@ -40,7 +40,7 @@ else
4040 EXENAME = mhash384g
4141 endif
4242
43-ifeq ($(words $(filter mingw% cygwin%,$(OS_TYPE))),0)
43+ifeq ($(words $(filter %mingw32 %windows-gnu %cygwin %cygnus,$(OS_TYPE))),0)
4444 SUFFIX = run
4545 else
4646 SUFFIX = exe
@@ -63,7 +63,7 @@ ifeq ($(STATIC),1)
6363 LDFLAGS += -static
6464 endif
6565
66-ifneq ($(words $(filter mingw%,$(OS_TYPE))),0)
66+ifneq ($(words $(filter %w64-mingw32 %w64-windows-gnu,$(OS_TYPE))),0)
6767 LDFLAGS += -municode
6868 endif
6969
--- a/frontend/src/main.cpp
+++ b/frontend/src/main.cpp
@@ -30,15 +30,14 @@
3030 #ifdef _WIN32
3131 #include <fcntl.h>
3232 #include <io.h>
33-#define fstat _fstat
34-#define stat _stat
33+#ifdef _MSC_VER
34+#define fstat _fstat
35+#define stat _stat
3536 #define fileno _fileno
3637 #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
4241 #endif
4342
4443 /* System type */
@@ -386,3 +385,18 @@ int EXTRY_POINT(int argc, CHAR_T* argv[])
386385 return _main_(argc, argv);
387386 #endif
388387 }
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
--- a/frontend/src/self_test.cpp
+++ b/frontend/src/self_test.cpp
@@ -25,8 +25,6 @@
2525 #include <cstring>
2626 #include <unordered_set>
2727 #include <array>
28-#include <iostream>
29-#include <fstream>
3028 #include <algorithm>
3129
3230 /*
@@ -126,6 +124,35 @@ typedef std::unordered_set<std::array<std::uint8_t,MHASH384_SIZE>, KeyHasher, Ke
126124 typedef UnorderedHashSet::iterator HashSetIter;
127125
128126 /*
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+/*
129156 * Compute hash and compare against reference
130157 */
131158 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)
212239 */
213240 bool stress_test(const CHAR_T *const file_name, const options_t &options)
214241 {
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)
217245 {
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);
225247 return false;
226248 }
227249
@@ -231,16 +253,16 @@ bool stress_test(const CHAR_T *const file_name, const options_t &options)
231253 stats[i].fill(0U);
232254 }
233255
234- bool success = true;
235256 UnorderedHashSet hash_set;
236- std::string line;
257+ char line[1024U];
258+ bool success = true, flag = false;
237259
238- while(instream.good())
260+ while(read_line(input, line, 1024U, flag))
239261 {
240- std::getline(instream, line);
241- if(!instream.fail())
262+ /*FPRINTF(stderr, STR("\"%") PRI_char STR("\"\n"), line);*/
263+ if(line[0U])
242264 {
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))
244266 {
245267 success = false;
246268 if(!options.keep_going)
@@ -268,7 +290,7 @@ bool stress_test(const CHAR_T *const file_name, const options_t &options)
268290
269291 if(success)
270292 {
271- if(instream.eof() && (!instream.bad()))
293+ if(!ferror(input))
272294 {
273295 FPRINTF(stderr, STR("\nStress-test completed successfully. [%") STR(PRIu64) STR("]\n"), static_cast<uint64_t>(hash_set.size()));
274296 }
@@ -283,9 +305,9 @@ bool stress_test(const CHAR_T *const file_name, const options_t &options)
283305 FPRINTF(stderr, STR("\nStress-test ended *with* collision! [%") STR(PRIu64) STR("]\n"), static_cast<uint64_t>(hash_set.size()));
284306 }
285307
286- if(file_name && infile.is_open())
308+ if(file_name)
287309 {
288- infile.close();
310+ fclose(input);
289311 }
290312
291313 return success;
Show on old repository browser