A
download bt.cpp
Language: C++
Copyright: Copyright 1987-96, Bit Bucket Software Co.
LOC: 411
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/*---------------------------------------------------------------------------*
 *
 *                               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/bt.cpp,v $
 * Revision    : $Revision: 1.2 $
 * Tagname     : $Name:  $
 * Last updated: $Date: 2005/01/03 03:27:00 $
 * State       : $State: Exp $
 * Orig. Author: Bob Hartman
 *
 * Description : BinkleyTerm "Main" Module
 *
 *---------------------------------------------------------------------------*/

/* Include this file before any other includes or defines! */

#include "includes.h"

void print_exeinfo (void);

#ifdef OS_2
	#ifdef EXCEPTIONS
ULONG APIENTRY exHandler (PEXCEPTIONREPORTRECORD, PEXCEPTIONREGISTRATIONRECORD, PCONTEXTRECORD, PVOID);
	#endif
#endif

#ifndef NO_SIGNALS
SIGTYPE handler (SIGARGS);
	#ifdef SIGTERM
SIGTYPE handler_sigterm (SIGARGS);
	#endif
#endif

extern char compiled[];

static char far *DOS_commands[] = {
                                      "noforce",
                                      "mail",
                                      "share",
                                      "dynam",
                                      "unattended",
                                      "config",
                                      "poll",
                                      "debug",
                                      "term",                       /* MR 970307 */
                                      "info",                       /* MR 980503 - display additional infos */
                                      NULL
                                  };


/* MMP 960419 main() is now another function implementing the Respawn command
 * line keyword
 **/

