A
download b_term.cpp
Language: C++
Copyright: Copyright 1987-96, Bit Bucket Software Co.
LOC: 565
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
/*---------------------------------------------------------------------------*
 *
 *                               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/b_term.cpp,v $
 * Revision    : $Revision: 1.1 $
 * Tagname     : $Name:  $
 * Last updated: $Date: 2005/01/01 15:18:11 $
 * State       : $State: Exp $
 * Orig. Author: Vince Perriello
 *
 * Description : BinkleyTerm Terminal Module
 *
 *---------------------------------------------------------------------------*/

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

#include "includes.h"
#include "vt100.h"

void term_Poll (ADDR*);

void
send_modem (char *s, int len)
{
    int i;

    for (i = 0; i < len; i++)
        SENDBYTE (*s++);
}

static REGIONP callwinsave, termwin;

void termwin_init (void)
{
    short rows, rows_call, termwin_size;

    callwinsave = callwin;
    rows_call = CALLWIN_HIGH;

    if (rows_call >= 29)
        rows = 25;
    else
        rows = 8;
    rows_call -= rows;

    termwin_size = SB_COLS;

    termwin = sb_new (TOP_PARTS_ROWS, 0, rows, termwin_size);
    termwin->wflags |= SB_SCROLL | SB_WRAP;
    termwin->wflags &= ~(SB_ADDLF | SB_IGNLF);

    sb_fill (termwin, ' ', colors.background);

    callwin = sb_new_win ((short) (TOP_PARTS_ROWS + rows), 0,
                          rows_call, termwin_size,
                          ' ', colors.call,
                          boxtype, colors.frames,
                          MSG_TXT (M_RECENT_ACTIVITY));
    callwin->linesize = callwinsave->linesize;
    callwin->buffer = callwinsave->buffer;
    callwin->endbuff = callwinsave->endbuff;
    callwin->lastline = callwinsave->lastline;
    callwin->lastshown = callwinsave->lastshown;

    vt_init (ANSI, WHITE, BLACK, 1, 0);
    sb_box (callwin, boxtype, colors.frames);
    sb_caption (callwin, MSG_TXT (M_RECENT_ACTIVITY), colors.frames);
    redraw_callwin ();
    sb_show ();
}

void
termwin_exit (void)
{
    callwinsave->linesize = callwin->linesize;
    callwinsave->buffer = callwin->buffer;
    callwinsave->endbuff = callwin->endbuff;
    callwinsave->lastline = callwin->lastline;
    callwinsave->lastshown = callwin->lastshown;

    /* MR 970215 added free; shouldn't we give back allocated memory!? */
    free (callwin);
    free (termwin);

    callwin = callwinsave;
    termwin = NULL;

    sb_fill (callwin, ' ', colors.call);
    sb_box (callwin, boxtype, colors.frames);
    sb_caption (callwin, MSG_TXT (M_RECENT_ACTIVITY), colors.frames);
    redraw_callwin ();
}


