home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_escape.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  2.7 KB  |  117 lines

  1. #include  "d_proto.h"
  2. #include <signal.h>
  3. #include  "d_syscodes.h"
  4. #include  "d_returns.h"
  5.  
  6. /*
  7.  *     D_FINDESC
  8.  *
  9.  *     this routine attempts to find a suitable escape character to be used
  10.  *     by the remote host for packets transmitted to us.  the character is
  11.  *     chosen from the 'd_esclist' by checking each of the proposed escapes
  12.  *     to see if it can be both transmitted by the remote system and received
  13.  *     by us.  the selected character is returned, if one is found; otherwise
  14.  *     D_FATAL.
  15.  */
  16.  
  17. char
  18.     d_findesc()
  19.     {
  20.     extern char  d_esclist[];
  21.     extern unsigned  short d_lrill[], d_rxill[];
  22.     extern int  d_errno;
  23.     register char  *cp;
  24.  
  25.     for (cp = d_esclist; *cp; cp++)
  26.       if (!d_testbit(*cp, d_lrill) && !d_testbit(*cp, d_rxill))
  27.         {
  28. #ifdef D_DBGLOG
  29.         d_dbglog("d_findesc", "Character '%c' selected as escape for receiving",
  30.             *cp);
  31. #endif D_DBGLOG
  32.         return(*cp);
  33.         }
  34.  
  35. #ifdef D_LOG
  36.     d_log("d_findesc", "Can't find suitable escape character");
  37. #endif D_LOG
  38.     d_errno = D_NOESC;
  39.     return(D_FATAL);
  40. }
  41.  
  42. /*
  43.  *     D_SNDESCAPE
  44.  *
  45.  *     this routine forms an ESCAPE packet and sends it to the remote host
  46.  */
  47.  
  48. d_snfescape()
  49.     {
  50.     extern char  d_rcvesc;
  51.     extern int  d_snseq;
  52.     register int  length, result;
  53.     char  packet[MAXPACKET + 2], esctemp[4];
  54.  
  55. #ifdef D_DBGLOG
  56.     d_dbglog("d_snfescape", "sending ESCAPE to other end");
  57. #endif D_DBGLOG
  58.  
  59.     /*  find an escape character  */
  60.     if ((d_rcvesc = d_findesc()) < 0)
  61.       return(d_rcvesc);
  62.  
  63.     /*  form text containing the ascii value of the escape
  64.      *  character expressed as a 2 digit hex number and send it.
  65.      */
  66.     esctemp[0] = d_tohex((d_rcvesc >> 4) & 017);
  67.     esctemp[1] = d_tohex(d_rcvesc & 017);
  68.     esctemp[2] = '\0';
  69.  
  70.     d_snseq = d_incseq(d_snseq);
  71.     length = d_bldpack(ESCAPE, d_snseq, 1, esctemp, packet);
  72.  
  73.     result = d_snpkt(ESCAPE, packet, length);
  74.     return(result);
  75. }
  76.  
  77.  
  78. /*
  79.  *     D_GETESCAPE
  80.  *
  81.  *     this routine watches for an incoming ESCAPE packet from the remote
  82.  *     host.  it thens set the transmit escape character.
  83.  *
  84.  */
  85.  
  86. d_getescape()
  87.     {
  88.     extern int  d_errno;
  89.     extern char  d_snesc;
  90.     register int  length;
  91.     char  packet[MAXPACKET + 2];
  92.  
  93. #ifdef D_DBGLOG
  94.     d_dbglog("d_getescape", "looking for ESCAPE from other end");
  95. #endif D_DBGLOG
  96.  
  97. /*  set timer so we don't wait forever  */
  98.  
  99.     length = d_watch(packet, ESCAPE);
  100.  
  101.     if (length < 0)
  102.     return(length);
  103.  
  104.     if (length != LESCAPE)
  105.     {
  106. #ifdef D_DBGLOG
  107.       d_dbglog("d_escape", "bad ESCAPE packet length (%d)", length);
  108. #endif D_DBGLOG
  109.       d_errno = D_INITERR;
  110.       return (D_FATAL);
  111.     }
  112.  
  113.       d_snesc = d_fromhex(packet[ESCOFF]);
  114.       d_snesc = (d_snesc << 4) | d_fromhex(packet[ESCOFF + 1]);
  115.       return(D_OK);
  116.     }
  117.