A
download v7debug.cpp
Language: C++
Copyright: Copyright 1987-96, Bit Bucket Software Co.
LOC: 384
Project Info
BinkleyTerm XE(btxe)
Server: SourceForge
Type: cvs
...e\b\btxe\btxe\btnt\sources\
   Addr.cpp
   Addr.h
   aglcrc.cpp
   aglcrc.h
   asyn_lnx.cpp
   asyn_os2.cpp
   asyn_w32.cpp
   async.h
   asyos2v1.h
   b_banner.cpp
   b_bbs.cpp
   b_faxrcv.cpp
   b_flofil.cpp
   b_frproc.cpp
   b_help.cpp
   b_initva.cpp
   b_logs.cpp
   b_passwo.cpp
   b_proto.cpp
   b_rspfil.cpp
   b_sbinit.cpp
   b_script.cpp
   b_search.cpp
   b_sessio.cpp
   b_spawn.cpp
   b_term.cpp
   b_termov.cpp
   b_today.cpp
   b_wazoo.cpp
   b_whack.cpp
   b_wzsend.cpp
   banner.cpp
   banner.h
   BasicString.h
   bbs_ctra.cpp
   bbs_data.cpp
   bbs_incl.h
   bbs_io.cpp
   bink.h
   bink_asm.cpp
   binkdlg.cpp
   binkpipe.h
   box.h
   brec.cpp
   bsend.cpp
   bt.cpp
   btconfig.cpp
   btutil.cpp
   buffer.h
   cache.cpp
   cache.h
   callback.cpp
   callerid.cpp
   callwin.cpp
   callwin.h
   capi.cpp
   cfosline.cpp
   chat.cpp
   com.h
   com_dos.h
   com_lnx.h
   com_os2.h
   com_w32.h
   common.cpp
   cpuload.cpp
   css.cpp
   css.h
   data.cpp
   debug.cpp
   debug.h
   defines.h
   dosfuncs.cpp
   emsi.cpp
   emxmxcom.cpp
   evtparse.cpp
   evtsetup.cpp
   exceptio.cpp
   exceptio.h
   Exceptions.cpp
   Exceptions.h
   externs.h
   faxproto.h
   fcfgread.cpp
   fidomail.h
   file_all.cpp
   file_dos.cpp
   file_io.h
   file_lnx.cpp
   file_os2.cpp
   file_w32.cpp
   foffsets.h
   fossil.cpp
   freepoll.cpp
   ftsc.cpp
   gethcomm.h
   heap.cpp
   history.cpp
   history.h
   hydra.cpp
   hydra.h
   includes.cpp
   includes.h
   janus.cpp
   janus.h
   keybd.h
   keyfncs.h
   keymap.cpp
   langload.cpp
   language.h
   lngmagic.h
   m7rec.cpp
   m7send.cpp
   mailer.cpp
   mailovly.cpp
   mailroot.cpp
   maxcomm.h
   maxmcp.cpp
   maxmcp.h
   maxprm.cpp
   mdm_proc.cpp
   misc.cpp
   msgs.h
   Node.cpp
   Node.h
   NodeList.cpp
   NodeList.h
   nodeproc.cpp
   os2_pm.cpp
   outbound.cpp
   pipe.cpp
   pktmsgs.cpp
   pktmsgs.h
   protcomm.cpp
   prototyp.h
   recvbark.cpp
   recvsync.cpp
   sbuf.cpp
   sbuf.h
   sched.cpp
   sched.h
   script2.cpp
   SelfTest.cpp
   SelfTest.h
   sendbark.cpp
   sendsync.cpp
   squish.cpp
   squish.h
   srif.cpp
   statetbl.cpp
   stats.cpp
   stdafx.cpp
   stdafx.h
   timer.cpp
   timer.h
   times.cpp
   types.h
   v7debug.cpp
   version.cpp
   version7.cpp
   version7.h
   vfos_dos.cpp
   vfos_lnx.cpp
   vfos_os2.cpp
   vfos_qnx.cpp
   vfos_w32.cpp
   vfossil.h
   video.h
   vt100.cpp
   vt100.h
   xfer.h
   xmrec.cpp
   xmsend.cpp
   xstring.h
   yoohoo.cpp
   zmodem.cpp
   zmodem.h

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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/*---------------------------------------------------------------------------*
 *
 *                               BinkleyTerm
 *
 *              (C) Copyright 1987-96, Bit Bucket Software Co.
 *     For license and contact information see /doc/orig_260/license.260.
 *
 *           This version was modified by the BinkleyTerm XE Team.
 *        For contact information see /doc/team.lst and /doc/join.us.
 *  For a complete list of changes see /doc/xe_user.doc and /doc/xe_hist.doc.
 *
 * Filename    : $Source: /cvsroot/btxe/btnt/sources/v7debug.cpp,v $
 * Revision    : $Revision: 1.1 $
 * Tagname     : $Name:  $
 * Last updated: $Date: 2005/01/01 15:18:13 $
 * State       : $State: Exp $
 *
 * Description : V7 debugger
 *
 *---------------------------------------------------------------------------*/