int
b_term ()
{
#ifdef BUFFERED_CONSOLE_WRITE
    char tbuf[200];               /*PLF Sun  12-01-1991  06:28:59 */

    /* TJW 960526 static -> dynamic */
    int tcnt = 0;                 /*PLF Sun  12-01-1991  06:29:06 */

#endif

    char junk[256];
    short j, k;
    short c;
    unsigned int mask = 0xff;
    int gateway_mode = 0;
    int done;
    struct _key_fnc_hdr *OldKeyFncHdr;
    char *autodl = "**\030B00";   /* Zmodem autodl str.  */
    char *search_autodl = autodl;

#ifdef HAVE_HYDRA
    char *hauto = "\030cA\\f5\\a3\030a";
    char *search_hauto = hauto;

#endif /* HAVE_HYDRA */

    FILE *logfile = NULL;         /* log file stream */
    char prot;
    char *p;

    int retval = 1;               /* What to tell the mainline */
    ADDR baddr;

    ctrl_modemwin (0);            /* MR 970216 switch off modemwin in terminal */
    termwin_init ();
    vt_install (send_modem, NULL, termwin);

    OldKeyFncHdr = KbMapSet (&TrmnlKeyFncHdr);

    sb_dirty ();                  // ???
    // opening_banner ();         /* MR 970307 */

    strcpy (GenStats.remote, "*** TERMINAL MODE ***");

    IPC_SetStatus (MSG_TXT (M_MCP_TERM));
    IPC_Ping ();

    // vfossil_cursor (1);
    done = 0;
    first_block = 0;
    modem_init ();

    do_status (M_READY_TERMINAL, NULL);

    while (!done)
    {
        show_alive ();
        c = -1;
        if (CHAR_AVAIL ())
        {
            c = MODEM_IN ();

            if (comm_bits == BITS_7)
                c &= 0x7f;

            /* Check for Zmodem AutoDownload sequence */
            if ((c & 0x7f) == (int) *search_autodl)
            {
                if (!*++search_autodl)
                {
                    sb_puts (termwin, MSG_TXT (M_ZMODEM_STARTED));
                    CLEAR_INBOUND ();

                    Download (NULL, (int) 'Z', NULL);

                    sb_puts (termwin, MSG_TXT (M_ZMODEM_FINISHED));
                    search_autodl = autodl;
                }
            }
            else
                search_autodl = autodl;

#ifdef HAVE_HYDRA
            /* Check for HYDRA AutoStart sequence */
            if ((c & 0x7f) == (int) *search_hauto)
            {
                if (!*++search_hauto)
                {
                    sb_puts (termwin, MSG_TXT (M_HYDRA_AUTO_STARTED));

                    Download (NULL, (int) 'H', NULL);

                    sb_puts (termwin, MSG_TXT (M_HYDRA_AUTO_FINISHED));
                    search_hauto = hauto;
                }
            }
            else
                search_hauto = hauto;
#endif /* HAVE_HYDRA */

            /* I really don't like looking for this piece of crap, but people
             * seem to really want it, so I guess I lose.  Now if only
             * QuickBBS would do things that were ANSI compatible - ugh! */

            if (c == '')
            {
                screen_clear ();
#ifdef BUFFERED_CONSOLE_WRITE
                tcnt = 0;
#endif
            }
            else if ((c == ENQ) && (answerback != NULL))
            {
                mdm_cmd_string (answerback, 1);
            }
            else
            {
#ifndef BUFFERED_CONSOLE_WRITE
                vt_out (c);             // TJW experimental, was: WRITE_ANSI ((char)c);
#else
tbuf[tcnt++] = (char) c;  /*PLF Sun  12-01-1991  06:31:52 */
                if (tcnt == sizeof (tbuf) - 1)
                {
                    tbuf[tcnt] = 0;
                    puts (tbuf);
                    tcnt = 0;
                }
#endif
            }

            if (logfile != NULL)
                fwrite (&c, 1, 1, logfile);
        }
#ifdef BUFFERED_CONSOLE_WRITE
        else if (tcnt)              /* No characters received */
        {
            tbuf[tcnt] = 0;
            puts (tbuf);
            tcnt = 0;
            c = 0;
        }
#endif

        if (KEYPRESS () || ctrlc_ctr)
        {
            if (ctrlc_ctr)
            {
                /* We got a ^C, so output it properly */
                while (KEYPRESS ())     /* Flush keyboard buffer */
                    FOSSIL_CHAR ();
                ctrlc_ctr = 0;
                SENDBYTE (3);
                continue;
            }

            /* Get the keystroke. Map it, saving the original keystroke. */
            k = (short) KbRemap (j = FOSSIL_CHAR ());

            /* See if it mapped into 'toggle gateway'. If so, do it.     */
            if ((unsigned short) k == F_TERM_GATEWAYMODE)
            {
                gateway_mode = ~gateway_mode;
                continue;
            }

            /* It wasn't 'toggle gateway'. See if it's a command at all.
             * Or if we are currently in gateway mode.
             *
             * If we are in gateway mode, we will send the raw keystroke
             * out the comm port (zero plus scan code in the case of a
             * function key).
             *
             * Otherwise, we'll send normal keystrokes out verbatim, and
             * apply "ANSI mapping" to function keys. */

            if (gateway_mode || ((unsigned short) k & F_TRM_BS) != F_TRM_BS)
            {
                if (comm_bits == BITS_7)
                    mask = 0x7f;
                else
                    mask = 0xff;

                if (gateway_mode)
                {
                    SENDBYTE ((unsigned char) (c = (j & mask)));
                    if (c == 0)
                        SENDBYTE ((unsigned char) (((unsigned short) j >> 8) & mask));
                }
                else
                {
                    c = k & mask;
                    if (c != 0)
                        SENDBYTE ((unsigned char) c);
                    else
                        ansi_map ((unsigned short) k);
                }

                continue;
            }

            /* It's a command key, which has been remapped to one of our internal
             * codes. Dispatch on it. */

            if (!term_overlay (k))
                continue;

            switch ((unsigned short) k)
            {
            case F_TERM_CAPTUREFILE:
                if (logfile != NULL)
                {
                    fclose (logfile);
                    logfile = NULL;
                    status_line (MSG_TXT (M_LOG_CLOSED), capturename);
                    break;
                }

                if ((logptr == NULL) || (*logptr == '\0'))
                {
                    scr_printf (MSG_TXT (M_INPUT_LOGFILE));
                    fgets (capturename, 100, stdin);
                    if ((k = (short) strlen (capturename)) != 0)
                        capturename[--k] = '\0';  /* no '\n' */
                }
                else
                {
                    strcpy (capturename, logptr);
                    k = 1;
                }

                if (k)
                {
                    logfile = share_fopen (capturename, append_binary, DENY_WRITE);
                    if (logfile == NULL)
                        status_line (MSG_TXT (M_LOG_NOT_OPEN), capturename);
                    else
                        status_line (MSG_TXT (M_LOG_OPEN), capturename);
                }
                break;

            case F_TERM_POLLBOSS:
                term_Poll (&boss_addr);
                break;

            case F_TERM_POLLNODE:
                scr_printf ("\n");
                scr_printf (MSG_TXT (M_ENTER_NET_NODE));
                if (!get_number (junk))
                    break;
                if ((find_address (junk, &baddr) == 0)
                        || ((short) (baddr.Net) < 0)
                        || ((short) (baddr.Node) < 0)
                        || (nodefind (&baddr, 1) == 0))
                {
                    printf ("\n%s '%s'\n", &(MSG_TXT (M_NO_ADDRESS)[1]), junk);
                    break;
                }

                if (!baddr.Zone)
                    baddr.Zone = found_zone;

                term_Poll (&baddr);
                break;

            case F_TERM_DIALGROUP:
                if (!list_search ())
                    screen_clear ();
                break;

            case F_TERM_MAILERMODE:
                if (port_ptr != original_port)
                {
                    status_line (" %s %s%d:",
                                 MSG_TXT (M_SWITCHING_BACK),
                                 port_device,
                                 1 + original_port);
                    MDM_DISABLE ();
                    port_ptr = original_port;
                    if (Cominit (port_ptr, buftmo) != 0x1954)
                    {
                        port_ptr = c;
                        Cominit (port_ptr, buftmo);
                    }
                    program_baud ();
                    RAISE_DTR ();
                }
                retval = 0;
                /* Fall into exit code */

            case F_TERM_EXITBINK:
                if (logfile != NULL)
                    fclose (logfile);
                done = 1;
                break;

            case F_TERM_UPLOAD:
                scr_printf (MSG_TXT (M_READY_TO_SEND));
                scr_printf (MSG_TXT (M_WHICH_PROTOCOL));
#ifdef HAVE_HYDRA
                scr_printf ("H)ydra    Z)modem     S)EAlink     T)elink     X)modem\r\n");
#else
scr_printf ("Z)modem   S)EAlink    T)elink      X)modem\r\n");
#endif /* HAVE_HYDRA */
                if (extern_protocols != NULL)
                {
                    scr_printf (extern_protocols);
                    scr_printf ("\r\n");
                }

                scr_printf (MSG_TXT (M_CHOOSE));
                junk[0] = '\0';
                fgets (junk, 100, stdin);

                if ((junk[0] == '\0') || (junk[0] == '\n'))
                    break;

                if (!(prot = (char) toupper (junk[0])))
                    break;

                p = NULL;
                if ((strchr (native_protocols, prot) == NULL)
                        && ((extern_protocols == NULL) ? (1) : (p = strchr (extern_protocols, prot)) == NULL))
                {
                    scr_printf (MSG_TXT (M_DONT_KNOW_PROTO));
                    break;
                }

                scr_printf (MSG_TXT (M_FILE_TO_SEND));
                junk[0] = '\0';
                fgets (junk, 100, stdin);

                if ((k = strlen (junk)) != 0)
                    junk[--k] = '\0';

                if ((junk[0] == '\0') || (junk[0] == '\n'))
                    break;

                if ((!k) || (!dexists (junk)))
                    break;

                Upload (junk, (int) prot, p);
                break;

            case F_TERM_DOWNLOAD:
                scr_printf (MSG_TXT (M_READY_TO_RECEIVE));
                scr_printf (MSG_TXT (M_WHICH_PROTOCOL));

#ifdef HAVE_HYDRA
                scr_printf ("H)ydra    Z)modem     S)EAlink     T)elink     X)modem\r\n");
#else
                scr_printf ("Z)modem   S)EAlink    T)elink      X)modem\r\n");
#endif /* HAVE_HYDRA */

                if (extern_protocols != NULL)
                {
                    scr_printf (extern_protocols);
                    scr_printf ("\r\n");
                }

                scr_printf (MSG_TXT (M_CHOOSE));
                junk[0] = '\0';
                fgets (junk, 100, stdin);

                if ((junk[0] == '\0') || (junk[0] == '\n'))
                    break;

                if (!(prot = (char) toupper (junk[0])))
                    break;

                p = NULL;
                if ((strchr (native_protocols, prot) == NULL)
                        && ((extern_protocols == NULL) ? (1) : (p = strchr (extern_protocols, prot)) == NULL))
                {
                    scr_printf (MSG_TXT (M_DONT_KNOW_PROTO));
                    break;
                }

                Download (NULL, (int) prot, p);
                break;

            case F_TERM_HELPSCREEN:
                main_help ();
                break;

            default:
                break;
            }
        }

        if (c == -1)
            time_release ();
    }

    KbMapSet (OldKeyFncHdr);

    set_prior (PRIO_REGULAR);

    termwin_exit ();
    return (retval);
}

