1 /*****************************************************************************/
2 /* */
3 /* (C) Copyright 1992-1997 Alberto Pasquale */
4 /* Portions (C) Copyright 1999 Per Lundberg */
5 /* */
6 /* A L L R I G H T S R E S E R V E D */
7 /* */
8 /*****************************************************************************/
9 /* */
10 /* How to contact the author: Alberto Pasquale of 2:332/504@fidonet */
11 /* Viale Verdi 106 */
12 /* 41100 Modena */
13 /* Italy */
14 /* */
15 /*****************************************************************************/
16
17 #include "apgenlib.hpp"
18 #include "bbsgenlb.hpp"
19 #include "cfgdata.hpp"
20 #include "inpblk.hpp"
21 #include "daydir.hpp"
22 #include "misc.hpp"
23 #include "edit.hpp"
24 #include "filesbbs.hpp"
25 #include "export.hpp"
26 #include <stdlib.h>
27 #include <string.h>
28
ChkNew(void)29 BOOL InpncBlk::ChkNew (void) // must this nodelist trigger recompilation ?
30 {
31 if (s->NodeTime == 0) // this nodelist must be recompiled (new cfg)
32 return TRUE;
33
34 if (ChkNewList (s->NodeDay))
35 return TRUE;
36
37 if (l->NodeDiff)
38 if (ChkNewDiff (s->NodeDay))
39 return TRUE;
40
41 if (l->ArcList)
42 if (ChkNewArcList (s->NodeDay))
43 return TRUE;
44
45 if (l->ArcDiff)
46 if (ChkNewArcDiff (s->NodeDay))
47 return TRUE;
48
49 return FALSE;
50 }
51
ChkNewList(int LatestList)52 BOOL InpncBlk::ChkNewList (int LatestList)
53 {
54 if (l->VarNodeList) { // List is .nnn
55 DAYDIR DayDir (NODELIST, this, LatestList);
56 return DayDir.NewAvail ();
57 } else { // List is fixed
58 time_t newtime = DosFileTime (l->NodeList);
59 if (newtime != 0)
60 if (newtime != s->NodeTime) // this nodelist is new
61 return TRUE;
62 return FALSE;
63 }
64 }
65
66
ChkNewDiff(int LatestList)67 BOOL InpncBlk::ChkNewDiff (int LatestList)
68 {
69 DAYDIR DayDir (NODEDIFF, this, LatestList, s->FutDiff);
70 return DayDir.NewAvail ();
71 }
72
73
ChkNewArcList(int LatestList)74 BOOL InpncBlk::ChkNewArcList (int LatestList)
75 {
76 DAYDIR DayDir (ARCLIST, this, l->VarNodeList ? LatestList : -2);
77 return DayDir.NewAvail ();
78 }
79
80
ChkNewArcDiff(int LatestList)81 BOOL InpncBlk::ChkNewArcDiff (int LatestList)
82 {
83 DAYDIR DayDir (ARCDIFF, this, LatestList, s->FutDiff);
84 return DayDir.NewAvail ();
85 }
86
87
Prepare(BOOL NeededOnly,BOOL * SomeNew)88 BOOL InpncBlk::Prepare (BOOL NeededOnly, BOOL *SomeNew)
89 {
90 if (v->AlreadyPrepared || (NeededOnly && !a->NeededBeforeKill))
91 return a->NeededBeforeKill;
92
93 if (l->VarNodeList) { // var name nodelist
94 int LatestList = GetLatestList (); // -1 if none available
95 if (l->ArcList) {
96 DoArcList (LatestList); // Unarc newer list if available
97 LatestList = GetLatestList ();
98 }
99 if (LatestList != -1) { // nodelist available
100 if (l->ArcDiff)
101 DoArcDiff (LatestList);
102 if (l->NodeDiff)
103 LatestList = ApplyNewDiffs (LatestList);
104 SetDay3 (l->NodeList, LatestList); // resolve NodeList
105 if (short (LatestList) != s->NodeDay) {
106 s->NodeDay = (short)LatestList;
107 if (SomeNew)
108 *SomeNew = TRUE;
109 }
110 }
111 } else { // fixed name nodelist
112 if (l->ArcList)
113 DoArcList (fexist (l->NodeList) ? -2 : -1); // UnArc new list if available
114 }
115
116 time_t newtime = DosFileTime (l->NodeList);
117 if (newtime == 0) {
118 vprintlog ("Cannot find \"%s\"\n", l->NodeList);
119 myexit (NO_NODELIST);
120 }
121
122 if (s->NodeTime != newtime) { // new nodelist: Arc it !
123 if (l->ArcList) {
124 if (l->ArcListKeep > 0)
125 ExecArcList ();
126 DAYDIR DayDir (ARCLIST, this);
127 DayDir.KillOld ();
128 }
129 s->NodeTime = newtime;
130 if (SomeNew)
131 *SomeNew = TRUE;
132 }
133
134 v->AlreadyPrepared = TRUE;
135
136 return a->NeededBeforeKill;
137 }
138
139
DoArcList(int LatestList)140 void InpncBlk::DoArcList (int LatestList)
141 {
142 DAYDIR DayDir (ARCLIST, this, LatestList);
143
144 if (DayDir.NewAvail ()) {
145 char *ArcFile = DayDir.LatestName ();
146 ExecUnarcList (ArcFile);
147 s->ArcTime = arcfiletime (ArcFile);
148 }
149
150 DayDir.KillOld ();
151 }
152
153
DoArcDiff(int LatestList)154 void InpncBlk::DoArcDiff (int LatestList)
155 {
156 DAYDIR DayDir (ARCDIFF, this, LatestList, s->FutDiff);
157
158 if (l->NodeDiff) {
159 char *arcdiffname = DayDir.FindNewName (TRUE);
160 while (arcdiffname) {
161 ExecUnarcDiff (arcdiffname);
162 arcdiffname = DayDir.FindNewName ();
163 }
164 }
165
166 DayDir.KillOld ();
167 }
168
169
ApplyNewDiffs(int LatestList)170 int InpncBlk::ApplyNewDiffs (int LatestList)
171 {
172 DAYDIR DayDir (NODEDIFF, this, LatestList, s->FutDiff);
173
174 DayDir.KillOld ();
175
176 int difres,
177 NewList = LatestList;
178
179 int day;
180
181 if (l->ArcDiff) {
182 day = DayDir.FindNewDay (TRUE); // arc diffs if ArcDiffMethod used
183 while (day != -1) {
184 ExecArcDiff (day);
185 day = DayDir.FindNewDay ();
186 }
187 }
188
189 day = DayDir.FindNewDay (TRUE); // apply all diffs
190 while (day != -1) {
191 difres = ApplyDiff (NewList, day);
192 if (difres == -1) // ApplyDiff failed
193 break;
194 NewList = difres;
195 day = DayDir.FindNewDay ();
196 }
197
198 if (NewList != LatestList) // If some Diff applied, do not check CRC again
199 v->crcchk = FALSE;
200
201 return NewList;
202 }
203
204
ApplyDiff(int ListDay,int DiffDay)205 int InpncBlk::ApplyDiff (int ListDay, int DiffDay) // -1 on error
206 { // DiffDay on success
207 int ret;
208
209 EDIT* edit = new EDIT (a->BeforeEdit, a->AfterEdit);
210 switch (edit->Apply (l->NodeList, ListDay, l->NodeDiff, DiffDay)) {
211 case 0: // success
212 s->FutDiff = 0;
213 ret = DiffDay;
214 break;
215 case 1: // day mismatch
216 s->FutDiff = (short)DiffDay;
217 ret = -1;
218 break;
219 default:
220 case -1: // error
221 s->FutDiff = 0;
222 ret = -1;
223 break;
224 }
225 delete edit;
226
227 return ret;
228 }
229
230
GetLatestList(void)231 int InpncBlk::GetLatestList (void) // 0 -> 366, -1 if none found
232 {
233 DAYDIR DayDir (NODELIST, this);
234 DayDir.KillOld ();
235 return DayDir.LatestDay ();
236 }
237
238
ExecUnarcList(char * ArcFile)239 void InpncBlk::ExecUnarcList (char *ArcFile)
240 {
241 ExecUnarc (ArcFile, l->NodeList, a->BeforeUnArcList, a->AfterUnArcList);
242 }
243
244
ExecUnarcDiff(char * ArcFile)245 void InpncBlk::ExecUnarcDiff (char *ArcFile)
246 {
247 ExecUnarc (ArcFile, l->NodeDiff, a->BeforeUnArcDiff, a->AfterUnArcDiff);
248 }
249
250
ExecArcList()251 void InpncBlk::ExecArcList ()
252 {
253 time_t ftime = ExecArc (l->ArcList, l->NodeList, s->NodeDay,
254 a->ArcMethHead, a->BeforeArcList, a->AfterArcList,
255 l->ArcListDesc);
256
257 s->ArcTime = __max (s->ArcTime, ftime); // make sure ArcTime is latest. Usually ftime is less than ArcTime
258 }
259
260
ExecArcDiff(int day)261 void InpncBlk::ExecArcDiff (int day)
262 {
263 ExecArc (l->ArcDiff, l->NodeDiff, day,
264 a->ArcDiffMethHead, a->BeforeArcDiff, a->AfterArcDiff,
265 l->ArcDiffDesc);
266 }
267
268