#include "includes.h"

static int LOCALFUNC btree (void);
static int LOCALFUNC _btree (long, int);
static struct _ndx far *LOCALFUNC get7node (FILE *, long, struct _ndx far *);
static void LOCALFUNC unpk (char *instr, char *outp, int many);
static int LOCALFUNC addr_compare (void *, void *, int);
static int LOCALFUNC name_compare (void *, void *, int);

static struct _ndx *noderef = NULL;  /* index file             */
static char aline[160];

static FILE *idx_fp, *dat_fp;

static int find_first;          /* is this findfirst or findnext ? */

static ADDR searchaddr;
static char searchname[40];

static void *desired;
static int desired_len;
static int (LOCALFUNC * compare_fn) (void *key, void *desired, int len);

static PV7RCB pv7rcb;

static PV7NODEL beginp, lastp, actp;

#define status_line(X) printf("#X")
#define share_fopen(fn, mode, share) fopen(fn, mode)

int
V7Initialize (void)
{                               /* allocate memory */
    if (noderef == NULL)
        noderef = _fmalloc (sizeof (struct _ndx));

    if (!noderef)
    {
        status_line (MSG_TXT (M_NODELIST_MEM));
        return V7NL_ERROR;
    }

    return V7NL_SUCCESS;
}

void
V7Finish (void)
{                               /* free memory */
    _ffree (noderef);
    noderef = NULL;
}

int
V7FindFirstNode (PV7RCB p)
{                               /* open node idx/dat and find first match */
    idx_fp = share_fopen (p->pszIndexName, read_binary, DENY_WRITE);
    if (idx_fp == NULL)
    {
        status_line (MSG_TXT (M_UNABLE_TO_OPEN), p->pszIndexName);
        return (V7NL_NODEINDEX_OPENFAILED);  /* no file, no work to do */
    }

    dat_fp = share_fopen (p->pszDataName, read_binary, DENY_WRITE);
    if (dat_fp == NULL)
    {
        status_line (MSG_TXT (M_UNABLE_TO_OPEN), p->pszDataName);
        return (V7NL_NODEDAT_OPENFAILED);  /* no file, no work to do */
    }

    searchaddr.Zone = p->pV7Node->ZoneNumber;
    searchaddr.Net = p->pV7Node->NetNumber;
    searchaddr.Node = p->pV7Node->NodeNumber;
    searchaddr.Point = p->pV7Node->HubNode;

    compare_fn = addr_compare;
    desired = &searchaddr;
    desired_len = p->wLen;

    find_first = 1;

    return btree ();
}

