download b_script.cpp
Language: C++
Copyright: Copyright 1987-96, Bit Bucket Software Co.
LOC: 568
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
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*---------------------------------------------------------------------------*
 *
 *                               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_script.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 Script Handler Module
 *
 *---------------------------------------------------------------------------*/

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

#include "includes.h"

static int LOCALFUNC nextline (char *);
static int LOCALFUNC get_line (void);

/*--------------------------------------------------------------------------*/
/*   Define our current script functions for use in our dispatch table.     */
/*--------------------------------------------------------------------------*/

static int LOCALFUNC script_port (void);  /* Change the current port  */
static int LOCALFUNC script_upload (void);  /* Upload files             */
static int LOCALFUNC script_download (void);  /* Download files           */
static int LOCALFUNC script_baud (void);  /* Set our baud rate to     *

                                           * that of remote           */
static int LOCALFUNC script_xmit (void);  /* transmit characters out  *

                                           * the port                 */
static int LOCALFUNC script_rawxmit (void);  /* transmit characters out  *

                                              * the port (no translation)*/
static int LOCALFUNC script_pattern (void);  /* define pattern to wait on */
static int LOCALFUNC script_wait (void);  /* wait for pattern         */
static int LOCALFUNC script_dial (void);  /* dial the whole number    */
static int LOCALFUNC script_areacode (void);  /* transmit the areacode    */
static int LOCALFUNC script_phone (void);  /* transmit the phone number */
static int LOCALFUNC script_carrier (void);  /* test for carrier         */
static int LOCALFUNC script_session (void);  /* Exit script w/"success"  */
static int LOCALFUNC script_if (void);  /* Branch on pattern match  */
static int LOCALFUNC script_goto (void);  /* Absolute branch          */
static int LOCALFUNC script_timer (void);  /* Set master script timeout */
static int LOCALFUNC script_bps100 (void);  /* Send BPS/100 to remote   */
static int LOCALFUNC script_break (void);  /* Send break to remote     */
static int LOCALFUNC script_params (void);  /* Set comm parameters      */
static int LOCALFUNC script_DOS (void);  /* Execute a DOS command    */
static int LOCALFUNC script_abort (void);  /* Abort in certain hours   */
static int LOCALFUNC script_noWaZOO (void);  /* No WaZOO this session    */
static int LOCALFUNC script_noEMSI (void);  /* No EMSI this session only */

struct dispatch
{
    char *string;
    int (LOCALFUNC * fun) (void);
};

static struct dispatch disp_table[] =
    {
        {"download", script_download},
        {"upload", script_upload},
        {"baud", script_baud},
        {"xmit", script_xmit},
        {"rawxmit", script_rawxmit},
        {"pattern", script_pattern},
        {"wait", script_wait},
        {"dial", script_dial},
        {"areacode", script_areacode},
        {"phone", script_phone},
        {"carrier", script_carrier},
        {"session", script_session},
        {"if", script_if},
        {"goto", script_goto},
        {"timer", script_timer},
        {"speed", script_bps100},
        {"break", script_break},
        {"comm", script_params},
        {"dos", script_DOS},
        {"abort", script_abort},
        {"port", script_port},
        {"nowazoo", script_noWaZOO},
        {"noemsi", script_noEMSI},
        {(char *) NULL, NULL}
    };

static char *script_dial_string = NULL;  /* string for 'dial'    */
static char *script_phone_string = NULL;  /* string for 'phone'   */
static char *script_areacode_string = "          ";  /* string for 'areacode' */

#define PATTERNS 9
#define PATSIZE 22

static char pattern[PATTERNS][PATSIZE];  /* 'wait' patterns      */
static int scr_session_flag = 0;  /* set by "session".    */
static int pat_matched = -1;
static char *script_function_argument;  /* function argument ptr */

#define MAX_LABELS 50
#define MAX_LAB_LEN 20
typedef struct                  /* TJW 960526 don't do this STATIC, 1.6KB mem! */
{
    char name[MAX_LAB_LEN + 1];
    long foffset;
    int line;
}
LABELENTRY;
typedef LABELENTRY LABELTAB[MAX_LABELS];

