home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / b_script.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-20  |  21.5 KB  |  799 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*               This module was written by Vince Perriello                 */
  13. /*                                                                          */
  14. /*                    BinkleyTerm Script Handler Module                     */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. static int LOCALFUNC nextline (char *);
  49. static int LOCALFUNC get_line (void);
  50.  
  51. /*--------------------------------------------------------------------------*/
  52. /*   Define our current script functions for use in our dispatch table.     */
  53. /*--------------------------------------------------------------------------*/
  54.  
  55. static int LOCALFUNC script_port (void);        /* Change the current port  */
  56. static int LOCALFUNC script_upload (void);        /* Upload files             */
  57. static int LOCALFUNC script_download (void);    /* Download files           */
  58. static int LOCALFUNC script_baud (void);        /* Set our baud rate to     *
  59.                                                  * that of remote           */
  60. static int LOCALFUNC script_xmit (void);        /* transmit characters out    *
  61.                                                  * the port                 */
  62. static int LOCALFUNC script_rawxmit (void);        /* transmit characters out  *
  63.                                                  * the port (no translation)*/
  64. static int LOCALFUNC script_pattern (void);        /* define pattern to wait on*/
  65. static int LOCALFUNC script_wait (void);        /* wait for pattern         */
  66. static int LOCALFUNC script_dial (void);        /* dial the whole number    */
  67. static int LOCALFUNC script_areacode (void);    /* transmit the areacode    */
  68. static int LOCALFUNC script_phone (void);        /* transmit the phone number*/
  69. static int LOCALFUNC script_carrier (void);        /* test for carrier         */
  70. static int LOCALFUNC script_session (void);        /* Exit script w/"success"  */
  71. static int LOCALFUNC script_if (void);            /* Branch on pattern match  */
  72. static int LOCALFUNC script_goto (void);        /* Absolute branch          */
  73. static int LOCALFUNC script_timer (void);        /* Set master script timeout*/
  74. static int LOCALFUNC script_bps100 (void);        /* Send BPS/100 to remote   */
  75. static int LOCALFUNC script_break (void);        /* Send break to remote     */
  76. static int LOCALFUNC script_params (void);        /* Set comm parameters      */
  77. static int LOCALFUNC script_DOS (void);            /* Execute a DOS command    */
  78. static int LOCALFUNC script_abort (void);        /* Abort in certain hours   */
  79. static int LOCALFUNC script_noWaZOO (void);        /* No WaZOO this session    */
  80. static int LOCALFUNC script_noEMSI (void);        /* No EMSI this session only*/
  81.  
  82. struct dispatch
  83. {
  84.     char *string;
  85.     int (LOCALFUNC * fun) (void);
  86. };
  87.  
  88. static struct dispatch disp_table[] =
  89. {
  90.     {"download", script_download},
  91.     {"upload", script_upload},
  92.     {"baud", script_baud},
  93.     {"xmit", script_xmit},
  94.     {"rawxmit", script_rawxmit},
  95.     {"pattern", script_pattern},
  96.     {"wait", script_wait},
  97.     {"dial", script_dial},
  98.     {"areacode", script_areacode},
  99.     {"phone", script_phone},
  100.     {"carrier", script_carrier},
  101.     {"session", script_session},
  102.     {"if", script_if},
  103.     {"goto", script_goto},
  104.     {"timer", script_timer},
  105.     {"speed", script_bps100},
  106.     {"break", script_break},
  107.     {"comm", script_params},
  108.     {"dos", script_DOS},
  109.     {"abort", script_abort},
  110.     {"port", script_port},
  111.     {"NoWaZOO", script_noWaZOO},
  112.     {"NoEMSI", script_noEMSI},
  113.     {(char *) NULL, NULL}
  114. };
  115.  
  116. static char *script_dial_string = NULL;                /* string for 'dial'    */
  117. static char *script_phone_string = NULL;            /* string for 'phone'   */
  118. static char *script_areacode_string = "          ";    /* string for 'areacode'*/
  119.  
  120. #define PATTERNS 9
  121. #define PATSIZE 22
  122.  
  123. static char pattern[PATTERNS][PATSIZE];                /* 'wait' patterns      */
  124. static int scr_session_flag = 0;                    /* set by "session".    */
  125. static int pat_matched = -1;
  126. static char *script_function_argument;                /* function argument ptr*/
  127.  
  128. #define MAX_LABELS 50
  129. #define MAX_LAB_LEN 20
  130. static struct lab
  131. {
  132.     char name[MAX_LAB_LEN + 1];
  133.     long foffset;
  134.     int line;
  135. } labels[MAX_LABELS];
  136.  
  137. static long offset;
  138. static long script_alarm;                            /* for master timeout   */
  139. static int num_labels = 0;
  140. static int curline;
  141. static FILE *stream;
  142.  
  143. static char *temp = NULL;
  144.  
  145. int 
  146. do_script (char *phone_number)
  147. {
  148.     register int i, j, k;
  149.     register char *c, *f;
  150.     char s[64], *t;
  151.  
  152.     /*----------------------------------------------------------------------*/
  153.     /* Reset everything from possible previous use of this function.        */
  154.     /*----------------------------------------------------------------------*/
  155.  
  156.     /* Get rid of cr/lf stuff if it is there */
  157.  
  158.     if ((c = strchr (phone_number, '\r')) != NULL)
  159.         *c = '\0';
  160.     if ((c = strchr (phone_number, '\n')) != NULL)
  161.         *c = '\0';
  162.  
  163.     if (temp == NULL)
  164.         if ((temp = calloc (1, 256)) == NULL)
  165.             return (0);
  166.  
  167.     curline = 0;
  168.     pat_matched = -1;
  169.     num_labels = 0;
  170.     *script_areacode_string = '\0';                /* reset the special strings*/
  171.     script_dial_string = script_phone_string = NULL;
  172.     script_alarm = 0L;                            /* reset timeout            */
  173.     for (i = 0; i < PATTERNS; i++)
  174.     {
  175.         pattern[i][0] = 1;
  176.         pattern[i][1] = '\0';                    /* and the 'wait' patterns  */
  177.     }
  178.     scr_session_flag = 0;
  179.  
  180.     /*----------------------------------------------------------------------*/
  181.     /* Now start doing things with phone number:                            */
  182.     /*     1) construct the name of the script file into temp               */
  183.     /*     2) build script_dial_string, script_areacode_string and          */
  184.     /*        script_phone_string                                           */
  185.     /*----------------------------------------------------------------------*/
  186.  
  187.     if (script_path == NULL)
  188.         (void) strcpy (temp, BINKpath);            /* get our current path     */
  189.     else
  190.         (void) strcpy (temp, script_path);        /* Otherwise use given path */
  191.  
  192.     t = c = &temp[strlen (temp)];                /* point past paths         */
  193.     f = phone_number;                            /* then get input side      */
  194.     while (*++f != '\"')                        /* look for end of string   */
  195.     {
  196.         if ((*c++ = *f) == '\0')                /* if premature ending,     */
  197.             return (0);
  198.     }
  199.     *c = '\0';                                    /* Now we have file name    */
  200.     (void) strcpy (s, t);
  201.  
  202.     c = script_areacode_string;                    /* point to area code       */
  203.     if (*++f)                                    /* if there's anything left */
  204.     {
  205.         script_dial_string = f;                    /* dial string is remainder */
  206.  
  207.         for (i = 0; (i < 10) && (*f != '\0') && (*f != '-'); i++)
  208.             *c++ = *f++;                        /* copy it for 'areacode'   */
  209.     }
  210.     *c = '\0';                                    /* terminate areacode       */
  211.     if (*f && *f++ == '-')                        /* If more, and we got '-', */
  212.         script_phone_string = f;                /* point to phone string    */
  213.  
  214.     if (script_dial_string == NULL)                /* To make the log happy,   */
  215.         script_dial_string = "";                /* NULL => 0-length string  */
  216.  
  217.     /*----------------------------------------------------------------------*/
  218.     /* Finally open the script file and start doing some WORK.              */
  219.     /*----------------------------------------------------------------------*/
  220.  
  221.     status_line (MSG_TXT (M_DIALING_SCRIPT), script_dial_string, s);
  222.  
  223.     /* OK, let's open the file */
  224.  
  225.     if ((stream = share_fopen (temp, read_binary, DENY_WRITE)) == NULL)
  226.     {
  227.         status_line (MSG_TXT (M_NOOPEN_SCRIPT), temp);
  228.         return (0);                                /* no file, no work to do   */
  229.     }
  230.  
  231.     k = 0;                                        /* default return is "fail" */
  232.     while (nextline (NULL))                        /* Now we parse the file ...*/
  233.     {
  234.         k = 0;                                    /* default return is "fail" */
  235.         for (j = 0; (c = disp_table[j].string) != NULL; j++)
  236.         {
  237.             i = (int) strlen (c);
  238.             if (strnicmp (temp, c, (unsigned int) i) == 0)
  239.             {
  240.                 script_function_argument = temp + i + 1;
  241.                 k = (*disp_table[j].fun) ();
  242.                 break;
  243.             }
  244.         }
  245.  
  246.         if (script_alarm && timeup (script_alarm)) /* Check master timer    */
  247.         {
  248.             status_line (MSG_TXT (M_MASTER_SCRIPT_TIMER));
  249.             k = 0;
  250.         }
  251.  
  252.         if (!k || scr_session_flag)                /* get out for failure      */
  253.             break;                                /* or 'session'.            */
  254.  
  255.     }
  256.  
  257.     (void) fclose (stream);                        /* close input file         */
  258.     if (!k)
  259.     {
  260.         status_line (MSG_TXT (M_SCRIPT_FAILED), s, curline);
  261.         LOWER_DTR ();
  262.         timer (1);
  263.     }
  264.  
  265.     free (temp);
  266.     temp = NULL;
  267.  
  268.     return (k);                                    /* return success/fail      */
  269. }
  270.  
  271. static int LOCALFUNC 
  272. script_download ()
  273. {
  274.     int c = toupper (*script_function_argument);
  275.  
  276.     if (c != 'S' && c != 'Z')
  277.         return (0);
  278.  
  279.     return (Download (NULL, c, NULL));
  280. }
  281.  
  282. static int LOCALFUNC 
  283. script_upload ()
  284. {
  285.     char *p = script_function_argument;
  286.     int c = toupper (*p);
  287.  
  288.     if (c != 'S' && c != 'Z')
  289.         return (0);
  290.  
  291.     p = skip_to_blank (p);
  292.     p = skip_blanks (p);
  293.  
  294.     if (p == NULL || strlen (p) == 0)
  295.         return (0);
  296.  
  297.     return (Upload (p, c, NULL));
  298. }
  299.  
  300. static int LOCALFUNC 
  301. script_xmit ()
  302. {
  303.     mdm_cmd_string (script_function_argument, 1);
  304.     return (1);
  305. }
  306.  
  307. static int LOCALFUNC 
  308. script_rawxmit ()
  309. {
  310.     char *p;
  311.  
  312.     p = script_function_argument;
  313.  
  314.     while (*p)
  315.     {
  316.         SENDBYTE ((unsigned char) *p);
  317.         ++p;
  318.     }
  319.     return (1);
  320. }
  321.  
  322. static int LOCALFUNC 
  323. script_DOS ()
  324. {
  325.     close_up ();
  326.     vfossil_cursor (1);
  327.     b_spawn (script_function_argument);
  328.     come_back ();
  329.     return (1);
  330. }
  331.  
  332. static int LOCALFUNC 
  333. script_abort ()
  334. {
  335.     time_t long_time;
  336.     struct tm *tm;
  337.  
  338.     int s1, s2, e1, e2;
  339.     int starttime, endtime, us;
  340.  
  341.     /* If we don't get everything we need, it is a true abort */
  342.  
  343.     if (sscanf (script_function_argument, "%d:%d %d:%d", &s1, &s2, &e1, &e2) != 4)
  344.         return (0);
  345.  
  346.     /* Get the current time into a structure */
  347.  
  348.     (void) time (&long_time);
  349.     tm = localtime (&long_time);
  350.  
  351.     starttime = s1 * 60 + s2;
  352.     endtime = e1 * 60 + e2;
  353.     us = tm->tm_hour * 60 + tm->tm_min;
  354.  
  355.     if (endtime < starttime)
  356.     {
  357.         endtime += 60 * 60;
  358.     }
  359.  
  360.     if (us < starttime)
  361.     {
  362.         us += 24 * 60;
  363.     }
  364.  
  365.     if ((us >= starttime) && (us <= endtime))
  366.     {
  367.         return (0);
  368.     }
  369.  
  370.     return (1);
  371. }
  372.  
  373. static int LOCALFUNC 
  374. script_break ()
  375. {
  376.     int t;
  377.  
  378.     t = atoi (script_function_argument);
  379.     if (t == 0)
  380.         t = 100;
  381.  
  382.     if (old_fossil)
  383.     {
  384.         status_line (MSG_TXT (M_NO_BREAK));
  385.     }
  386.     else
  387.     {
  388.         send_break (t);
  389.     }
  390.     return (1);
  391. }
  392.  
  393. static int LOCALFUNC 
  394. script_params ()
  395. {
  396.     char c;
  397.     int i, j;
  398.  
  399.     (void) sscanf (script_function_argument, "%d%c%d", &i, &c, &j);
  400.     comm_bits = (i == 7) ? BITS_7 : BITS_8;
  401.     switch (toupper (c))
  402.     {
  403.     case 'E':
  404.         parity = EVEN_PARITY;
  405.         break;
  406.  
  407.     case 'O':
  408.         parity = ODD_PARITY;
  409.         break;
  410.  
  411.     case 'N':
  412.         parity = NO_PARITY;
  413.         break;
  414.     }
  415.     stop_bits = (j == 1) ? STOP_1 : STOP_2;
  416.     program_baud ();
  417.     return (1);
  418. }
  419.  
  420. static int LOCALFUNC 
  421. script_bps100 ()
  422. {
  423.     char rgchT[10];
  424.  
  425.     (void) sprintf (rgchT, "%ld", cur_baud.rate_value / 100L);
  426.     mdm_cmd_string (rgchT, 0);
  427.     return (1);
  428. }
  429.  
  430. static int LOCALFUNC 
  431. script_areacode ()
  432. {
  433.     mdm_cmd_string (script_areacode_string, 0);
  434.     return (1);
  435. }
  436.  
  437. static int LOCALFUNC 
  438. script_phone ()
  439. {
  440.     mdm_cmd_string (script_phone_string, 0);
  441.     return (1);
  442. }
  443.  
  444. static int LOCALFUNC 
  445. script_dial ()
  446. {
  447.     mdm_cmd_string (script_dial_string, 0);
  448.     mdm_cmd_char (CR);                            /* terminate the string     */
  449.     if (modem_response (7500) == 2)                /* we got a good response,  */
  450.     {
  451.         timer (20);                                /* wait for other side      */
  452.         return (1);                                /* Carrier should be on now */
  453.     }
  454.     return (0);                                    /* no good */
  455. }
  456.  
  457. static int LOCALFUNC 
  458. script_carrier ()
  459. {
  460.     return ((int) CARRIER);
  461. }
  462.  
  463. static int LOCALFUNC 
  464. script_session ()
  465. {
  466.     ++scr_session_flag;                            /* signal end of script     */
  467.     return (1);
  468. }
  469.  
  470. static int LOCALFUNC 
  471. script_pattern ()
  472. {
  473.     register int i, j;
  474.     register char *c;
  475.  
  476.     c = script_function_argument;                /* copy the pointer   */
  477.     i = atoi (c);                                /* get pattern number */
  478.     if (i < 0 || i >= PATTERNS)                    /* check bounds       */
  479.         return (0);
  480.     c += 2;                                        /* skip digit, space  */
  481.     for (j = 1; (j <= PATSIZE) && (*c != '\0'); j++)
  482.         pattern[i][j] = *c++;                    /* store the pattern  */
  483.     pattern[i][j] = '\0';                        /* terminate it here  */
  484.     return (1);
  485. }
  486.  
  487. static int LOCALFUNC 
  488. script_wait ()
  489. {
  490.     long t1;
  491.     register int i, j;
  492.     register char c;
  493.     int cnt;
  494.     unsigned int iWaitT;
  495.     int got_it = 0;
  496.  
  497.     pat_matched = -1;
  498.  
  499.     /* try to get wait length */
  500.  
  501.     iWaitT = (unsigned int) (100 * atoi (script_function_argument));
  502.     if (!iWaitT)
  503.         iWaitT = 4000;                            /* default is 40 seconds    */
  504.     t1 = timerset (iWaitT);
  505.     (void) printf ("\n");
  506.     clear_eol ();
  507.     cnt = 0;
  508.     while (!timeup (t1) && !KEYPRESS ())
  509.     {
  510.         if (script_alarm && timeup (script_alarm)) /* Check master timer    */
  511.             break;                                /* Oops, out of time...     */
  512.  
  513.         if (!CHAR_AVAIL ())                        /* if nothing ready yet,    */
  514.         {
  515.             time_release ();                    /* give others a shot       */
  516.             continue;                            /* just process timeouts    */
  517.         }
  518.  
  519.         t1 = timerset (iWaitT);                    /* reset the timeout        */
  520.         c = (char) MODEM_IN ();                    /* get a character          */
  521.         if (!c)
  522.             continue;                            /* ignore null characters   */
  523.         if (c >= ' ')
  524.         {
  525.             WRITE_ANSI ((byte) (c & 0x7f));
  526.             if (++cnt >= (int) SB_COLS - 10)
  527.             {
  528.                 cnt = 0;
  529.                 (void) printf ("\r");
  530.                 clear_eol ();
  531.                 (void) printf ("(cont): ");
  532.             }
  533.         }
  534.         for (i = 0; i < PATTERNS; i++)
  535.         {
  536.             j = pattern[i][0];                    /* points to next match char*/
  537.             if (c == pattern[i][j])                /* if it matches,           */
  538.             {
  539.                 ++j;                            /* bump the pointer         */
  540.                 pattern[i][0] = (char) j;        /* store it                 */
  541.                 if (!pattern[i][j])                /* if at the end of pattern,*/
  542.                 {
  543.                     ++got_it;
  544.                     pat_matched = i;
  545.                     goto done;
  546.                 }
  547.             }
  548.             else
  549.             {
  550.                 pattern[i][0] = 1;                /* back to start of string  */
  551.             }
  552.         }
  553.     }
  554.  
  555. done:
  556.  
  557.     for (i = 0; i < PATTERNS; i++)
  558.     {
  559.         pattern[i][0] = 1;                        /* reset these for next time*/
  560.     }
  561.  
  562.     if (!got_it)                                /* timed out,look for label */
  563.     {
  564.         /* First skip over the numeric argument for "wait" */
  565.  
  566.         while (isdigit (*script_function_argument))
  567.             script_function_argument++;
  568.  
  569.         /* Then skip over any spaces that follow it */
  570.  
  571.         while (isspace (*script_function_argument))
  572.             script_function_argument++;
  573.  
  574.         /* Now, if there's anything more, treat it as a goto */
  575.  
  576.         if (*script_function_argument)
  577.             return (script_goto ());
  578.     }
  579.     return (got_it);
  580. }
  581.  
  582. static int LOCALFUNC 
  583. script_baud ()
  584. {
  585.     unsigned long b;
  586.  
  587.     if ((b = (unsigned long) atol (script_function_argument)) != 0)
  588.     {
  589.         return set_baud (b, 0);
  590.     }
  591.     return (1);
  592. }
  593.  
  594. static int LOCALFUNC 
  595. script_goto ()
  596. {
  597.     int i;
  598.  
  599.     /* First see if we already found this guy */
  600.  
  601.     for (i = 0; i < num_labels; i++)
  602.     {
  603.         if (stricmp (script_function_argument, labels[i].name) == 0)
  604.         {
  605.             /* We found it */
  606.  
  607.             (void) fseek (stream, labels[i].foffset, SEEK_SET);
  608.             curline = labels[i].line;
  609.             return (1);
  610.         }
  611.     }
  612.  
  613.     return (nextline (script_function_argument));
  614. }
  615.  
  616. static int LOCALFUNC 
  617. script_if ()
  618. {
  619.  
  620.     /* First, move past any spaces that might be between IF and value.  */
  621.  
  622.     while (isspace (*script_function_argument) && (*script_function_argument))
  623.         ++script_function_argument;
  624.  
  625.    /* Then check for digit. Only current legal non-digit is 'B' but     *
  626.     * that might change with time...                                    *
  627.     *                                                                   *
  628.     * If it's a non-digit,                                              *
  629.     *                                                                   *
  630.     *    a) look for "BPS". If not, return error.                       *
  631.     *                                                                   *
  632.     *    b) compare current baud with number that should follow         *
  633.     *       "BPS". If no match, return error.                           *
  634.     *                                                                   *
  635.     * If it's a digit, compare the number of the last pattern we matched*
  636.     * with the argument value. If no match, return error.               *
  637.     *                                                                   */
  638.  
  639.     if (!isdigit (*script_function_argument))
  640.     {
  641.         if (strnicmp (script_function_argument, "BPS", 3) != 0)
  642.             return (1);
  643.  
  644.         script_function_argument += 3;
  645.         if (atol (script_function_argument) != (long) cur_baud.rate_value)
  646.             return (1);
  647.     }
  648.  
  649.     else if (atoi (script_function_argument) != pat_matched)
  650.         return (1);
  651.  
  652.     /* We matched, skip the pattern number and the space                */
  653.  
  654.     while ((*script_function_argument) &&
  655.         (!isspace (*script_function_argument)))
  656.         ++script_function_argument;
  657.  
  658.     while (isspace (*script_function_argument))
  659.         ++script_function_argument;
  660.  
  661.     return (script_goto ());
  662. }
  663.  
  664. static int LOCALFUNC 
  665. script_timer ()                    /* Set a master timer */
  666. {
  667.     int i;
  668.  
  669.    /*
  670.     * If we got a number, set the master timer. Note: this could be
  671.     * done many times in the script, allowing you to program timeouts
  672.     * on individual parts of the script.
  673.     */
  674.  
  675.     i = atoi (script_function_argument);
  676.     if (i)
  677.         script_alarm = timerset ((unsigned int) (i * 100));
  678.  
  679.     return (1);
  680. }
  681.  
  682. static int LOCALFUNC 
  683. script_port ()
  684. {
  685.     int c;
  686.  
  687.     c = port_ptr;
  688.     MDM_DISABLE ();
  689.     port_ptr = atoi (script_function_argument) - 1;
  690.     if (Cominit (port_ptr, buftmo) != 0x1954)
  691.     {
  692.         port_ptr = c;
  693.         (void) Cominit (port_ptr, buftmo);
  694.         return (0);
  695.     }
  696.     program_baud ();
  697.     RAISE_DTR ();
  698.     return (1);
  699. }
  700.  
  701. static int LOCALFUNC 
  702. script_noWaZOO ()
  703. {
  704.     ++no_WaZOO_Session;
  705.     return (1);
  706. }
  707.  
  708. static int LOCALFUNC 
  709. script_noEMSI ()
  710. {
  711.     ++no_EMSI_Session;
  712.     return (1);
  713. }
  714.  
  715. static int LOCALFUNC 
  716. nextline (char *str)
  717. {
  718.     char save[256];
  719.  
  720.     if (str != NULL)
  721.         (void) strcpy (save, str);
  722.     else
  723.         save[0] = '\0';
  724.  
  725.     while (get_line ())            /* Now we parse the file ... */
  726.     {
  727.         if (!isalpha (temp[0]))
  728.         {
  729.             if (temp[0] != ':')
  730.             {
  731.                 /* This line is a comment line */
  732.                 continue;
  733.             }
  734.             else
  735.             {
  736.                 /* It is a label */
  737.                 if (num_labels >= MAX_LABELS)
  738.                 {
  739.                     status_line (MSG_TXT (M_TOO_MANY_LABELS));
  740.                     return (0);
  741.                 }
  742.                 (void) strcpy (labels[num_labels].name, &(temp[1]));
  743.                 labels[num_labels].foffset = offset;
  744.                 labels[num_labels].line = curline;
  745.                 ++num_labels;
  746.  
  747.                 if (stricmp (&temp[1], save))
  748.                 {
  749.                     continue;
  750.                 }
  751.                 else
  752.                 {
  753.                     return (1);
  754.                 }
  755.             }
  756.         }
  757.  
  758.         if (!save[0])
  759.             return (1);
  760.     }
  761.  
  762.     return (0);
  763. }
  764.  
  765. static int LOCALFUNC 
  766. get_line ()
  767. {
  768.     char *c;
  769.     char j[100];
  770.  
  771.     if (fgets (temp, 255, stream) == NULL)
  772.         return (0);
  773.  
  774.     ++curline;
  775.  
  776.     /* Deal with side effects of opening the script file in binary mode  */
  777.  
  778.     c = &temp[strlen (temp) - 1];
  779.     while ((*c == '\r') || (*c == '\n'))
  780.         c--;
  781.  
  782.     *++c = '\0';            /* Don't want newlines, terminate after text */
  783.  
  784.     (void) sprintf (j, script_line, curline, temp);
  785.     if ((un_attended || doing_poll) && fullscreen)
  786.     {
  787.         sb_move (filewin, 2, 2);
  788.         sb_puts (filewin, j);
  789.         sb_show ();
  790.     }
  791.     else
  792.     {
  793.         (void) printf ("\n%s", j);
  794.     }
  795.     offset = ftell (stream);
  796.     return (1);
  797. }
  798.  
  799.