1 //  This may look like C code, but it is really -*- C++ -*-
2 
3 //  ------------------------------------------------------------------
4 //  The Goldware Library
5 //  Copyright (C) 1990-1999 Odinn Sorensen
6 //  ------------------------------------------------------------------
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Library General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Library General Public
18 //  License along with this program; if not, write to the Free
19 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //  MA 02111-1307, USA
21 //  ------------------------------------------------------------------
22 //  $Id: gmoezyc2.cpp,v 1.5 2006/05/14 11:45:05 ssianky Exp $
23 //  ------------------------------------------------------------------
24 //  Ezycom msgbase handling
25 //  ------------------------------------------------------------------
26 
27 #include <gdbgtrk.h>
28 #include <gmoezyc.h>
29 
30 
31 //  ------------------------------------------------------------------
32 
raw_scan(int __keep_index)33 void EzycomArea::raw_scan(int __keep_index) {
34 
35   GFTRK("EzycomRawScan");
36 
37   int _wasopen = isopen;
38   if(not _wasopen) {
39     if(ispacked()) {
40       const char* newpath = Unpack(path());
41       if(newpath == NULL)
42         packed(false);
43       set_real_path(newpath ? newpath : path());
44     }
45     isopen++;
46     data_open();
47     test_raw_open(__LINE__);
48   }
49 
50   Msgn->Resize((uint)(filelength(data->fhhdr) / sizeof(EzycHdr)));
51 
52   for(uint _count=0; _count<Msgn->Count(); _count++)
53     Msgn->at(_count) = _count + 1;
54 
55   int _fh = ::sopen(AddPath(wide->userbasepath, "LASTCOMB.BBS"), O_RDONLY|O_BINARY, SH_DENYNO, S_STDRD);
56   if(_fh != -1) {
57     word _lastread;
58     lseekset(_fh, wide->userno * (wide->maxmess / 16) * sizeof(EzycLast) +
59       (((board() - 1) / 16) * sizeof(EzycLast) + sizeof(word)) +
60       (board()-1) % 16 * sizeof(word)
61     );
62     read(_fh, &_lastread, sizeof(word));
63     if(_lastread)
64       _lastread--;
65 
66     uint _active = Msgn->Count();
67     uint _count = 1;
68     uint32_t* _msgnoptr = Msgn->tag;
69     uint _lastread_reln = 0;
70     uint _firstmsgno = 0;
71     uint _lastmsgno = 0;
72     uint _lastreadfound = 0;
73 
74     if(_active) {
75 
76       _firstmsgno = Msgn->at(0);
77       _lastmsgno = Msgn->at(_active-1);
78 
79       while(1) {
80 
81         // Set lastread pointer
82         if((*_msgnoptr >= _lastread) and (_lastread_reln == 0)) {
83           _lastreadfound = *_msgnoptr;
84           _lastread_reln = _count - (*_msgnoptr != _lastread ? 1 : 0);
85           break;
86         }
87         if((++_count) > _active)
88           break;
89         _msgnoptr++;
90       }
91     }
92 
93     // If the exact lastread was not found
94     if(_active and (_lastreadfound != _lastread)) {
95 
96       // Higher than highest or lower than lowest?
97       if(_lastread > _lastmsgno)
98         _lastread_reln = _active;
99       else if(_lastread < _firstmsgno)
100         _lastread_reln = 0;
101     }
102 
103     // Update area data
104     lastread = _lastread_reln;
105     lastreadentry = _lastreadfound;
106 
107     ::close(_fh);
108   }
109 
110   if(not __keep_index)
111     Msgn->Reset();
112 
113   if(not _wasopen) {
114     raw_close();
115     data_close();
116     if(ispacked()) {
117       CleanUnpacked(real_path());
118     }
119     isopen--;
120   }
121 
122   GFTRK(0);
123 }
124 
125 
126 //  ------------------------------------------------------------------
127 
scan()128 void EzycomArea::scan() {
129 
130   GFTRK("EzycomScan");
131 
132   raw_scan(true);
133 
134   GFTRK(0);
135 }
136 
137 
138 //  ------------------------------------------------------------------
139 
scan_area()140 void EzycomArea::scan_area() {
141 
142   GFTRK("EzycomScanArea");
143 
144   raw_scan(false);
145 
146   GFTRK(0);
147 }
148 
149 
150 //  ------------------------------------------------------------------
151 
scan_area_pm()152 void EzycomArea::scan_area_pm() {
153 
154   GFTRK("EzycomScanArea*M");
155 
156   scan_area();
157 
158   GFTRK(0);
159 }
160 
161 
162 //  ------------------------------------------------------------------
163