static LABELENTRY *labels = NULL;  /* TJW 960526 static -> heap */

static long offset;
static long script_alarm;       /* for master timeout   */
static int num_labels = 0;
static int curline;
static FILE *stream;

static char *temp = NULL;

int
do_script (char *phone_number)
{
    register int i, j, retval;
    register char *c, *f;
    char s[64], *t;

    /* ---------------------------------------------------------------------- */
    /* Reset everything from possible previous use of this function.          */
    /* ---------------------------------------------------------------------- */

    /* Get rid of cr/lf stuff if it is there */

    if ((c = strchr (phone_number, '\r')) != NULL)
        *c = '\0';
    if ((c = strchr (phone_number, '\n')) != NULL)
        *c = '\0';

    if (labels == NULL)           /* TJW 960526 */
        if ((labels = (LABELENTRY *) calloc (MAX_LABELS, sizeof (LABELENTRY))) == NULL)
            return (FAILURE);

    if (temp == NULL)
        if ((temp = (char*)calloc (1, 256)) == NULL)
            return (FAILURE);

    curline = 0;
    pat_matched = -1;
    num_labels = 0;
    *script_areacode_string = '\0';  /* reset the special strings */
    script_dial_string = script_phone_string = NULL;
    script_alarm = 0L;            /* reset timeout            */

    for (i = 0; i < PATTERNS; i++)
    {
        pattern[i][0] = 1;
        pattern[i][1] = '\0';       /* and the 'wait' patterns  */
    }

    scr_session_flag = 0;

    /* ---------------------------------------------------------------------- */
    /* Now start doing things with phone number:                              */
    /*     1) construct the name of the script file into temp                 */
    /*     2) build script_dial_string, script_areacode_string and            */
    /*        script_phone_string                                             */
    /* ---------------------------------------------------------------------- */

    if (script_path == NULL)
        strcpy (temp, BINKpath);    /* get our current path     */
    else
        strcpy (temp, script_path); /* Otherwise use given path */

    t = c = &temp[strlen (temp)]; /* point past paths         */
    f = phone_number;             /* then get input side      */

    while (*++f != '\"')          /* look for end of string   */
    {
        if ((*c++ = *f) == '\0')    /* if premature ending,     */
            return (FAILURE);
    }

    *c = '\0';                    /* Now we have file name    */
    strcpy (s, t);

    c = script_areacode_string;   /* point to area code       */
    if (*++f)                     /* if there's anything left */
    {
        script_dial_string = f;     /* dial string is remainder */

        for (i = 0; (i < 10) && (*f != '\0') && (*f != '-'); i++)
            *c++ = *f++;              /* copy it for 'areacode'   */
    }

    *c = '\0';                    /* terminate areacode       */
    if (*f && *f++ == '-')        /* If more, and we got '-', */
        script_phone_string = f;    /* point to phone string    */

    if (script_dial_string == NULL)  /* To make the log happy,   */
        script_dial_string = "";    /* NULL => 0-length string  */

    /* ---------------------------------------------------------------------- */
    /* Finally open the script file and start doing some WORK.                */
    /* ---------------------------------------------------------------------- */

    status_line (MSG_TXT (M_DIALING_SCRIPT), script_dial_string, s);

    /* OK, let's open the file */

    if ((stream = share_fopen (temp, read_binary, DENY_WRITE)) == NULL)
    {
        status_line (MSG_TXT (M_NOOPEN_SCRIPT), temp);
        return (FAILURE);           /* no file, no work to do   */
    }

    retval = FAILURE;             /* default return is "fail" */
    while (nextline (NULL))       /* Now we parse the file ... */
    {
        retval = FAILURE;           /* default return is "fail" */
        for (j = 0; (c = disp_table[j].string) != NULL; j++)
        {
            i = (int) strlen (c);
            if (strnicmp (temp, c, (unsigned int) i) == 0)
            {
                script_function_argument = temp + i + 1;
                retval = (*disp_table[j].fun) ();
                break;
            }
        }

        if (script_alarm && longtimeup (script_alarm))  /* Check master timer    */
        {
            status_line (MSG_TXT (M_MASTER_SCRIPT_TIMER));
            retval = FAILURE;
        }

        if (retval == FAILURE || scr_session_flag)  /* get out for failure    */
            break;                    /* or 'session'.           */

    }

    fclose (stream);              /* close input file         */

    if (retval == FAILURE)
    {
        status_line (MSG_TXT (M_SCRIPT_FAILED), s, curline);
        modem_hangup ();
    }

    free (temp);
    temp = NULL;

    free (labels);                /* TJW 960526 */
    labels = NULL;

    return (retval);              /* return success/fail      */
}

