1 
2 //  ------------------------------------------------------------------
3 //  GoldED+
4 //  Copyright (C) 1990-1999 Odinn Sorensen
5 //  Copyright (C) 1999-2000 Alexander S. Aganichev
6 //  ------------------------------------------------------------------
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License as
9 //  published by the Free Software Foundation; either version 2 of the
10 //  License, or (at your option) any later version.
11 //
12 //  This program 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 //  General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //  MA 02111-1307 USA
21 //  ------------------------------------------------------------------
22 //  $Id: gescan.cpp,v 1.9 2006/04/26 17:06:23 ssianky Exp $
23 //  ------------------------------------------------------------------
24 //  Area scanning functions.
25 //  ------------------------------------------------------------------
26 
27 #include <golded.h>
28 #include <gmoprot.h>
29 
30 
31 //  ------------------------------------------------------------------
32 
33 extern bool in_arealist;
34 extern GPickArealist* PickArealist;
35 
36 //  ------------------------------------------------------------------
37 
UpdateAreadata()38 void Area::UpdateAreadata() {
39 
40   if(isscanned) {
41 
42     uint _unread = Msgn.Count() - lastread();
43     if(not isvalidchg) {
44       unread = _unread;
45       isvalidchg = true;
46     }
47     isunreadchg = (unread != _unread);
48     unread = _unread;
49     word oldmask = AL.mask;
50     AL.mask = 0;
51     set_marked(make_bool(_unread));
52     AL.mask = oldmask;
53   }
54 }
55 
56 
57 //  ------------------------------------------------------------------
58 
ScanArea()59 void Area::ScanArea() {
60 
61   if(cmdlinedebughg)
62     LOG.printf("- ScanArea: %s", echoid());
63 
64   area->Msgn = &Msgn;
65   area->PMrk = &PMrk;
66 
67   area->scan_area();
68 
69   isscanned = true;
70 
71   UpdateAreadata();
72 }
73 
74 
75 //  ------------------------------------------------------------------
76 
ScanAreaPM()77 void Area::ScanAreaPM() {
78 
79   if(cmdlinedebughg)
80     LOG.printf("- ScanAreaPM: %s", echoid());
81 
82   area->Msgn = &Msgn;
83   area->PMrk = &PMrk;
84 
85   area->scan_area_pm();
86 
87   isscanned = true;
88   ispmscanned = true;
89 
90   UpdateAreadata();
91 }
92 
93 
94 //  ------------------------------------------------------------------
95 
SetActiveAreaNo(int __areano)96 int AreaList::SetActiveAreaNo(int __areano) {
97 
98   AA = idx[__areano];
99   CurrArea = AA->areaid();
100   CFG->originno = AA->originno();
101 
102   return CurrArea;  // Return the areaid
103 }
104 
105 
106 //  ------------------------------------------------------------------
107 
AreaScan(int mode,uint currno,int pmscan,int & pmails,int & pmareas,const char * file)108 int AreaList::AreaScan(int mode, uint currno, int pmscan, int& pmails, int& pmareas, const char* file) {
109 
110   // Never scan if there's active area
111   if(AA and AA->isopen())
112     return false;
113 
114   gstrarray bag;
115   int groupid = -1;
116 
117   // Load scan list into a string bag
118   if (mode == SCAN_LIST)
119   {
120     Path tmp;
121     strcpy(tmp, file ? file : ListScan.File());
122     char* listfile;
123     char* option=tmp;
124     getkeyval(&listfile, &option);
125     gfile fp(AddPath(CFG->goldpath, listfile), "rt");
126 
127     if (fp.isopen())
128     {
129       char buf[512];
130       while (fp.Fgets(buf, sizeof(buf)))
131       {
132         strbtrim(buf);
133         char* val = strtok(buf, ", \t");
134         while(val) {
135           bag.push_back(val);
136           val = strtok(NULL, ", \t");
137         }
138       }
139       fp.Fclose();
140       if (((*option == '-') or (*option == '/')) and strieql(option+1, "delete"))
141         remove(listfile);
142     }
143   }
144   else if(mode == SCAN_GROUP) {
145     groupid = idx[currno]->groupid();
146   }
147 
148   int currid = AreaNoToId(currno);
149 
150   int scanned = false;
151 
152   // For optimized overlay usage, sort arealist by msgbase type, path, board and echoid
153   if(*CFG->areascansort) {
154     Sort(CFG->areascansort);
155     scanned = true;
156   }
157 
158   currno = AreaIdToNo(currid);
159 
160   #ifndef GMB_NOPCB
161   if(find(AL.basetypes, "PCBOARD"))    PcbWideOpen();
162   #endif
163   #ifndef GMB_NOGOLD
164   if(find(AL.basetypes, "GOLDBASE"))   GoldWideOpen();
165   #endif
166   #ifndef GMB_NOHUDS
167   if(find(AL.basetypes, "HUDSON"))     HudsWideOpen();
168   #endif
169 
170   for(uint n=0; n<idx.size(); n++) {
171 
172     // Check if ESC was pressed to skip the scan
173     gkey xch = kbxhit();
174     if(xch) {
175       xch = kbxget();
176       if(xch == Key_Esc)
177         break;
178       else
179         kbput(xch);
180     }
181 
182     SetActiveAreaNo(n);
183 
184     if(not AA->isseparator()) {
185 
186       int scanit     = false;
187 
188       int dopmscan     = pmscan and AA->pmscan();
189       int dopmscanexcl = pmscan and AA->pmscanexcl();
190       int dopmscanincl = pmscan and AA->pmscanincl();
191 
192       int doscan     = AA->scan()     or dopmscan;
193       //if Area is excluded from pm-scanning, scan it instead
194       int doscanexcl = AA->scanexcl();
195       int doscanincl = AA->scanincl() or dopmscanincl or (dopmscanexcl and doscan);
196 
197       if(mode != SCAN_STARTUP and pmscan)
198         dopmscan = true;
199 
200       switch(mode) {
201         case SCAN_STARTUP:
202           if(doscan and (not doscanexcl or doscanincl))
203             scanit = true;
204           break;
205         case SCAN_ALL:
206           if(not doscanexcl or doscanincl)
207             scanit = true;
208           break;
209         case SCAN_CURRENT:
210           scanit = n == currno;
211           break;
212         case SCAN_MARKED:
213           if(AA->ismarked())
214             scanit = true;
215           break;
216         case SCAN_MATCHING:
217           if(striinc(area_maybe, AA->echoid()))
218             scanit = true;
219           break;
220         case SCAN_UNSCANNED:
221           scanit = not (pmscan ? AA->ispmscanned : AA->isscanned);
222           break;
223         case SCAN_GROUP:
224           scanit = AA->groupid() == groupid;
225           break;
226         case SCAN_NETMAIL:
227           scanit = AA->isnet();
228           break;
229         case SCAN_LIST:
230           {
231             gstrarray::iterator i;
232             for(i = bag.begin(); i != bag.end(); i++)
233               if(strwild(AA->echoid(), i->c_str())) {
234                 scanit = true;
235                 break;
236               }
237           }
238           break;
239       }
240 
241       if(scanit) {
242         if(not AA->isopen()) {
243           AA->Msgn.Reset();
244           AA->Mark.ResetAll();
245           AA->PMrk.ResetAll();
246         }
247         scanned = YES;
248         if(not blanked)
249           update_statuslinef("%s %s", "", 1+LNG->ScanningArea, AA->echoid());
250         if(dopmscan and (not dopmscanexcl or dopmscanincl)) {
251           AA->ScanAreaPM();
252           uint count = AA->PMrk.Count();
253           if(count) {
254             pmails += count;
255             pmareas++;
256           }
257           if(CFG->personalmail & PM_LISTONLY)
258             AA->PMrk.Reset();
259         }
260         else {
261           AA->ScanArea();
262         }
263       }
264     }
265   }
266 
267   #ifndef GMB_NOHUDS
268   if(find(AL.basetypes, "HUDSON"))     HudsWideClose();
269   #endif
270   #ifndef GMB_NOGOLD
271   if(find(AL.basetypes, "GOLDBASE"))   GoldWideClose();
272   #endif
273   #ifndef GMB_NOPCB
274   if(find(AL.basetypes, "PCBOARD"))    PcbWideClose();
275   #endif
276 
277   return scanned;
278 }
279 
280 
281 //  ------------------------------------------------------------------
282 
CheckSemaphores()283 void CheckSemaphores() {
284 
285   Path file;
286   int scanned = 0;
287   int pmareas = 0;
288   int pmails = 0;
289 
290   if(fexist(AddPath(CFG->areapath, CFG->semaphore.qwkimport))) {
291     ImportQWK();
292     remove(AddPath(CFG->areapath, CFG->semaphore.qwkimport));
293     scanned++;
294   }
295 
296   if(fexist(AddPath(CFG->areapath, CFG->semaphore.qwkexport))) {
297     ExportQWK();
298     remove(AddPath(CFG->areapath, CFG->semaphore.qwkexport));
299   }
300 
301   if(fexist(AddPath(CFG->areapath, CFG->semaphore.soupimport))) {
302     ImportSOUP();
303     remove(AddPath(CFG->areapath, CFG->semaphore.soupimport));
304     scanned++;
305   }
306 
307   if(fexist(AddPath(CFG->areapath, CFG->semaphore.soupexport))) {
308     ExportSOUP();
309     remove(AddPath(CFG->areapath, CFG->semaphore.soupexport));
310   }
311 
312   if(fexist(AddPath(CFG->areapath, CFG->semaphore.exitnow)) and in_arealist) {
313     gkbd.quitall = YES;
314     kbput(KK_AreaAbort);
315     remove(AddPath(CFG->areapath, CFG->semaphore.exitnow));
316   }
317   else {
318 
319     if(fexist(AddPath(CFG->areapath, CFG->semaphore.scanall))) {
320       scanned += AL.AreaScan(SCAN_ALL, 0, false, pmails, pmareas);
321       remove(AddPath(CFG->areapath, CFG->semaphore.scanall));
322     }
323 
324     if(fexist(AddPath(CFG->areapath, CFG->semaphore.scanthis))) {
325       sprintf(file, "%s -delete", AddPath(CFG->areapath, CFG->semaphore.scanthis));
326       scanned += AL.AreaScan(SCAN_LIST, 0, false, pmails, pmareas, file);
327     }
328 
329     if(fexist(AddPath(CFG->areapath, CFG->semaphore.scannetmail))) {
330       scanned += AL.AreaScan(SCAN_NETMAIL, 0, false, pmails, pmareas);
331       remove(AddPath(CFG->areapath, CFG->semaphore.scannetmail));
332     }
333 
334     if(fexist(AddPath(CFG->areapath, CFG->semaphore.pmscanall))) {
335       scanned += AL.AreaScan(SCAN_ALL, 0, true, pmails, pmareas);
336       remove(AddPath(CFG->areapath, CFG->semaphore.pmscanall));
337     }
338 
339     if(fexist(AddPath(CFG->areapath, CFG->semaphore.pmscanthis))) {
340       sprintf(file, "%s -delete", AddPath(CFG->areapath, CFG->semaphore.pmscanthis));
341       scanned += AL.AreaScan(SCAN_LIST, 0, true, pmails, pmareas, file);
342     }
343 
344     if(fexist(AddPath(CFG->areapath, CFG->semaphore.pmscannetmail))) {
345       scanned += AL.AreaScan(SCAN_NETMAIL, 0, true, pmails, pmareas);
346       remove(AddPath(CFG->areapath, CFG->semaphore.pmscannetmail));
347     }
348   }
349 
350   if(scanned) {
351     AL.Sort();
352     if(in_arealist and not blanked) {
353       PickArealist->update();        // update arealist-display
354       PickArealist->do_delayed();    // update statusline
355     }
356     AL.WriteGoldLast();
357   }
358 }
359 
360 
361 //  ------------------------------------------------------------------
362 
363