Sorry, refactoring!

This commit is contained in:
Ianos Gnatiuc
2006-04-24 16:38:44 +00:00
parent bcf5ac98c1
commit 6cac338f3e
24 changed files with 755 additions and 741 deletions

View File

@@ -29,11 +29,56 @@
#include <cstdarg>
#include <gfile.h>
#if defined(_MSC_VER) /*&& (_MSC_VER >= 1400)*/
#define g_sopen(fn, of, sh, pm) _tsopen(fn, of, sh, pm)
#define g_close(fh) _close(fh)
#define g_read(fh, buf, cnt) _read(fh, buf, cnt)
#define g_write(fh, buf, cnt) _write(fh, buf, cnt)
#define g_tell(fh) _tell(fh)
#define g_lseek(fh, off, org) _lseek(fh, off, org)
#define g_filelength(fh) _filelength(fh)
#define g_chsize(fh, size) _chsize(fh, size)
#define g_fsopen(fn, of, sh) _tfsopen(fn, of, sh)
#define g_fdopen(fp, of) _tfdopen(fp, of)
#define g_fileno(fp) _fileno(fp)
#else
#define g_sopen(fn, of, sh, pm) sopen(fn, of, sh, pm)
#define g_close(fh) close(fh)
#define g_read(fh, buf, cnt) read(fh, buf, cnt)
#define g_write(fh, buf, cnt) write(fh, buf, cnt)
#define g_tell(fh) tell(fh)
#define g_lseek(fh, off, org) lseek(fh, off, org)
#define g_filelength(fh) filelength(fh)
#define g_chsize(fh, size) chsize(fh, size)
#define g_fsopen(fn, of, sh) fsopen(fn, of, sh)
#define g_fdopen(fp, of) fdopen(fp, of)
#define g_fileno(fp) fileno(fp)
#endif
#define g_lock(fh, off, len) lock(fh, off, len)
#define g_unlock(fh, off, len) unlock(fh, off, len)
#define g_fclose(fp) fclose(fp)
#define g_fread(buf, rsz, cnt, fp) fread(buf, rsz, cnt, fp)
#define g_fwrite(buf, rsz, cnt, fp) fwrite(buf, rsz, cnt, fp)
#define g_fgetc(fp) fgetc(fp)
#define g_fputc(c, fp) fputc(c, fp)
#define g_fgets(str, cnt, fp) fgets(str, cnt, fp)
#define g_fputs(str, fp) fputs(str, fp)
#define g_fflush(fp) fflush(fp)
#define g_ftell(fp) ftell(fp)
// ------------------------------------------------------------------
gfile::gfile() {
gfile::gfile()
{
fh = -1;
fp = NULL;
status = EBADF;
@@ -42,8 +87,8 @@ gfile::gfile() {
// ------------------------------------------------------------------
gfile::gfile(int __fh) {
gfile::gfile(int __fh)
{
fh = __fh;
fp = NULL;
status = 0;
@@ -52,8 +97,8 @@ gfile::gfile(int __fh) {
// ------------------------------------------------------------------
gfile::gfile(FILE* __fp) {
gfile::gfile(FILE* __fp)
{
fh = -1;
fp = __fp;
status = 0;
@@ -62,51 +107,42 @@ gfile::gfile(FILE* __fp) {
// ------------------------------------------------------------------
gfile::gfile(const char* __path, int __access, int __shflag, int __mode) {
open(__path, __access, __shflag, __mode);
}
// ------------------------------------------------------------------
gfile::gfile(const char* __path, const char* __mode, int __shflag) {
fopen(__path, __mode, __shflag);
}
// ------------------------------------------------------------------
gfile::~gfile() {
if(fp != NULL)
fclose();
if(fh != -1)
close();
}
// ------------------------------------------------------------------
int gfile::okay() {
return !status;
gfile::gfile(const char* __path, int __access, int __shflag, int __mode)
{
fh = -1;
fp = NULL;
Open(__path, __access, __shflag, __mode);
}
// ------------------------------------------------------------------
bool gfile::isopen() {
gfile::gfile(const char* __path, const char* __mode, int __shflag)
{
fh = -1;
fp = NULL;
Fopen(__path, __mode, __shflag);
}
if((fh != -1) or (fp != NULL))
return true;
// ------------------------------------------------------------------
gfile::~gfile()
{
if (fp != NULL) Fclose();
if (fh != -1) Close();
}
// ------------------------------------------------------------------
bool gfile::isopen()
{
if ((fh != -1) or (fp != NULL)) return true;
return false;
}
// ------------------------------------------------------------------
int gfile::setfh(int __fh) {
int gfile::setfh(int __fh)
{
fh = __fh;
status = 0;
return fh;
@@ -114,8 +150,8 @@ int gfile::setfh(int __fh) {
// ------------------------------------------------------------------
FILE* gfile::setfp(FILE* __fp) {
FILE* gfile::setfp(FILE* __fp)
{
fp = __fp;
status = 0;
return fp;
@@ -123,31 +159,35 @@ FILE* gfile::setfp(FILE* __fp) {
// ------------------------------------------------------------------
int gfile::open(const char* __path, int __access, int __shflag, int __mode) {
fh = ::sopen(__path, __access, __shflag, __mode);
int gfile::Open(const char* __path, int __access, int __shflag, int __mode)
{
#if defined(_tsopen_s)
status = _tsopen_s(&fh, __path, __access, __shflag, __mode);
return fh;
#else
fh = g_sopen(__path, __access, __shflag, __mode);
status = (fh == -1) ? errno : 0;
return fh;
#endif
}
// ------------------------------------------------------------------
int gfile::open(const char* __path, int __access, char* __fmode, int __shflag, int __mode) {
open(__path, __access, __shflag, __mode);
fdopen(__fmode);
int gfile::Open(const char* __path, int __access, const char* __fmode, int __shflag, int __mode)
{
Open(__path, __access, __shflag, __mode);
Fdopen(__fmode);
return fh;
}
// ------------------------------------------------------------------
int gfile::close() {
int gfile::Close()
{
if (fp) return Fclose();
if(fp)
return fclose();
int _ret = ::close(fh);
int _ret = g_close(fh);
status = _ret ? errno : 0;
fh = -1;
return _ret;
@@ -155,223 +195,214 @@ int gfile::close() {
// ------------------------------------------------------------------
int gfile::read(void* __ptr, size_t __len) {
int _ret = ::read(fh, __ptr, (unsigned)__len);
int gfile::Read(void* __ptr, size_t __len)
{
int _ret = g_read(fh, __ptr, unsigned(__len));
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::write(void* __ptr, size_t __len) {
int _ret = ::write(fh, __ptr, (unsigned)__len);
int gfile::Write(void* __ptr, size_t __len)
{
int _ret = g_write(fh, __ptr, unsigned(__len));
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::tell() {
long _ret = ::tell(fh);
long gfile::Tell()
{
long _ret = g_tell(fh);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::lseek(long __offset, int __direction) {
long _ret = ::lseek(fh, __offset, __direction);
long gfile::Lseek(long __offset, int __direction)
{
long _ret = g_lseek(fh, __offset, __direction);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::filelength() {
long _ret = ::filelength(fh);
long gfile::FileLength()
{
long _ret = g_filelength(fh);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::chsize(long __size) {
int _ret = ::chsize(fh, __size);
int gfile::ChSize(long __size)
{
int _ret = g_chsize(fh, __size);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::lock(long __offset, long __len) {
int _ret = ::lock(fh, __offset, __len);
int gfile::Lock(long __offset, long __len)
{
int _ret = g_lock(fh, __offset, __len);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::unlock(long __offset, long __len) {
int _ret = ::unlock(fh, __offset, __len);
int gfile::Unlock(long __offset, long __len)
{
int _ret = g_unlock(fh, __offset, __len);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::getftime(dword* __ftime) {
int gfile::GetFTime(time32_t *__ftime)
{
struct stat s;
if(fp)
fflush();
int rv = fstat (fh, &s);
if (fp) Fflush();
int rv = fstat(fh, &s);
status = (rv) ? errno : 0;
if(rv == 0)
*__ftime = gfixstattime(s.st_mtime);
else
__ftime = 0;
if (rv == 0) *__ftime = gfixstattime(time32_t(s.st_mtime));
else __ftime = 0;
return rv;
}
// ------------------------------------------------------------------
FILE* gfile::fopen(const std::string& __path, const char* __mode, int __shflag) {
return fopen(__path.c_str(), __mode, __shflag);
}
// ------------------------------------------------------------------
FILE* gfile::fopen(const char* __path, const char* __mode, int __shflag) {
fp = ::fsopen(__path, __mode, __shflag);
FILE* gfile::Fopen(const char* __path, const char* __mode, int __shflag)
{
fp = g_fsopen(__path, __mode, __shflag);
status = (fp == NULL) ? errno : 0;
if(fp)
fh = fileno(fp);
if (fp) fh = g_fileno(fp);
return fp;
}
// ------------------------------------------------------------------
FILE* gfile::fdopen(char* __mode) {
fp = ::fdopen(fh, __mode);
FILE* gfile::Fdopen(const char* __mode)
{
fp = g_fdopen(fh, __mode);
status = fp ? 0 : errno;
if(fp)
fh = fileno(fp);
if (fp) fh = g_fileno(fp);
return fp;
}
// ------------------------------------------------------------------
int gfile::fclose() {
int gfile::Fclose()
{
int _ret = 0;
if(fp)
_ret = ::fclose(fp);
if (fp) _ret = g_fclose(fp);
status = _ret ? errno : 0;
fp = NULL;
fh = -1;
fp = NULL; fh = -1;
return _ret;
}
// ------------------------------------------------------------------
size_t gfile::fread(void* __ptr, size_t __size, size_t __items) {
size_t _ret = ::fread(__ptr, __size, __items, fp);
size_t gfile::Fread(void* __ptr, size_t __size, size_t __items)
{
size_t _ret = g_fread(__ptr, __size, __items, fp);
status = ferror_() ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
size_t gfile::fwrite(const void* __ptr, size_t __size, size_t __items) {
size_t _ret = ::fwrite(__ptr, __size, __items, fp);
size_t gfile::Fwrite(const void* __ptr, size_t __size, size_t __items)
{
size_t _ret = g_fwrite(__ptr, __size, __items, fp);
status = (_ret < __items) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fgetc() {
int gfile::Fgetc()
{
int _ret = g_fgetc(fp);
status = ferror_() ? errno : 0;
return _ret;
}
int _ret = ::fgetc(fp);
// ------------------------------------------------------------------
int gfile::Fputc(int __ch)
{
int _ret = g_fputc(__ch, fp);
status = ferror_() ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fputc(int __ch) {
int _ret = ::fputc(__ch, fp);
status = ferror_() ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
char* gfile::fgets(char* __str, size_t __len) {
char* _ret = ::fgets(__str, __len, fp);
char* gfile::Fgets(char* __str, size_t __len)
{
char* _ret = g_fgets(__str, int(__len), fp);
status = (_ret == NULL) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fputs(const char* __str) {
int _ret = ::fputs(__str, fp);
int gfile::Fputs(const char* __str)
{
int _ret = g_fputs(__str, fp);
status = (_ret == EOF) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::printf(const char* __format, ...) {
int gfile::Printf(const char* __format, ...)
{
va_list _argptr;
va_start(_argptr, __format);
int _outcount = ::vfprintf(fp, __format, _argptr);
int _outcount = vfprintf(fp, __format, _argptr);
va_end(_argptr);
return _outcount;
}
// ------------------------------------------------------------------
int gfile::fflush() {
int _ret = ::fflush(fp);
int gfile::Fflush()
{
int _ret = g_fflush(fp);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
long gfile::ftell() {
long _ret = ::ftell(fp);
long gfile::Ftell()
{
long _ret = g_ftell(fp);
status = (_ret == -1) ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
int gfile::fseek(long __offset, int __direction) {
int gfile::Fseek(long __offset, int __direction)
{
int _ret = ::fseek(fp, __offset, __direction);
status = _ret ? errno : 0;
return _ret;
@@ -379,31 +410,12 @@ int gfile::fseek(long __offset, int __direction) {
// ------------------------------------------------------------------
int gfile::setvbuf(char* __buf, int __type, size_t __size) {
int gfile::SetvBuf(char* __buf, int __type, size_t __size)
{
int _ret = ::setvbuf(fp, __buf, __type, __size);
status = _ret ? errno : 0;
return _ret;
}
// ------------------------------------------------------------------
#ifdef __GOLDWARE_HAS_BOOL
gfile& gfile::operator>> (bool& i) { fread(&i, sizeof(bool)); return *this; }
#endif
gfile& gfile::operator>> (uint8_t& i) { fread(&i, sizeof(uint8_t)); return *this; }
gfile& gfile::operator>> (uint16_t& i) { fread(&i, sizeof(uint16_t)); return *this; }
gfile& gfile::operator>> (uint32_t& i) { fread(&i, sizeof(uint32_t)); return *this; }
gfile& gfile::operator>> (unsigned long& i) { fread(&i, sizeof(unsigned long)); return *this; }
#ifdef __GOLDWARE_HAS_BOOL
gfile& gfile::operator<< (bool o) { fwrite(&o, sizeof(o)); return *this; }
#endif
gfile& gfile::operator<< (uint8_t o) { fwrite(&o, sizeof(o)); return *this; }
gfile& gfile::operator<< (uint16_t o) { fwrite(&o, sizeof(o)); return *this; }
gfile& gfile::operator<< (uint32_t o) { fwrite(&o, sizeof(o)); return *this; }
gfile& gfile::operator<< (unsigned long o) { fwrite(&o, sizeof(o)); return *this; }
// ------------------------------------------------------------------

View File

@@ -43,8 +43,8 @@
// ------------------------------------------------------------------
// Stream/Unix-style file I/O class
class gfile {
class gfile
{
public:
// ----------------------------------------------------------------
@@ -63,8 +63,9 @@ public:
// --------------------------------------------------------------
// Handy utility functions
int okay(); // Returns non-zero if no errors were detected
int okay() { return (0 == status); }
bool isopen(); // true if the file is open
operator bool() { return isopen(); }
// --------------------------------------------------------------
@@ -78,8 +79,6 @@ public:
~gfile(); // Destructor (closes file)
operator bool() { return isopen(); }
// --------------------------------------------------------------
// Set file handle or stream pointer
@@ -91,73 +90,73 @@ public:
// --------------------------------------------------------------
// UNIX-style raw I/O
int open (const char* __path, int __access, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int open (const char* __path, int __access, char* __fmode, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int close ();
int Open (const char* __path, int __access, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int Open (const char* __path, int __access, const char* __fmode, int __shflag=SH_DENYNO, int __mode=S_IREAD|S_IWRITE);
int Close ();
int read (void* __ptr, size_t __len);
int write (void* __ptr, size_t __len);
int Read (void* __ptr, size_t __len);
int Write (void* __ptr, size_t __len);
long tell ();
long lseek (long __offset, int __direction);
long lseek (long __record, long __recordsize, int __direction);
long lseekset (long __record, long __recordsize=1);
long Tell ();
long Lseek (long __offset, int __direction);
long Lseek (long __record, long __recordsize, int __direction) { return Lseek(__record*__recordsize, __direction); }
long LseekSet (long __record, long __recordsize = 1) { return Lseek(__record*__recordsize, SEEK_SET); }
long filelength ();
long FileLength ();
int chsize (long __size);
int ChSize (long __size);
int lock (long __offset, long __len);
int unlock (long __offset, long __len);
int Lock (long __offset, long __len);
int Unlock (long __offset, long __len);
int getftime (dword* __ftime);
int GetFTime (dword* __ftime);
// --------------------------------------------------------------
// ANSI-style streaming buffered I/O
FILE* fopen (const char* __path, const char* __mode, int __shflag=SH_DENYNO);
FILE* fopen (const std::string& __path, const char* __mode, int __shflag=SH_DENYNO);
FILE* fdopen (char* __mode);
int fclose ();
FILE* Fopen (const char* __path, const char* __mode, int __shflag=SH_DENYNO);
FILE* Fopen (const std::string& __path, const char* __mode, int __shflag=SH_DENYNO) { return Fopen(__path.c_str(), __mode, __shflag); }
FILE* Fdopen (const char* __mode);
int Fclose ();
size_t fread (void* __ptr, size_t __size, size_t __items=1);
size_t fwrite (const void* __ptr, size_t __size, size_t __items=1);
size_t Fread (void* __ptr, size_t __size, size_t __items=1);
size_t Fwrite (const void* __ptr, size_t __size, size_t __items=1);
int fgetc ();
int fputc (int __ch);
int Fgetc ();
int Fputc (int __ch);
char* fgets (char* __str, size_t __len);
int fputs (const char* __str);
char* Fgets (char* __str, size_t __len);
int Fputs (const char* __str);
int printf (const char* __format, ...) __attribute__ ((format (printf, 2, 3)));
int Printf (const char* __format, ...) __attribute__ ((format (printf, 2, 3)));
int fflush ();
int Fflush ();
long ftell ();
int fseek (long __offset, int __direction);
int fseek (long __record, long __recordsize, int __direction);
int fseekset(long __record, long __recordsize=1);
long Ftell ();
int Fseek (long __offset, int __direction);
int Fseek (long __record, long __recordsize, int __direction) { return Fseek(__record*__recordsize, __direction); }
int FseekSet(long __record, long __recordsize = 1) { return Fseek(__record*__recordsize, SEEK_SET); }
void rewind ();
void Rewind () { rewind(fp); }
int setvbuf (char* __buf=NULL, int __type=_IOFBF, size_t __size=8192);
int setvbuf (size_t __size) { return setvbuf(NULL, _IOFBF, __size); }
int SetvBuf (char* __buf=NULL, int __type=_IOFBF, size_t __size=8192);
int SetvBuf (size_t __size) { return SetvBuf(NULL, _IOFBF, __size); }
int feof_ ();
int ferror_ ();
int feof_ () { return feof(fp); }
int ferror_ () { return ferror(fp); }
// ----------------------------------------------------------------
#ifdef __GOLDWARE_HAS_BOOL
gfile& operator>> (bool& i);
gfile& operator>> (bool& i) { Fread(&i, sizeof(bool)); return *this; }
#endif
gfile& operator>> (uint8_t& i);
gfile& operator>> (uint16_t& i);
gfile& operator>> (uint32_t& i);
gfile& operator>> (uint8_t& i) { Fread(&i, sizeof(uint8_t)); return *this; }
gfile& operator>> (uint16_t& i) { Fread(&i, sizeof(uint16_t)); return *this; }
gfile& operator>> (uint32_t& i) { Fread(&i, sizeof(uint32_t)); return *this; }
#if !defined(__CYGWIN__)
gfile& operator>> (unsigned long& i);
gfile& operator>> (unsigned long& i) { Fread(&i, sizeof(unsigned long)); return *this; }
#endif
gfile& operator>> (char& i) { return operator>>((uint8_t&)i); }
@@ -171,13 +170,13 @@ public:
#endif
#ifdef __GOLDWARE_HAS_BOOL
gfile& operator<< (bool o);
gfile& operator<< (bool o) { Fwrite(&o, sizeof(o)); return *this; }
#endif
gfile& operator<< (uint8_t o);
gfile& operator<< (uint16_t o);
gfile& operator<< (uint32_t o);
gfile& operator<< (uint8_t o) { Fwrite(&o, sizeof(o)); return *this; }
gfile& operator<< (uint16_t o) { Fwrite(&o, sizeof(o)); return *this; }
gfile& operator<< (uint32_t o) { Fwrite(&o, sizeof(o)); return *this; }
#if !defined(__CYGWIN__)
gfile& operator<< (unsigned long o);
gfile& operator<< (unsigned long o) { Fwrite(&o, sizeof(o)); return *this; }
#endif
gfile& operator<< (char o) { return operator<<((uint8_t )o); }
@@ -189,70 +188,9 @@ public:
#if !defined(__CYGWIN__)
gfile& operator<< (long o) { return operator<<((unsigned long)o); }
#endif
};
// ------------------------------------------------------------------
// Inline implementations
// ------------------------------------------------------------------
inline long gfile::lseek(long __record, long __recordsize, int __direction) {
return lseek(__record*__recordsize, __direction);
}
// ------------------------------------------------------------------
inline long gfile::lseekset(long __record, long __recordsize) {
return lseek(__record*__recordsize, SEEK_SET);
}
// ------------------------------------------------------------------
inline int gfile::ferror_() {
return ferror(fp);
}
// ------------------------------------------------------------------
inline int gfile::fseek(long __record, long __recordsize, int __direction) {
return fseek(__record*__recordsize, __direction);
}
// ------------------------------------------------------------------
inline int gfile::fseekset(long __record, long __recordsize) {
return fseek(__record*__recordsize, SEEK_SET);
}
// ------------------------------------------------------------------
inline void gfile::rewind() {
::rewind(fp);
}
// ------------------------------------------------------------------
inline int gfile::feof_() {
return feof(fp);
}
// ------------------------------------------------------------------
#endif

View File

@@ -159,10 +159,10 @@ inline bool fexist(const TCHAR *filename) { return *filename ? (0 == (_taccess(f
#endif
inline bool fexist(const std::string& filename) { return fexist(filename.c_str()); }
dword gfixstattime(time32_t st_time);
time32_t gfixstattime(time32_t st_time);
dword GetFiletime(const char* file);
inline dword GetFiletime(const std::string& file) { return GetFiletime(file.c_str()); }
time32_t GetFiletime(const char* file);
inline time32_t GetFiletime(const std::string& file) { return GetFiletime(file.c_str()); }
inline long FiletimeCmp(const char* file1, const char* file2) { return long(GetFiletime(file1) - GetFiletime(file2)); }
inline long FiletimeCmp(const std::string& file1, const std::string& file2) { return FiletimeCmp(file1.c_str(), file2.c_str()); }
@@ -184,7 +184,7 @@ char* StripBackslash(char* p);
char* PathCopy(char* dst, const char* src);
void PathCopy(std::string& dst, const char* src);
void TouchFile(const char* __filename);
void TouchFile(const TCHAR *filename);
int TestLockPath(const char* __path);
void WipeFile(const char* file, int options);

View File

@@ -28,6 +28,8 @@
#include <gtimall.h>
#include <gstrall.h>
#include <gfilutil.h>
#include <gfile.h>
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <sys/utime.h>
#else
@@ -96,7 +98,7 @@ long GetFilesize(const char* file) {
// ------------------------------------------------------------------
// Convert time returned with stat to FFTime
dword gfixstattime(time32_t st_time)
time32_t gfixstattime(time32_t st_time)
{
#if (defined(__MINGW32__) && !defined(__MSVCRT__)) || defined(__CYGWIN__)
struct tm f; ggmtime(&f, &st_time);
@@ -138,7 +140,7 @@ dword gfixstattime(time32_t st_time)
// ------------------------------------------------------------------
// Get timestamp of file
dword GetFiletime(const char* file) {
time32_t GetFiletime(const char* file) {
struct stat st;
if(stat(file, &st) == 0) {
@@ -301,11 +303,14 @@ FILE *fsopen(const char *path, const char *type, int shflag) {
// ------------------------------------------------------------------
void TouchFile(const char* filename) {
if(not fexist(filename))
close(open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_STDRW));
else {
void TouchFile(const TCHAR *filename)
{
if (not fexist(filename))
{
gfile fh(filename, O_WRONLY|O_CREAT|O_TRUNC);
}
else
{
struct utimbuf ut;
ut.actime = ut.modtime = time(NULL);
utime(filename, &ut);

View File

@@ -62,17 +62,18 @@ glog::~glog() {
// ------------------------------------------------------------------
int glog::open(const char* filename, const char* name, const char* shortname, int type, uint bufsz, int shflag) {
fp.fopen(filename, "at", shflag);
if(fp.status) {
int glog::open(const char* filename, const char* name, const char* shortname, int type, uint bufsz, int shflag)
{
fp.Fopen(filename, "at", shflag);
if (fp.status)
{
status = fp.status;
return status;
}
count++;
bufsize = bufsz;
fp.setvbuf(NULL, bufsize ? _IOFBF : _IONBF, bufsize);
fp.SetvBuf(NULL, bufsize ? _IOFBF : _IONBF, bufsize);
init(name, shortname, type);
@@ -82,9 +83,9 @@ int glog::open(const char* filename, const char* name, const char* shortname, in
// ------------------------------------------------------------------
void glog::close() {
fp.fclose();
void glog::close()
{
fp.Fclose();
count--;
}
@@ -138,8 +139,8 @@ void glog::printf(const char* format, ...) {
break;
}
if(fp.isopen())
fp.printf("%s", logbuf);
if (fp.isopen())
fp.Printf("%s", logbuf);
}
*buf = NUL;
@@ -172,9 +173,10 @@ void glog::printf(const char* format, ...) {
sprintf(logbuf, "%s %s", strftimei(timebuf, 20, "%m/%d/%y %H:%M", &time_now), buf+2);
break;
}
if(fp.isopen()) {
fp.printf("%s\n", logbuf);
fp.fflush();
if (fp.isopen())
{
fp.Printf("%s\n", logbuf);
fp.Fflush();
}
if(storelines != -1) {
if(storelines < GLOG_STORELINES)

View File

@@ -293,30 +293,29 @@ uint GTag::ToReln(uint32_t __tagn) {
// ------------------------------------------------------------------
void GTag::Load(gfile& fp) {
void GTag::Load(gfile& fp)
{
dword val;
fp.fread(&val, sizeof(dword));
fp.Fread(&val, sizeof(dword));
count = (uint) val;
if(count) {
if (count)
{
Resize(count);
fp.fread(tag, sizeof(uint32_t), count);
fp.Fread(tag, sizeof(uint32_t), count);
}
}
// ------------------------------------------------------------------
void GTag::Save(gfile& fp) {
void GTag::Save(gfile& fp)
{
dword val = (dword) count;
fp.Fwrite(&val, sizeof(dword));
dword val;
val = (dword) count;
fp.fwrite(&val, sizeof(dword));
if(tag and count)
fp.fwrite(tag, sizeof(uint32_t), count);
if (tag and count)
fp.Fwrite(tag, sizeof(uint32_t), count);
}

View File

@@ -131,20 +131,22 @@ static int find_cat_name(const char* cat) {
int found=NO;
// Reset file pointer.
whelp.fp->fseekset(whelp.offset);
whelp.fp->FseekSet(whelp.offset);
// Check for "*I" marker.
whelp.fp->fgets(buf, BUFSIZE);
if(strnieql(buf,"*I",2)) {
whelp.fp->Fgets(buf, BUFSIZE);
if (strnieql(buf,"*I",2))
{
// Search index for help category entry. If found,
// then advance file pointer to specified position.
for(;;) {
whelp.fp->fread(&recd,sizeof(Hlpr));
for(;;)
{
whelp.fp->Fread(&recd,sizeof(Hlpr));
if(recd.offset==-1L)
break;
if(strieql(recd.category,cat)) {
whelp.fp->fseekset(whelp.offset + recd.offset);
if (strieql(recd.category,cat))
{
whelp.fp->FseekSet(whelp.offset + recd.offset);
found=YES;
break;
}
@@ -166,20 +168,22 @@ static int find_cat_number(int cat) {
int found=NO;
// Reset file pointer.
whelp.fp->fseekset(whelp.offset);
whelp.fp->FseekSet(whelp.offset);
// Check for "*I" marker.
whelp.fp->fgets(buf, BUFSIZE);
if(strnieql(buf,"*I",2)) {
whelp.fp->Fgets(buf, BUFSIZE);
if (strnieql(buf,"*I",2))
{
// Search index for help category entry. If found,
// then advance file pointer to specified position.
for(;;) {
whelp.fp->fread(&recd,sizeof(Hlpr));
if(recd.offset==-1L)
for (;;)
{
whelp.fp->Fread(&recd,sizeof(Hlpr));
if (recd.offset==-1L)
break;
if(recd.help==cat) {
whelp.fp->fseekset(whelp.offset + recd.offset);
if (recd.help==cat)
{
whelp.fp->FseekSet(whelp.offset + recd.offset);
found=YES;
break;
}
@@ -205,18 +209,21 @@ static int find_page(long startpos, int pageofs) {
int lines = whelp.srow;
lastpagepos = currpos = startpos;
whelp.fp->fseekset(startpos);
whelp.fp->FseekSet(startpos);
while(currpage < pageofs) {
whelp.fp->fgets(buf, BUFSIZE);
if(not whelp.fp->okay()) {
whelp.fp->fseekset(lastpagepos);
while (currpage < pageofs)
{
whelp.fp->Fgets(buf, BUFSIZE);
if (not whelp.fp->okay())
{
whelp.fp->FseekSet(lastpagepos);
break;
}
lines++;
currpos=whelp.fp->ftell();
if(strnieql(buf, "*E", 2)) {
whelp.fp->fseekset(lastpagepos);
currpos=whelp.fp->Ftell();
if (strnieql(buf, "*E", 2))
{
whelp.fp->FseekSet(lastpagepos);
break;
}
if(strnieql(buf, "*P", 2)) {
@@ -252,7 +259,7 @@ static void disp_cat() {
page = wrow = wcol = end = menuopen = itemopen = 0;
// save current info
startpos = whelp.fp->ftell();
startpos = whelp.fp->Ftell();
curr = gwin.cmenu;
// set text attribute
@@ -261,7 +268,7 @@ static void disp_cat() {
for(;;) {
// read next line from help file into buffer
whelp.fp->fgets(buf,BUFSIZE);
whelp.fp->Fgets(buf,BUFSIZE);
strtrim(buf);
// if end-of-file or "*E" was found, assume end-of-category
@@ -326,10 +333,10 @@ static void disp_cat() {
// try to find selected category, if found set
// file pointer to it, otherwise reset file
// pointer back to previous help category
if(find_cat_name(catarray[i]))
startpos=whelp.fp->ftell();
if (find_cat_name(catarray[i]))
startpos = whelp.fp->Ftell();
else
whelp.fp->fseekset(startpos);
whelp.fp->FseekSet(startpos);
// clear help window and set
// position to upper left corner
@@ -501,11 +508,13 @@ static void help_handler() {
}
else {
if(not whelp.fp) {
if (not whelp.fp)
{
whelpclosefile = true;
whelp.fp = new gfile; throw_new(whelp.fp);
whelp.fp->fopen(whelp.file,"rb");
if(not whelp.fp->isopen()) {
whelp.fp->Fopen(whelp.file,"rb");
if (!whelp.fp->isopen())
{
wtextattr(whelp.textattr);
wputs("\nHelp file not found: ");
wputs(whelp.file);
@@ -514,9 +523,9 @@ static void help_handler() {
}
}
if(whelp.fp->isopen()) {
whelp.fp->fseekset(whelp.offset);
if (whelp.fp->isopen())
{
whelp.fp->FseekSet(whelp.offset);
// find help category in help file
found=find_cat_number(cat);
@@ -526,8 +535,9 @@ static void help_handler() {
disp_cat();
}
if(whelpclosefile) {
whelp.fp->fclose();
if (whelpclosefile)
{
whelp.fp->Fclose();
delete whelp.fp;
whelp.fp = NULL;
}

View File

@@ -42,30 +42,32 @@ extern _help_t whelp;
void whelpcompile(const char* helpfile, long& offset) {
gfile ifp(helpfile, "rb");
if(ifp) {
ifp.setvbuf();
if (ifp.isopen())
{
ifp.SetvBuf();
int count = 0;
char buf[1024];
while(ifp.fgets(buf, sizeof(buf))) {
while (ifp.Fgets(buf, sizeof(buf)))
{
if(strnieql(buf, "*B ", 3))
count++;
}
ifp.rewind();
ifp.Rewind();
Hlpr* helpindex = (Hlpr*)throw_xcalloc(count+2, sizeof(Hlpr));
long relative_offset = 0;
whelp.fp->fputs("*I\r\n");
whelp.fp->fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->fputs("\r\n\r\n");
whelp.fp->Fputs("*I\r\n");
whelp.fp->Fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->Fputs("\r\n\r\n");
relative_offset += 4 + ((count+1)*sizeof(Hlpr)) + 4;
int counter = 0;
bool comment = true;
while(ifp.fgets(buf, sizeof(buf))) {
while (ifp.Fgets(buf, sizeof(buf)))
{
if(strnieql(buf, "*B ", 3)) {
comment = false;
helpindex[counter].help = atow(buf+3);
@@ -74,8 +76,9 @@ void whelpcompile(const char* helpfile, long& offset) {
helpindex[counter].offset = relative_offset + strlen(buf);
counter++;
}
if(not comment) {
whelp.fp->fputs(buf);
if (not comment)
{
whelp.fp->Fputs(buf);
relative_offset += strlen(buf);
}
if(strnieql(buf, "*E", 2))
@@ -83,15 +86,15 @@ void whelpcompile(const char* helpfile, long& offset) {
}
helpindex[counter].offset = -1L;
whelp.fp->fseekset(offset);
whelp.fp->fputs("*I\r\n");
whelp.fp->fwrite(helpindex, count+1, sizeof(Hlpr));
whelp.fp->FseekSet(offset);
whelp.fp->Fputs("*I\r\n");
whelp.fp->Fwrite(helpindex, count+1, sizeof(Hlpr));
offset += relative_offset;
whelp.fp->fseekset(offset);
whelp.fp->FseekSet(offset);
throw_xfree(helpindex);
ifp.fclose();
ifp.Fclose();
}
}

View File

@@ -1231,8 +1231,9 @@ int wmenuget() {
// separate ASCII code from keypress code, if ASCII
// code is zero, then it must be an extended key
ch=(char)xch;
if(!ch and gmnudropthrough) {
ch = char(xch & 0xFF);
if (!ch and gmnudropthrough)
{
if((xch != Key_PgDn) and (xch != Key_PgUp))
kbput(xch);
goto ESCAPE_KEY;

View File

@@ -678,7 +678,7 @@ int wpickstr(int srow, int scol, int erow, int ecol, int btype, vattr bordattr,
// position for the item that begins with the same ASCII
// character as the keypress. If not found after current
// position, search from the beginning for a match
ch = (char)g_toupper((char)xch);
ch = (char)g_toupper(char(xch & 0xFF));
if(!ch)
break;
for(i=r.curr+1; i<r.numelems; i++)