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: gxpcb.cpp,v 1.9 2006/05/13 16:13:48 ssianky Exp $
23 // ------------------------------------------------------------------
24 // Read areas from PCBoard.
25 // ------------------------------------------------------------------
26
27 #include <cstdlib>
28 #include <gmemdbg.h>
29 #include <gstrall.h>
30 #if defined(__GOLD_GUI__)
31 #include <gvidall.h>
32 #include <gvidgui.h>
33 #endif
34 #undef GCFG_NOPCB
35 #include <gedacfg.h>
36 #include <gs_pcb.h>
37
38
39 // ------------------------------------------------------------------
40
ReadPCBoard(char * tag)41 void gareafile::ReadPCBoard(char* tag) {
42
43 AreaCfg aa;
44 Path _path;
45 char _options[80];
46 Path _usersidxpath;
47 Path _userspath;
48 Path _cnamespath;
49 Path _fidopath;
50
51 PcbFidoArea* areap = NULL;
52 PcbFidoDirectories* dirp = NULL;
53 PcbFidoAddress* akap = NULL;
54 int akanumrecs = 0;
55 int numareas = 0;
56
57 PcbDirectories* dir3 = NULL;
58 PcbAreasDat* area3 = NULL;
59 PcbAkasDat* aka3 = NULL;
60 PcbOriginsDat* origin3 = NULL;
61
62 word fido_version = 0;
63
64 *_fidopath = NUL;
65 strcpy(_path, pcboardpath);
66 strcpy(_options, tag);
67
68 char* ptr = strtok(tag, " \t");
69 while(ptr) {
70 if(*ptr != '-') {
71 AddBackslash(strcpy(_path, ptr));
72 break;
73 }
74 ptr = strtok(NULL, " \t");
75 }
76 if(*_path == NUL) {
77 ptr = getenv("PCBOARD");
78 if(ptr)
79 AddBackslash(strcpy(_path, ptr));
80 }
81 if(*_path == NUL)
82 strcpy(_path, areapath);
83
84 CfgPcboardpath(_path);
85
86 const char* _file = AddPath(_path, "pcboard.dat");
87 gfile fp(_file, "rt");
88 if (fp.isopen())
89 {
90 if (not quiet)
91 STD_PRINTNL("* Reading " << _file);
92
93 int _line = 0;
94
95 char _buf[256];
96 while (fp.Fgets(_buf, sizeof(_buf)))
97 {
98 _line++;
99 switch(_line) {
100 case 28: // Location of User INDEX Files
101 strxcpy(_usersidxpath, strbtrim(_buf), GMAXPATH);
102 break;
103 case 29: // Name/Location of USERS File
104 strxcpy(_userspath, strbtrim(_buf), GMAXPATH);
105 break;
106 case 31: // Name/Location of CNAMES File
107 strxcpy(_cnamespath, strbtrim(_buf), GMAXPATH);
108 break;
109 case 324: // Path to FidoNet config files
110 strxcpy(_fidopath, strbtrim(_buf), GMAXPATH);
111 break;
112 }
113 }
114
115 fp.Fclose();
116
117 if (*_fidopath)
118 {
119 const char* _file = AddPath(_fidopath, "pcbfido.cfg");
120 fp.Fopen(_file, "rb");
121 if (fp.isopen())
122 {
123 if (not quiet)
124 STD_PRINTNL("* Reading " << _file);
125
126 // Get configuration file version
127 fp.Fread(&fido_version, 2);
128
129 if(fido_version == 2) {
130
131 word numrecs = 0;
132
133 // Get areas
134 fp.Fread(&numrecs, 2);
135 numareas = numrecs;
136 areap = (PcbFidoArea*)throw_calloc(1+numrecs, sizeof(PcbFidoArea));
137 fp.Fread(areap, sizeof(PcbFidoArea), numrecs);
138
139 // Skip archivers
140 fp.Fseek(sizeof(PcbFidoArchivers), SEEK_CUR);
141
142 // Get directories
143 dirp = (PcbFidoDirectories*)throw_calloc(1, sizeof(PcbFidoDirectories));
144 fp.Fread(dirp, sizeof(PcbFidoDirectories));
145
146 // Skip EMSI profile
147 fp.Fseek(sizeof(PcbFidoEmsiData), SEEK_CUR);
148
149 // Get akas
150 fp.Fread(&numrecs, 2);
151 akanumrecs = numrecs;
152 akap = (PcbFidoAddress*)throw_calloc(1+numrecs, sizeof(PcbFidoAddress));
153 fp.Fread(akap, sizeof(PcbFidoAddress), numrecs);
154 int akano = 0;
155 while(akano < numrecs) {
156 CfgAddress(akap[akano].nodestr);
157 akano++;
158 }
159 }
160 else if(fido_version == 3) {
161
162 dir3 = (PcbDirectories*)throw_calloc(1, sizeof(PcbDirectories));
163 fp.Fread(dir3, sizeof(PcbDirectories));
164 fp.Fclose();
165
166 _file = AddPath(_fidopath, "areas.dat");
167 fp.Fopen(_file, "rb");
168 if (fp.isopen())
169 {
170 if (not quiet)
171 STD_PRINTNL("* Reading " << _file);
172
173 word cfgver = 0;
174 fp.Fread(&cfgver, 2);
175 if (cfgver == 3)
176 {
177 word numrecs = (word)(fp.FileLength() / sizeof(PcbAreasDat));
178 area3 = (PcbAreasDat*)throw_calloc(1+numrecs, sizeof(PcbAreasDat));
179 fp.Fread(area3, sizeof(PcbAreasDat), numrecs);
180 numareas = numrecs;
181 }
182 fp.Fclose();
183 }
184
185 _file = AddPath(_fidopath, "akas.dat");
186 fp.Fopen(_file, "rb");
187 if (fp.isopen())
188 {
189 if (not quiet)
190 STD_PRINTNL("* Reading " << _file);
191
192 word cfgver = 0;
193 fp.Fread(&cfgver, 2);
194 if (cfgver == 3)
195 {
196 word numrecs = (word)(fp.FileLength() / sizeof(PcbAkasDat));
197 akanumrecs = numrecs;
198 aka3 = (PcbAkasDat*)throw_calloc(1+numrecs, sizeof(PcbAkasDat));
199 fp.Fread(aka3, sizeof(PcbAkasDat), numrecs);
200 int akano = 0;
201 while(akano < numrecs) {
202 char abuf[40];
203 CfgAddress(aka3[akano].addr.make_string(abuf));
204 akano++;
205 }
206 }
207 fp.Fclose();
208 }
209
210 _file = AddPath(_fidopath, "origins.dat");
211 fp.Fopen(_file, "rb");
212 if (fp.isopen())
213 {
214 if (not quiet)
215 STD_PRINTNL("* Reading " << _file);
216
217 word cfgver = 0;
218 fp.Fread(&cfgver, 2);
219 if (cfgver == 3)
220 {
221 word numrecs = (word)(fp.FileLength() / sizeof(PcbOriginsDat));
222 origin3 = (PcbOriginsDat*)throw_calloc(1+numrecs, sizeof(PcbOriginsDat));
223 fp.Fread(origin3, sizeof(PcbOriginsDat), numrecs);
224 }
225 fp.Fclose();
226 }
227 }
228
229 fp.Fclose();
230 }
231
232 Path netmailpath;
233 *netmailpath = NUL;
234 if(dirp)
235 strcpy(netmailpath, dirp->outgoing_msg);
236 else if(dir3)
237 strcpy(netmailpath, dir3->outgoing_msg);
238 if(*netmailpath) {
239 aa.reset();
240 aa.basetype = fidomsgtype;
241 aa.type = GMB_NET;
242 aa.attr = attribsnet;
243 if(fido_version == 2)
244 aa.aka.reset(akap[0].nodestr);
245 else if(fido_version == 3) {
246 for(int n=0; n<akanumrecs; n++) {
247 if(aka3[n].primary_address) {
248 aa.aka = aka3[n].addr;
249 break;
250 }
251 }
252 }
253 aa.setpath(netmailpath);
254 aa.setdesc("PCBoard Netmail (*.MSG)");
255 aa.setautoid("NETMAIL.MSG");
256 AddNewArea(aa);
257 }
258 }
259
260 _file = AddPath(_cnamespath, ".@@@");
261 fp.Fopen(_file, "rb");
262 if (fp.isopen())
263 {
264 if (not quiet)
265 STD_PRINTNL("* Reading " << _file);
266
267 gfile fp2;
268 _file = AddPath(_cnamespath, ".add");
269 fp2.Fopen(_file, "rb");
270 if (fp2.isopen())
271 {
272 if (not quiet)
273 STD_PRINTNL("* Reading " << _file);
274
275 word _recsize = 0;
276 fp.Fread(&_recsize, 2);
277
278 int confno = 0;
279 PcbConf* _cnames = (PcbConf*)throw_calloc(1, _recsize);
280 PcbAddConf* _cnamesadd = (PcbAddConf*)throw_calloc(1, sizeof(PcbAddConf));
281 while (fp.Fread(_cnames, _recsize) == 1)
282 {
283 fp2.Fread(_cnamesadd, sizeof(PcbAddConf));
284 if (*_cnames->name and *_cnames->msgfile)
285 {
286 aa.reset();
287 aa.basetype = "PCBOARD";
288 switch(_cnamesadd->conftype) {
289 case PCBCONFTYPE_EMAIL:
290 case PCBCONFTYPE_USENETMOD:
291 aa.type = GMB_EMAIL;
292 aa.attr = attribsemail;
293 break;
294 case PCBCONFTYPE_USENETJUNK:
295 case PCBCONFTYPE_USENETPUB:
296 aa.type = GMB_NEWSGROUP;
297 aa.attr = attribsnews;
298 break;
299 case PCBCONFTYPE_FIDOCONF:
300 aa.type = GMB_ECHO;
301 aa.attr = attribsecho;
302 break;
303 case PCBCONFTYPE_NORMAL:
304 default:
305 if(_cnames->echomail) {
306 aa.type = GMB_ECHO;
307 aa.attr = attribsecho;
308 }
309 else {
310 aa.type = GMB_LOCAL;
311 aa.attr = attribslocal;
312 }
313 }
314 if(_cnamesadd->readonly)
315 aa.attr.r_o1();
316 if(_cnames->privmsgs)
317 aa.attr.pvt1();
318 aa.board = confno;
319 aa.setpath(_cnames->msgfile);
320 char namebuf[61];
321 strcpy(stpcpy(namebuf, _cnames->name), _cnamesadd->name2);
322 aa.setdesc(namebuf);
323 strchg(namebuf, ' ', '_');
324 aa.setechoid(namebuf);
325 int areano = 0;
326 while(areano < numareas) {
327 if(fido_version == 2) {
328 if(areap[areano].pcbconference == confno) {
329 strchg(areap[areano].areaname, ' ', '_');
330 aa.setechoid(areap[areano].areaname);
331 aa.aka.set(areap[areano].defaultaka);
332 aa.setorigin(areap[areano].origin);
333 aa.setpath(areap[areano].messages);
334 break;
335 }
336 }
337 else if(fido_version == 3) {
338 if(area3[areano].confno == confno) {
339 aa.setechoid(area3[areano].areatag);
340 aa.aka = aka3[area3[areano].aka].addr;
341 aa.setorigin(origin3[area3[areano].origin].origin);
342 break;
343 }
344 }
345 areano++;
346 }
347 if(strieql(aa.echoid, "NETMAIL")) {
348 aa.type = GMB_NET;
349 aa.attr = attribsnet;
350 }
351 AddNewArea(aa);
352 }
353 confno++;
354 }
355
356 throw_free(_cnamesadd);
357 throw_free(_cnames);
358
359 fp2.Fclose();
360 }
361
362 fp.Fclose();
363 }
364 }
365
366 throw_free(origin3);
367 throw_free(area3);
368 throw_free(dir3);
369 throw_free(aka3);
370 throw_free(areap);
371 throw_free(dirp);
372 throw_free(akap);
373 }
374
375
376 // ------------------------------------------------------------------
377