static int
binkmain (int argc, char *argv[])
{
    int argc2 = argc;
    char **argv2 = argv;
    int done;
    char *envptr;
    ADDR baddr;
    long init_timer;
    char *poll_addr = NULL;
    char junk[256];
    int additional_info = 0;


    // CEH991001: read Config from command-line before reading the
    // language-file, to be able to read it from the same path.

#ifdef USE_FIDOCONFIG
    // but first: Create the path for config_name (and eventfile)
    // from fidoconfig
    setpathsfromfidoconfig ();
#endif

    while (--argc2)
    {
        ++argv2;
        switch (parse (argv2[0], DOS_commands))
        {
        case 6:                    /* Config     */
            config_name = argv2[1];
            --argc2;
            ++argv2;
            break;

        case 7:                    /* Poll       */
            --argc2;                  // just skip

            ++argv2;
            break;
        }
    }

    load_language (*argv);

    /* MMP 960419 signal handling was here */

    init_timer = timerset (2 * PER_SECOND);

    b_initvars ();

    while (--argc)
    {
        ++argv;

        switch (parse (argv[0], DOS_commands))
        {
        case 1:                    /* Noforce    */
            noforce = 1;
            break;

        case 2:                    /* Mail       */
            mail_only = 1;
            break;

        case 3:                    /* Share      */
            share = 1;
            break;

        case 4:                    /* Dynam      */
            redo_dynam = 1;
            break;

        case 5:                    /* Unattended */
            un_attended = 1;
            command_line_un = 1;
            break;

        case 6:                    /* Config     */
            // CEH: moved before load_language
            // config_name = argv[1];
            --argc;
            ++argv;
            break;

        case 7:                    /* Poll       */
            poll_addr = argv[1];
            --argc;
            ++argv;
            break;

        case 8:                    /* Debug      */
            debugging_log = 1;
            break;

        case 9:                    /* MR 970307 Term */
            command_line_term = 1;
            break;

        case 10:                   /* MR 980503 Info */
            additional_info = 1;
            break;

        default:                   /* Not there  */
            if (strchr (*argv, '='))
            {
                /* MMP 960420 Set environment variable */
                char *c;

                for (c = *argv; *c != '='; c++)
                    *c = (char) toupper (*c);
                putenv (*argv);
            }
            else
            {
                printf (MSG_TXT (M_UNRECOGNIZED_OPTION), argv[0]);
                exit (1);
            }
        }
    }

    /* MR 970714 set OS environment variable */

#if defined OS_2
    putenv ("OS=OS2");
#elif defined _WIN32
putenv ("OS=W32");
#elif defined __unix__
    putenv ("OS=UNIX");
#else
putenv ("OS=DOS");
#endif

    /* MR 970715 set BTXEVER environment variable */

    sprintf (junk, "BTXEVER=%s", version_base);
    putenv (strdup (junk));

    /* TJW 960421 changed version string generation vvv */

    sprintf (junk, "%s %s/%s-%s%s%s %s",
             PRD_SH_PRTY, PRDCT_VRSN,
             version_type, version_base, version_modified, version_opts,
             compilerinfo);
    ANNOUNCE = strdup (junk);

    /* TJW 960421 changed version string generation ^^^ */

    /* MR 991003 removed developer names as there are too many... */
    printf
    ("\n /----------------------------------------------------------------------------\\\n");
    printf (" | %-74s |\n", ANNOUNCE);
    printf
    (" | (C) Copyright 1987-96, Bit Bucket Software, Co. ALL RIGHTS RESERVED.       |\n");
    printf
    (" +----------------------------------------------------------------------------+\n");
    printf
    (" | Note: This version contains modifications done by the BinkleyTerm XE Team  |\n");
    printf
    (" |       and contributers (see included team.lst).                            |\n");
    printf
    (" \\----------------------------------------------------------------------------/\n");
    printf
    ("  \\--   feel free to visit our homepage at http://btxe.sourceforge.net/    --/\n\n");

    if (additional_info)
        print_exeinfo ();

    printf ("%s", MSG_TXT (M_SYSTEM_INITIALIZING));

    /* MR 961121 if the environment variable BINKLEY is set then this is
     *           binkley's home directory (BINKpath).
     */

    envptr = getenv (PRDCT_PRFX); /* get path from environment */

    if (envptr != NULL)
    {
        BINKpath = (char*)calloc (1, (strlen (envptr) + 2)); /* make room for new   */
        strcpy (BINKpath, envptr);  /* use BINKLEY as our path */
        add_backslash (BINKpath);
    }
    else
    {
        BINKpath = (char*)calloc (1, PATHLEN + 1); /* make room for new   */

        getcwd (BINKpath, PATHLEN - 1); /* get current directory   */
        add_backslash (BINKpath);
    }

    task_dir = BINKpath;          /* TJW 960830 */

    memset (&hist, 0x00, sizeof (HISTORY));

    envptr = getenv ("TASK");     /* TJW 960422 get TaskNumber from environment */

    if (envptr)
        TaskNumber = atoi (envptr);
    else
    {
        printf (MSG_TXT (M_NOENVVARTASK));
        exit (1);
    }

#ifdef USE_FIDOCONFIG
    if (read_fidoconfig ())
    {
        printf ("\nNot enough memory or error in fidoconfig\n\n");
        exit (1);
    }
    else
    {
        printf (". done\n\n");
    }
#endif

    parse_config (config_name);   /* TJW 960830 changed parse order */

    if (!read_sched ())
        parse_config (eventfile);   /* r. hoerner */

    if (num_events == 0)
    {
        printf
        ("ERR: No Events defined. Please define at least one event 00:00 - 24:00.\n");
        exit (1);
    }

    scdcompiletime = unix_time (NULL); // TJW 971031 remember compile time

    openlogs (1);                 /* TJW 960527 open the log files, print \n into main log */
    b_defaultvars ();

    /* We have everything we need to handle addresses now.
     * Parse the 'poll' address if there was one. */

    if (poll_addr != NULL && find_address (poll_addr, &baddr))
    {
        doing_poll = 1;
    }

    /* We expect this to fail right away, but in order to keep the copyright
     * notice displayed long enough, we check anyway */

    while (!timeup (init_timer))
        time_release ();

    done = 0;

    b_sbinit ();

    if (mail_only)
    {
        doing_poll = 1;
        baddr = boss_addr;
    }

    start_hist = hist;

    if (doing_poll)
    {
        if (baddr.Zone == 0)
            baddr.Zone = addrMyAddr->Zone;
        un_attended = 1;
        opening_banner ();
        mailer_banner ();
        sprintf (junk, "%s", Full_Addr_Str (&baddr));
        junk[28] = '\0';

        sb_fill (holdwin, ' ', colors.hold);
        sb_move_puts (holdwin, 1, 11, MSG_TXT (M_POLLING_COLON));
        sb_move_puts (holdwin, 3, (short) (15 - strlen (junk) / 2), junk);
        sb_show ();

        find_event ();
        set_prior (PRIO_MODEM);
        if (!ComIsOnline(hcModem))
            modem_hangup ();
        do_mail (&baddr, 1);
        set_prior (PRIO_REGULAR);
        done = 1;
    }

    while (!done)
    {
        if (un_attended)
        {
            done = unattended ();
            un_attended = 0;
        }
        else
        {
            done = b_term ();
            un_attended = done ? 0 : 1;
        }
    }

    b_sbexit ();
    b_exitproc ();

#if defined(OS_2) && !defined(__EMX__)
    if (UseCAPICID)               /* CFS 970310 - Unlink from CAPI on exit */
        CAPIStop ();
#endif

    return (1);
}


