home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 199_01 / ged7.c < prev    next >
Text File  |  1987-12-17  |  5KB  |  248 lines

  1. /*
  2. Header:          CUG199;
  3. Title:           Module 7 of ged editor;
  4. Last Updated:    09/19/87;
  5.  
  6. Description:    "PURPOSE: low level terminal i/o functions";
  7.  
  8. Keywords:        e, editor, qed, ged, DeSmet, MSDOS;
  9. Filename:        ged7.c;
  10. Warnings:       "O file must be present during link for ged";
  11.  
  12. Authors:         G. Nigel Gilbert, James W. Haefner, and Mel Tearle;
  13. Compilers:       DeSmet 3.0;
  14.  
  15. References:
  16. Endref;
  17. */
  18.  
  19. /*
  20. e/qed/ged  screen editor
  21.  
  22. (C) G. Nigel Gilbert, MICROLOGY, 1981 - August-December 1981
  23.  
  24. Modified:  Aug-Dec   1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  25.            March     1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  26.  
  27.            May       1986:  qed converted to ged         (Mel Tearle)
  28.            August    1987:  ged converted to MSC 4.0     (Mel Tearle)
  29.  
  30. File:      ged7.c
  31.  
  32. Functions: getkey, testkey, getlow, testlow, getscankey,
  33.            inkey, putret, chkbuf, inword,
  34.            makedim, makebright, makeother, beep, show_table
  35. */
  36.  
  37.  
  38. #ifndef  TC
  39. #include "ged.h"
  40. #else
  41. #include "ged.t"
  42. #endif
  43.  
  44.  
  45. /* wait for a key to be pressed & return it,
  46.  * translating to internal codes
  47.  */
  48. char getkey()
  49. {
  50. unsigned char c;
  51.  
  52. while ( !( c = testkey() ) );
  53. return c;
  54. }
  55.  
  56.  
  57. /* if a key has been pressed, return it, else 0
  58.  * see pcio.a for mods to scr_ci
  59.  */
  60. char testkey()
  61. {
  62. unsigned char c, *tranp;
  63. int  i;
  64.  
  65. if ( !( c = inkey() ) )  return 0;
  66.  
  67. /* try and match translation keys
  68.  * would appreciate someone explaining this to me - mt.
  69.  */
  70. if ( c == *(tranp = tran) )  {
  71.      while ( !( c = inkey()) );
  72.                c |= PARBIT;
  73. }
  74. /* synonym for move cursor left
  75.  */
  76. if ( c == BACKSP )  return LEFTKEY;
  77.  
  78. for ( i = 1, tranp++; i < NKEYS; i++, tranp++ )  {
  79.       if ( c == *tranp )
  80.            return ( unsigned char )i;
  81. }
  82. return c;
  83. }
  84.  
  85.  
  86. /* get a key, converting control and u/c keys to l/c,
  87.  * translation of ESCKEY only
  88.  */
  89. char getlow()
  90. {
  91. unsigned char c;
  92.  
  93. while ( !(c = testlow()) );
  94. return  c;
  95. }
  96.  
  97.  
  98. /* test for a key, convert upper
  99.  * and control chars to lower case
  100.  */
  101. char testlow()
  102. {
  103. unsigned char c;
  104.  
  105. if ( !( c = inkey() ) )              return  0;
  106. if ( tran[ESCKEY] == c )             return  ESCKEY;
  107. if ( c >= F1KEY  &&  c  <= F10KEY )  return  c;
  108.  
  109. if ( c < ' ') c = c + 96;
  110.  
  111. return ( c >= 'A' && c <= 'Z' ? c + 32 : c );
  112. }
  113.  
  114.  
  115. /* get a key, translation of ESCKEY, CR, LEFTKEY,
  116.  * DELLEFT, RETRIEVE only
  117.  */
  118. char getscankey()
  119. {
  120. unsigned char c;
  121.  
  122. while ( !( c = inkey()) );
  123.   if ( tran[ESCKEY] == c)   return ( char )  ESCKEY_P;
  124.   if ( tran[CR] == c)       return ( char )  CR_P;
  125.   if ( tran[LEFTKEY] == c)  return ( char )  LEFTKEY_P;
  126.   if ( tran[DELLEFT] == c)  return ( char )  DELLEFT_P;
  127.   if ( tran[RETRIEVE] == c) return ( char )  RETRIEVE_P;
  128. return c;
  129. }
  130.  
  131.  
  132. /* return last key pressed
  133.  * here's where all the goodies come from
  134.  * add chkbuf() to capture where desired
  135.  */
  136. char inkey()
  137. {
  138. unsigned char c;
  139. int i;
  140.  
  141. if ( inbufp )  {
  142.      c = inbuf[0];
  143.      inbufp--;
  144.      for (i = 0; i < inbufp; i++)
  145.           inbuf[i] = inbuf[i+1];
  146.      return c;
  147. }
  148.  
  149. if ( ( c = scr_csts() ) == 0 )
  150.             ;
  151. return c;
  152. }
  153.  
  154.  
  155. /* type a CR/LF
  156.  */
  157. void putret()
  158. {
  159. scr_co( '\r' );
  160. scr_co( '\n' );
  161. }
  162.  
  163.  
  164. /* if something in character que
  165.  * and inbufp less than sizeof buffer, add to buffer
  166.  */
  167. void chkbuf()
  168. {
  169. unsigned char cc;
  170.  
  171. if ( ( cc = scr_csts() ) != 0  &&  inbufp < BUFFER )
  172.        inbuf[inbufp++] = cc;
  173. }
  174.  
  175.  
  176. void show_time()
  177. {
  178. xgettime();
  179. scr_cursoff();
  180. scr_aputs( TIMEPOS, 0, timestr, DIM );
  181. scr_curson();
  182. }
  183.  
  184.  
  185. /* return true if c is a letter, digit or punctuation
  186.  * not very elegant but lots of control, used to delete a word
  187.  */
  188. int inword(c)
  189. char c;
  190. {
  191. return  isalnum( c )  ||  index( "\"\\!@#$%^&*()_+-[]{};'`:~,./<>?|", c );
  192. }
  193.  
  194.  
  195. void makedim()
  196. {
  197. dim(); isdim = YES;
  198. }
  199.  
  200.  
  201. void makebright()
  202. {
  203. high(); isdim = NO;
  204. }
  205.  
  206.  
  207. void makeother()
  208. {
  209. if ( isdim )
  210.       makebright();
  211. else
  212.       makedim();
  213. }
  214.  
  215.  
  216. /* display the proper table
  217.  */
  218. void show_table(table)
  219. int table;
  220. {
  221.  
  222. topline = window;
  223.  
  224. if ( !screen )  {
  225.      pfirst  = loc( pfirst, ( window - 1 ) );
  226.      plast   = loc( pfirst, SHEIGHT - topline );
  227. }
  228.  
  229. switch( table )  {
  230.   case  HELP :
  231.         display_help();
  232.         break;
  233.   case  TABLE1 :
  234.         display_table1();
  235.         break;
  236.   case  TABLE2 :
  237.         display_table2();
  238.         break;
  239.   default :
  240.         screen = NO;
  241.         return;
  242. }
  243.  
  244. puttext();
  245. if ( !screen )  putpage();
  246. screen = table;
  247. }
  248.