home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / B_RSPFIL.C < prev    next >
C/C++ Source or Header  |  1990-07-11  |  11KB  |  316 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 File Request Failure Message 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. #include <stdio.h>
  46. #include <time.h>
  47. #include <ctype.h>
  48. #include <string.h>
  49. #include <stdlib.h>
  50.  
  51. #ifdef __TURBOC__
  52. #include <mem.h>
  53. #include <alloc.h>
  54. #else
  55. #include <memory.h>
  56. #include <malloc.h>
  57. #endif
  58.  
  59. #define WAZOO_SECTION
  60. #include "com.h"
  61. #include "xfer.h"
  62. #include "zmodem.h"
  63. #include "keybd.h"
  64. #include "sbuf.h"
  65. #include "sched.h"
  66. #include "externs.h"
  67. #include "prototyp.h"
  68.  
  69. void Make_Response(char *, int);         /* Build a response      */
  70.  
  71. void Make_Response (data, failure)
  72. char *data;                             /* input = response, output = filename */
  73. int failure;                            /* failure code from file req module   */
  74. {
  75.     FILE *Template, *Response;
  76.     char *dummy_text;
  77.     char *text;
  78.     char *failure_text[10];
  79.     char resp_filename[13];
  80.     char *p, *q, *s;
  81.     struct tm *tp;
  82.     time_t ltime;
  83.     int i;
  84.  
  85.     if (Netmail_Session == 2)
  86.       {
  87.       text = strchr (data, ' ');
  88.       if (text != NULL)
  89.          *text = '\0';
  90.       }
  91.  
  92.     Template = Response = NULL;
  93.  
  94.     for (i = 0; i < 9; i++)
  95.        failure_text[i] = NULL;
  96.  
  97.     if (((text = malloc (256)) == NULL)
  98.     || ((dummy_text = malloc (256)) == NULL))
  99.        goto resp_failed;
  100.  
  101.     (void) time (<ime);
  102.     tp = localtime (<ime);
  103.     
  104.     if ((Template = fopen (CurrentReqTemplate, read_ascii)) == NULL)
  105.       {
  106.       (void) got_error (msgtxt[M_OPEN_MSG], CurrentReqTemplate);
  107.       goto resp_failed;
  108.       }
  109.  
  110.     (void) sprintf (resp_filename, "%s.RSP", Hex_Addr_Str (&(alias[assumed])));
  111.     if ((Response = fopen (resp_filename, write_binary)) == NULL)
  112.       {
  113.       (void) got_error (msgtxt[M_OPEN_MSG], resp_filename);
  114.       goto resp_failed;
  115.       }
  116.     
  117.     while (!feof (Template))
  118.        {
  119.  
  120. read_line:
  121.  
  122.        e_input[0] = '\0';
  123.        if (fgets (text, 254, Template) == NULL)
  124.           break;
  125.  
  126.        if (text[0] == '%' && text[1] == ';')
  127.           continue;                     /* Comment at start, no output */
  128.        
  129.        p = text;
  130.        q = e_input;
  131.  
  132.        while (*p)
  133.           {
  134.  
  135.           if (*p == '\n')               /* All done if newline seen    */
  136.              break;
  137.  
  138.           if (*p != '%')                /* Copy until(unless) we see % */
  139.              {
  140.              *q++ = *p++;
  141.              continue;
  142.              }
  143.              
  144.           if (*++p == ';')              /* If followed by ; just skip  */
  145.              break;
  146.  
  147.           if ((i = parse(p, rspverbs)) == -1)/* Check against arg list */
  148.              {
  149.              *q++ = '%';                /* No match, use the % literal */
  150.              continue;
  151.              }
  152.           
  153.           switch (i)
  154.           
  155.              {
  156.              
  157.              case 1:                    /* "text"                      */
  158.  
  159.              if (((i = atoi (p = skip_blanks (&p[4]))) < 1) || (i > 9))
  160.                 goto read_line; 
  161.  
  162.              if (!*(p = skip_to_blank (p)) || !*++p)
  163.                 goto read_line; 
  164.              
  165.              if (failure_text[--i] != NULL)
  166.                 free(failure_text[i]);
  167.  
  168.              failure_text[i] = s = malloc (1 + strlen (p));
  169.              if (s == NULL)
  170.                 goto read_line;
  171.              while ((*p) && (*p != '\n'))
  172.                 *s++ = *p++;
  173.              *s++ = '\0';
  174.  
  175.              goto read_line;
  176.              
  177.              case 2:                    /* "date"                      */
  178.              p += 4;
  179.              (void) sprintf (dummy_text,"%2d-%3s-%02d", tp->tm_mday, mtext[tp->tm_mon], tp->tm_year);
  180. scopy:
  181.              s = dummy_text;
  182. ccopy:
  183.              while (*s)
  184.                *q++ = *s++;
  185.              
  186.              break;
  187.              
  188.              case 3:                    /* "time"                      */
  189.              p += 4;
  190.              (void) sprintf (dummy_text, "%2d:%02d", tp->tm_hour, tp->tm_min);
  191.              goto scopy;
  192.              
  193.              case 4:                    /* "bink"                      */
  194.              p += 4;
  195.              s = ANNOUNCE;
  196.              goto ccopy;
  197.              
  198.              case 5:                    /* "mynode"                    */
  199.              p += 6;
  200.              (void) sprintf (dummy_text, "%s", Full_Addr_Str (&(alias[assumed])));
  201.              goto scopy;
  202.              
  203.              case 6:                    /* "system"                    */
  204.              p += 6;
  205.              s = system_name;
  206.              goto ccopy;
  207.              
  208.              case 7:                    /* "sysop"                     */
  209.              p += 5;
  210.              s = sysop;
  211.              goto ccopy;
  212.              
  213.              case 8:                    /* "yrnode"                    */
  214.              p += 6;
  215.              (void) sprintf (dummy_text, "%s", Full_Addr_Str (&remote_addr));
  216.              goto scopy;
  217.              
  218.              case 9:                    /* "request"                   */
  219.              p += 7;
  220.              s = data;
  221.              goto ccopy;
  222.              
  223.              case 10:                   /* "status"                    */
  224.              p += 6;
  225.              (void) strcpy (dummy_text, p);
  226.              (void) strcpy (text, failure_text [failure-1]);
  227.              (void) strcat (text, dummy_text);
  228.              p = text;
  229.              break;
  230.  
  231.              case 11:                   /* "abort"                     */
  232.  
  233.              if (*(p = skip_blanks (&p[5])))/* If there's an argument, */
  234.                 {
  235.                 if (failure != atoi (p))/* See if it matches failure   */
  236.                    goto read_line;      /* No, keep going.             */
  237.                 }
  238.  
  239.              (void) fclose (Response);         /* Abort things: Close file,   */
  240.              Response = NULL;           /* Keep track of closed file   */
  241.              (void) unlink (resp_filename);    /* Then delete it              */
  242.              goto resp_failed;          /* And take the failure exit   */
  243.  
  244.              case 12:                   /* "exit"                      */
  245.  
  246.              if (*(p = skip_blanks (&p[4])))/* If there's an argument, */
  247.                 {
  248.                 if (failure != atoi (p))/* See if it matches failure   */
  249.                    goto read_line;      /* No, keep going.             */
  250.                 }
  251.              goto resp_done;       /* A match, close the file     */
  252.  
  253.              case 13:                   /* "line"                      */
  254.  
  255.              if ((!(*(p = skip_blanks (&p[4]))))
  256.              || (failure != atoi (p)))  /* If argument doesn't match,  */
  257.                    goto read_line;      /* throw out line, keep going. */
  258.              if (*(p = skip_to_blank (p))) /* If there's any text,     */
  259.                 {
  260.                 (void) strcpy (text, ++p);     /* Copy rest of line down      */
  261.                 p = text;               /* Move pointer to front       */
  262.                 }
  263.              break;
  264.  
  265.              }          /* End switch                 */
  266.           }             /* End while *p               */
  267.  
  268.        *q++ = '\r';
  269.        *q++ = '\n';
  270.        *q = '\0';
  271.  
  272.        i = q - e_input;
  273.        (void) fwrite (e_input, (unsigned int) i, 1, Response);
  274.        }                /* End while !feof (Template) */
  275.  
  276. resp_done:
  277.  
  278.    (void) strcpy (data, resp_filename);
  279.  
  280.    (void) fclose (Template);
  281.    Template = NULL;
  282.  
  283.    (void) fclose (Response);
  284.    Response = NULL;
  285.    goto cleanup;
  286.  
  287. resp_failed:
  288.  
  289.    *data = '\0';
  290.  
  291.    if (Response != NULL)
  292.       (void) fclose (Response);
  293.  
  294.    if (Template != NULL)
  295.       (void) fclose (Template);
  296.  
  297. cleanup:
  298.  
  299.    for (i = 0; i < 9; i++)
  300.        {
  301.        if (failure_text[i] != NULL)
  302.           {
  303.           free(failure_text[i]);
  304.           failure_text[i] = NULL;
  305.           }
  306.        }
  307.  
  308.    if (text != NULL)
  309.       free (text);
  310.  
  311.    if (dummy_text != NULL)
  312.       free (dummy_text);
  313.  
  314.    return;
  315. }
  316.