/* MMP 960423 signal(SIGBREAK,SIG_IGN) seems to be broken using Watcom */

#ifndef NO_SIGNALS

#ifdef __WATCOMC__

void
handler (int signo)
{
    switch (signo)
    {
    case SIGINT:
        signal (SIGINT, handler);
        ctrlc_ctr++;
        break;
    case SIGBREAK:
        signal (SIGBREAK, handler);
        break;
    }
}

#else /* __WATCOMC__ */

SIGTYPE
handler (SIGARGS)               /* Function called at system interrupt */
{
#ifdef SIGNAL_ARGUMENT
    happy_compiler = (int) sigarg; /* For the compiler */
#endif

    signal (SIGINT, SIG_IGN);     /* Disallow CTRL + C during handler    */
    ctrlc_ctr++;
    signal (SIGINT, handler);

    /* This is necessary so that the next CTRL+C interrupt will call
    * "handler", since the DOS 3.x operating system resets the
    * interrupt handler to the system default after the
    * user-defined handler is called */
}

#ifdef SIGTERM
SIGTYPE
handler_sigterm (SIGARGS)       /* Function called at system interrupt */
{
#ifdef SIGNAL_ARGUMENT
    happy_compiler = (int) sigarg; /* For the compiler */
#endif
    ctrlc_ctr++;
    signal (SIGTERM, handler);
}
#endif

#endif /* __WATCOMC__ */

#endif /* NO_SIGNALS */


/* MMP 960419 This new main contains the implementation of the Respawn
 * command line keyword. On OS/2, if this keyword is used, Binkley is
 * respawned if it exits irregularly. I hate to put strings in here
 * that really belongs to the language file, but it would be overkill
 * to load the language file twice just for those few string.. Also, I
 * would like to have a respawn keyword in the configuration file, but
 * this requires the first Binkley to do a lot of initialization (and
 * memory allocation).
 */

#ifndef exit
#error exit undefined!?
#endif
#undef exit

#define BINKEXIT "_BINKLEY_EXIT_"

#ifdef _WIN32
static unsigned old_console_cp; /* SVM 171099: restore old code page */
static unsigned old_console_output_cp; /* SVM 991025 */

static void
RestoreConsole (void)
{
    SetConsoleCP (old_console_cp);
    SetConsoleOutputCP (old_console_output_cp);
}
#endif

