1 // This may look like C code, but it is really -*- C++ -*-
2
3 // ------------------------------------------------------------------
4 // The Goldware Library
5 // Copyright (C) 1999-2002 Alexander S. Aganichev
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: gxspace.cpp,v 1.10 2006/01/20 11:55:12 stas_degteff Exp $
23 // ------------------------------------------------------------------
24 // Read areas from SpaceToss 1.10 and higher
25 // ------------------------------------------------------------------
26
27 #include <cstdlib>
28 #include <gcrcall.h>
29 #include <gstrall.h>
30 #include <gutlmisc.h>
31 #if defined(__GOLD_GUI__)
32 #include <gvidall.h>
33 #include <gvidgui.h>
34 #endif
35 #undef GCFG_NOSPCT
36 #include <gedacfg.h>
37
38 static Path SpaceTossAreafile;
39
40
41 // ------------------------------------------------------------------
42
ParseSpaceArea(const char * type_path,AreaCfg & aa)43 void gareafile::ParseSpaceArea(const char *type_path, AreaCfg &aa) {
44
45 if(strnieql(type_path, "msg", 3))
46 aa.basetype = fidomsgtype;
47 else if(strnieql(type_path, "hud", 3)) {
48 aa.basetype = "HUDSON";
49 aa.board = atoi(type_path+3);
50 return;
51 }
52 else if(strnieql(type_path, "jam", 3))
53 aa.basetype = "JAM";
54 else if(strnieql(type_path, "sqh", 3))
55 aa.basetype = "SQUISH";
56 else if(strnieql(type_path, "smb", 3))
57 aa.basetype = "SMB";
58 else {
59 aa.basetype = "";
60 return;
61 }
62 aa.setpath(type_path+3);
63 }
64
65
66 // ------------------------------------------------------------------
67
ReadSpaceAr(const char * file)68 void gareafile::ReadSpaceAr(const char* file) {
69
70 const word CRC_BEGINAREA = 0x78EE;
71 const word CRC_NAME = 0x3B63;
72 const word CRC_DESC = 0x8A2A;
73 const word CRC_PATH = 0x0212;
74 const word CRC_FLAGS = 0xF81A;
75 const word CRC_GROUP = 0x1C9B;
76 const word CRC_TYPE = 0x59E2;
77 const word CRC_USEAKA = 0x2F7D;
78 const word CRC_ENDAREA = 0x3E9F;
79
80 FILE* fp = fsopen(file, "rb", sharemode);
81 if (fp)
82 {
83 setvbuf(fp, NULL, _IOFBF, 8192);
84
85 if (not quiet)
86 STD_PRINTNL("* Reading " << file);
87
88 char buf[4000];
89 AreaCfg aa;
90
91 aa.reset();
92
93 while(fgets(buf, 4000, fp) != NULL) {
94
95 char* key;
96 char* val = buf;
97 switch(getkeyvalcrc(&key, &val)) {
98 case CRC_BEGINAREA:
99 aa.type = GMB_ECHO;
100 aa.attr = attribsecho;
101 aa.aka = primary_aka;
102 break;
103 case CRC_NAME:
104 aa.setechoid(val);
105 break;
106 case CRC_DESC:
107 aa.setdesc(val);
108 break;
109 case CRC_PATH:
110 ParseSpaceArea(val, aa);
111 break;
112 case CRC_USEAKA:
113 aa.aka.set(val);
114 break;
115 case CRC_FLAGS:
116 if(strpbrk(val,"Ll")) {
117 aa.type = GMB_LOCAL;
118 aa.attr = attribslocal;
119 }
120 break;
121 case CRC_TYPE: {
122 const word CRC_ECHO = 0xC2D1;
123 const word CRC_NET = 0xEC5E;
124 const word CRC_LOCAL = 0x4CD5;
125 const word CRC_DUPE = 0x9B1D;
126 const word CRC_BAD = 0x29C2;
127
128 switch(getkeyvalcrc(&key, &val)) {
129 case CRC_ECHO:
130 aa.type = GMB_ECHO;
131 aa.attr = attribsecho;
132 break;
133 case CRC_NET:
134 aa.type = GMB_NET;
135 aa.attr = attribsnet;
136 break;
137 case CRC_LOCAL:
138 case CRC_DUPE:
139 case CRC_BAD:
140 aa.type = GMB_LOCAL;
141 aa.attr = attribslocal;
142 break;
143 }
144 break;
145 }
146 case CRC_GROUP:
147 if(isdigit(*val))
148 aa.groupid = 0x8000+atoi(val);
149 else if(g_isalpha(*val))
150 aa.groupid = g_toupper(*val);
151 break;
152 case CRC_ENDAREA:
153 if(aa.basetype[0] != '\0')
154 AddNewArea(aa);
155 aa.reset();
156 break;
157 }
158 }
159
160 fclose(fp);
161 }
162 }
163
164
165 // ------------------------------------------------------------------
166
ReadSpaceNtm(const char * file)167 void gareafile::ReadSpaceNtm(const char* file) {
168
169 const word CRC_BEGINNETMAIL = 0x4DF0;
170 const word CRC_NAME = 0x3B63;
171 const word CRC_ADDRESS = 0xFDD6;
172 const word CRC_PATH = 0x0212;
173 const word CRC_AUTOEXPORT = 0xE0E1;
174 const word CRC_ENDNETMAIL = 0xD995;
175
176 FILE* fp = fsopen(file, "rb", sharemode);
177 if (fp)
178 {
179 setvbuf(fp, NULL, _IOFBF, 8192);
180
181 if (not quiet)
182 STD_PRINTNL("* Reading " << file);
183
184 char buf[4000];
185 AreaCfg aa;
186 bool exportarea = false;
187
188 aa.reset();
189
190 while(fgets(buf, 4000, fp) != NULL) {
191
192 char* key;
193 char* val = buf;
194 switch(getkeyvalcrc(&key, &val)) {
195 case CRC_BEGINNETMAIL:
196 aa.setautoid("NETMAIL");
197 aa.type = GMB_NET;
198 aa.attr = attribsnet;
199 aa.aka = primary_aka;
200 exportarea = false;
201 break;
202 case CRC_ADDRESS:
203 aa.aka.set(val);
204 case CRC_NAME: {
205 char echodesc[256];
206 strxmerge(echodesc, 256, "Netmail for ", val, NULL);
207 aa.setdesc(echodesc);
208 break;
209 }
210 case CRC_PATH:
211 ParseSpaceArea(val, aa);
212 break;
213 case CRC_AUTOEXPORT:
214 exportarea = make_bool(GetYesno(val));
215 break;
216 case CRC_ENDNETMAIL:
217 if(exportarea and (aa.basetype[0] != '\0'))
218 AddNewArea(aa);
219 aa.reset();
220 break;
221 }
222 }
223
224 fclose(fp);
225 }
226 }
227
228
229 // ------------------------------------------------------------------
230
ReadSpaceCtl(const char * file)231 void gareafile::ReadSpaceCtl(const char* file) {
232
233 const word CRC_ADDRESS = 0xFDD6;
234 const word CRC_AKA = 0x13A4;
235 const word CRC_NETMAIL = 0xE42E;
236 const word CRC_BADMAIL = 0xE697;
237 const word CRC_DUPEMAIL = 0xB38B;
238 const word CRC_HUDSONPATH = 0x52A7;
239 const word CRC_EXPORTLISTS = 0xB709;
240 const word CRC_AREAFILE = 0xB487;
241
242 FILE* fp = fsopen(file, "rb", sharemode);
243 if (fp)
244 {
245 setvbuf(fp, NULL, _IOFBF, 8192);
246
247 if (not quiet)
248 STD_PRINTNL("* Reading " << file);
249
250 char buf[4000];
251 AreaCfg aa;
252
253 aa.reset();
254
255 while(fgets(buf, 4000, fp) != NULL) {
256
257 aa.type = GMB_NONE;
258
259 char* key;
260 char* val = buf;
261 switch(getkeyvalcrc(&key, &val)) {
262 case CRC_ADDRESS:
263 case CRC_AKA:
264 CfgAddress(buf);
265 break;
266 case CRC_NETMAIL:
267 aa.setautoid("NETMAIL");
268 aa.setdesc("SpaceToss Netmail");
269 aa.type = GMB_NET;
270 aa.attr = attribsnet;
271 break;
272 case CRC_BADMAIL:
273 aa.setautoid("BADMAIL");
274 aa.setdesc("SpaceToss Badmail");
275 aa.type = GMB_LOCAL;
276 aa.attr = attribslocal;
277 break;
278 case CRC_DUPEMAIL:
279 aa.setautoid("DUPEMAIL");
280 aa.setdesc("SpaceToss Dupemail");
281 aa.type = GMB_LOCAL;
282 aa.attr = attribslocal;
283 break;
284 case CRC_HUDSONPATH:
285 CfgHudsonpath(val);
286 break;
287 case CRC_EXPORTLISTS:
288 CfgJampath(val);
289 break;
290 case CRC_AREAFILE:
291 strxcpy(SpaceTossAreafile, val, sizeof(SpaceTossAreafile));
292 break;
293 }
294
295 if(aa.type != GMB_NONE) {
296
297 aa.aka = primary_aka;
298
299 // Get type/path
300 ParseSpaceArea(val, aa);
301
302 if(aa.basetype[0] != '\0') {
303 AddNewArea(aa);
304 }
305 }
306
307 aa.reset();
308 }
309
310 fclose(fp);
311 }
312 }
313
314
315 // ------------------------------------------------------------------
316 // Read areas from SpaceToss (echomail processor)
317
ReadSpaceToss(char * tag)318 void gareafile::ReadSpaceToss(char* tag) {
319
320 Path file, path;
321 char options[80];
322
323 strcpy(options, tag);
324 char* ptr = strtok(tag, " \t");
325 while(ptr) {
326 if(*ptr != '-') {
327 strcpy(file, ptr);
328 }
329 ptr = strtok(NULL, " \t");
330 }
331
332 extractdirname(path, file);
333
334 CfgSquishuserpath(path);
335
336 strcpy(SpaceTossAreafile, "spctoss.ar");
337
338 MakePathname(file, path, "spctoss.ctl");
339 ReadSpaceCtl(file);
340 MakePathname(file, path, "spctoss.ntm");
341 ReadSpaceNtm(file);
342 MakePathname(file, path, SpaceTossAreafile);
343 ReadSpaceAr(file);
344 }
345
346
347 // ------------------------------------------------------------------
348