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