Fixing warnings and errors for MSVS 2005 compiler

This commit is contained in:
Ianos Gnatiuc
2006-04-21 19:57:30 +00:00
parent e3bbfbee86
commit df0f689816
44 changed files with 417 additions and 289 deletions

View File

@@ -51,9 +51,9 @@ extern dword __crc32_table[];
// fill is guaranteed for unsigned operands, and besides we use
// prototyped unsigned parameters anyway, so we have no problem here.
inline word updCrc16(byte ch, word crc) { return (word)(__crc16_table[byte(crc >> 8)] ^ (crc << 8) ^ (ch)); }
inline word updCrc16c(byte ch, word crc) { return (word)(__crc16_table[byte(crc >> 8) ^ (ch)] ^ (crc << 8)); }
inline dword updCrc32(byte ch, dword crc) { return (dword)(__crc32_table[byte(crc) ^ byte(ch)] ^ (crc >> 8)); }
inline word updCrc16(byte ch, word crc) { return (word)(__crc16_table[crc >> 8] ^ ((crc << 8) & 0xFFFF) ^ ch); }
inline word updCrc16c(byte ch, word crc) { return (word)(__crc16_table[(crc >> 8) ^ ch] ^ ((crc << 8) & 0xFFFF)); }
inline dword updCrc32(byte ch, dword crc) { return (dword)(__crc32_table[(crc & 0xFF) ^ ch] ^ (crc >> 8)); }
// ------------------------------------------------------------------

View File

@@ -31,6 +31,8 @@
#define __goldall_h
/* ------------------------------------------------------------------ */
#include <tchar.h>
#ifdef __cplusplus
#include <cstddef>
#endif
@@ -43,6 +45,11 @@
#else
#endif
#if !defined(ARRAYSIZE)
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
#endif
/* ------------------------------------------------------------------
// Disable some MS Visual C warnings */

View File