int
V7FindFirstSysOp (PV7RCB p)
{                               /* open sysop idx/dat and find first match */
    char last_name_first[26], midname[26], *c, *p2, *m;
    int namelen;

    idx_fp = share_fopen (p->pszSysOpIndex, read_binary, DENY_WRITE);
    if (idx_fp == NULL)
    {
        status_line (MSG_TXT (M_UNABLE_TO_OPEN), p->pszSysOpIndex);
        return (V7NL_SYSOPINDEX_OPENFAILED);  /* no file, no work to do */
    }

    dat_fp = share_fopen (p->pszDataName, read_binary, DENY_WRITE);
    if (dat_fp == NULL)
    {
        status_line (MSG_TXT (M_UNABLE_TO_OPEN), p->pszDataName);
        return (V7NL_NODEDAT_OPENFAILED);  /* no file, no work to do */
    }

    c = midname;                  /* Start of temp name buff   */
    p2 = p->pV7Node->SysopName;   /* Point to start of name    */
    m = NULL;                     /* Init pointer to space     */

    *c = *p2++;
    while (*c)                    /* Go entire length of name  */
    {
        if (*c == ' ')              /* Look for space            */
            m = c;                    /* Save location             */
        c++;
        *c = *p2++;
    }

    if (m != NULL)                /* If we have a pointer,     */
    {
        *m++ = '\0';                /* Terminate the first half  */
        strcpy (last_name_first, m);  /* Now copy the last name    */
        strcat (last_name_first, ", ");  /* Insert a comma and space  */
        strcat (last_name_first, midname);  /* Finally copy first half */
    }
    else
        strcpy (last_name_first, midname);  /* Use whole name otherwise */

    namelen = (int) strlen (last_name_first);  /* Calc length now           */
    namelen = min (25, namelen);

    strncpy (searchname, last_name_first, namelen);
    searchname[namelen] = '\0';

    compare_fn = name_compare;
    desired = &searchname;
    desired_len = namelen;

    find_first = 1;

    return btree ();
}

void
V7FindClose (PV7RCB p)
{                               /* close files */
    if (idx_fp)
    {
        fclose (idx_fp);
        idx_fp = NULL;
    }

    if (dat_fp)
    {
        fclose (dat_fp);
        dat_fp = NULL;
    }
}

static int LOCALFUNC
foundmatch (long datpos, int level)
{
    struct _vers7 vers7;
    char aline[160], aline2[160];
    char *cp;
    char PhoneNumber[40], Password[9], SystemName[34], SysopName[26], MiscInfo[30];
    char *indent;

    if (fseek (dat_fp, datpos, SEEK_SET))
    {                             /* point at record  */
        status_line (MSG_TXT (M_NODELIST_SEEK_ERR), pv7rcb->pszDataName);
        return 1;
    }

    if (fread ((char *) &vers7, sizeof (struct _vers7), 1, dat_fp) != 1)
    {
        status_line (MSG_TXT (M_NODELIST_REC_ERR), pv7rcb->pszDataName);
        return 1;
    }

    memset (PhoneNumber, 0, 40);
    fread (PhoneNumber, vers7.Phone_len, 1, dat_fp);

    memset (Password, 0, 9);
    fread (Password, vers7.Password_len, 1, dat_fp);

    memset (aline, '\0', 160);
    memset (aline2, '\0', 160);

    if (fread (aline2, vers7.pack_len, 1, dat_fp) != 1)
    {
        status_line (MSG_TXT (M_NODELIST_REC_ERR), pv7rcb->pszDataName);
        return 1;
    }

    unpk (aline2, aline, vers7.pack_len);

    cp = &aline[0];

    memset (SystemName, 0, 34);
    memcpy (SystemName, cp, min (33, vers7.Bname_len));
    cp += vers7.Bname_len;

    memset (SysopName, 0, 26);
    memcpy (SysopName, cp, min (25, vers7.Sname_len));
    cp += vers7.Sname_len;

    memset (MiscInfo, 0, 30);
    memcpy (MiscInfo, cp, min (29, vers7.Cname_len));

    indent = "----------"[9 - level];

    printf ("%-10s %-32s ", indent, SysopName);

    sprintf (aline,
             "%d:%d/%d.%d",
             (int) vers7.Zone,
             (int) vers7.Net,
             (int) vers7.Node,
             (int) (vers7.NodeFlags & B_point) ? vers7.HubNode : 0);
    printf ("%-16s ", aline);

    printf ("%2s %5d %3d '%-8s'\n",
            (vers7.NodeFlags & B_CM) ? "CM" : "  ",
            (int) vers7.BaudRate * 300,
            (int) vers7.ModemType,
            (Password[0] != '\0') ? "-" : Password);

    return 0;
}

