home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d026 / c-kermit.lha / C-kermit / src / ckicon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-16  |  5.8 KB  |  179 lines

  1. char *connv = "Connect Command, V4.2(007)+1 9 March 85";
  2.      
  3. /*  C K A C O N  --  Dumb terminal connection to remote system, for AMIGA  */
  4. /*
  5.  Adapted from the VMS C-Kermit connect module, which was:
  6.  
  7.  Adapted from the Unix C-Kermit connect module by S. Rubenstein for systems
  8.  without fork().  This version of conect() uses contti(&c, &src) to return
  9.  when a character is available from either the console or the comm line,
  10.  to allow sending/receiving without breaking connection.
  11. */
  12.  
  13. #include <ctype.h>            /* Isupper & Iscntrl  (fnf) */
  14.  
  15. #include "ckcker.h"
  16. #include "ckcdeb.h"
  17.      
  18. extern int local, speed, escape, duplex, parity, flow, seslog, mdmtyp;
  19. extern char ttname[], sesfil[];
  20.      
  21. int i, active;                          /* Variables global to this module */
  22. char *chstr();
  23.      
  24. #define LBUFL 100                       /* Line buffer */
  25. char lbuf[LBUFL];
  26.  
  27.      
  28. /*  C O N E C T  --  Perform terminal connection  */
  29.      
  30. conect() {
  31.     int c;                      /* c is a character, but must be signed
  32.                                    integer to pass thru -1, which is the
  33.                                    modem disconnection signal, and is
  34.                                    different from the character 0377 */
  35.  
  36.         if (!local) {
  37.             printf("Sorry, you must 'set line' first\n");
  38.             return(-2);
  39.         }
  40.         if (speed < 0) {
  41.             printf("Sorry, you must 'set speed' first\n");
  42.             return(-2);
  43.         }
  44.         if ((escape < 0) || (escape > 0177)) {
  45.             printf2("Your escape character is not ASCII - %d\n",escape);
  46.             return(-2);
  47.         }
  48.         if (ttopen(ttname,&local,mdmtyp) < 0) {
  49.             printf2("Sorry, can't open %s",ttname);
  50.             return(-2);
  51.         }
  52.         printf3("Connecting thru %s, speed %d.\r\n",ttname,speed);
  53.         printf3("The escape character is %s (%d).\r\n",chstr(escape),escape);
  54.         printf("Type the escape character followed by C to get back,\r\n");
  55.         printf("or followed by ? to see other options.\r\n");
  56.         if (seslog) printf2("(Session logged to %s.)\r\n",sesfil);
  57.      
  58. /* Condition console terminal and communication line */ 
  59.      
  60.         if (conbin(escape) < 0) {
  61.             printf("Sorry, can't condition console terminal\n");
  62.             return(-2);
  63.         }
  64.         if (ttvt(speed,flow) < 0) {
  65.             conres();
  66.             printf("Sorry, Can't condition communication line\n");
  67.             return(-2);
  68.         }
  69.         active = 1;
  70.         do {
  71.             int src;
  72.      
  73.             contti(&c, &src);
  74.             if (src < 0) {              /* Comm line hangup or other error */
  75.                 printf("\r\nC-Kermit: Communications line failure\r\n");
  76.                 active = 0;
  77.             } else if (src) {           /* Character from comm. line */
  78.                 c &= 0177;              /* Got a char, strip parity. */
  79.                 conoc(c);               /* Put it on the screen. */
  80.                 if (seslog) zchout(ZSFILE,c); /* If logging, log it. */
  81.             } else {                    /* Character from console */
  82.                 c &= 0177;
  83.                 if (c == escape) {      /* Look for escape char */
  84.                     c = coninc(0) & 0177;
  85.                     doesc(c);
  86.                 } else {                /* Ordinary character */
  87.                     ttoc(dopar(c));
  88.                     if (duplex) {       /* Half duplex? */
  89.                         conoc(c);       /* Yes, also echo it. */
  90.                         if (seslog) zchout(ZSFILE,c);   /* And maybe log it. */
  91.                     }                   
  92.                 }
  93.             }
  94.         } while (active);
  95.         cancio();
  96.         conres();
  97.         printf("\r\nC-Kermit Disconnected\r\n");
  98.         return(0);
  99. }
  100.  
  101.      
  102. /*  H C O N N E  --  Give help message for connect.  */
  103.      
  104. hconne() {
  105.     int c;
  106.     static char *hlpmsg[] = {"\
  107. \r\nC to close the connection, or:",
  108. "\r\n  S for status",
  109. "\r\n  ? for help",
  110. "\r\n  H to hang up the phone",
  111. "\r\n  B to send a BREAK",
  112. "\r\n  0 to send a null",
  113. "\r\n escape character twice to send the escape character.\r\n\r\n",
  114. "" };
  115.     conola(hlpmsg);                     /* Print the help message. */
  116.     conol("Command>");                  /* Prompt for command. */
  117.     c = coninc(0);
  118.     conoc(c);                           /* Echo it. */
  119.     conoll("");
  120.     doesc(c);
  121. }
  122.      
  123.      
  124. /*  C H S T R  --  Make a printable string out of a character  */
  125.      
  126. char *
  127. chstr(c) int c; {
  128.     static char s[8];
  129.     char *cp = s;
  130.      
  131.     if (c < SP) {
  132.         sprintf(cp,"CTRL-%c",ctl(c));
  133.     } else sprintf(cp,"'%c'\n",c);
  134.     cp = s;
  135.     return(cp);
  136. }
  137.  
  138.      
  139. /*  D O E S C  --  Process an escape character argument  */
  140.      
  141. doesc(c) char c; {
  142.     int d;
  143.      
  144.     c &= 0177;
  145.      
  146.     if (c == escape) {              /* Send escape character */
  147.         d = dopar(c);
  148.         ttoc(d);
  149.     } else {
  150.                                     /* Or else look it up below. */
  151.         if (isupper(c)) c = tolower(c);
  152.         if (iscntrl(c)) c += 'a' - '\001';
  153.      
  154.         if (c == 'c') {                 /* Close connection */
  155.             active = 0;
  156.             conol("\r\n");
  157.         } else if (c == 'b') {          /* Send a BREAK */
  158.             ttsndb();
  159.         } else if (c == 'h') {          /* Hang up the line */
  160.             tthang();
  161.         } else if (c == 's') {          /* Status */
  162.             conol("\r\nConnected thru ");
  163.             conoll(ttname);
  164.             if (seslog) {
  165.                 conol(", logging to ");
  166.                 conol(sesfil);
  167.             }
  168.         } else if (c == '?') {          /* Help */
  169.             hconne();
  170.         } else if (c == '0') {          /* Send a null */
  171.             c = '\0';
  172.             d = dopar(c);
  173.             ttoc(d);
  174.         } else if (c != SP) {           /* Space, ignore */
  175.             conoc(BEL);                 /* Invalid esc arg, beep */
  176.         }
  177.     }
  178. }
  179.