main (int argc, char *argv[])
{
#ifdef OS_2
#ifdef EXCEPTIONS

    EXCEPTIONREGISTRATIONRECORD xcpthand;

#endif
#endif

    char flagbuf[40], *flagname;
    const char **av;
    int errlev, rc;
    int i, j;

    /* Disable Ctrl-C/Break */

#ifndef NO_SIGNALS

#ifdef __WATCOMC__
    signal (SIGINT, handler);
    signal (SIGBREAK, handler);
#else

if (signal (SIGINT, handler) == SIG_ERR)
    fprintf (stderr, MSG_TXT (M_NO_SIGINT));
#ifdef SIGTERM
    if (signal (SIGTERM, handler_sigterm) == SIG_ERR)
        fprintf (stderr, MSG_TXT (M_NO_SIGINT));
#endif

#ifdef SIGBREAK
    signal (SIGBREAK, SIG_IGN);
#endif

#endif /* __WATCOMC__ */

#endif /* NO_SIGNALS */

    // ===================================================================

#ifdef OS_2
#ifdef EXCEPTIONS
    xcpthand.prev_structure = 0;
    xcpthand.ExceptionHandler = &exHandler;
    DosError (FERR_DISABLEEXCEPTION | FERR_DISABLEHARDERR);
    DosSetExceptionHandler (&xcpthand);
#endif
#endif

    // ===================================================================

#ifdef OS_2
    DosSetProcessCp (437);        // MR 970113 set codepage to 437 (US-English)
#endif

#ifdef _WIN32
    old_console_cp = GetConsoleCP (); /* SVM 171099: save old codepage */
    old_console_output_cp = GetConsoleCP (); /* SVM 991025 */
    atexit (RestoreConsole);

    SetConsoleCP (437);           //HJK 980802 set codepage to 437 (US-English)
    SetConsoleOutputCP (437);     //SVM 991025

    //NS971214  switch off mouse cursor
    SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE),
                    ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
    FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
#endif

    /* Check if "Respawn" is specified. If not, act normally */

    for (i = 1; i < argc; i++)
        if (!stricmp (argv[i], "respawn"))
            break;

    if (i == argc)
        binkexit (binkmain (argc, argv));

    /* Set BINKEXIT filename */

    strcpy (flagbuf, BINKEXIT);
    flagname = flagbuf + strlen (flagbuf);
    *flagname++ = '=';
    sprintf (flagname, "bink%04x.xit", getpid () & 0xFFFF);
    putenv (strdup (flagbuf));

    /* Set up argument vector (argv[] may not be NULL terminated) */

    if ((av = (const char**)malloc ((argc) * sizeof (char *))) == NULL)
        exit (3);

    for (i = j = 0; i < argc; i++)
        if (stricmp (argv[i], "respawn"))
            av[j++] = argv[i];
    av[j] = NULL;

    /* Keep spawning Binkley until we succesfully can unlink the flag file */

    do
    {
        errlev = spawnv (P_WAIT, av[0], av);
        if (errlev == -1)
        {
            printf ("Error spawning %s: %s\n", av[0], strerror (errno));
            exit (1);
        }
        rc = unlink (flagname);
        if (rc)
            printf ("\n\nBinkley died (errorlevel %d) - respawning!\a\n", errlev);
    }
    while (rc);

    /* Now, do final exit */

#ifdef  OS_2                    /*  TS 970403   */
    SendToDlg ((PSZ) "---*---", 0, 0, BINK_END);
#endif

    // ===================================================================
#ifdef OS_2
#ifdef EXCEPTIONS
    DosUnsetExceptionHandler (&xcpthand);
#endif
#endif
    // ===================================================================

#ifdef INTMAIN                  /* MMP 960419 main() is still declared void for some compilers */
    return (errlev);              /* CE/TJW 960418 makes compiler happy, was: exit (1); */
#else
exit (errlev);
#endif
}

void
binkexit (int n)
{
    char *c;

    movelogs ();
    if ((c = getenv (BINKEXIT)) != NULL)
        if (fopen (c, write_binary) == NULL)
            printf
            ("\nError opening %s. This may cause Binkley to be respawned!\n", c);

#ifdef  OS_2                    /*  TS 970403   */
    SendToDlg ((PSZ) "---*---", 0, 0, BINK_END);
#endif
    exit (n);
}

/* $Id: bt.cpp,v 1.2 2005/01/03 03:27:00 vildanov Exp $ */

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