home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume9 / xterm / part06 / input.c next >
Encoding:
C/C++ Source or Header  |  1987-04-20  |  3.5 KB  |  150 lines

  1. /*
  2.  *    $Source: /u1/X/xterm/RCS/input.c,v $
  3.  *    $Header: input.c,v 10.100 86/12/01 14:44:04 jg Rel $
  4.  */
  5.  
  6. #ifndef lint
  7. static char *rcsid_input_c = "$Header: input.c,v 10.100 86/12/01 14:44:04 jg Rel $";
  8. #endif    lint
  9.  
  10. #include <X/mit-copyright.h>
  11.  
  12. /* Copyright    Massachusetts Institute of Technology    1984, 1985    */
  13.  
  14. /* input.c */
  15.  
  16. #ifndef lint
  17. static char sccs_id[] = "@(#)input.c\tX10/6.6B\t12/26/86";
  18. #endif    lint
  19.  
  20. #include <X/Xlib.h>
  21. #include <X/Xkeyboard.h>
  22. #include "scrollbar.h"
  23. #include "ptyx.h"
  24. #include <stdio.h>
  25.  
  26. static char *kypd_num = "0x.\r123456,789-";
  27. static char *kypd_apl = "pxnMqrstuvlwxym";
  28. static char *cur = "DCBA";
  29.  
  30. Input (keyboard, screen, event)
  31. register Keyboard    *keyboard;
  32. register Screen        *screen;
  33. register XKeyPressedEvent *event;
  34. {
  35.     register int keycode = event->detail;
  36.     register char *string;
  37.     register int col, key = FALSE;
  38.     int    pty    = screen->respond;
  39.     int    nbytes;
  40.     ANSI    reply;
  41.  
  42.     string = XLookupMapping (event, &nbytes);
  43.  
  44.     if (nbytes > 0) {
  45.         if(screen->TekGIN) {
  46.             TekEnqMouse(*string++);
  47.             TekGINoff();
  48.             nbytes--;
  49.         }
  50.         while (nbytes-- > 0)
  51.             unparseputc(*string++, pty);
  52.         key = TRUE;
  53.     } else {
  54.         keycode &= ValueMask; /* no longer need shift bits for anything */
  55.         reply.a_pintro = 0;
  56.         reply.a_final = 0;
  57.         reply.a_nparam = 0;
  58.         reply.a_inters = 0;
  59.         if (IsKeypadKey(keycode)) {
  60.           if (keyboard->flags & KYPD_APL)    {
  61.             reply.a_type   = SS3;
  62.             unparseseq(&reply, pty);
  63.             unparseputc(kypd_apl[keycode-KC_KEYPAD_0], pty);
  64.         } else
  65.             unparseputc(kypd_num[keycode-KC_KEYPAD_0], pty);
  66.         key = TRUE;
  67.         } else if (IsCursorKey(keycode)) {
  68.                if (keyboard->flags & CURSOR_APL) {
  69.             reply.a_type = SS3;
  70.             unparseseq(&reply, pty);
  71.             unparseputc(cur[keycode-KC_CURSOR_LEFT], pty);
  72.         } else {
  73.             reply.a_type = CSI;
  74.             reply.a_final = cur[keycode-KC_CURSOR_LEFT];
  75.             unparseseq(&reply, pty);
  76.         }
  77.         key = TRUE;
  78.         } else if (IsPFKey(keycode)) {
  79.         reply.a_type = SS3;
  80.         unparseseq(&reply, pty);
  81.         unparseputc((char)(keycode-KC_PF1+'P'), pty);
  82.         key = TRUE;
  83.         } else if (IsFunctionKey(keycode)) {
  84.         reply.a_type = CSI;
  85.         reply.a_nparam = 1;
  86.         reply.a_param[0] = funcvalue(keycode);
  87.         reply.a_final = '~';
  88.         if (reply.a_param[0] > 0)
  89.             unparseseq(&reply, pty);
  90.         key = TRUE;
  91.         }
  92.     }
  93.     if(key && !screen->TekEmu) {
  94.         if(screen->scrollkey && screen->topline != 0)
  95.             ScrollToBottom(screen->sb);
  96.         if(screen->marginbell) {
  97.             col = screen->max_col - screen->nmarginbell;
  98.             if(screen->bellarmed >= 0) {
  99.                 if(screen->bellarmed == screen->cur_row) {
  100.                     if(screen->cur_col >= col) {
  101.                         if(screen->cur_col == col)
  102.                             Bell();
  103.                         screen->bellarmed = -1;
  104.                     }
  105.                 } else
  106.                     screen->bellarmed = screen->cur_col <
  107.                      col ? screen->cur_row : -1;
  108.             } else if(screen->cur_col < col)
  109.                 screen->bellarmed = screen->cur_row;
  110.         }
  111.     }
  112. #ifdef ENABLE_PRINT
  113.     if (keycode == KC_F2) TekPrint();
  114. #endif
  115.     return;
  116. }
  117.  
  118. funcvalue(keycode)
  119. {
  120.     switch (keycode) {
  121.         case KC_F1:    return(11);
  122.         case KC_F2:    return(12);
  123.         case KC_F3:    return(13);
  124.         case KC_F4:    return(14);
  125.         case KC_F5:    return(15);
  126.         case KC_F6:    return(17);
  127.         case KC_F7:    return(18);
  128.         case KC_F8:    return(19);
  129.         case KC_F9:    return(20);
  130.         case KC_F10:    return(21);
  131.         case KC_F11:    return(23);
  132.         case KC_F12:    return(24);
  133.         case KC_F13:    return(25);
  134.         case KC_F14:    return(26);
  135.         case KC_F15:    return(28);
  136.         case KC_F16:    return(29);
  137.         case KC_F17:    return(31);
  138.         case KC_F18:    return(32);
  139.         case KC_F19:    return(33);
  140.         case KC_F20:    return(34);
  141.         case KC_E1 :    return(1);
  142.         case KC_E2:    return(2);
  143.         case KC_E3:    return(3);
  144.         case KC_E4:    return(4);
  145.         case KC_E5:    return(5);
  146.         case KC_E6:    return(6);
  147.         default:    return(-1);
  148.     }
  149. }
  150.