static int LOCALFUNC
name_compare (void *key, void *desired, int _len)
{
    return (strnicmp ((char *) key, (char *) desired, (unsigned int) min (desired_len, _len)));
}

static int LOCALFUNC
addr_compare (void *key, void *desired, int _len)
{
    int k, len = desired_len;     /* min(desired_len, _len); */

    if (len >= 2)
    {
        k = ((ADDRP) key)->Zone - ((ADDRP) desired)->Zone;
        if (k)
            return (k);
    }
    else
        return 0;

    if (len >= 4)
    {
        k = ((ADDRP) key)->Net - ((ADDRP) desired)->Net;
        if (k)
            return (k);
    }
    else
        return 0;

    if (len >= 6)
    {
        k = ((ADDRP) key)->Node - ((ADDRP) desired)->Node;
        if (k)
            return (k);
    }
    else
        return 0;

    if (_len == 6)                /* spezial treatment for key point */
        ((ADDRP) key)->Point = 0;

    if (len >= 8)
    {
        k = ((ADDRP) key)->Point - ((ADDRP) desired)->Point;
        if (k)
            return (k);
    }
    else
        return 0;

    return 0;
}

/* General V7 nodelist engine. Used by both the by-node and by-sysop
 * lookups.
 *
 * Thanks to Phil Becker for showing me how nice it looks in assembler.
 * It helped me see how nice it could be in C.
 *
 * (I know, Phil, it's still nicer in assembler!) */

static int LOCALFUNC
btree (void)
{
    /* Get CtlRec */
    if (get7node (idx_fp, 0L, noderef) == NULL)
        return 1;

    return _btree (noderef->ndx.CtlBlk.CtlRoot, 0);  /* start recursion */
}

static int LOCALFUNC
_btree (long record, int level)
{
    struct _ndx nodeidx;
    int j, j_done = -1, k, l, ret = 0, count;
    struct _IndxRef far *ip = NULL;
    struct _LeafRef far *lp = NULL;
    char far *tp;
    char *np;

    if (get7node (idx_fp, record * noderef->ndx.CtlBlk.CtlBlkSize, &nodeidx) == NULL)
        return 1;

    /* Follow the node tree until we either match a key right in the index
     * node, or locate the leaf node which must contain the entry. */

    if (nodeidx.ndx.INodeBlk.IndxFirst != -1)  /* INodeBlk */
    {
        count = nodeidx.ndx.INodeBlk.IndxCnt;  /* count may be 0 */
        if (count == 0)
        {
            status_line (">Down 1");
            ret = _btree (nodeidx.ndx.INodeBlk.IndxFirst, level + 1);
            status_line (">Up   1");
        }
        else
        {
            for (j = 0; j < count; j++)  /* check 20 or less */
            {
                ip = &(nodeidx.ndx.INodeBlk.IndxRef[j]);
                tp = (char far *) &nodeidx + ip->IndxOfs;

                k = l = ip->IndxLen;    /* binary length in bytes */
                /* addresses are stored as ADDR structs */
                /* names are stored as "2ndName, 1stName" */

                for (np = aline; k > 0; k--)
                    *np++ = *tp++;

                k = (*compare_fn) ((void *) aline, desired, l);  /* k=key-desired */

                if (k > 0)
                    break;

                if (k == 0)
                {
                    /* Key matches in the index node. Since we're just doing lookup, we
                     * can assume its pointer is valid. If we were doing updates, that
                     * assumption would not work, because leaf nodes update first. So in
                     * an update environment, the entire code segment relating to k == 0
                     * should not execute, and we should walk the tree all the way down.
                     */

                    if (j == 0)
                    {
                        status_line (">Down 2");
                        ret = ret + _btree (nodeidx.ndx.INodeBlk.IndxFirst, level + 1);
                        status_line (">Up   2");
                    }
                    else if (j - 1 != j_done)
                    {
                        status_line (">Down 3");
                        ret = ret + _btree (nodeidx.ndx.INodeBlk.IndxRef[j - 1].IndxPtr, level + 1);
                        status_line (">Up   3");
                    }

                    /* foundmatch (nodeidx.ndx.INodeBlk.IndxRef[j].IndxData); */
                    status_line (">Down 4");
                    ret = ret + _btree (nodeidx.ndx.INodeBlk.IndxRef[j].IndxPtr, level + 1);
                    status_line (">Up   4");
                    j_done = j;
                }
            }

            if (k != 0)
            {
                if (j == 0)
                {
                    status_line (">Down 5");
                    ret = ret + _btree (nodeidx.ndx.INodeBlk.IndxFirst, level + 1);
                    status_line (">Up   5");
                }
                else if (j - 1 != j_done)
                {
                    status_line (">Down 6");
                    ret = ret + _btree (nodeidx.ndx.INodeBlk.IndxRef[j - 1].IndxPtr, level + 1);
                    status_line (">Up   6");
                }
            }
        }
    }
    else
    {                             /* LNodeBlk */
        count = nodeidx.ndx.LNodeBlk.IndxCnt;  /* count may be 0 */

        /* Search for a higher key */
        for (j = 0; j < count; j++) /* check 30 or less */
        {
            lp = &(nodeidx.ndx.LNodeBlk.LeafRef[j]);
            tp = (char far *) &nodeidx + lp->KeyOfs;

            k = l = lp->KeyLen;

            for (np = aline; k > 0; k--)
                *np++ = *tp++;

            k = (*compare_fn) ((void *) aline, desired, l);

            if (k > 0)
                break;
            else if (k == 0)
                ret = ret + foundmatch (nodeidx.ndx.LNodeBlk.LeafRef[j].KeyVal, level);
        }
    }

    return ret;
}

