home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pub / researchmachines / rmlkey.c < prev    next >
Text File  |  2020-01-01  |  8KB  |  334 lines

  1.  
  2. /***********************************************************************/
  3.  
  4. /*  File  KKEY.C  -  RML Kermit  -  Keyboard/Screen Routines
  5.         Chris Kennington,    RML.    6th June 1985    */
  6.  
  7. #define     DEFS1    1
  8. #define  F4    0x9b
  9.  
  10. #include  "stdio.h"
  11. #include  "ctype.h"
  12. #include  "b:kext.h"
  13.  
  14.  
  15.  
  16. /* Globals local to this file:                    */
  17. static    int    dtr = 1;    /* DTR toggle-switch        */
  18.  
  19. static  char    *valid[] = {0,    /* validity strings per mode    */
  20. /* one string for each kmode, contains all valid chars as l.c.;
  21.     ESC maps to {, ? maps to DELT (\175 & \177)            */
  22.     0,                /* KERMit mode        */
  23.     "\177bcefhklpqrsz",        /* CONN mode        */
  24.     "\177abcfhklnqrt",        /* SEND mode        */
  25.     "\177abcfhklnqt",        /* RECeive mode        */
  26.     "\177abcfhklnqrt",        /* CoMmaND mode        */
  27.     "\177kq",            /* PARaMeter mode    */
  28.     "\177abcfhklnqrt",        /* AUTO mode        */
  29.     "\177cefhklpqrs",        /* DISK mode        */
  30.     0,0};            /* end of table            */
  31.  
  32. static  char    *texts[] = {   /* help-texts or 0, one per char    */
  33.     0,
  34.     "A  -  Abort transfer",
  35.     "B  -  send 1-sec line-Break",
  36.     "C  -  Clear screen",
  37.     0,"E+ E- switch Echo on/off",
  38.     "F  -  Front panel",
  39.     0,"H  -  Help on ESC facility",
  40.     0,0,"K  -  return to Kermit command-mode",
  41.     "L  -  Set Listing/Debugging level",
  42.     0,"N  -  set slow-Network option",
  43.     0,
  44.     "P  -  set Parameters",
  45.     "Q  -  Quit from Kermit",
  46.     "R  -  switch to Receive mode",
  47.     "S  -  switch to Send mode",
  48.     "T  -  simulate Timeout (send NAK)",
  49.     0,0,0,0,0,"Z+ Z- toggle DTR on/off", 
  50.     0,0,0,0,"?  -  print this help-text",0};
  51.  
  52. static  char  confm[] = {NL,"To confirm, hit CR or \"Y\".  Enter new <F4> for each command."};
  53.  
  54.  
  55.  
  56. confirm()        /* verify destructive action        */
  57. /* Prod user for "Y" as confirmation, return TRUE or FALSE     */
  58. {
  59.     char c;
  60.  
  61.     txtout(" - Yes? ");
  62.     while( (c = kbdin()) == 0 )
  63.     ;            /* force next read    */
  64.     c &= 0x5f;
  65.     if ( (c == 'Y') || (c == CR) ) {
  66.     txtout("OK ");
  67.     return(TRUE);
  68.     }
  69.     else {
  70.     outc(c);
  71.     return(FALSE);
  72. }   }        /* end of confirm()            */
  73.  
  74.  
  75.  
  76. keyget(ic)        /* get char from keyboard    */
  77. /* Returns 1 if char, else 0; char in *ic;
  78.    Handles low-level escape-sequences.            */
  79. char  *ic;
  80. {
  81.     char  c, ch, i, *string;
  82.     int   *ip;
  83.  
  84.     if ( (ch = kbdin()) == 0 )    /* try to read        */
  85.     return(0);        /* no char (or null)    */
  86.  
  87. /* there is a char to deal with                */
  88.     *ic = ch;
  89.     ch &= (char)0x7f;
  90.     if ( (ch == CTLC) && (kmode != CONN) )
  91.     kermkill(0);        /* kill if confirmed    */
  92.   /* if not confirmed, fall through            */
  93.     if (ch != ESC)
  94.     return(1);        /* normal return    */
  95.  
  96. /* ESC (or F4) is break-in                */
  97.     if ( (kmode == CONN) && (*ic == ESC) )
  98.     return(1);        /* ESC in CONN        */
  99.  
  100.     string = valid[kmode];    /* validity string    */
  101.     if (string == 0)        /* F4s invalid        */
  102.     return(0);
  103.  
  104. Rept:
  105.     txtout(eprompt);        /* respond with prompt    */
  106. Ignore:
  107.     while ( (ch = kbdin()) == 0)
  108.     ;            /* force next read    */
  109.  
  110.     for (i=0; (ch|(char)0x60) != (c = string[i]); ++i) {
  111. /* search string for match to char; ESC matches {, ? matches DEL */
  112.     if (c == 0) {          /* end of string, invalid    */
  113.         if (ch == F4)    /* F4            */
  114.         goto Rept;
  115.         goto End;
  116.     }    }
  117.  
  118. /* fall through when test satisfied, i.e. matching char in string;
  119.     char represents an action valid in this mode        */
  120.     ch |= 0x20;            /* force lower case    */
  121.     switch(ch) {        /* select action    */
  122.   /* come out of case by break if CR/prompt wanted, by return(0) if not    */
  123.       case SP:
  124.       case '-':
  125.     goto Ignore;
  126.       case 0x23:        /* CTLC - quit or abort    */
  127.     kermkill(0);
  128.   /* if not confirmed, fall through            */
  129.       case 'a':            /* abort transfer    */
  130.     txtout("A ** Abort current transfer");
  131.     if (confirm() == TRUE) {
  132.         printmsg("Aborting;%s%s",dots,trying);
  133.         abtflag = 1;
  134.         *ic = CR;        /* supply phantom CR    */
  135.         return(1);
  136.     }
  137.     break;
  138.       case 'b':            /* send break        */
  139.     txtout("B - sending 1-sec \"break\" ... ");
  140.     s4break(10);
  141.     txtout("Sent");
  142.     break;
  143.       case 'c':            /* clear screen        */
  144.     clrscrn();
  145.     break;
  146.       case 'e':            /* Echo switch        */
  147.     txtout("E ** Echo now ");
  148.     ip = &echo;
  149.     goto Next;
  150.       case 'f':            /* Front panel        */
  151.     txtout("F ** calling Front Panel - K to continue; ");
  152.     fpanel();
  153.     break;
  154.       case 'h':
  155.     txtout("The F4 key provides a means of setting some parameters or");
  156.     txtout("\r  taking actions, depending on what Kermit mode you are in.");
  157.     txtout("\rInput is a single character or one followed by +, - or a digit;");
  158.     txtout("\r  <F4>? will tell you what chars are valid at any time. ");
  159.     break;
  160.       case 'k':            /* Back to Kermit    */
  161.     outc('K');
  162.     abtflag = 1;
  163.     kmode = KERM;
  164.     return(0);
  165.       case 'l':        /* list chars transferred    */
  166.     txtout("L ** List/Debug now ");
  167.     ip = &list;
  168.     goto Next;
  169.       case 'n':            /* slow-network option    */
  170.     txtout("N ** Slow-network option now ");
  171.     ip = &netslow;
  172.     goto Next;
  173.       case 'p':            /* set parameters    */
  174.     i = kmode;
  175.     kmode = PARM;
  176.     setshow();
  177.     cursor(9);        /* this is arbitrary    */
  178.     kmode = i;
  179.     break;
  180.       case 'q':            /* cancel program    */
  181.     outc('Q');
  182.     kermkill(0);
  183.     break;
  184.       case 'r':            /* switch to receive    */
  185.     outc('R');
  186.     kmode = RECV;
  187.     return(0);
  188.      case 's':            /* switch to send    */
  189.     outc('S');
  190.     kmode = SEND;
  191.     return(0);
  192.      case 't':            /* simulate timeout    */
  193.     txtout("T ** simulate Timeout ");
  194.     ++timouts;
  195.     nakflag = 1;
  196.     break;
  197.       case 'z':            /* toggle DTR        */
  198.     txtout("Z - toggle DTR (enter + or -) ");
  199.     ip = &dtr;
  200.     goto Next;
  201.       case '?':            /* help            */
  202.     txtout("? - Valid inputs after F4 in this mode are:-");
  203.     while ( (c = *string++) != 0 ) {
  204.         outc(NL);
  205.         txtout("    ");
  206.         c &= 0x1f;        /* range 0-31        */
  207.         txtout(texts[c]);
  208.     }
  209.     txtout(confm);
  210.     break;
  211.       default:
  212.     bell();
  213.     }            /* end switch            */
  214.     goto End;
  215.  
  216. /* end of main-line code                */
  217.  
  218. Next:        /* 3rd char of input, +, - or digit    */
  219.     while ( (c = kbdin()) == 0 )
  220.     ;
  221.     outc(c);
  222. Next2:
  223.     switch (c) {
  224.       case '+':
  225.       case ';':
  226.     ++(*ip);
  227.     printf(" ON = %d ",(char)*ip);
  228.     break;
  229.       case '-':
  230.       case '=':
  231.       case '0':
  232.     *ip = 0;
  233.     txtout(" OFF ");
  234.     break;
  235.       case '1':
  236.       case '2':
  237.       case '3':
  238.     if (ip != &parity) {
  239.         c - '+';
  240.         goto Next2;
  241.     }
  242.     *ip = c - '0';
  243.     printf(" = %s. ", parsets[parity]);
  244.     setpar();
  245.     break;
  246.       case F4:
  247.     goto Rept;
  248.       default:
  249.     bell();
  250.     txtout(" unchanged ");
  251.     }            /* end of switch        */
  252.     if (ip == &dtr) {
  253.     if (dtr == 0)
  254.         comctrl &= 0x7f;        /* drop DTR    */    
  255.     else
  256.         comctrl |= 0x80;        /* raise DTR    */
  257.     s4set(commode,comctrl);
  258.     }
  259. /* end of second-character processing            */
  260.  
  261. End:
  262.     outc(NL);
  263.     return(0);            /* no char for Kermit    */
  264.  
  265. }            /* end of keyget()        */
  266.  
  267.  
  268.  
  269. keyline(str)        /* get line of text from keyboard    */
  270. char    *str;
  271. /* Read keyboard until a line has accumulated in str[], max
  272.      length 80 char.  Terminate on CR or LF, cancel (returning
  273.      null string) on CTL-C, allow deletion by DELT or CTL-H,
  274.      store & echo all other chars except controls after conversion to U.C.
  275.    Return length of string.                     */
  276. {
  277.     char  ptr, c;
  278.  
  279.     outc(DEOL);
  280.     ptr = 0;
  281.     while (TRUE) {
  282.     while (keyget(&c) == 0)
  283.         ;
  284.     switch(c) {
  285.       case CTLC:
  286.         ptr = 0;
  287.       case CR:
  288.       case LF:
  289.         str[ptr] = 0;
  290.         txtout(".  ");
  291.         return(ptr);
  292.       case DELT:
  293.       case BKSP:
  294.         if (ptr > 0) {
  295.         --ptr;
  296.         outc(BKSP);
  297.         outc(SP);
  298.         outc(BKSP);
  299.         }
  300.         else
  301.         bell();
  302.         break;
  303.       default:        /* other chars        */
  304.         if (c < SP)
  305.         ;        /* discard controls    */
  306.         else if (ptr < 80) {
  307.         outc(c);
  308.         str[ptr++] = c;
  309.         }
  310.         else
  311.         bell();        /* overfull        */
  312.  
  313.     }    }        /* end of while & switch    */
  314. /* we never reach here        */
  315. }        /* End of keyline()            */
  316.  
  317.  
  318.  
  319. upper(line)        /* convert line to upper case    */
  320. char    *line;
  321. {
  322.     CHAR    c;
  323.  
  324.     while ( (c = *line) != 0 ) {
  325.     if (islower(c))
  326.         *line &= (CHAR)0x0df;
  327.     ++line;
  328.    }
  329.    return;
  330. }            /* end of upper()        */
  331.  
  332. /*************  END of file KERMKEY.C  *****************/
  333.  
  334.