@@ -149,10 +149,14 @@ struct Stamp {
FILE* fsopen(const char* path, const char* type, int shflag);
inline FILE* fsopen(const std::string& path, const char* type, int shflag) { return fsopen(path.c_str(), type, shflag); }
int is_dir(const char* path);
inline int is_dir(const std::string& path) { return is_dir(path.c_str()); }
bool is_dir(const TCHAR *path);
inline bool is_dir(const std::string &path) { return is_dir(path.c_str()); }
inline bool fexist(const char* filename) { return *filename ? ((access(filename, R_OK) == 0) and not is_dir(filename)) : false; }
#if defined(_taccess_s)
inline bool fexist(const TCHAR *filename) { return *filename ? (0 == (_taccess_s(filename, R_OK)) && !is_dir(filename)) : false; }
#else
inline bool fexist(const TCHAR *filename) { return *filename ? (0 == (_taccess(filename, R_OK)) && !is_dir(filename)) : false; }
#endif
inline bool fexist(const std::string& filename) { return fexist(filename.c_str()); }
dword gfixstattime(time32_t st_time);
@@ -193,8 +197,8 @@ int strschg_environ(std::string& s);
char* MapPath(char* map, bool reverse = false); // gcarea.cpp
inline char* ReMapPath(char* map) { return MapPath(map, true); }
inline long lseekset(int fh, long offset) { return lseek(fh, offset, SEEK_SET); }
inline long lseekset(int fh, long record, long recordsize) { return lseek(fh, record*recordsize, SEEK_SET); }
inline long lseekset(int fh, long offset) { return _lseek(fh, offset, SEEK_SET); }
inline long lseekset(int fh, long record, long recordsize) { return _lseek(fh, record*recordsize, SEEK_SET); }
int gchdir(const char* dir);

View File

@@ -96,12 +96,12 @@ long GetFilesize(const char* file) {
// ------------------------------------------------------------------
// Convert time returned with stat to FFTime
dword gfixstattime(time32_t st_time) {
dword gfixstattime(time32_t st_time)
{
#if (defined(__MINGW32__) && !defined(__MSVCRT__)) || defined(__CYGWIN__)
struct tm &f = *ggmtime(&st_time);
struct tm f; ggmtime(&f, &st_time);
#else
struct tm &f = *glocaltime(&st_time);
struct tm f; glocaltime(&f, &st_time);
#endif
FFTime t;
t.ft_year = f.tm_year - 80;
@@ -164,8 +164,8 @@ long fsize(FILE* fp) {
// ------------------------------------------------------------------
// Check if a pathname is a directory
int is_dir(const char* path) {
bool is_dir(const TCHAR *path)
{
// Check if it's a root path (X:\)
#if defined(__HAVE_DRIVES__)
if(g_isalpha(path[0]) and (path[1] == ':') and isslash(path[2]) and (path[3] == NUL))

View File

@@ -1572,7 +1572,7 @@ gkey kbxget_raw(int mode) {
// TO_PORT_TAG: kbxget_raw(3)
#if defined(__WIN32__)
KeyCtrlState = (gkey)inp.Event.KeyEvent.dwControlKeyState;
KeyCtrlState = (gkey)(inp.Event.KeyEvent.dwControlKeyState & 0xFFFF);
#endif
return k;
}

View File

@@ -34,10 +34,10 @@
// ------------------------------------------------------------------
struct tm* glog::time_now;
int glog::count = 0;
time32_t glog::secs_now;
char glog::timebuf[20];
struct tm glog::time_now;
int glog::count = 0;
time32_t glog::secs_now;
char glog::timebuf[20];
// ------------------------------------------------------------------
@@ -109,7 +109,7 @@ void glog::printf(const char* format, ...) {
char logbuf[256];
secs_now = gtime(NULL);
time_now = glocaltime(&secs_now);
glocaltime(&time_now, &secs_now);
lineswritten++;
@@ -118,23 +118,23 @@ void glog::printf(const char* format, ...) {
switch(logtype) {
case GLOG_FD:
sprintf(logbuf, "\n---------- %s, %s\n", strftimei(timebuf, 20, "%a %d %b %y", time_now), progname);
sprintf(logbuf, "\n---------- %s, %s\n", strftimei(timebuf, 20, "%a %d %b %y", &time_now), progname);
break;
case GLOG_MAX:
sprintf(logbuf, "\n+ %s %4.4s Begin, %s\n", strftimei(timebuf, 20, "%d %b %H:%M:%S", time_now), shortprogname, progname);
sprintf(logbuf, "\n+ %s %4.4s Begin, %s\n", strftimei(timebuf, 20, "%d %b %H:%M:%S", &time_now), shortprogname, progname);
break;
case GLOG_BINK:
sprintf(logbuf, "\n> %s %4.4s %s\n", strftimei(timebuf, 20, "%d-%b %H:%M:%S", time_now), shortprogname, progname);
sprintf(logbuf, "\n> %s %4.4s %s\n", strftimei(timebuf, 20, "%d-%b %H:%M:%S", &time_now), shortprogname, progname);
break;
case GLOG_QBBS:
sprintf(logbuf, "\n%s **************************************************\n%s %s\n", strftimei(timebuf, 20, "%d-%b-%y %H:%M", time_now), timebuf, progname);
sprintf(logbuf, "\n%s **************************************************\n%s %s\n", strftimei(timebuf, 20, "%d-%b-%y %H:%M", &time_now), timebuf, progname);
break;
case GLOG_DB:
sprintf(logbuf, "\n%s %s\n", strftimei(timebuf, 20, "%m/%d/%y %H:%M", time_now), progname);
sprintf(logbuf, "\n%s %s\n", strftimei(timebuf, 20, "%m/%d/%y %H:%M", &time_now), progname);
break;
}
@@ -153,23 +153,23 @@ void glog::printf(const char* format, ...) {
switch(logtype) {
case GLOG_FD:
sprintf(logbuf, "%c %s %s", *buf, strftimei(timebuf, 10, "%H:%M:%S", time_now), buf+2);
sprintf(logbuf, "%c %s %s", *buf, strftimei(timebuf, 10, "%H:%M:%S", &time_now), buf+2);
break;
case GLOG_MAX:
sprintf(logbuf, "%c %s %4.4s %s", *buf, strftimei(timebuf, 20, "%d %b %H:%M:%S", time_now), shortprogname, buf+2);
sprintf(logbuf, "%c %s %4.4s %s", *buf, strftimei(timebuf, 20, "%d %b %H:%M:%S", &time_now), shortprogname, buf+2);
break;
case GLOG_BINK:
sprintf(logbuf, "%c %s %4.4s %s", *buf, strftimei(timebuf, 20, "%d-%b %H:%M:%S", time_now), shortprogname, buf+2);
sprintf(logbuf, "%c %s %4.4s %s", *buf, strftimei(timebuf, 20, "%d-%b %H:%M:%S", &time_now), shortprogname, buf+2);
break;
case GLOG_QBBS:
sprintf(logbuf, "%s %s", strftimei(timebuf, 20, "%d-%b-%y %H:%M", time_now), buf+2);
sprintf(logbuf, "%s %s", strftimei(timebuf, 20, "%d-%b-%y %H:%M", &time_now), buf+2);
break;
case GLOG_DB:
sprintf(logbuf, "%s %s", strftimei(timebuf, 20, "%m/%d/%y %H:%M", time_now), buf+2);
sprintf(logbuf, "%s %s", strftimei(timebuf, 20, "%m/%d/%y %H:%M", &time_now), buf+2);
break;
}
if(fp.isopen()) {

View File

@@ -60,7 +60,7 @@ private:
gfile fp;
static int count;
static struct tm* time_now;
static struct tm time_now;
static time32_t secs_now;
static char timebuf[20];

View File

@@ -492,8 +492,8 @@ typedef ftn_attr Attr;
// ------------------------------------------------------------------
inline void AttrAdd(Attr* a, Attr* b) { a->add(*b); }
inline void GetAttribstr(Attr* attr, const char* attrs) { attr->get(attrs); }
inline char* MakeAttrStr(char* str, size_t maxlen, const Attr* attr) { std::string tmp; attr->make_string(tmp); strxcpy(str, tmp.c_str(), maxlen); return str; }
inline void GetAttribstr(Attr* attr, const TCHAR *attrs) { attr->get(attrs); }
inline TCHAR *MakeAttrStr(TCHAR *str, size_t maxlen, const Attr *attr) { std::string tmp; attr->make_string(tmp); strxcpy(str, tmp.c_str(), maxlen); return str; }
// ------------------------------------------------------------------

View File

@@ -82,7 +82,7 @@ char* longdotstr(char* str, long num); // Convert a long to a
char* StripQuotes(char* str);
// Safe versions of strcpy, strcat, sequencial strcat...
char* strxcpy(char* d, const char* s, int n);
TCHAR *strxcpy(TCHAR *d, const TCHAR *s, size_t n);
char* strxcat(char *dest, const char *src, size_t max);
char* strxmerge(char *dest, size_t max, ...);
@@ -105,10 +105,10 @@ char* strunrevname(char* unreversedname, const char* name);
inline char* strbtrim(char* st) { return strtrim(strltrim(st)); }
inline bool streql(const char* str1, const char* str2) { return not strcmp(str1,str2); }
inline bool strieql(const char* str1, const char* str2) { return not stricmp(str1,str2); }
inline bool strneql(const char* str1, const char* str2, int n) { return not strncmp(str1,str2,n); }
inline bool strnieql(const char* str1, const char* str2, int n) { return not strnicmp(str1,str2,n); }
inline bool streql (const TCHAR *str1, const TCHAR *str2) { return (0 == _tcscmp (str1, str2)); }
inline bool strieql (const TCHAR *str1, const TCHAR *str2) { return (0 == _tcsicmp (str1, str2)); }
inline bool strneql (const TCHAR *str1, const TCHAR *str2, int n) { return (0 == _tcsncmp (str1, str2, n)); }
inline bool strnieql(const TCHAR *str1, const TCHAR *str2, int n) { return (0 == _tcsnicmp(str1, str2, n)); }
inline const char* strskip_to(const char* p, char* s) { return p+strcspn(p, s); }
inline char* strskip_to(char* p, char* s) { return p+strcspn(p, s); }
@@ -142,20 +142,26 @@ char* strcvtc(char* s);
// ------------------------------------------------------------------
// String tokenizer class
class GTok {
class GTok
{
protected:
const char* separator;
char* token;
const TCHAR *separator;
TCHAR *token;
#if defined(_tcstok_s)
TCHAR *next_token;
#endif
public:
GTok(TCHAR *sep = NULL);
GTok(char* sep=NULL);
char* First(char* buf) { token = strtok(buf, separator); return token; }
char* Next() { token = strtok(NULL, separator); return token; }
char* Token() { return token; }
#if defined(_tcstok_s)
TCHAR *First(TCHAR *buf) { token = _tcstok_s(buf, separator, &next_token); return token; }
TCHAR *Next() { token = _tcstok_s(NULL, separator, &next_token); return token; }
#else
TCHAR *First(TCHAR *buf) { token = _tcstok(buf, separator); return token; }
TCHAR *Next() { token = _tcstok(NULL, separator); return token; }
#endif
TCHAR *Token() { return token; }
};

View File

@@ -44,16 +44,28 @@ typedef std::vector<std::string> gstrarray;
// ------------------------------------------------------------------
inline void tokenize(gstrarray& array, const char* str, const char* delim = NULL) {
if(delim == NULL)
delim = ", \t";
char* tmp = throw_xstrdup(str);
char* token = strtok(tmp, delim);
while(token) {
array.push_back(token);
token = strtok(NULL, delim);
}
throw_xfree(tmp);
inline void tokenize(gstrarray &array, const TCHAR* str, const TCHAR *delim = NULL)
{
if (delim == NULL) delim = ", \t";
TCHAR *tmp = throw_xstrdup(str);
#if defined(_tcstok_s)
TCHAR *next_token;
TCHAR *token = _tcstok_s(tmp, delim, &next_token);
#else
TCHAR *token = _tcstok(tmp, delim);
#endif
while (NULL != token)
{
array.push_back(token);
#if defined(_tcstok_s)
token = _tcstok_s(NULL, delim, &next_token);
#else
token = _tcstok(NULL, delim);
#endif
}
throw_xfree(tmp);
}

View File

@@ -562,14 +562,19 @@ const char* strrword(const char* str, const char *separator) {
// ------------------------------------------------------------------
char* strxcpy(char* d, const char* s, int n) {
if(n) {
strncpy(d, s, n-1);
TCHAR *strxcpy(TCHAR *d, const TCHAR *s, size_t n)
{
#if defined(_tcsncpy_s)
_tcsncpy_s(d, n, s, _TRUNCATE);
#else
if (n)
{
_tcsncpy(d, s, n-1);
d[n-1] = NUL;
}
else
*d = NUL;
#endif
return d;
}

View File

@@ -45,7 +45,9 @@
#ifdef __WIN32__
#include <windows.h>
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#include <time.h>
#endif
// ------------------------------------------------------------------
@@ -123,39 +125,69 @@ extern const char* gmonths[];
// ------------------------------------------------------------------
// Prototypes
inline struct tm *ggmtime(const time32_t *timep)
inline void ggmtime(struct tm *_tm, const time32_t *timep)
{
const time_t temp(*timep);
#if defined(__WIN32__)
const time_t zero(0);
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if (0 != gmtime_s(_tm, &temp))
{
const time_t zero(0);
gmtime_s(_tm, &zero);
}
#else
struct tm *time = gmtime(&temp);
return time ? time : gmtime(&zero);
#else
return gmtime(&temp);
#if defined(__WIN32__)
if (NULL == time)
{
const time_t zero(0);
time = gmtime(&zero);
}
#endif
*_tm = *time;
#endif
}
inline struct tm *glocaltime(const time32_t *timep)
inline void glocaltime(struct tm *_tm, const time32_t *timep)
{
const time_t temp(*timep);
#if defined(__WIN32__)
const time_t zero(0);
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if (0 != localtime_s(_tm, &temp))
{
const time_t zero(0);
localtime_s(_tm, &zero);
}
#else
struct tm *time = localtime(&temp);
return time ? time : localtime(&zero);
#else
return localtime(&temp);
#if defined(__WIN32__)
if (NULL == time)
{
const time_t zero(0);
time = localtime(&zero);
}
#endif
*_tm = *time;
#endif
}
inline char *gctime(const time32_t *timep)
inline void gctime(TCHAR *buffer, size_t sizeInChars, const time32_t *timep)
{
const time_t temp(*timep);
#if defined(__WIN32__)
const time_t zero(0);
char *time = ctime(&temp);
return time ? time : ctime(&zero);
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
if (0 != _tctime_s(buffer, sizeInChars, &temp))
{
const time_t zero(0);
_tctime_s(buffer, sizeInChars, &zero);
}
#else
return ctime(&temp);
const char *time = _tctime(&temp);
#if defined(__WIN32__)
if (NULL == time)
{
const time_t zero(0);
time = _tctime(&zero);
}
#endif
strxcpy(buffer, time, sizeInChars);
#endif
}

View File

@@ -58,12 +58,12 @@ const char* gmonths[] = {
// ------------------------------------------------------------------
// Returns current timezone offset based on TZ environment variable.
int tzoffset() {
time32_t t1 = gtime(NULL);
struct tm *tp = ggmtime(&t1);
tp->tm_isdst = -1;
time32_t t2 = gmktime(tp);
int tzoffset()
{
time32_t t1 = gtime(NULL);
struct tm tp; ggmtime(&tp, &t1);
tp.tm_isdst = -1;
time32_t t2 = gmktime(&tp);
int dt = (int)(t1 - t2);
return (dt / 3600) * 100 + (dt % 3600) / 60;
}
@@ -350,10 +350,10 @@ time32_t FTimeToTime(FTime* __ftime, struct tm* __tm) {
__tm->tm_sec = __ftime->ft_tsec * 2;
__tm->tm_isdst = -1;
time32_t a = gmktime(__tm);
struct tm *tp = ggmtime(&a);
tp->tm_isdst = -1;
time32_t b = gmktime(tp);
time32_t a = gmktime(__tm);
struct tm tp; ggmtime(&tp, &a);
tp.tm_isdst = -1;
time32_t b = gmktime(&tp);
_time = a + a - b;
if(_time == (uint32_t)0xFFFFFFFFL)
@@ -373,15 +373,15 @@ FTime TimeToFTime(time32_t __time) {
FTime _ft;
memset(&_ft, 0, sizeof(FTime));
if(__time) {
struct tm* _tmp = ggmtime(&__time);
_ft.ft_year = (word)(_tmp->tm_year - 80);
_ft.ft_month = (word)(_tmp->tm_mon + 1);
_ft.ft_day = (word)(_tmp->tm_mday);
_ft.ft_hour = (word)(_tmp->tm_hour);
_ft.ft_min = (word)(_tmp->tm_min);
_ft.ft_tsec = (word)(_tmp->tm_sec / 2);
if (__time)
{
struct tm _tmp; ggmtime(&_tmp, &__time);
_ft.ft_year = (word)(_tmp.tm_year - 80);
_ft.ft_month = (word)(_tmp.tm_mon + 1);
_ft.ft_day = (word)(_tmp.tm_mday);
_ft.ft_hour = (word)(_tmp.tm_hour);
_ft.ft_min = (word)(_tmp.tm_min);
_ft.ft_tsec = (word)(_tmp.tm_sec / 2);
}
return _ft;
@@ -441,10 +441,10 @@ time32_t FidoTimeToUnix(char* ptr) {
t.tm_min = minute;
t.tm_sec = second;
t.tm_isdst = -1;
time32_t a = gmktime(&t);
struct tm *tp = ggmtime(&a);
tp->tm_isdst = -1;
time32_t b = gmktime(tp);
time32_t a = gmktime(&t);
struct tm tp; ggmtime(&tp, &a);
tp.tm_isdst = -1;
time32_t b = gmktime(&tp);
return a + a - b;
}
return (uint32_t)-1;
@@ -453,9 +453,10 @@ time32_t FidoTimeToUnix(char* ptr) {
// ------------------------------------------------------------------
char* TimeToStr(char* buf, time32_t t) {
return strftimei(buf, 20, "%Y-%m-%d %H:%M:%S", ggmtime(&t));
char* TimeToStr(char* buf, time32_t t)
{
struct tm tm; ggmtime(&tm, &t);
return strftimei(buf, 20, "%Y-%m-%d %H:%M:%S", &tm);
}

View File

@@ -439,8 +439,8 @@ inline vatch vcatch (vchar chr, vattr atr) { return chr | gvid_attrcalc(atr); }
inline vchar vgchar (vatch chat) { return chat.Char.AsciiChar; }
inline vattr vgattr (vatch chat) { return chat.Attributes; }
inline vatch vschar (vatch chat, vchar chr) { chat.Char.UnicodeChar = 0; chat.Char.AsciiChar = chr; return chat; }
inline vatch vsattr (vatch chat, vattr atr) { chat.Attributes = atr; return chat; }
inline vatch vcatch (vchar chr, vattr atr) { vatch chat; chat.Char.UnicodeChar = 0; chat.Char.AsciiChar = chr; chat.Attributes = atr; return chat; }
inline vatch vsattr (vatch chat, vattr atr) { chat.Attributes = WORD(atr); return chat; }
inline vatch vcatch (vchar chr, vattr atr) { vatch chat; chat.Char.UnicodeChar = 0; chat.Char.AsciiChar = chr; chat.Attributes = WORD(atr); return chat; }
#else