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

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                 This module was written by Bob Hartman                   */
  13. /*                                                                          */
  14. /*                 BinkleyTerm FTSC Mail Session Routines                   */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. int 
  49. Whack_CR ()
  50. {
  51.     long t1, t2;
  52.     unsigned char j;
  53.     char fGotAChar;                /* When set we have gotten at least 1 char */
  54.     char fDoingALine;            /* When set we're in middle of line        */
  55.     char fDidALine;                /* When set we've already gotten 1 CR      */
  56.     int k, l;
  57.     unsigned short i;
  58.     char buf[180];
  59.  
  60.     t1 = timerset (3000);        /* set 30 second timeout */
  61.     j = CR;
  62.     (void) strcpy (buf, MSG_TXT (M_INTRO));
  63.     l = (int) strlen (buf);
  64.     fGotAChar = fDoingALine = fDidALine = 0;
  65.     k = 2;
  66.     while (!timeup (t1) && CARRIER)    /* till then or CD lost  */
  67.     {
  68.         time_release ();        /*PLF Sun  12-01-1991  05:13:51 */
  69.  
  70.         /* We send two XON's to try to unstick a V.42 miscue */
  71.         if (k-- > 0)
  72.             SENDBYTE (XON);        /* Unstick other side?   */
  73.  
  74.         /* Send either the CR or SPACE */
  75.         SENDBYTE (j);
  76.  
  77.         /* Now switch to either CR or SPACE based on last output */
  78.         j = (unsigned char) (45 - j);
  79.  
  80.         /* Set a one second timer */
  81.         t2 = timerset (100);
  82.  
  83.         /* Now read what we get back to see if we get anything useful.
  84.            But only allow up to that one second to get it. */
  85.  
  86.         while (!timeup (t2))
  87.         {
  88.             /* Get a character if there is one. Otherwise give up cycles
  89.                to the system. */
  90.  
  91.             if ((i = (unsigned short) PEEKBYTE ()) == (unsigned short) -1)
  92.             {
  93.                 if (fDidALine)
  94.                     break;
  95.                 time_release ();
  96.                 continue;
  97.             }
  98.  
  99.             /* If we're doing EMSI, this is the first char and it's
  100.                an asterisk, exit now without losing it. */
  101.  
  102.             if (!fDoingALine && !no_EMSI_Session && (i == (unsigned short)'*'))
  103.             {
  104.                 if (un_attended && fullscreen)
  105.                     clear_filetransfer ();
  106.                 return (0);
  107.             }
  108.  
  109.             /* Eat the character */
  110.  
  111.             (void) TIMED_READ (0);
  112.  
  113.             /* If the character is a CR and we got a response, we can leave. */
  114.  
  115.             if (i == CR && fGotAChar)
  116.             {
  117.                 if (fDoingALine && !fDidALine)
  118.                 {
  119.                     if (un_attended && fullscreen)
  120.                     {
  121.                         clear_filetransfer ();
  122.  
  123.                         sb_move (filewin, 1, 2);
  124.                         sb_puts (filewin, buf);
  125.                         sb_show ();
  126.                         status_line ("*%s", buf);
  127.                     }
  128.                     else
  129.                     {
  130.                         set_xy (NULL);
  131.                         scr_printf (buf);
  132.                     }
  133.                     /* We got what we wanted */
  134.                     /* Now try to stop output on an Opus */
  135.                     SENDBYTE (' ');
  136.  
  137.                 }
  138.                 fDoingALine = 0;
  139.                 fDidALine = 1;
  140.             }
  141.  
  142.             /* Otherwise, if it's a printing character, save it for logging. */
  143.  
  144.             else if (i >= ' ')
  145.             {
  146.                 if (fDoingALine || i != ' ')
  147.                 {
  148.                     fDoingALine = 1;
  149.                     if (fDidALine)
  150.                         continue;
  151.                     buf[l++] = (char) (i & 0xff);
  152.                     buf[l] = '\0';
  153.                     if (l > (int) SB_COLS - 6)
  154.                         l = SB_COLS - 6;
  155.                 }
  156.  
  157.                 /* One-shot: reset the 1-second timeout for the first printable
  158.                    character we get. */
  159.  
  160.                 if (!fGotAChar)
  161.                 {
  162.                     fGotAChar = 1;
  163.                     t2 = timerset (100);
  164.                 }
  165.             }
  166.         } /* End 1-second inner timer loop */
  167.  
  168.         if (fDidALine)
  169.         {
  170.             if (un_attended && fullscreen)
  171.                 clear_filetransfer ();
  172.             return (0);
  173.         }
  174.  
  175.         /* Bail out for keyboard escape */
  176.  
  177.         if (got_ESC ())
  178.         {
  179.             status_line (MSG_TXT (M_CONNECT_ABORTED));
  180.             mdm_hangup ();
  181.             return (-1);
  182.         }
  183.  
  184.     } /* End 30-second braindead timer loop */
  185.  
  186.     if (CARRIER)
  187.         status_line (MSG_TXT (M_NOBODY_HOME));
  188.     else
  189.         status_line (MSG_TXT (M_NO_CARRIER));
  190.     return (-1);
  191. }
  192.