/* Handle polls from terminal mode. */

void
term_Poll (ADDR* address)
{
    unsigned save1, save2, save3;
    char junk[256];

    save1 = comm_bits;
    save2 = parity;
    save3 = stop_bits;

    un_attended = 1;
    sb_dirty ();
    opening_banner ();
    mailer_banner ();

    sprintf (junk, "%s", Full_Addr_Str (address));
    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 ();

    if (!ComIsOnline(hcModem))
        modem_hangup ();

    do_mail (address, 1);
    un_attended = 0;
    screen_clear ();
    scr_printf (MSG_TXT (M_MANUAL_MODE));

    comm_bits = save1;
    parity = save2;
    stop_bits = save3;
    program_baud ();

    gong ();
    // vfossil_cursor (1);
}

/* Handle uploads from terminal mode.
 * Note: filepath parameter below will be trashed if it's a wildcard! */

int
Upload (char *filepath, int prot, char *extern_ptr)
{
    unsigned save1, save2, save3;
    char *p;
    struct FILEINFO fileinfo;

    int err = FILE_SENT_OK;       /* Xmodem, Ymodem, Telink flag */

    if (dfind (&fileinfo, filepath, 0))
        return (FAILURE);

    save1 = comm_bits;
    save2 = parity;
    save3 = stop_bits;
    comm_bits = BITS_8;
    parity = NO_PARITY;
    stop_bits = STOP_1;
    program_baud ();
    XON_DISABLE ();

    /* If external protocol requested, call it */
    if (extern_ptr != NULL)
        do_extern ("Send", prot, filepath);
    else
    {
        css_init ();
        switch (prot)
        {
        case 'X':
        case 'Y':
            err = Xmodem_Send_File (filepath, NULL);
            break;

        default:
            switch (prot)             /* init the proper protocol if need be */
            {
#ifdef HAVE_HYDRA
            case 'H':
                hydra_init (hydra_options);
                break;
#endif /* HAVE_HYDRA */
            case 'Z':
                Send_Zmodem (NULL, NULL, ZMODEM_INIT, !DO_WAZOO);
                break;
            default:
                break;
            }
            /* Find the delimiter on the pathspec for use by the various
             * batch protocols. */

            p = strrchr (filepath, '\\');
            if (p == NULL)
                p = strrchr (filepath, '/');
            if (p == NULL)
                p = strchr (filepath, ':');
            if (p == NULL)
                p = filepath;
            else
                p++;

            /*  At this point *p points to the location in the input
             *  string where the prepended path information ends. All
             *  we need to do, then, is to keep plugging in the stuff
             *  we get from _dos_find(first|next) and transfer files.
             *  We already have the first matching filename from the
             *  _dos_findfirst we did above, so we use a "do" loop. */

            do
            {
                /* Append the current filename */
                strcpy (p, fileinfo.name);

                switch (prot)
                {
#ifdef HAVE_HYDRA
                case 'H':
                    err = hydra (filepath, NULL);
                    break;
#endif /* HAVE_HYDRA */
                case 'Z':
                    err = Send_Zmodem (filepath, NULL, 1, !DO_WAZOO);
                    break;
                default:
                    err = Batch_Send (filepath);
                    break;
                }
            }
            while ((err != CANNOT_SEND) && (!dfind (&fileinfo, NULL, 1)));

            switch (prot)             /* Finish the proper protocol if need be */
            {
#ifdef HAVE_HYDRA
            case 'H':
                hydra (NULL, NULL);
                hydra_deinit ();
                break;
#endif /* HAVE_HYDRA */
            case 'Z':
                Send_Zmodem (NULL, NULL, ZMODEM_ENDBATCH, !DO_WAZOO);
                break;
            default:
                Batch_Send (NULL);
                break;
            }
        }

        css_done ();
    }

    dfind (&fileinfo, NULL, 2);

    comm_bits = save1;
    parity = save2;
    stop_bits = save3;
    program_baud ();
    XON_ENABLE ();
    gong ();

    err = (err == CANNOT_SEND ? FAILURE : IGNORE);

    return (err);
}

