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