static int LOCALFUNC
script_download ()
{
    int c = toupper (*script_function_argument);

    switch (c)
    {
    case 'S':
    case 'X':
    case 'Z':
    case 'H':
        return (Download (NULL, c, NULL));

    default:
        break;
    }
    return (FAILURE);
}

static int LOCALFUNC
script_upload ()
{
    char *p = script_function_argument;
    int c = toupper (*p);

    switch (c)
    {
    case 'S':
    case 'X':
    case 'Z':
    case 'H':
        break;

    default:
        return (FAILURE);
    }

    p = skip_to_blank (p);
    p = skip_blanks (p);

    if (p == NULL || strlen (p) == 0)
        return (FAILURE);

    return (Upload (p, c, NULL));
}

static int LOCALFUNC
script_xmit ()
{
    mdm_cmd_string (script_function_argument, 1);
    return (IGNORE);
}

static int LOCALFUNC
script_rawxmit ()
{
    char *p;

    p = script_function_argument;

    while (*p)
    {
        SENDBYTE ((unsigned char) *p);
        ++p;
    }

    return (IGNORE);
}

static int LOCALFUNC
script_DOS ()
{
    vfossil_cursor (1);
    close_up (share);
    b_spawn (script_function_argument);
    come_back ();
    return (IGNORE);
}

static int LOCALFUNC
script_abort ()
{
    time_t long_time;
    struct tm *tm;

    int s1, s2, e1, e2;
    int starttime, endtime, us;

    /* If we don't get everything we need, it is a true abort */

    if (sscanf (script_function_argument, "%d:%d %d:%d", &s1, &s2, &e1, &e2) != 4)
        return (FAILURE);

    /* Get the current time into a structure */

    unix_time (&long_time);
    tm = unix_localtime (&long_time);

    starttime = s1 * 60 + s2;
    endtime = e1 * 60 + e2;
    us = tm->tm_hour * 60 + tm->tm_min;

    if (endtime < starttime)
        endtime += 60 * 60;

    if (us < starttime)
        us += 24 * 60;

    if ((us >= starttime) && (us <= endtime))
        return (FAILURE);           /* "Abort in certain hours!"  (r.hoerner) */

    return (IGNORE);
}

static int LOCALFUNC
script_break ()
{
    int t;

    t = atoi (script_function_argument);
    if (t == 0)
        t = 100;

    send_break (t);
    return (IGNORE);
}

static int LOCALFUNC
script_params ()
{
    char c;
    int i, j;

    sscanf (script_function_argument, "%d%c%d", &i, &c, &j);
    comm_bits = (i == 7) ? BITS_7 : BITS_8;
    switch (toupper (c))
    {
    case 'E':
        parity = EVEN_PARITY;
        break;

    case 'O':
        parity = ODD_PARITY;
        break;

    case 'N':
        parity = NO_PARITY;
        break;
    }

    stop_bits = (j == 1) ? STOP_1 : STOP_2;
    program_baud ();
    return (IGNORE);
}

static int LOCALFUNC
script_bps100 ()
{
    char rgchT[10];

    sprintf (rgchT, "%ld", cur_baud.rate_value / 100L);
    mdm_cmd_string (rgchT, 0);
    return (IGNORE);
}

static int LOCALFUNC
script_areacode ()
{
    mdm_cmd_string (script_areacode_string, 0);
    return (IGNORE);
}

static int LOCALFUNC
script_phone ()
{
    mdm_cmd_string (script_phone_string, 0);
    return (IGNORE);
}