/* Handle downloads from terminal mode.

 * If filespec is NULL and we need a filename, ask for it.
 * Otherwise, assume that the spec we got is OK and use it. */

int
Download (char *filepath, int prot, char *extern_ptr)
{
    int k;
    int err = 1;
    unsigned save1, save2, save3;
    char junk[256];

    if ((prot == 'X') || (prot == 'Y') || extern_ptr != NULL)
    {
        if (filepath != NULL)
            strcpy (junk, filepath);
        else
        {
            scr_printf (MSG_TXT (M_FILE_TO_RECEIVE));
            junk[0] = '\0';
            fgets (junk, 100, stdin);
            if ((junk[0] == '\0') || (junk[0] == '\n'))
                return (0);
            k = strlen (junk);
            if (k <= 1)
                return (0);
            junk[--k] = '\0';
        }
    }

    save1 = comm_bits;
    save2 = parity;
    save3 = stop_bits;
    comm_bits = BITS_8;
    parity = NO_PARITY;
    stop_bits = STOP_1;
    program_baud ();
    XON_DISABLE ();

    /* If external protocol requested, call it */

    if (extern_ptr != NULL)
        do_extern ("Get", prot, junk);
    else
    {
        css_init ();
        switch (prot)
        {

#ifdef HAVE_HYDRA
        case 'H':
            hydra_init (hydra_options);
            err = hydra (NULL, NULL);
            hydra_deinit ();
            break;
#endif /* HAVE_HYDRA */

        case 'X':
        case 'Y':
            err = Xmodem_Receive_File (download_path, junk);
            break;

        case 'Z':
            err = get_Zmodem (download_path, NULL);
            break;

        default:
            err = Batch_Receive (download_path);
            break;
        }

        css_done ();
    }

    comm_bits = save1;
    parity = save2;
    stop_bits = save3;
    program_baud ();
    XON_ENABLE ();
    gong ();

    err = err == CANNOT_RECV ? FAILURE : IGNORE;
    return (err);
}

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

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