static struct _ndx far *LOCALFUNC
            get7node (FILE * stream, long pos, struct _ndx far * ndx)
{
    fseek (stream, pos, SEEK_SET);

    if (fread (ndx, sizeof (struct _ndx), 1, stream) != 1)
    {
        status_line (MSG_TXT (M_NODELIST_READ_ERR));
        return (NULL);
    }
    return (ndx);
}

/* ====================================================================
 * unpack a dense version of a symbol (base 40 polynomial)
 * ==================================================================== */

static void LOCALFUNC
unpk (char *instr, char *outp, int count)
{
    /* This table has been modified to minimize searches */
    static char unwrk[] = " EANROSTILCHBDMUGPKYWFVJXZQ-'0123456789";

    struct chars
    {
        unsigned char c1;
        unsigned char c2;
    };

    union
    {
        unsigned short w1;
        struct chars d;
    }
    u;

    register short i, j;          /* MB int */
    char obuf[4];

    outp[0] = '\0';

    while (count)
    {
        u.d.c1 = *instr++;
        u.d.c2 = *instr++;
        count -= 2;
        for (j = 2; j >= 0; j--)
        {
            i = u.w1 % 40;
            u.w1 /= 40;
            obuf[j] = unwrk[i];
        }

        obuf[3] = '\0';
        strcat (outp, obuf);
    }
}

int
main (int argc, char *argv[])
{
    char *sysndxfname = argv[1];  /* sysop index filename     */
    char *adrndxfname = argv[2];  /* address index filename   */
    char *datfname = argv[3];     /* data filename            */
    V7RCB V7rcb;                  /* request block            */
    V7NODE V7node;                /* V7 format node record    */
    int V7rc;                     /* return code              */
    int count;

    V7Initialize ();
    memset (&V7rcb, '\0', sizeof (V7RCB));
    V7rcb.pszSysOpIndex = sysndxfname;
    V7rcb.pszDataName = datfname;
    V7rcb.pV7Node = &V7node;
    memset (&V7node, '\0', sizeof (V7NODE));
    strcpy (V7node.SysopName, "");
    V7FindFirstSysOp (&V7rcb);
    V7FindClose (&V7rcb);
    V7Finish ();
}

/* $Id: v7debug.cpp,v 1.1 2005/01/01 15:18:13 vildanov Exp $ */

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us