static int LOCALFUNC
script_dial ()
{
    mdm_cmd_string (script_dial_string, 0);
    mdm_cmd_char (CR);            /* terminate the string     */

    if (modem_response (7500) == CONNECTED)  /* we got a good response,  */
    {
        timer (20);                 /* wait for other side      */
        return (IGNORE);            /* Carrier should be on now */
    }

    return (FAILURE);             /* no good */
}

static int LOCALFUNC
script_carrier ()
{
    return ((int) ComIsOnline(hcModem));
}

static int LOCALFUNC
script_session ()
{
    ++scr_session_flag;           /* signal end of script     */
    return (IGNORE);
}

static int LOCALFUNC
script_pattern ()
{
    register int i, j;
    register char *c;

    c = script_function_argument; /* copy the pointer   */
    i = atoi (c);                 /* get pattern number */

    if (i < 0 || i >= PATTERNS)   /* check bounds       */
        return (FAILURE);

    c += 2;                       /* skip digit, space  */

    for (j = 1; (j <= PATSIZE) && (*c != '\0'); j++)
        pattern[i][j] = *c++;       /* store the pattern  */

    pattern[i][j] = '\0';         /* terminate it here  */
    return (IGNORE);
}

static int LOCALFUNC
script_wait ()
{
    long t1;
    long iWaitT;
    register int i, j;
    register char c;
    int cnt;
    int got_it = 0;

    pat_matched = -1;

    /* try to get wait length */

    iWaitT = atol (script_function_argument);
    if (!iWaitT)
        iWaitT = 40;                /* default is 40 seconds    */

    t1 = longtimerset (iWaitT * PER_SECOND);
    printf ("\n");
    clear_eol ();
    cnt = 0;
    while (!longtimeup (t1) && !KEYPRESS ())
    {
        if (script_alarm && longtimeup (script_alarm))  /* Check master timer */
            break;                    /* Oops, out of time...     */

        if (!CHAR_AVAIL ())         /* if nothing ready yet,    */
        {
            time_release ();          /* give others a shot       */
            continue;                 /* just process timeouts    */
        }

        t1 = longtimerset (iWaitT * PER_SECOND);  /* reset the timeout        */
        c = (char) MODEM_IN ();     /* get a character          */

        if (!c)
            continue;                 /* ignore null characters   */

        if (c >= ' ')
        {
            WRITE_ANSI ((byte) (c & 0x7f));
            if (++cnt >= (int) SB_COLS - 10)
            {
                cnt = 0;
                printf ("\r");
                clear_eol ();
                printf ("(cont): ");
            }
        }

        for (i = 0; i < PATTERNS; i++)
        {
            j = pattern[i][0];        /* points to next match char */
            if (c == pattern[i][j])   /* if it matches,           */
            {
                ++j;                    /* bump the pointer         */
                pattern[i][0] = (char) j;  /* store it                 */
                if (!pattern[i][j])     /* if at the end of pattern, */
                {
                    ++got_it;
                    pat_matched = i;
                    goto done;
                }
            }
            else
            {
                pattern[i][0] = 1;      /* back to start of string  */
            }
        }
    }

done:

    for (i = 0; i < PATTERNS; i++)
        pattern[i][0] = 1;          /* reset these for next time */

    if (!got_it)                  /* timed out,look for label */
    {
        /* First skip over the numeric argument for "wait" */

        while (isdigit (*script_function_argument))
            script_function_argument++;

        /* Then skip over any spaces that follow it */

        script_function_argument = skip_blanks (script_function_argument);

        /* Now, if there's anything more, treat it as a goto */

        if (*script_function_argument)
            return (script_goto ());
    }

    return (got_it);
}

static int LOCALFUNC
script_baud ()
{
    unsigned long b;

    if ((b = (unsigned long) atol (script_function_argument)) != 0)
        return set_baud (b, 0);

    return (IGNORE);
}

static int LOCALFUNC
script_goto ()
{
    int i;

    /* First see if we already found this guy */

    for (i = 0; i < num_labels; i++)
    {
        if (stricmp (script_function_argument, labels[i].name) == 0)
        {                           /* We found it */
            fseek (stream, labels[i].foffset, SEEK_SET);
            curline = labels[i].line;
            return (IGNORE);
        }
    }

    return (nextline (script_function_argument));
}

