home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / git-4.3 / git-4 / git-4.3.7 / src / gitkeys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-08  |  5.2 KB  |  218 lines

  1. /* gitkeys.c -- an utility designed to help users to find out what is the 
  2.    escape sequences sent by a particular key. Users can use this to set up
  3.    their configuration files. */
  4.  
  5. /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2, or (at your option)
  10.    any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Written by Tudor Hulubei and Andrei Pitis.  */
  22.  
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27.  
  28. #include <stdio.h>
  29.  
  30. #ifdef HAVE_STDLIB_H
  31. #include <stdlib.h>
  32. #else /* !HAVE_STDLIB_H */
  33. #include "ansi_stdlib.h"
  34. #endif /* !HAVE_STDLIB_H */
  35.  
  36. #include <sys/types.h>
  37.  
  38. #ifdef HAVE_POSIXTTY
  39. #include <termios.h>
  40. #else
  41. #ifdef HAVE_SYSTEMVTTY
  42. #include <termio.h>
  43. #else
  44. #include <sgtty.h>
  45. #endif /* HAVE_SYSTEMVTTY */
  46. #endif /* HAVE_POSIXTTY */
  47.  
  48. #include <signal.h>
  49.  
  50. #ifdef HAVE_UNISTD_H
  51. #include <unistd.h>
  52. #endif /* HAVE_UNISTD_H */
  53.  
  54. #include "stdc.h"
  55. #include "xio.h"
  56.  
  57.  
  58. #define TTY_OUTPUT 1
  59.  
  60.  
  61. #ifdef HAVE_POSIXTTY
  62. static struct termios old_term;
  63. static struct termios new_term;
  64. #else
  65. #ifdef HAVE_SYSTEMVTTY
  66. static struct termio old_term;
  67. static struct termio new_term;
  68. #else
  69. static struct sgttyb  old_arg;
  70. static struct tchars  old_targ;
  71. static struct ltchars old_ltarg;
  72. static struct sgttyb  new_arg;
  73. static struct tchars  new_targ;
  74. static struct ltchars new_ltarg;
  75.  
  76. /* NextStep doesn't define TILDE.  */
  77. #ifndef TILDE
  78. #define TILDE 0
  79. #endif
  80.  
  81. #endif /* HAVE_SYSTEMVTTY */
  82. #endif /* HAVE_POSIXTTY */
  83.  
  84.  
  85. RETSIGTYPE do_exit __P((int));
  86.  
  87.  
  88. void
  89. tty_init()
  90. {
  91. #ifdef HAVE_POSIXTTY
  92.     tcgetattr(TTY_OUTPUT, &old_term);
  93.  
  94.     signal(SIGTERM, do_exit);
  95.     signal(SIGQUIT, do_exit);
  96.     signal(SIGINT,  do_exit);
  97.  
  98.     new_term = old_term;
  99.     new_term.c_iflag &= ~(ICRNL | IGNCR | INLCR | IGNBRK | BRKINT);
  100.     new_term.c_oflag &= ~OPOST;
  101.     new_term.c_lflag |= ISIG | NOFLSH;
  102.     new_term.c_lflag &= ~(ICANON | ECHO);
  103.     new_term.c_cc[VINTR] = 7;   /* ^G */
  104.     new_term.c_cc[VQUIT] = 7;   /* ^G */
  105.     new_term.c_cc[VMIN]  = 1;
  106.     new_term.c_cc[VTIME] = 0;
  107.     tcsetattr(TTY_OUTPUT, TCSADRAIN, &new_term);
  108. #else
  109. #ifdef HAVE_SYSTEMVTTY
  110.     ioctl(TTY_OUTPUT, TCGETA, &old_term);
  111.  
  112.     signal(SIGTERM, do_exit);
  113.     signal(SIGQUIT, do_exit);
  114.     signal(SIGINT,  do_exit);
  115.  
  116.     new_term = old_term;
  117.     new_term.c_iflag &= ~(ICRNL | IGNCR | INLCR);
  118.     new_term.c_oflag = 0;
  119.     new_term.c_lflag = 0;
  120.     new_term.c_cc[VINTR] = 7;   /* ^G */
  121.     new_term.c_cc[VQUIT] = 7;   /* ^G */
  122.     new_term.c_cc[VMIN]  = 1;
  123.     new_term.c_cc[VTIME] = 0;
  124.     ioctl(TTY_OUTPUT, TCSETAW, &new_term);
  125. #else
  126.     ioctl(TTY_OUTPUT, TIOCGETP, &old_arg);
  127.     ioctl(TTY_OUTPUT, TIOCGETC, &old_targ);
  128.     ioctl(TTY_OUTPUT, TIOCGLTC, &old_ltarg);
  129.  
  130.     signal(SIGTERM, do_exit);
  131.     signal(SIGQUIT, do_exit);
  132.     signal(SIGINT,  do_exit);
  133.  
  134.     new_arg   = old_arg;
  135.     new_targ  = old_targ;
  136.     new_ltarg = old_ltarg;
  137.     new_arg.sg_flags = ((old_arg.sg_flags &
  138.                      ~(ECHO | CRMOD | XTABS | ALLDELAY | TILDE)) | CBREAK);
  139.     new_targ.t_intrc   =  7;    /* ^G */
  140.     new_targ.t_quitc   =  7;    /* ^G */
  141.     new_targ.t_eofc    = -1;
  142.     new_targ.t_brkc    = -1;
  143.     new_ltarg.t_suspc  = -1;
  144.     new_ltarg.t_dsuspc = -1;
  145.     new_ltarg.t_rprntc = -1;
  146.     new_ltarg.t_flushc = -1;
  147.     new_ltarg.t_werasc = -1;
  148.     new_ltarg.t_lnextc = -1;
  149.     ioctl(TTY_OUTPUT, TIOCSETN, &new_arg);
  150.     ioctl(TTY_OUTPUT, TIOCSETC, &new_targ);
  151.     ioctl(TTY_OUTPUT, TIOCSLTC, &new_ltarg);
  152. #endif /* HAVE_SYSTEMVTTY */
  153. #endif /* HAVE_POSIXTTY */
  154. }
  155.  
  156.  
  157. void
  158. tty_end()
  159. {
  160. #ifdef HAVE_POSIXTTY
  161.     tcsetattr(TTY_OUTPUT, TCSADRAIN, &old_term);
  162. #else
  163. #ifdef HAVE_SYSTEMVTTY
  164.     ioctl(TTY_OUTPUT, TCSETAW, &old_term);
  165. #else
  166.     ioctl(TTY_OUTPUT, TIOCSETN, &old_arg);
  167.     ioctl(TTY_OUTPUT, TIOCSETC, &old_targ);
  168.     ioctl(TTY_OUTPUT, TIOCSLTC, &old_ltarg);
  169. #endif /* HAVE_SYSTEMVTTY */
  170. #endif /* HAVE_POSIXTTY */
  171. }
  172.  
  173.  
  174. RETSIGTYPE
  175. do_exit(signum)
  176.     int signum;
  177. {
  178.     tty_end();
  179.     exit(1);
  180. }
  181.  
  182.  
  183. int
  184. main()
  185. {
  186.     char c;
  187.  
  188. #ifdef HAVE_GCC
  189.     printf(PRODUCT" "VERSION" - Display key sequence utility\n");
  190. #else
  191.     printf("GNU Interactive Tools 4.3.7 - Display key sequence utility\n");
  192. #endif /* !HAVE_GCC */
  193.     printf("GIT is free software; you can redistribute it and/or modify it under the\n");
  194.     printf("terms of the GNU General Public License as published by the Free Software\n");
  195.     printf("Foundation; either version 2, or (at your option) any later version.\n");
  196.     printf("Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.\n");
  197.     printf("Written by Tudor Hulubei and Andrei Pitis, students at PUB, Romania\n");
  198.  
  199.     printf("\nPress space when done.\n\n");
  200.  
  201.     tty_init();
  202.  
  203.     for (;;)
  204.     {
  205.         read(0, &c, 1);
  206.  
  207.         if (c == ' ')
  208.             break;
  209.  
  210.         printf("%x ", c);
  211.         fflush(stdout);
  212.     }
  213.  
  214.     tty_end();
  215.  
  216.     return 0;
  217. }
  218.