-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hippo.c
418 lines (347 loc) · 10.7 KB
/
Hippo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/****************************************************************
*
* NAME
* Hippo.c
*
* DESCRIPTION
* Hippo routines for abbs
*
* AUTHOR
* Geir Inge Høsteng
*
* $Id$
*
* MODIFICATION HISTORY
* $Log$
*
****************************************************************/
#include <exec/types.h>
#include <exec/memory.h>
#include <bbs.h>
#include <node.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/filehandler.h>
#include <utility/date.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#define a4a5 register __a4 struct ramblocks *nodebase,register __a5 struct Mainmemory *mainmeory
#define usea4a5 nodebase,mainmeory
__asm int hippopackmessages(a4a5);
__asm int hippounpackmessages (a4a5);
__asm int dohippograbmsg (register __d0 int nr, register __d1 int conf,register __d2 BPTR msgfil,a4a5,
register __d3 int *msgnr,register __d4 int *touser,register __d5 int *numgrabbed);
__asm int hippounpackmsg (register __d0 BPTR msgfil,a4a5);
extern far ULONG exebase;
extern far struct DosLibrary *DOSBase;
extern far struct Library *UtilityBase;
extern far char logentermsgtext[];
extern far char logreplymsgtext[];
extern far UBYTE fraISOtilIBN[128];
extern far UBYTE fraIBNtilISO[128];
extern far int msprintf(char *, const char *, ...);
extern __asm far writetexto (register __a0 char *text,a4a5);
extern __asm far writeerroro (register __a0 char *text,a4a5);
extern __asm far UWORD loadmsg (register __a0 char *msgtext,
register __a1 struct MessageRecord *msgheader,
register __d0 ULONG msgnr, register __d1 UWORD confnr,a4a5);
extern __asm far UWORD savemsg (register __a0 char *msgtext,
register __a1 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm far UWORD loadmsgheader (register __a0 struct MessageRecord *msgheader,
register __d0 ULONG msgnr, register __d1 UWORD confnr,a4a5);
extern __asm far UWORD loadmsgtext (register __a0 UBYTE *msgbyf,
register __a1 struct MessageRecord *msgheader,register __d0 UWORD confnr,a4a5);
extern __asm far UWORD savemsgheader (register __a0 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm far UWORD savemsgheader (register __a0 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm int kanskrive (register __a0 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm int getfromname (register __a0 struct MessageRecord *msgheader,
register __a1 UBYTE *msgtext,a4a5);
extern __asm int gettoname (register __a0 struct MessageRecord *msgheader,
register __a1 UBYTE *msgtext,a4a5);
extern __asm int skipnetnames (register __a0 UBYTE *msgtext,register __d0 int msgsize,a4a5);
extern __asm far void removefromqueue (register __d0 ULONG msgnr,a4a5);
extern __asm far ULONG gettopqueue (a4a5);
extern __asm far void unjoin (a4a5);
extern __asm short getnextconfnr (register __d0 short conf,a4a5);
__asm int hippounpackmessages (a4a5)
{
return (0);
}
/* returns -1 for fatal errors, 1 for endoffile, 2 for non-fatal error (msg skipped)
and 0 for all ok (1 message parsed)
*/
__asm int hippounpackmsg (register __d0 BPTR msgfil,a4a5)
{
return (0);
}
__asm int hippopackmessages(a4a5)
{
BPTR msgfil;
char tmpstring[40];
int conf;
int message,msgpacked,touser,tousertot;
int dobreak,highmsg;
int ret = 1;
int msgnr = 1,tmp;
int startconf;
char string[80];
struct ConfigRecord *configdata = &mainmeory->config;
putreg (REG_A6,exebase);
writetexto ("**************************** Making HIPPO Packet *****************************\n",usea4a5);
writetexto ("Conference High # Total For You",usea4a5);
while (1) {
msprintf (tmpstring,"%ls/%s.HD",nodebase->Nodemem.TmpPath,
configdata->BaseName);
if (!(msgfil = Open(tmpstring,MODE_NEWFILE))) {
putreg (REG_A6,exebase);
writeerroro ("Error opening msg file",usea4a5);
break;
}
putreg (REG_A6,exebase);
startconf = nodebase->confnr/2;
dobreak = 0;
msgpacked = 0;
touser = 0;
while ((message = gettopqueue(usea4a5)) && !dobreak) {
if (dohippograbmsg (message,startconf,msgfil,usea4a5,&msgnr,&touser,&msgpacked)) {
dobreak = 1;
break;
}
removefromqueue (message,usea4a5);
}
if (dobreak)
break;
unjoin(usea4a5);
if (msgpacked) {
msprintf (string,"%-33ls %-9ld %-9ld %ld",
configdata->firstconference[startconf].n_ConfName,
configdata->firstconference[startconf].n_ConfDefaultMsg,
msgpacked,touser);
writetexto (string,usea4a5);
}
tousertot = touser;
conf = startconf;
do {
conf = getnextconfnr(conf*2,usea4a5)/2;
if (conf >= configdata->Maxconferences)
conf = 0;
tmp = 0;
if (!*(configdata->firstconference[conf].n_ConfName))
continue;
if (!(nodebase->CU.firstuserconf[conf].uc_Access & ACCF_Read))
continue;
msgpacked = 0;
touser = 0;
highmsg = configdata->firstconference[conf].n_ConfDefaultMsg;
message = nodebase->CU.firstuserconf[conf].uc_LastRead+1;
/* Sjekker om vi skal bruke max scan */
if (message == 1) {
if ((highmsg - message) > configdata->firstconference[conf].n_ConfMaxScan)
message = highmsg - configdata->firstconference[conf].n_ConfMaxScan;
}
for (; message <= highmsg; message++) {
if (!message)
continue;
tmp = 1;
if (dohippograbmsg (message,conf,msgfil,usea4a5,&msgnr,&touser,&msgpacked)) {
dobreak = 1;
break;
}
}
/* Mark read
*/
if (!dobreak && tmp) {
nodebase->CU.firstuserconf[conf].uc_LastRead = highmsg;
msprintf (string,"%-33ls %-9ld %-9ld %ld",
configdata->firstconference[conf].n_ConfName,
configdata->firstconference[startconf].n_ConfDefaultMsg,
msgpacked,touser);
writetexto (string,usea4a5);
tousertot += touser;
}
} while (!dobreak && (conf != startconf));
if (dobreak)
break;
msprintf (string,"\nNumber of messages %-9ld",msgnr-1);
writetexto (string,usea4a5);
msprintf (string,"\nMessages to you %-9ld",tousertot);
writetexto (string,usea4a5);
writetexto ("\nPacking...",usea4a5);
ret = 0;
break;
}
if (msgfil)
Close (msgfil);
if (ret)
DeleteFile (tmpstring);
putreg (REG_A6,exebase);
return (ret ? -1L : (msgnr-1));
}
__asm int dohippograbmsg (register __d0 int nr, register __d1 int conf,register __d2 BPTR msgfil,a4a5,
register __d3 int *msgnr,register __d4 int *touser,register __d5 int *numgrabbed)
{
struct ClockData dt;
ULONG secs;
char *ptr,*ptr2;
char string[256];
int msgsize;
int ret = 1;
struct MessageRecord *msgheader;
struct ConfigRecord *configdata = &mainmeory->config;
msgheader = &nodebase->tmpmsgheader;
putreg (REG_A6,exebase);
if (loadmsg (nodebase->tmpmsgmem,msgheader,nr,conf*2,usea4a5)) {
msprintf (string,"Error loading message (%ls:%ld)",
configdata->firstconference[conf].n_ConfName,nr);
writeerroro (string,usea4a5);
return (1);
}
if (kanskrive (msgheader,conf*2,usea4a5))
return (0);
while (TRUE) {
if (FPuts (msgfil,"Command: Message\n")) {
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
msprintf (string,"Area: %ls\n",configdata->firstconference[conf].n_ConfName);
if (FPuts (msgfil,string)) {
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
if ((msgheader->MsgStatus & MSTATF_MsgRead) ||
(msgheader->Security & SECF_SecReceiver)) {
strcpy (string,"Status:");
if (msgheader->MsgStatus & MSTATF_MsgRead)
strcat (string," Private");
if (msgheader->Security & SECF_SecReceiver)
strcat (string," Read");
strcat (string,"\n");
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
}
msprintf (string,"Number: %ld\n",msgheader->Number);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
if (msgheader->RefTo)
{
msprintf (string,"Reply: %ld\n",msgheader->RefTo);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
}
if (msgheader->RefBy)
{
msprintf (string,"Next: %ld\n",msgheader->RefBy);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
}
if (msgheader->RefNxt)
{
msprintf (string,"NReply: %ld\n",msgheader->RefNxt);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
}
secs = msgheader->MsgTimeStamp.ds_Days*24*60*60;
secs += msgheader->MsgTimeStamp.ds_Minute*60;
secs += msgheader->MsgTimeStamp.ds_Tick/TICKS_PER_SECOND;
Amiga2Date (secs,&dt);
msprintf (string,"Subject: %ls\nDate: %ld%02ld%02ld%02ld%02ld%02ld\n",
msgheader->Subject,dt.year,dt.month,dt.mday,dt.hour,
dt.min,dt.sec);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
putreg (REG_A6,exebase);
getfromname (msgheader,nodebase->tmpmsgmem,usea4a5); ptr = (UBYTE *) getreg (REG_A0);
msprintf (string,"From: %ls\n",ptr);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
putreg (REG_A6,exebase);
gettoname (msgheader,nodebase->tmpmsgmem,usea4a5); ptr = (UBYTE *) getreg (REG_A0);
msprintf (string,"To: %ls\n",ptr);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
msprintf (string,"Lines: %ld\n",
msgheader->NrLines > 0 ? msgheader->NrLines : -msgheader->NrLines);
if (FPuts (msgfil,string))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
*msgnr += 1;
putreg (REG_A6,exebase);
msgsize = skipnetnames (nodebase->tmpmsgmem,msgheader->NrBytes,usea4a5);
ptr2 = (UBYTE *) getreg (REG_A0);
if (1 != FWrite (msgfil,ptr2,msgsize,1)) {
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
if (FPuts (msgfil,"\n"))
{
putreg (REG_A6,exebase); writeerroro ("File error",usea4a5); break;
}
ret = 0;
break;
}
putreg (REG_A6,exebase);
if (!ret)
*numgrabbed += 1;
return (ret);
}
static __asm unsigned char convertchartoiso (register __d0 unsigned char c,a4a5)
{
if (c > 127) {
c = fraIBNtilISO[c-128];
if (!c)
c = ' ';
}
return (c);
}
static __asm unsigned char convertcharfromiso (register __d0 unsigned char c,a4a5)
{
if (c > 127) {
c = fraISOtilIBN[c-128];
if (!c)
c = ' ';
}
return (c);
}
/*
{
int n;
/ * ingen oversetting hvis det er ISO
* /
if (NodeBase->Charset) {
if ((NodeBase->Charset < 3) || (NodeBase->Charset == 12)) {
if (NodeBase->Charset == 12)
n = 3;
else
n = NodeBase->Charset;
if (c > 127) {
c = convertISOtoxxx[n][c-128];
if (!c)
c = ' ';
}
} else {
}
}
return (c);
*/