This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-goldedplus/goldlib/gmb3/gmoxbbs2.cpp

243 lines
5.6 KiB
C++
Raw Normal View History

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$
// ------------------------------------------------------------------
// AdeptXBBS messagebase engine.
// ------------------------------------------------------------------
#include <gmemdbg.h>
#include <gdbgtrk.h>
#include <gmoxbbs.h>
// ------------------------------------------------------------------
void XbbsArea::refresh() {
GFTRK("XbbsRefresh");
long indexnum = filelength(data->fhindex) / (long)sizeof(XbbsIdx);
// Are there any msgs?
if(indexnum) {
// Read the index file
data->idx = (XbbsIdx*)throw_realloc(data->idx, (uint)(indexnum*sizeof(XbbsIdx)));
lseekset(data->fhindex, 0);
read(data->fhindex, data->idx, (uint)(indexnum*sizeof(XbbsIdx)));
}
data->idx_size = (uint)indexnum;
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsWideOpen() {
GFTRK("XbbsWideOpen");
// Open the personal mail index
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsWideClose() {
GFTRK("XbbsWideClose");
// Close the personal mail index
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::raw_scan(int __keep_index, int __scanpm) {
GFTRK("XbbsRawScan");
XbbsData* _was_data = data;
if(_was_data == NULL) {
data = xbbsdata;
wide = xbbswide;
}
2002-05-12 13:07:37 +00:00
int _wasopen = isopen;
if(not _wasopen) {
if(ispacked()) {
const char* newpath = Unpack(path());
if(newpath == NULL)
packed(false);
set_real_path(newpath ? newpath : path());
}
isopen++;
}
2000-02-25 10:15:17 +00:00
// Load the lastread
ulong _lastread = 0;
2002-05-12 13:07:37 +00:00
int _fh = ::sopen(AddPath(real_path(), ".lmr"), O_RDONLY|O_BINARY, WideSharemode, S_STDRD);
2000-02-25 10:15:17 +00:00
if(_fh != -1) {
lseekset(_fh, wide->userno+1, sizeof(ulong));
read(_fh, &_lastread, sizeof(ulong));
::close(_fh);
}
// Open AdeptXBBS files for scanning unless they are already open
2002-05-12 13:07:37 +00:00
if(not _wasopen) {
2000-02-25 10:15:17 +00:00
data->idx = NULL;
data->idx_size = 0;
// Open index file
2002-05-12 13:07:37 +00:00
data->fhindex = ::sopen(AddPath(real_path(), ".Index"), O_RDONLY|O_BINARY, WideSharemode, S_STDRD);
2000-02-25 10:15:17 +00:00
if(data->fhindex != -1) {
// Allocate index buffer and read from file
refresh();
// Close index file
::close(data->fhindex);
data->fhindex = -1;
}
2002-05-12 13:07:37 +00:00
if(ispacked()) {
CleanUnpacked(real_path());
}
isopen--;
2000-02-25 10:15:17 +00:00
}
register uint _active = 0;
register uint _lastread_reln = 0;
register ulong _lastreadfound = 0;
if(data->idx_size) {
// (Re)allocate message index
if(__keep_index)
Msgn->Resize(data->idx_size);
// Variables for the loop
register ulong _msgno;
register ulong* _msgndxptr = Msgn->tag;
register dword _totalmsgs = data->idx_size;
register ulong _firstmsgno = _totalmsgs ? 1 : 0;
register ulong _lastmsgno = 0;
// Fill message index
while(_active < _totalmsgs) {
_active++;
_msgno = _active;
2001-04-15 19:24:44 +00:00
if(not _firstmsgno)
2000-02-25 10:15:17 +00:00
_firstmsgno = _msgno;
if(__keep_index)
*_msgndxptr++ = _msgno;
// Get the lastread
2001-04-15 19:24:44 +00:00
if((_msgno >= _lastread) and (_lastread_reln == 0)) {
2000-02-25 10:15:17 +00:00
_lastreadfound = _msgno;
_lastread_reln = (uint)(_active - (_msgno != _lastread ? 1 : 0));
}
// Store last message number
_lastmsgno = _msgno;
}
// If the exact lastread was not found
2001-04-15 19:24:44 +00:00
if(_active and (_lastreadfound != _lastread)) {
2000-02-25 10:15:17 +00:00
// Higher than highest or lower than lowest?
if(_lastread > _lastmsgno)
_lastread_reln = _active;
else if(_lastread < _firstmsgno)
_lastread_reln = 0;
}
}
// Update area data
Msgn->SetCount(_active);
lastread = _lastread_reln;
lastreadentry = _lastreadfound;
// Scan for personal mail
if(__scanpm) {
// Not implemented yet
}
// Free index buffer if just counting
2001-04-15 19:24:44 +00:00
if(not __keep_index or __scanpm)
2000-02-25 10:15:17 +00:00
throw_release(data->idx);
if(_was_data == NULL) {
data = NULL;
wide = NULL;
}
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::scan() {
GFTRK("XbbsScan");
raw_scan(true);
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::scan_area() {
GFTRK("XbbsScanArea");
raw_scan(false);
GFTRK(NULL);
}
// ------------------------------------------------------------------
void XbbsArea::scan_area_pm() {
GFTRK("XbbsScanArea*M");
raw_scan(true, true);
Msgn->Reset();
GFTRK(NULL);
}
// ------------------------------------------------------------------