home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / mxterm.zip / mxterm / input.c < prev    next >
C/C++ Source or Header  |  1992-10-17  |  8KB  |  292 lines

  1. /*
  2.  *    $XConsortium: input.c,v 1.16 91/05/10 16:57:16 gildea Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  7.  *
  8.  *                         All Rights Reserved
  9.  *
  10.  * Permission to use, copy, modify, and distribute this software and its
  11.  * documentation for any purpose and without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and that
  13.  * both that copyright notice and this permission notice appear in
  14.  * supporting documentation, and that the name of Digital Equipment
  15.  * Corporation not be used in advertising or publicity pertaining to
  16.  * distribution of the software without specific, written prior permission.
  17.  *
  18.  *
  19.  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  21.  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  23.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  24.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  25.  * SOFTWARE.
  26.  */
  27.  
  28. /* input.c */
  29.  
  30. #include "ptyx.h"        /* gets Xt headers, too */
  31. #include <X11/keysym.h>
  32. #include <X11/DECkeysym.h>
  33. #include <X11/Xutil.h>
  34. #include <stdio.h>
  35.  
  36. static XComposeStatus compose_status = {NULL, 0};
  37. static char *kypd_num = " XXXXXXXX\tXXX\rXXXxxxxXXXXXXXXXXXXXXXXXXXXX*+,-./0123456789XXX=";
  38. static char *kypd_apl = " ABCDEFGHIJKLMNOPQRSTUVWXYZ??????abcdefghijklmnopqrstuvwxyzXXX";
  39. static char *cur = "DACB";
  40.  
  41. static int funcvalue(), sunfuncvalue();
  42. extern Boolean sunFunctionKeys;
  43.  
  44. static void
  45. AdjustAfterInput (screen)
  46. register TScreen *screen;
  47. {
  48.     if(screen->scrollkey && screen->topline != 0)
  49.         WindowScroll(screen, 0);
  50.     if(screen->marginbell) {
  51.         int col = screen->max_col - screen->nmarginbell;
  52.         if(screen->bellarmed >= 0) {
  53.             if(screen->bellarmed == screen->cur_row) {
  54.                 if(screen->cur_col >= col) {
  55.                 Bell();
  56.                 screen->bellarmed = -1;
  57.                 }
  58.             } else
  59.                 screen->bellarmed =
  60.                 screen->cur_col < col ? screen->cur_row : -1;
  61.         } else if(screen->cur_col < col)
  62.             screen->bellarmed = screen->cur_row;
  63.     }
  64. }
  65.  
  66. Input (keyboard, screen, event, eightbit)
  67.     register TKeyboard    *keyboard;
  68.     register TScreen    *screen;
  69.     register XKeyEvent *event;
  70.     Bool eightbit;
  71. {
  72.  
  73. #define STRBUFSIZE 100
  74.  
  75.     char strbuf[STRBUFSIZE];
  76.     register char *string;
  77.     register int key = FALSE;
  78.     int    pty    = screen->respond;
  79.     int    nbytes;
  80.     KeySym  keysym;
  81.     ANSI    reply;
  82.     char    tmp[STRBUFSIZE];
  83.     char    *bp = strbuf;
  84.     int    count;
  85.     XEvent    ev;
  86.  
  87.     count = XLookupString (event, tmp, STRBUFSIZE,
  88.                    &keysym, &compose_status);
  89.     strncpy(bp, tmp, count);
  90.     bp += count;
  91.     nbytes = count;
  92.     /*
  93.      * Make sure we get every keystroke available
  94.      * before we start doing the update, so can issue a single
  95.      * DrawString instead of several.
  96.      */
  97.     while (nbytes < STRBUFSIZE && 
  98.            XCheckMaskEvent(screen->display, KeyPressMask, &ev))    {
  99.         count = XLookupString ((XKeyEvent *)&ev, tmp, STRBUFSIZE,
  100.                    &keysym, &compose_status);
  101.         if (nbytes + count <= STRBUFSIZE) {
  102.         strncpy(bp, tmp, count);
  103.         bp += count;
  104.         nbytes += count;
  105.         } else {
  106.         XPutBackEvent(screen->display, &ev);
  107.         break;
  108.         }
  109.     }
  110.  
  111.     string = &strbuf[0];
  112.     reply.a_pintro = 0;
  113.     reply.a_final = 0;
  114.     reply.a_nparam = 0;
  115.     reply.a_inters = 0;
  116.  
  117.     if (IsPFKey(keysym)) {
  118.         reply.a_type = SS3;
  119.         unparseseq(&reply, pty);
  120.         unparseputc((char)(keysym-XK_KP_F1+'P'), pty);
  121.         key = TRUE;
  122.     } else if (IsKeypadKey(keysym)) {
  123.           if (keyboard->flags & KYPD_APL)    {
  124.             reply.a_type   = SS3;
  125.             unparseseq(&reply, pty);
  126.             unparseputc(kypd_apl[keysym-XK_KP_Space], pty);
  127.         } else
  128.             unparseputc(kypd_num[keysym-XK_KP_Space], pty);
  129.         key = TRUE;
  130.         } else if (IsCursorKey(keysym) &&
  131.             keysym != XK_Prior && keysym != XK_Next) {
  132.                if (keyboard->flags & CURSOR_APL) {
  133.             reply.a_type = SS3;
  134.             unparseseq(&reply, pty);
  135.             unparseputc(cur[keysym-XK_Left], pty);
  136.         } else {
  137.             reply.a_type = CSI;
  138.             reply.a_final = cur[keysym-XK_Left];
  139.             unparseseq(&reply, pty);
  140.         }
  141.         key = TRUE;
  142.      } else if (IsFunctionKey(keysym) || IsMiscFunctionKey(keysym) ||
  143.          keysym == XK_Prior || keysym == XK_Next ||
  144.          keysym == DXK_Remove) {
  145.         reply.a_type = CSI;
  146.         reply.a_nparam = 1;
  147.         if (sunFunctionKeys) {
  148.             reply.a_param[0] = sunfuncvalue (keysym);
  149.             reply.a_final = 'z';
  150.         } else {
  151.             reply.a_param[0] = funcvalue (keysym);
  152.             reply.a_final = '~';
  153.         }
  154.         if (reply.a_param[0] > 0)
  155.             unparseseq(&reply, pty);
  156.         key = TRUE;
  157.     } else if (nbytes > 0) {
  158.         if(screen->TekGIN) {
  159.             TekEnqMouse(*string++);
  160.             TekGINoff();
  161.             nbytes--;
  162.         }
  163.         if ((nbytes == 1) && eightbit) {
  164.             if (screen->input_eight_bits)
  165.               *string |= 0x80;    /* turn on eighth bit */
  166.             else
  167.               unparseputc (033, pty);  /* escape */
  168.         }
  169.         while (nbytes-- > 0)
  170.             unparseputc(*string++, pty);
  171.         key = TRUE;
  172.     }
  173.     if(key && !screen->TekEmu)
  174.             AdjustAfterInput(screen);
  175. #ifdef ENABLE_PRINT
  176.     if (keysym == XK_F2) TekPrint();
  177. #endif
  178.     return;
  179. }
  180.  
  181. StringInput (screen, string, nbytes)
  182.     register TScreen    *screen;
  183.     register char *string;
  184.     int nbytes;
  185. {
  186.     int    pty    = screen->respond;
  187.  
  188.     if(nbytes && screen->TekGIN) {
  189.         TekEnqMouse(*string++);
  190.         TekGINoff();
  191.         nbytes--;
  192.     }
  193.     while (nbytes-- > 0)
  194.         unparseputc(*string++, pty);
  195.     if(!screen->TekEmu)
  196.             AdjustAfterInput(screen);
  197. }
  198.  
  199. static int funcvalue (keycode)
  200.     int keycode;
  201. {
  202.     switch (keycode) {
  203.         case XK_F1:    return(11);
  204.         case XK_F2:    return(12);
  205.         case XK_F3:    return(13);
  206.         case XK_F4:    return(14);
  207.         case XK_F5:    return(15);
  208.         case XK_F6:    return(17);
  209.         case XK_F7:    return(18);
  210.         case XK_F8:    return(19);
  211.         case XK_F9:    return(20);
  212.         case XK_F10:    return(21);
  213.         case XK_F11:    return(23);
  214.         case XK_F12:    return(24);
  215.         case XK_F13:    return(25);
  216.         case XK_F14:    return(26);
  217.         case XK_F15:    return(28);
  218.         case XK_Help:    return(28);
  219.         case XK_F16:    return(29);
  220.         case XK_Menu:    return(29);
  221.         case XK_F17:    return(31);
  222.         case XK_F18:    return(32);
  223.         case XK_F19:    return(33);
  224.         case XK_F20:    return(34);
  225.  
  226.         case XK_Find :    return(1);
  227.         case XK_Insert:    return(2);
  228.         case XK_Delete:    return(3);
  229.         case DXK_Remove: return(3);
  230.         case XK_Select:    return(4);
  231.         case XK_Prior:    return(5);
  232.         case XK_Next:    return(6);
  233.         default:    return(-1);
  234.     }
  235. }
  236.  
  237.  
  238. static int sunfuncvalue (keycode)
  239.     int keycode;
  240.   {
  241.       switch (keycode) {
  242.         case XK_F1:    return(224);
  243.         case XK_F2:    return(225);
  244.         case XK_F3:    return(226);
  245.         case XK_F4:    return(227);
  246.         case XK_F5:    return(228);
  247.         case XK_F6:    return(229);
  248.         case XK_F7:    return(230);
  249.         case XK_F8:    return(231);
  250.         case XK_F9:    return(232);
  251.         case XK_F10:    return(233);
  252.         case XK_F11:    return(192);
  253.         case XK_F12:    return(193);
  254.         case XK_F13:    return(194);
  255.         case XK_F14:    return(195);
  256.         case XK_F15:    return(196);
  257.         case XK_Help:    return(196);
  258.         case XK_F16:    return(197);
  259.         case XK_Menu:    return(197);
  260.         case XK_F17:    return(198);
  261.         case XK_F18:    return(199);
  262.         case XK_F19:    return(200);
  263.         case XK_F20:    return(201);
  264.  
  265.         case XK_R1:    return(208);
  266.         case XK_R2:    return(209);
  267.         case XK_R3:    return(210);
  268.         case XK_R4:    return(211);
  269.         case XK_R5:    return(212);
  270.         case XK_R6:    return(213);
  271.         case XK_R7:    return(214);
  272.         case XK_R8:    return(215);
  273.         case XK_R9:    return(216);
  274.         case XK_R10:    return(217);
  275.         case XK_R11:    return(218);
  276.         case XK_R12:    return(219);
  277.         case XK_R13:    return(220);
  278.         case XK_R14:    return(221);
  279.         case XK_R15:    return(222);
  280.   
  281.         case XK_Find :    return(1);
  282.         case XK_Insert:    return(2);
  283.         case XK_Delete:    return(3);
  284.         case DXK_Remove: return(3);
  285.         case XK_Select:    return(4);
  286.         case XK_Prior:    return(5);
  287.         case XK_Next:    return(6);
  288.         default:    return(-1);
  289.     }
  290. }
  291.  
  292.