Sorry, refactoring!
This commit is contained in:
@@ -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; }
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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++)
|
||||
|
@@ -66,8 +66,7 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
|
||||
const char* _file = AddPath(_path, "fd.sys");
|
||||
|
||||
gfile fp;
|
||||
fp.fopen(_file, "rb");
|
||||
gfile fp(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
_ctl* ctl = (_ctl*)throw_calloc(1, sizeof(_ctl));
|
||||
@@ -75,11 +74,11 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
fp.fread(ctl, sizeof(_ctl));
|
||||
fp.Fread(ctl, sizeof(_ctl));
|
||||
|
||||
if(not memcmp(ctl->fingerprint, "JoHo", 5) and (ctl->sysrev == IM_THISREV)) {
|
||||
|
||||
fp.fclose();
|
||||
if (not memcmp(ctl->fingerprint, "JoHo", 5) and (ctl->sysrev == IM_THISREV))
|
||||
{
|
||||
fp.Fclose();
|
||||
|
||||
CfgHudsonpath(ctl->e.qbase);
|
||||
|
||||
@@ -136,7 +135,7 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
if(fexist(_file)) {
|
||||
|
||||
_file = AddPath(ctl->s.systempath, "imfolder.cfg");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
@@ -144,8 +143,8 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
|
||||
FOLDER* _folder = (FOLDER*)throw_calloc(1, sizeof(FOLDER));
|
||||
|
||||
while(fp.fread(_folder, sizeof(FOLDER)) == 1) {
|
||||
|
||||
while (fp.Fread(_folder, sizeof(FOLDER)) == 1)
|
||||
{
|
||||
aa.reset();
|
||||
switch(_folder->ftype) {
|
||||
case F_MSG: aa.basetype = "OPUS"; break;
|
||||
@@ -174,13 +173,13 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
}
|
||||
}
|
||||
throw_free(_folder);
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
else
|
||||
{
|
||||
_file = AddPath(ctl->s.systempath, "folder.cfg");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
@@ -188,7 +187,8 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
|
||||
OLDFOLDER* _folder = (OLDFOLDER*)throw_calloc(1, sizeof(OLDFOLDER));
|
||||
|
||||
while(fp.fread(_folder, sizeof(OLDFOLDER)) == 1) {
|
||||
while (fp.Fread(_folder, sizeof(OLDFOLDER)) == 1)
|
||||
{
|
||||
long _behave = _folder->behave;
|
||||
if(not (DELETED & _behave)) {
|
||||
|
||||
@@ -216,7 +216,7 @@ void gareafile::ReadInterMail(char* tag) {
|
||||
}
|
||||
}
|
||||
throw_free(_folder);
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -66,17 +66,16 @@ void gareafile::ReadLoraBBS(char* tag) {
|
||||
if(*_path == NUL)
|
||||
strcpy(_path, areapath);
|
||||
|
||||
gfile fp;
|
||||
const char* _file = AddPath(_path, "config.dat");
|
||||
fp.fopen(_file, "rb");
|
||||
gfile fp(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
_configuration* cfg = (_configuration*)throw_calloc(1, sizeof(_configuration));
|
||||
fp.fread(cfg, sizeof(_configuration));
|
||||
fp.fclose();
|
||||
fp.Fread(cfg, sizeof(_configuration));
|
||||
fp.Fclose();
|
||||
|
||||
//CfgUsername(cfg->sysop);
|
||||
|
||||
@@ -134,18 +133,18 @@ void gareafile::ReadLoraBBS(char* tag) {
|
||||
}
|
||||
|
||||
_file = AddPath(_path, "sysmsg.dat");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
fp.setvbuf(NULL, _IOFBF, 8192);
|
||||
fp.SetvBuf(NULL, _IOFBF, 8192);
|
||||
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
_sysmsg* sysmsg = (_sysmsg*)throw_calloc(1, sizeof(_sysmsg));
|
||||
|
||||
while(fp.fread(sysmsg, sizeof(_sysmsg)) == 1) {
|
||||
|
||||
while (fp.Fread(sysmsg, sizeof(_sysmsg)) == 1)
|
||||
{
|
||||
if(sysmsg->passthrough)
|
||||
continue;
|
||||
|
||||
@@ -196,7 +195,7 @@ void gareafile::ReadLoraBBS(char* tag) {
|
||||
AddNewArea(aa);
|
||||
}
|
||||
throw_free(sysmsg);
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
throw_free(cfg);
|
||||
}
|
||||
|
@@ -84,9 +84,8 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
|
||||
CfgPcboardpath(_path);
|
||||
|
||||
gfile fp;
|
||||
const char* _file = AddPath(_path, "pcboard.dat");
|
||||
fp.fopen(_file, "rt");
|
||||
gfile fp(_file, "rt");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
@@ -95,7 +94,8 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
int _line = 0;
|
||||
|
||||
char _buf[256];
|
||||
while(fp.fgets(_buf, sizeof(_buf))) {
|
||||
while (fp.Fgets(_buf, sizeof(_buf)))
|
||||
{
|
||||
_line++;
|
||||
switch(_line) {
|
||||
case 28: // Location of User INDEX Files
|
||||
@@ -113,44 +113,45 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
}
|
||||
}
|
||||
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
|
||||
if(*_fidopath) {
|
||||
if (*_fidopath)
|
||||
{
|
||||
const char* _file = AddPath(_fidopath, "pcbfido.cfg");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
// Get configuration file version
|
||||
fp.fread(&fido_version, 2);
|
||||
fp.Fread(&fido_version, 2);
|
||||
|
||||
if(fido_version == 2) {
|
||||
|
||||
word numrecs = 0;
|
||||
|
||||
// Get areas
|
||||
fp.fread(&numrecs, 2);
|
||||
fp.Fread(&numrecs, 2);
|
||||
numareas = numrecs;
|
||||
areap = (PcbFidoArea*)throw_calloc(1+numrecs, sizeof(PcbFidoArea));
|
||||
fp.fread(areap, sizeof(PcbFidoArea), numrecs);
|
||||
fp.Fread(areap, sizeof(PcbFidoArea), numrecs);
|
||||
|
||||
// Skip archivers
|
||||
fp.fseek(sizeof(PcbFidoArchivers), SEEK_CUR);
|
||||
fp.Fseek(sizeof(PcbFidoArchivers), SEEK_CUR);
|
||||
|
||||
// Get directories
|
||||
dirp = (PcbFidoDirectories*)throw_calloc(1, sizeof(PcbFidoDirectories));
|
||||
fp.fread(dirp, sizeof(PcbFidoDirectories));
|
||||
fp.Fread(dirp, sizeof(PcbFidoDirectories));
|
||||
|
||||
// Skip EMSI profile
|
||||
fp.fseek(sizeof(PcbFidoEmsiData), SEEK_CUR);
|
||||
fp.Fseek(sizeof(PcbFidoEmsiData), SEEK_CUR);
|
||||
|
||||
// Get akas
|
||||
fp.fread(&numrecs, 2);
|
||||
fp.Fread(&numrecs, 2);
|
||||
akanumrecs = numrecs;
|
||||
akap = (PcbFidoAddress*)throw_calloc(1+numrecs, sizeof(PcbFidoAddress));
|
||||
fp.fread(akap, sizeof(PcbFidoAddress), numrecs);
|
||||
fp.Fread(akap, sizeof(PcbFidoAddress), numrecs);
|
||||
int akano = 0;
|
||||
while(akano < numrecs) {
|
||||
CfgAddress(akap[akano].nodestr);
|
||||
@@ -160,41 +161,43 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
else if(fido_version == 3) {
|
||||
|
||||
dir3 = (PcbDirectories*)throw_calloc(1, sizeof(PcbDirectories));
|
||||
fp.fread(dir3, sizeof(PcbDirectories));
|
||||
fp.fclose();
|
||||
fp.Fread(dir3, sizeof(PcbDirectories));
|
||||
fp.Fclose();
|
||||
|
||||
_file = AddPath(_fidopath, "areas.dat");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
word cfgver = 0;
|
||||
fp.fread(&cfgver, 2);
|
||||
if(cfgver == 3) {
|
||||
word numrecs = (word)(fp.filelength() / sizeof(PcbAreasDat));
|
||||
fp.Fread(&cfgver, 2);
|
||||
if (cfgver == 3)
|
||||
{
|
||||
word numrecs = (word)(fp.FileLength() / sizeof(PcbAreasDat));
|
||||
area3 = (PcbAreasDat*)throw_calloc(1+numrecs, sizeof(PcbAreasDat));
|
||||
fp.fread(area3, sizeof(PcbAreasDat), numrecs);
|
||||
fp.Fread(area3, sizeof(PcbAreasDat), numrecs);
|
||||
numareas = numrecs;
|
||||
}
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
|
||||
_file = AddPath(_fidopath, "akas.dat");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
word cfgver = 0;
|
||||
fp.fread(&cfgver, 2);
|
||||
if(cfgver == 3) {
|
||||
word numrecs = (word)(fp.filelength() / sizeof(PcbAkasDat));
|
||||
fp.Fread(&cfgver, 2);
|
||||
if (cfgver == 3)
|
||||
{
|
||||
word numrecs = (word)(fp.FileLength() / sizeof(PcbAkasDat));
|
||||
akanumrecs = numrecs;
|
||||
aka3 = (PcbAkasDat*)throw_calloc(1+numrecs, sizeof(PcbAkasDat));
|
||||
fp.fread(aka3, sizeof(PcbAkasDat), numrecs);
|
||||
fp.Fread(aka3, sizeof(PcbAkasDat), numrecs);
|
||||
int akano = 0;
|
||||
while(akano < numrecs) {
|
||||
char abuf[40];
|
||||
@@ -202,28 +205,29 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
akano++;
|
||||
}
|
||||
}
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
|
||||
_file = AddPath(_fidopath, "origins.dat");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
word cfgver = 0;
|
||||
fp.fread(&cfgver, 2);
|
||||
if(cfgver == 3) {
|
||||
word numrecs = (word)(fp.filelength() / sizeof(PcbOriginsDat));
|
||||
fp.Fread(&cfgver, 2);
|
||||
if (cfgver == 3)
|
||||
{
|
||||
word numrecs = (word)(fp.FileLength() / sizeof(PcbOriginsDat));
|
||||
origin3 = (PcbOriginsDat*)throw_calloc(1+numrecs, sizeof(PcbOriginsDat));
|
||||
fp.fread(origin3, sizeof(PcbOriginsDat), numrecs);
|
||||
fp.Fread(origin3, sizeof(PcbOriginsDat), numrecs);
|
||||
}
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
}
|
||||
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
|
||||
Path netmailpath;
|
||||
@@ -255,7 +259,7 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
}
|
||||
|
||||
_file = AddPath(_cnamespath, ".@@@");
|
||||
fp.fopen(_file, "rb");
|
||||
fp.Fopen(_file, "rb");
|
||||
if (fp.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
@@ -263,21 +267,23 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
|
||||
gfile fp2;
|
||||
_file = AddPath(_cnamespath, ".add");
|
||||
fp2.fopen(_file, "rb");
|
||||
fp2.Fopen(_file, "rb");
|
||||
if (fp2.isopen())
|
||||
{
|
||||
if (not quiet)
|
||||
STD_PRINTNL("* Reading " << _file);
|
||||
|
||||
word _recsize = 0;
|
||||
fp.fread(&_recsize, 2);
|
||||
fp.Fread(&_recsize, 2);
|
||||
|
||||
int confno = 0;
|
||||
PcbConf* _cnames = (PcbConf*)throw_calloc(1, _recsize);
|
||||
PcbAddConf* _cnamesadd = (PcbAddConf*)throw_calloc(1, sizeof(PcbAddConf));
|
||||
while(fp.fread(_cnames, _recsize) == 1) {
|
||||
fp2.fread(_cnamesadd, sizeof(PcbAddConf));
|
||||
if(*_cnames->name and *_cnames->msgfile) {
|
||||
while (fp.Fread(_cnames, _recsize) == 1)
|
||||
{
|
||||
fp2.Fread(_cnamesadd, sizeof(PcbAddConf));
|
||||
if (*_cnames->name and *_cnames->msgfile)
|
||||
{
|
||||
aa.reset();
|
||||
aa.basetype = "PCBOARD";
|
||||
switch(_cnamesadd->conftype) {
|
||||
@@ -351,10 +357,10 @@ void gareafile::ReadPCBoard(char* tag) {
|
||||
throw_free(_cnamesadd);
|
||||
throw_free(_cnames);
|
||||
|
||||
fp2.fclose();
|
||||
fp2.Fclose();
|
||||
}
|
||||
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -80,16 +80,16 @@ void PcbInit(const char* path, int userno) {
|
||||
*_cnamespath = NUL;
|
||||
|
||||
// Open PCBOARD.DAT
|
||||
gfile fp;
|
||||
const char* _file = AddPath(_path, "PCBOARD.DAT");
|
||||
fp.fopen(_file, "rt", WideSharemode);
|
||||
if(fp.isopen()) {
|
||||
|
||||
gfile fp(_file, "rt", WideSharemode);
|
||||
if (fp.isopen())
|
||||
{
|
||||
// Get some paths/filenames
|
||||
int _line = 0;
|
||||
char _buf[256];
|
||||
fp.setvbuf(NULL, _IOFBF, 8192);
|
||||
while(fp.fgets(_buf, sizeof(_buf))) {
|
||||
fp.SetvBuf(NULL, _IOFBF, 8192);
|
||||
while (fp.Fgets(_buf, sizeof(_buf)))
|
||||
{
|
||||
_line++;
|
||||
if(_line == 28)
|
||||
strxcpy(pcbwide->usersidxpath, strbtrim(_buf), sizeof(Path));
|
||||
@@ -102,32 +102,34 @@ void PcbInit(const char* path, int userno) {
|
||||
else if(_line == 208)
|
||||
pcbwide->foreign = atoi(_buf);
|
||||
}
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
|
||||
// Open CNAMES.@@@
|
||||
_file = AddPath(_cnamespath, ".@@@");
|
||||
fp.fopen(_file, "rb", WideSharemode);
|
||||
fp.Fopen(_file, "rb", WideSharemode);
|
||||
|
||||
// Get board numbers for lastread indexing in the userfiles
|
||||
word _recsize = 0;
|
||||
fp.setvbuf(NULL, _IOFBF, 8192);
|
||||
fp.fread(&_recsize, 2);
|
||||
if(_recsize) {
|
||||
fp.SetvBuf(NULL, _IOFBF, 8192);
|
||||
fp.Fread(&_recsize, 2);
|
||||
if (_recsize)
|
||||
{
|
||||
PcbConf* _cnames = (PcbConf*)throw_calloc(1, _recsize);
|
||||
int _rec = 0;
|
||||
pcbwide->numareas = (int)((fp.filelength()-2)/_recsize);
|
||||
pcbwide->numareas = (int)((fp.FileLength()-2)/_recsize);
|
||||
pcbwide->confbytelen = (pcbwide->numareas/8) + ((pcbwide->numareas%8) != 0 ? 1 : 0);
|
||||
if(pcbwide->confbytelen < 5)
|
||||
pcbwide->confbytelen = 5;
|
||||
pcbwide->extconflen = pcbwide->confbytelen - 5;
|
||||
pcbwide->lastread = (int32_t*)throw_calloc(pcbwide->numareas, sizeof(int32_t));
|
||||
while(fp.fread(_cnames, _recsize) == 1) {
|
||||
while (fp.Fread(_cnames, _recsize) == 1)
|
||||
{
|
||||
PcbAdjustArea((uint)_rec, _cnames->msgfile);
|
||||
_rec++;
|
||||
}
|
||||
throw_free(_cnames);
|
||||
}
|
||||
fp.fclose();
|
||||
fp.Fclose();
|
||||
|
||||
const char* _username = WideUsername[0];
|
||||
pcbwide->user->fh = ::sopen(AddPath(_path, pcbwide->users), O_RDONLY|O_BINARY, WideSharemode, S_STDRD);
|
||||
|
Reference in New Issue
Block a user