From 499128809ad805236ea6c32771d448554cbd9a98 Mon Sep 17 00:00:00 2001 From: "Alexander S. Aganichev" Date: Tue, 24 Sep 2002 10:16:04 +0000 Subject: [PATCH] MSVC friendly fixes [2] --- goldlib/gall/gcmpall.h | 5 +++++ goldlib/gall/gctype.h | 5 +++++ goldlib/gall/gdefs.h | 7 ++++++- goldlib/gall/gfile.h | 2 +- goldlib/gall/gfilutil.h | 14 +++++++++++++- goldlib/gall/gfilutl1.cpp | 11 +++++------ goldlib/gall/gregex.cpp | 9 ++++----- goldlib/gall/gregex.h | 3 ++- goldlib/gall/gstrmail.h | 16 ++++++++-------- goldlib/gall/gtimall.h | 22 ++++++++++++++++++++-- goldlib/gall/gutlgrp.cpp | 4 ++-- goldlib/gall/gutlgrp.h | 16 ++++++++-------- goldlib/gall/gutlmtsk.cpp | 2 +- goldlib/gall/gutlwin.cpp | 8 +------- goldlib/gall/gvidinit.cpp | 1 + goldlib/gall/gwildmat.cpp | 3 +++ goldlib/gall/gwinput2.cpp | 4 ++-- goldlib/glibc/regex.h | 2 +- 18 files changed, 88 insertions(+), 46 deletions(-) diff --git a/goldlib/gall/gcmpall.h b/goldlib/gall/gcmpall.h index c815adc..0b43e21 100644 --- a/goldlib/gall/gcmpall.h +++ b/goldlib/gall/gcmpall.h @@ -79,6 +79,11 @@ #endif #endif +#ifndef __GNUC__ +#define __attribute__(A) +#define __inline__ static +#define __extension__ +#endif // ------------------------------------------------------------------ // Check if type "char" is unsigned or signed diff --git a/goldlib/gall/gctype.h b/goldlib/gall/gctype.h index 9e455a5..49dc9fc 100644 --- a/goldlib/gall/gctype.h +++ b/goldlib/gall/gctype.h @@ -28,6 +28,11 @@ #define __gctype_h +// ------------------------------------------------------------------ + +#include + + // ------------------------------------------------------------------ #ifdef __BORLANDC__ diff --git a/goldlib/gall/gdefs.h b/goldlib/gall/gdefs.h index c004de6..8f1c421 100644 --- a/goldlib/gall/gdefs.h +++ b/goldlib/gall/gdefs.h @@ -59,7 +59,7 @@ #define GAUTO 3 #define MAYBE 4 -#define NUL '\x00' // Common ASCII control codes +#define NUL ((char)'\x00') // Common ASCII control codes #define BEL '\x07' #define BS '\x08' #define HT '\x09' @@ -118,8 +118,13 @@ typedef int (*StdCmpCP)(const void*, const void*); template inline bool in_range(T a, T b, T c) { return (a >= b) and (a <= c); } template inline T absolute(T a) { return a < 0 ? -a : a; } template inline int compare_two(T a, T b) { return a < b ? -1 : a > b ? 1 : 0; } +#ifdef __GNUC__ template inline T minimum_of_two(T a, T b) { return __extension__ (a inline T maximum_of_two(T a, T b) { return __extension__ (a >? b); } +#else +template inline T minimum_of_two(T a, T b) { return (a < b) ? a : b; } +template inline T maximum_of_two(T a, T b) { return (a > b) ? a : b; } +#endif template inline int zero_or_one(T e) { return e ? 1 : 0; } template inline bool make_bool(T a) { return a ? true : false; } diff --git a/goldlib/gall/gfile.h b/goldlib/gall/gfile.h index 6ccf59e..f3759d8 100644 --- a/goldlib/gall/gfile.h +++ b/goldlib/gall/gfile.h @@ -78,7 +78,7 @@ public: ~gfile(); // Destructor (closes file) - operator bool() { return isopen(); } + operator bool() { return isopen() ? true : false; } // -------------------------------------------------------------- diff --git a/goldlib/gall/gfilutil.h b/goldlib/gall/gfilutil.h index a3e81d6..417e50e 100644 --- a/goldlib/gall/gfilutil.h +++ b/goldlib/gall/gfilutil.h @@ -38,6 +38,7 @@ #include #else #include +#include #endif #include #include @@ -68,6 +69,17 @@ #define S_STDRD S_IRUSR #endif +#ifndef S_ISDIR +#define S_ISDIR(st_mode) ((st_mode)&_S_IFDIR) +#endif + +#ifndef S_ISREG +#define S_ISREG(st_mode) ((st_mode)&_S_IFREG) +#endif + +#ifndef R_OK +#define R_OK 0 +#endif // ------------------------------------------------------------------ @@ -138,7 +150,7 @@ inline FILE* fsopen(const std::string& path, const char* type, int shflag) { ret int is_dir(const char* path); inline int is_dir(const std::string& path) { return is_dir(path.c_str()); } -inline bool fexist(const char* filename) { return *filename ? ((access(filename, 0) == 0) and not is_dir(filename)) : false; } +inline bool fexist(const char* filename) { return *filename ? ((access(filename, R_OK) == 0) and not is_dir(filename)) : false; } inline bool fexist(const std::string& filename) { return fexist(filename.c_str()); } dword gfixstattime(time_t st_time); diff --git a/goldlib/gall/gfilutl1.cpp b/goldlib/gall/gfilutl1.cpp index e8571f9..1c5f43d 100644 --- a/goldlib/gall/gfilutl1.cpp +++ b/goldlib/gall/gfilutl1.cpp @@ -28,7 +28,7 @@ #include #include #include -#if defined(__MINGW32__) +#if defined(__MINGW32__) || defined(_MSC_VER) #include #else #include @@ -360,11 +360,10 @@ void WipeFile(const char* file, int options) { uint n; byte buf[512]; - switch(options) { - default: - for(n=0; n<512; n++) - buf[n] = (byte)(rand() % 256); - } + (void)options; + + for(n=0; n<512; n++) + buf[n] = (byte)(rand() % 256); int fh = sopen(file, O_RDWR|O_BINARY, SH_DENYRW, S_STDRW); if(fh != -1) { diff --git a/goldlib/gall/gregex.cpp b/goldlib/gall/gregex.cpp index 504badf..42453ab 100644 --- a/goldlib/gall/gregex.cpp +++ b/goldlib/gall/gregex.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -52,8 +51,8 @@ gregex::~gregex() { void gregex::reset() { if(preg) { - regfree((regex_t*)preg); - throw_delete((regex_t*)preg); + regfree(preg); + throw_delete(preg); } } @@ -72,7 +71,7 @@ bool gregex::compile(const char* pattern, int cflags) { throw_new(preg); } - return (bool)regcomp((regex_t*)preg, pattern, cflgs); + return regcomp(preg, pattern, cflgs) ? true : false; } @@ -84,7 +83,7 @@ bool gregex::match(const char* str, int eflags) { if(eflags & notbol) eflgs |= REG_NOTBOL; if(eflags & noteol) eflgs |= REG_NOTEOL; - return not regexec((regex_t*)preg, str, 0, NULL, eflgs); + return not regexec(preg, str, 0, NULL, eflgs); } diff --git a/goldlib/gall/gregex.h b/goldlib/gall/gregex.h index 34f8a84..a19b931 100644 --- a/goldlib/gall/gregex.h +++ b/goldlib/gall/gregex.h @@ -31,6 +31,7 @@ // ------------------------------------------------------------------ #include +#include // ------------------------------------------------------------------ @@ -39,7 +40,7 @@ class gregex { protected: - void* preg; + regex_t* preg; public: diff --git a/goldlib/gall/gstrmail.h b/goldlib/gall/gstrmail.h index a4e28f9..1fbc55d 100644 --- a/goldlib/gall/gstrmail.h +++ b/goldlib/gall/gstrmail.h @@ -57,19 +57,19 @@ extern mail_ctype mail_ctype_global; // ------------------------------------------------------------------ -inline bool is_mail_char(uint c) { return mail_ctype_global.table[c] & mail_ctype::mail_char; } -inline bool is_mail_alpha(uint c) { return mail_ctype_global.table[c] & mail_ctype::mail_alpha; } -inline bool is_mail_ctl(uint c) { return mail_ctype_global.table[c] & mail_ctype::mail_ctl; } +inline bool is_mail_char(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_char) ? true : false; } +inline bool is_mail_alpha(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_alpha) ? true : false; } +inline bool is_mail_ctl(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_ctl) ? true : false; } inline bool is_mail_cr(uint c) { return c == CR; } inline bool is_mail_lf(uint c) { return c == LF; } inline bool is_mail_space(uint c) { return c == ' '; } inline bool is_mail_htab(uint c) { return c == HT; } inline bool is_mail_crlf(uint c) { return is_mail_cr(c) or is_mail_lf(c); } -inline bool is_mail_lwsp(uint c) { return mail_ctype_global.table[c] & mail_ctype::mail_lwsp; } -inline bool is_mail_special(uint c) { return mail_ctype_global.table[c] & mail_ctype::mail_special; } -inline bool is_mail_delimiters(uint c) { return mail_ctype_global.table[c] & mail_ctype::mail_delimiters; } -inline bool is_mime_tspecial(uint c) { return mail_ctype_global.table[c] & mail_ctype::mime_tspecial; } -inline bool is_mime_especial(uint c) { return mail_ctype_global.table[c] & mail_ctype::mime_especial; } +inline bool is_mail_lwsp(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_lwsp) ? true : false; } +inline bool is_mail_special(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_special) ? true : false; } +inline bool is_mail_delimiters(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mail_delimiters) ? true : false; } +inline bool is_mime_tspecial(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mime_tspecial) ? true : false; } +inline bool is_mime_especial(uint c) { return (mail_ctype_global.table[c] & mail_ctype::mime_especial) ? true : false; } inline bool is_mail_atom_delimiters(uint c) { return is_mail_delimiters(c) or is_mail_ctl(c); } inline bool is_mime_ct_token_valid(uint c) { return not (is_mail_lwsp(c) or is_mail_ctl(c) or is_mime_tspecial(c)); } diff --git a/goldlib/gall/gtimall.h b/goldlib/gall/gtimall.h index a8354f8..057d178 100644 --- a/goldlib/gall/gtimall.h +++ b/goldlib/gall/gtimall.h @@ -52,6 +52,13 @@ typedef long Clock; +// ------------------------------------------------------------------ + +#if defined(GOLD_CANPACK) +#pragma pack(1) +#endif + + // ------------------------------------------------------------------ // DOS "findfirst" timestamp @@ -65,7 +72,7 @@ struct gfiletime { const char* c_str(char* buf); dword number() { return *(dword*)this; } -} __attribute__((packed)); +}; typedef gfiletime FFTime; @@ -83,11 +90,18 @@ struct gopustime { const char* c_str(char* buf); dword number() { return *(dword*)this; } -} __attribute__((packed)); +}; typedef gopustime FTime; +// ------------------------------------------------------------------ + +#if defined(GOLD_CANPACK) +#pragma pack() +#endif + + // ------------------------------------------------------------------ // Externs for strftimei() @@ -129,6 +143,10 @@ inline void usleep(long duration) { DosSleep(duration); } inline void usleep(long duration) { Sleep(duration); } #endif +#ifndef CLK_TCK +#define CLK_TCK CLOCKS_PER_SEC +#endif + #ifdef __UNIX__ inline Clock gclock() { struct tms z; return Clock(times(&z)*10/sysconf(_SC_CLK_TCK)); } #else diff --git a/goldlib/gall/gutlgrp.cpp b/goldlib/gall/gutlgrp.cpp index 4539893..28484bb 100644 --- a/goldlib/gall/gutlgrp.cpp +++ b/goldlib/gall/gutlgrp.cpp @@ -53,9 +53,9 @@ Grp::~Grp() { std::multimap::iterator i; for(currgrp = container.begin(); currgrp != container.end(); currgrp++) for(i = currgrp->second.begin(); i != currgrp->second.end(); i++) { - if(i->second.type == TYPE_OBJECT) + if(i->second.type == grp_stock::TYPE_OBJECT) throw_free(i->second.data.object_item); - else if(i->second.type == TYPE_STRING) + else if(i->second.type == grp_stock::TYPE_STRING) throw_delete(i->second.data.string_item); } } diff --git a/goldlib/gall/gutlgrp.h b/goldlib/gall/gutlgrp.h index 5563e19..8bb4ff7 100644 --- a/goldlib/gall/gutlgrp.h +++ b/goldlib/gall/gutlgrp.h @@ -116,18 +116,18 @@ class Grp { private: - enum { - TYPE_BOOL, - TYPE_CHAR, - TYPE_INT, - TYPE_STRING, - TYPE_OBJECT - }; - class grp_stock { public: + enum { + TYPE_BOOL, + TYPE_CHAR, + TYPE_INT, + TYPE_STRING, + TYPE_OBJECT + }; + int type; union { bool bool_item; diff --git a/goldlib/gall/gutlmtsk.cpp b/goldlib/gall/gutlmtsk.cpp index 259712d..e4b51df 100644 --- a/goldlib/gall/gutlmtsk.cpp +++ b/goldlib/gall/gutlmtsk.cpp @@ -82,7 +82,7 @@ int GMTsk::os2() { #if defined(__OS2__) detected = GMTSK_OS2; name = "OS/2"; - #elif !defined(__GNUC__) + #elif !defined(__GNUC__) && !defined(_MSC_VER) if(_osmajor >= 10) { detected = GMTSK_OS2; name = "OS/2"; diff --git a/goldlib/gall/gutlwin.cpp b/goldlib/gall/gutlwin.cpp index 71216d6..81029a9 100644 --- a/goldlib/gall/gutlwin.cpp +++ b/goldlib/gall/gutlwin.cpp @@ -115,13 +115,7 @@ char tl[256] = { 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -WCHAR oem2unicode[256] = { -// MB_USEGLYPHCHARS should do the same :-) -// 0x0000, 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2219, -// 0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c, -// 0x25ba, 0x25c4, 0x2195, 0x203c, 0x00b6, 0x00a7, 0x25a0, 0x21a8, -// 0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc -}; +WCHAR oem2unicode[256]; // ------------------------------------------------------------------ diff --git a/goldlib/gall/gvidinit.cpp b/goldlib/gall/gvidinit.cpp index 9444141..fc5ace7 100644 --- a/goldlib/gall/gvidinit.cpp +++ b/goldlib/gall/gvidinit.cpp @@ -26,6 +26,7 @@ // Device-independent video functions // ------------------------------------------------------------------ +#include #include #include #include diff --git a/goldlib/gall/gwildmat.cpp b/goldlib/gall/gwildmat.cpp index a46349d..0bb1971 100644 --- a/goldlib/gall/gwildmat.cpp +++ b/goldlib/gall/gwildmat.cpp @@ -26,6 +26,9 @@ #include #include +#ifdef _MSC_VER +#include +#endif // ------------------------------------------------------------------ diff --git a/goldlib/gall/gwinput2.cpp b/goldlib/gall/gwinput2.cpp index 1192c06..79d7285 100644 --- a/goldlib/gall/gwinput2.cpp +++ b/goldlib/gall/gwinput2.cpp @@ -1004,12 +1004,12 @@ bool gwinput::field::delete_word(bool left) { if(entry != gwinput::entry_noedit) { - bool state = isspace(buf[buf_pos-((int) left)]); + bool state = isspace(buf[buf_pos-((int) left)]) ? true : false; while(left ? buf_pos > 0 : buf_pos < buf_end_pos) { left ? delete_left() : delete_char(); - if(isspace(buf[buf_pos-((int) left)]) != state) + if((isspace(buf[buf_pos-((int) left)]) ? true : false) != state) break; } return true; diff --git a/goldlib/glibc/regex.h b/goldlib/glibc/regex.h index 2bca537..4ffe52c 100644 --- a/goldlib/glibc/regex.h +++ b/goldlib/glibc/regex.h @@ -429,7 +429,7 @@ typedef struct unfortunately clutters up the declarations a bit, but I think it's worth it. */ -#if __STDC__ +#if 1 /*__STDC__*/ # define _RE_ARGS(args) args