static int LOCALFUNC
script_if ()
{

    /* First, move past any spaces that might be between IF and value.  */

    script_function_argument = skip_blanks (script_function_argument);

    /* Then check for digit. Only current legal non-digit is 'B' but     *
     * that might change with time...                                    *
     *                                                                   *
     * If it's a non-digit,                                              *
     *                                                                   *
     *    a) look for "BPS". If not, return error.                       *
     *                                                                   *
     *    b) compare current baud with number that should follow         *
     *       "BPS". If no match, return error.                           *
     *                                                                   *
     * If it's a digit, compare the number of the last pattern we matched*
     * with the argument value. If no match, return error.               *
     *                                                                   */

    if (!isdigit (*script_function_argument))
    {
        if (strnicmp (script_function_argument, "BPS", 3) != 0)
            return (IGNORE);

        script_function_argument += 3;
        if (atol (script_function_argument) != (long) cur_baud.rate_value)
            return (IGNORE);
    }
    else if (atoi (script_function_argument) != pat_matched)
        return (IGNORE);

    /* We matched, skip the pattern number and the space                */

    script_function_argument = skip_to_blank (script_function_argument);
    script_function_argument = skip_blanks (script_function_argument);

    return (script_goto ());
}

static int LOCALFUNC
script_timer ()                 /* Set a master timer */
{
    int i;

    /* If we got a number, set the master timer. Note: this could be
     * done many times in the script, allowing you to program timeouts
     * on individual parts of the script. */

    i = atoi (script_function_argument);
    if (i)
        script_alarm = longtimerset ((long) (i * PER_SECOND));

    return (IGNORE);
}

static int LOCALFUNC
script_port ()
{
    int c;

    c = port_ptr;
    MDM_DISABLE ();
    port_ptr = atoi (script_function_argument) - 1;

    if (Cominit (port_ptr, buftmo) != 0x1954)
    {
        port_ptr = c;
        Cominit (port_ptr, buftmo);
        return (FAILURE);
    }

    program_baud ();
    RAISE_DTR ();
    return (IGNORE);
}

static int LOCALFUNC
script_noWaZOO ()
{
    no_WaZOO_Session = 1;
    return (IGNORE);
}

static int LOCALFUNC
script_noEMSI ()
{
    no_EMSI_Session = 1;
    return (IGNORE);
}

static int LOCALFUNC
nextline (char *str)
{
    char save[256];

    if (str != NULL)
        strcpy (save, str);
    else
        save[0] = '\0';

    while (get_line ())           /* Now we parse the file ... */
    {
        if (!isalpha (temp[0]))
        {
            if (temp[0] != ':')
            {                         /* This line is a comment line */
                continue;
            }
            else
            {                         /* It is a label */
                if (num_labels >= MAX_LABELS)
                {
                    status_line (MSG_TXT (M_TOO_MANY_LABELS));
                    return (FAILURE);
                }

                strcpy (labels[num_labels].name, &(temp[1]));
                labels[num_labels].foffset = offset;
                labels[num_labels].line = curline;
                ++num_labels;

                if (stricmp (&temp[1], save))
                    continue;
                else
                    return (IGNORE);
            }
        }

        if (!save[0])
            return (IGNORE);
    }

    return (FAILURE);
}

static int LOCALFUNC
get_line ()
{
    char *c;
    char j[100];

    if (fgets (temp, 255, stream) == NULL)
        return (FAILURE);

    ++curline;

    /* Deal with side effects of opening the script file in binary mode  */

    c = &temp[strlen (temp) - 1];
    while ((*c == '\r') || (*c == '\n'))
        c--;

    *++c = '\0';                  /* Don't want newlines, terminate after text */

    sprintf (j, script_line, curline, temp);
    if (un_attended || doing_poll)
    {
        sb_move_puts (filewin, 1, 0, j);
        sb_show ();
    }
    else
        printf ("\n%s", j);

    offset = ftell (stream);
    return (IGNORE);
}

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

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