home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / EVTPARSE.C < prev    next >
C/C++ Source or Header  |  1990-07-02  |  16KB  |  513 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 Bob Hartman                   */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                     BinkleyTerm Scheduler Routines                       */
  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 <ctype.h>
  48. #include <sys/types.h>
  49. #include <sys/stat.h>
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <process.h>
  53. #include <time.h>
  54.  
  55. #ifdef __TURBOC__
  56. #include "tc_utime.h"
  57. #include <alloc.h>
  58. #include <mem.h>
  59. #else
  60. #include <sys/utime.h>
  61. #include <malloc.h>
  62. #include <memory.h>
  63. #endif
  64.  
  65. #include "com.h"
  66. #include "xfer.h"
  67. #include "zmodem.h"
  68. #include "keybd.h"
  69. #include "sbuf.h"
  70. #include "sched.h"
  71. #include "externs.h"
  72. #include "prototyp.h"
  73.  
  74. static char *start_time (EVENT *, char *);
  75. static char *end_time (EVENT *, char *);
  76.  
  77.  
  78. static char *start_time (e, p)
  79. EVENT *e;
  80. char *p;
  81. {
  82.    int i, j, k, l, n;
  83.  
  84.    if ((n = sscanf (p, "%d:%d,%d,%d", &i, &j, &k, &l)) < 2)
  85.       {
  86.       return NULL;
  87.       }
  88.  
  89.    e->minute = i * 60 + j;
  90.    if ((e->minute < 0) || (e->minute > (24 * 60)))
  91.       {
  92.       return (NULL);
  93.       }
  94.  
  95.    if (n >= 3)
  96.       e->month = (char)k;
  97.    if (n >= 4)
  98.       e->day = (char)l;
  99.  
  100.    p = skip_to_blank (p);
  101.  
  102.    return (p);
  103. }
  104.  
  105. static char *end_time (e, p)
  106. EVENT *e;
  107. char *p;
  108. {
  109.    int i, j, k;
  110.  
  111.    if (sscanf (p, "%d:%d", &i, &j) != 2)
  112.       {
  113.       return NULL;
  114.       }
  115.  
  116.    k = i * 60 + j;
  117.    if ((k > (24 * 60)) || (k < 0))
  118.       {
  119.       return (NULL);
  120.       }
  121.  
  122.    if (k < e->minute)
  123.       {
  124.       (void) printf (msgtxt[M_NO_END_MIDNIGHT]);
  125.       return (NULL);
  126.       }
  127.  
  128.    e->length = k - e->minute;
  129.  
  130.    p = skip_to_blank (p);
  131.  
  132.    return (p);
  133. }
  134.  
  135. int parse_event (e_line)
  136. char *e_line;
  137. {
  138.    int i, j, j1, j2;
  139.    char *p, *p1;
  140.    EVENT *e;
  141.  
  142.    /* If we already have a schedule, then forget it */
  143.    if (got_sched)
  144.       return (0);
  145.  
  146.    /* Skip blanks to get to the days field */
  147.    p = skip_blanks (e_line);
  148.  
  149.    /* Parse the days field */
  150.    e = (EVENT *) calloc (sizeof (EVENT), 1);
  151.    e->days = 0;
  152.    e->wait_time = 120;
  153.    while ((*p) && (!isspace (*p)))
  154.       {
  155.       switch (toupper (*p))
  156.          {
  157.          case 'S':                              /* Sunday or Saturday */
  158.             if (!strnicmp (p, "sun", 3))
  159.                {
  160.                e->days |= DAY_SUNDAY;
  161.                }
  162.             else if (!strnicmp (p, "sat", 3))
  163.                {
  164.                e->days |= DAY_SATURDAY;
  165.                }
  166.             else /* Error condition */ 
  167.                {
  168.                goto err;
  169.                }
  170.             p += 3;
  171.             break;
  172.  
  173.          case 'M':                              /* Monday */
  174.             if (!strnicmp (p, "mon", 3))
  175.                {
  176.                e->days |= DAY_MONDAY;
  177.                }
  178.             else /* Error condition */ 
  179.                {
  180.                goto err;
  181.                }
  182.             p += 3;
  183.             break;
  184.  
  185.          case 'T':                              /* Tuesday or Thursday */
  186.             if (!strnicmp (p, "tue", 3))
  187.                {
  188.                e->days |= DAY_TUESDAY;
  189.                }
  190.             else if (!strnicmp (p, "thu", 3))
  191.                {
  192.                e->days |= DAY_THURSDAY;
  193.                }
  194.             else /* Error condition */ 
  195.                {
  196.                goto err;
  197.                }
  198.             p += 3;
  199.             break;
  200.  
  201.          case 'W':                              /* Wednesday, Week or
  202.                                                   * Weekend */
  203.             if (!strnicmp (p, "wed", 3))
  204.                {
  205.                e->days |= DAY_WEDNESDAY;
  206.                p += 3;
  207.                }
  208.             else if (!strnicmp (p, "week", 4))
  209.                {
  210.                e->days |= DAY_WEEK;
  211.                p += 4;
  212.                }
  213.             else if (!strnicmp (p, "wkend", 5))
  214.                {
  215.                e->days |= DAY_WKEND;
  216.                p += 5;
  217.                }
  218.             else /* Error condition */ 
  219.                {
  220.                goto err;
  221.                }
  222.             break;
  223.  
  224.          case 'F':                              /* Friday */
  225.             if (!strnicmp (p, "fri", 3))
  226.                {
  227.                e->days |= DAY_FRIDAY;
  228.                }
  229.             else /* Error condition */ 
  230.                {
  231.                goto err;
  232.                }
  233.             p += 3;
  234.             break;
  235.  
  236.          case 'A':                              /* All */
  237.             if (!strnicmp (p, "all", 3))
  238.                {
  239.                e->days |= (DAY_WEEK | DAY_WKEND);
  240.                }
  241.             else /* Error condition */ 
  242.                {
  243.                goto err;
  244.                }
  245.             p += 3;
  246.             break;
  247.  
  248.          default:                               /* Error condition */
  249.             goto err;
  250.          }
  251.  
  252.       if (*p == '|')
  253.          ++p;
  254.       }
  255.  
  256.    /* Did we get something valid? */
  257.    if (e->days == 0)
  258.       {
  259.       goto err;
  260.       }
  261.  
  262.    /* Skip blanks to get to the start-time field */
  263.    p = skip_blanks (p);
  264.  
  265.    /* Parse the start-time field */
  266.    if ((p = start_time (e, p)) == NULL)
  267.       {
  268.       (void) printf (msgtxt[M_INVALID_START], e_line);
  269.       free (e);
  270.       return (1);
  271.       }
  272.  
  273.    /* Give each event a default of 60 minutes */
  274.    e->length = 60;
  275.  
  276.    /* Give each event a local cost of 0 */
  277.    e->node_cost = 0;
  278.  
  279.    /* Give each event a default of T=3,10000 */
  280.    e->with_connect = 3;
  281.    e->no_connect = 10000;
  282.  
  283.    /* While there are still things on the line */
  284.    while (*p)
  285.       {
  286.       /* Skip blanks to get to the next field */
  287.       p = skip_blanks (p);
  288.  
  289.       /* switch to find what thing is being parsed */
  290.       switch (tolower (*p))
  291.          {
  292.          case '\0':                             /* No more stuff */
  293.             break;
  294.  
  295.          case '0':                              /* Digits must be an ending
  296.                                                   * time */
  297.          case '1':
  298.          case '2':
  299.          case '3':
  300.          case '4':
  301.          case '5':
  302.          case '6':
  303.          case '7':
  304.          case '8':
  305.          case '9':
  306.             /* Parse ending time */
  307.             if ((p = end_time (e, p)) == NULL)
  308.                {
  309.                (void) printf (msgtxt[M_INVALID_END], e_line);
  310.                free (e);
  311.                return (1);
  312.                }
  313.             break;
  314.  
  315.          case ';':                              /* Comment */
  316.          case '%':
  317.             *p = '\0';
  318.             break;
  319.  
  320.          case '"':                              /* Extra chars to append to
  321.                                                   * packer strings */
  322.             ++p;
  323.             p1 = e->cmd;
  324.             *p1++ = ' ';
  325.             while (*p != '"')
  326.                *p1++ = *p++;
  327.             *p1 = '\0';
  328.             ++p;
  329.             break;
  330.  
  331.          case 'a':                              /* Average wait */
  332.             ++p;
  333.             if (*p == '=')
  334.                {
  335.                ++p;
  336.                if (isdigit (*p))
  337.                   {
  338.                   i = atoi (p);
  339.                   if ((i > 1800) || (i < 0))
  340.                      {
  341.                      (void) printf (msgtxt[M_INVALID_AVGWAIT], e_line);
  342.                      free (e);
  343.                      return (1);
  344.                      }
  345.                   e->wait_time = i;
  346.                   p = skip_to_blank (p);
  347.                   break;
  348.                   }
  349.                }
  350.             (void) printf (msgtxt[M_INVALID_AVGWAIT], e_line);
  351.             free (e);
  352.             return (1);
  353.  
  354.          case 'b':                              /* BBS type event */
  355.             p = skip_to_blank (p);
  356.             e->behavior |= MAT_BBS;
  357.             break;
  358.  
  359.          case 'c':                              /* #CM event */
  360.             p = skip_to_blank (p);
  361.             e->behavior |= MAT_CM;
  362.             break;
  363.  
  364.          case 'd':                              /* Dynamic event */
  365.             p = skip_to_blank (p);
  366.             e->behavior |= MAT_DYNAM;
  367.             break;
  368.  
  369.          case 'e':                              /* An errorlevel exit */
  370.             ++p;
  371.             if (isdigit (*p))
  372.                {
  373.                i = *p - '0';
  374.                ++p;
  375.                if (*p == '=')
  376.                   {
  377.                   if ((i <= 3) && (i > 0))
  378.                      {
  379.                      ++p;
  380.                      if (isdigit (*p))
  381.                         {
  382.                         j = atoi (p);
  383.                         e->errlevel[i - 1] = j;
  384.                         p = skip_to_blank (p);
  385.                         break;
  386.                         }
  387.                      }
  388.                   else if ((i > 3) && (i <= 9))
  389.                      {
  390.                      ++p;
  391.                      if (isdigit (*p))
  392.                         {
  393.                         j = atoi (p);
  394.                         e->errlevel[i - 1] = j;
  395.                         while (*p && (*p != ','))
  396.                            ++p;
  397.                         ++p;
  398.                         (void) strncpy (&(e->err_extent[i - 4][0]), p, 3);
  399.                         p = skip_to_blank (p);
  400.                         break;
  401.                         }
  402.                      }
  403.                   }
  404.                }
  405.             (void) printf (msgtxt[M_BAD_ERRORLEVEL], e_line);
  406.             free (e);
  407.             return (1);
  408.  
  409.          case 'f':                              /* Forced event */
  410.             p = skip_to_blank (p);
  411.             e->behavior |= MAT_FORCED;
  412.             break;
  413.  
  414.          case 'k':                              /* no #CM event */
  415.             p = skip_to_blank (p);
  416.             e->behavior |= MAT_NOCM;
  417.             break;
  418.  
  419.          case 'l':                              /* Local only mail */
  420.             ++p;
  421.             e->node_cost = 0;
  422.             if (*p == '=')
  423.                {
  424.                ++p;
  425.                if (isdigit (*p))
  426.                   {
  427.                   e->node_cost = atoi (p);
  428.                   }
  429.                }
  430.             else if (*p == '>')
  431.                {
  432.                ++p;
  433.                if (isdigit (*p))
  434.                   {
  435.                   e->node_cost = -atoi (p) - 1;
  436.                   }
  437.                }
  438.             else if (*p == '<')
  439.                {
  440.                ++p;
  441.                if (isdigit (*p))
  442.                   {
  443.                   e->node_cost = atoi (p) - 1;
  444.                   }
  445.                }
  446.             p = skip_to_blank (p);
  447.             e->behavior |= MAT_LOCAL;
  448.             break;
  449.  
  450.          case 'm':                              /* Mailable 24 hours */
  451.             p = skip_to_blank (p);
  452.             e->behavior |= MAT_NOMAIL24;
  453.             break;
  454.  
  455.          case 'n':                              /* No requests */
  456.             p = skip_to_blank (p);
  457.             e->behavior |= MAT_NOREQ;
  458.             break;
  459.  
  460.          case 'r':                              /* Receive only */
  461.             p = skip_to_blank (p);
  462.             e->behavior |= MAT_NOOUT;
  463.             break;
  464.  
  465.          case 's':                              /* Send only */
  466.             p = skip_to_blank (p);
  467.             e->behavior |= MAT_OUTONLY;
  468.             break;
  469.  
  470.          case 't':                              /* Tries */
  471.             ++p;
  472.             if (sscanf (p, "=%d,%d", &j1, &j2) != 2)
  473.                {
  474.                (void) printf (msgtxt[M_BAD_TRIES], e_line);
  475.                return (1);
  476.                }
  477.             else
  478.                {
  479.                if ((j1 > 8) || (j1 < 1))
  480.                   {
  481.                   (void) printf (msgtxt[M_BAD_TRIES], e_line);
  482.                   return (1);
  483.                   }
  484.                e->with_connect = j1;
  485.                e->no_connect = j2;
  486.                }
  487.             p = skip_to_blank (p);
  488.             break;
  489.  
  490.          case 'x':                              /* No outbound requests here */
  491.             p = skip_to_blank (p);
  492.             e->behavior |= MAT_NOOUTREQ;
  493.             break;
  494.  
  495.          default:                               /* Error condition */
  496.             (void) printf (msgtxt[M_INDECIPHERABLE], e_line);
  497.             free (e);
  498.             return (1);
  499.          }
  500.       }
  501.  
  502.    /* Save it in the array  of pointers */
  503.    e_ptrs[num_events++] = e;
  504.  
  505.    /* Return that everything is cool */
  506.    return (0);
  507.  
  508. err:
  509.    (void) printf (msgtxt[M_BAD_DAY], e_line);
  510.    free (e);
  511.    return (1);
  512. }
  513.