2000-02-25 10:15:17 +00:00
|
|
|
// This may look like C code, but it is really -*- C++ -*-
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// The Goldware Library
|
|
|
|
// Copyright (C) 1990-1999 Odinn Sorensen
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this program; if not, write to the Free
|
|
|
|
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
// MA 02111-1307, USA
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// $Id$
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// WildCat! 4.x messagebase engine.
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <gdbgerr.h>
|
|
|
|
#include <gmemdbg.h>
|
|
|
|
#include <gdbgtrk.h>
|
|
|
|
#include <gmowcat.h>
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
WCatWide* wcatwide = NULL;
|
|
|
|
WCatData* wcatdata = NULL;
|
|
|
|
int wcatdatano = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::data_open() {
|
|
|
|
|
|
|
|
wide = wcatwide;
|
|
|
|
data = wcatdata + (wcatdatano++);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::data_close() {
|
|
|
|
|
|
|
|
wcatdatano--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::raw_close() {
|
|
|
|
|
|
|
|
GFTRK("WCatRawClose");
|
|
|
|
|
|
|
|
if(data->fhix != -1) ::close(data->fhix); data->fhix = -1;
|
|
|
|
if(data->fhdat != -1) ::close(data->fhdat); data->fhdat = -1;
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
int WCatArea::test_open(const char* __file) {
|
|
|
|
|
|
|
|
GFTRK("WCatTestOpen");
|
|
|
|
|
|
|
|
int _fh;
|
|
|
|
long _tries = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
_fh = ::sopen(__file, O_RDWR|O_BINARY|O_CREAT, WideSharemode, S_STDRW);
|
|
|
|
if(_fh == -1) {
|
|
|
|
|
|
|
|
// Tell the world
|
2002-10-26 16:28:01 +00:00
|
|
|
if((errno != EACCES) or (PopupLocked(++_tries, false, __file) == false)) {
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
// User requested to exit
|
|
|
|
WideLog->ErrOpen();
|
|
|
|
raw_close();
|
|
|
|
WideLog->printf("! A WildCat! msgbase file could not be opened.");
|
|
|
|
WideLog->printf(": %s.", __file);
|
|
|
|
WideLog->ErrOSInfo();
|
|
|
|
OpenErrorExit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(_fh == -1);
|
|
|
|
|
|
|
|
// Remove the popup window
|
|
|
|
if(_tries)
|
|
|
|
PopupLocked(0, 0, NULL);
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
return _fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::raw_open() {
|
|
|
|
|
|
|
|
GFTRK("WCatRawOpen");
|
|
|
|
|
2002-05-12 13:07:37 +00:00
|
|
|
data->fhix = test_open(AddPath(real_path(), ".ix"));
|
|
|
|
data->fhdat = test_open(AddPath(real_path(), ".dat"));
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatExit() {
|
|
|
|
|
|
|
|
throw_xrelease(wcatwide);
|
|
|
|
throw_xrelease(wcatdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatInit(int userno) {
|
|
|
|
|
2000-08-23 19:24:19 +00:00
|
|
|
wcatdata = (WCatData*)throw_calloc(3, sizeof(WCatData));
|
2000-02-25 10:15:17 +00:00
|
|
|
wcatwide = (WCatWide*)throw_calloc(1, sizeof(WCatWide));
|
|
|
|
|
|
|
|
wcatwide->userno = userno;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::open() {
|
|
|
|
|
|
|
|
GFTRK("WCatOpen");
|
|
|
|
|
|
|
|
isopen++;
|
|
|
|
if(isopen > 2) {
|
|
|
|
WideLog->ErrTest();
|
|
|
|
WideLog->printf("! Trying to open a WildCat! msgbase more than twice.");
|
|
|
|
WideLog->printf(": %s, %s.", echoid(), path());
|
|
|
|
WideLog->printf("+ Info: This indicates a serious bug.");
|
|
|
|
WideLog->printf("+ Advice: Report to the Author immediately.");
|
|
|
|
TestErrorExit();
|
|
|
|
}
|
|
|
|
if(isopen == 1) {
|
2001-12-17 15:44:55 +00:00
|
|
|
if(ispacked()) {
|
|
|
|
isopen--;
|
|
|
|
const char* newpath = Unpack(path());
|
2001-12-26 13:00:18 +00:00
|
|
|
if(newpath == NULL)
|
|
|
|
packed(false);
|
2001-12-17 15:44:55 +00:00
|
|
|
set_real_path(newpath ? newpath : path());
|
|
|
|
isopen++;
|
|
|
|
}
|
2000-02-25 10:15:17 +00:00
|
|
|
data_open();
|
|
|
|
raw_open();
|
|
|
|
refresh();
|
|
|
|
scan();
|
|
|
|
}
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::save_lastread() {
|
|
|
|
|
|
|
|
GFTRK("WCatSaveLastread");
|
|
|
|
|
2002-05-12 13:07:37 +00:00
|
|
|
int _fh = ::sopen(AddPath(real_path(), ".lrd"), O_RDWR|O_CREAT|O_BINARY, WideSharemode, S_STDRW);
|
2000-02-25 10:15:17 +00:00
|
|
|
if(_fh != -1) {
|
|
|
|
word _lastread = (word)Msgn->CvtReln(lastread);
|
|
|
|
lseekset(_fh, wcatwide->userno, sizeof(word));
|
|
|
|
write(_fh, &_lastread, sizeof(word));
|
|
|
|
::close(_fh);
|
|
|
|
}
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::close() {
|
|
|
|
|
|
|
|
GFTRK("WCatClose");
|
|
|
|
|
|
|
|
if(isopen) {
|
|
|
|
if(isopen == 1) {
|
|
|
|
save_lastread();
|
|
|
|
raw_close();
|
|
|
|
Msgn->Reset();
|
|
|
|
throw_release(data->idx);
|
|
|
|
data_close();
|
2001-12-17 15:44:55 +00:00
|
|
|
if(ispacked()) {
|
|
|
|
CleanUnpacked(real_path());
|
|
|
|
}
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
isopen--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
WideLog->ErrTest();
|
|
|
|
WideLog->printf("! Trying to close an already closed WildCat! msgbase.");
|
|
|
|
WideLog->printf(": %s, %s.", echoid(), path());
|
|
|
|
WideLog->printf("+ Info: This indicates a potentially serious bug.");
|
|
|
|
WideLog->printf("+ Advice: Report to the Author immediately.");
|
|
|
|
TestErrorExit();
|
|
|
|
}
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::suspend() {
|
|
|
|
|
|
|
|
GFTRK("WCatSuspend");
|
|
|
|
|
|
|
|
save_lastread();
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
|
|
|
|
void WCatArea::resume() {
|
|
|
|
|
|
|
|
GFTRK("WCatResume");
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-14 11:45:05 +00:00
|
|
|
GFTRK(0);
|
2000-02-25 10:15:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|