home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vile-src.zip / vile-8.1 / dumbterm.c < prev    next >
C/C++ Source or Header  |  1998-05-14  |  3KB  |  169 lines

  1. /*    Dumb terminal driver, for I/O before we get into screen mode.
  2.  *
  3.  * $Header: /usr/build/vile/vile/RCS/dumbterm.c,v 1.13 1998/05/14 23:19:42 tom Exp $
  4.  *
  5.  */
  6.  
  7. #include    "estruct.h"
  8. #include    "edef.h"
  9.  
  10. #define MARGIN    8
  11. #define SCRSIZ    64
  12. #define NPAUSE    10            /* # times thru update to pause */
  13.  
  14. static OUTC_DCL dumb_putc (OUTC_ARGS);
  15. static int  dumb_cres     (const char * res);
  16. static int  dumb_getc     (void);
  17. static int  dumb_typahead (void);
  18. static void dumb_beep     (void);
  19. static void dumb_eeol     (void);
  20. static void dumb_eeop     (void);
  21. static void dumb_flush    (void);
  22. static void dumb_kclose   (void);
  23. static void dumb_kopen    (void);
  24. static void dumb_move     ( int row, int col );
  25. static void dumb_rev      ( UINT state );
  26.  
  27. static void flush_blanks  (void);
  28.  
  29. TERM dumb_term = {
  30.     1,
  31.     1,
  32.     80,
  33.     80,
  34.     MARGIN,
  35.     SCRSIZ,
  36.     NPAUSE,
  37.     0,        /* use this to put us into raw mode */
  38.     0,        /* ...and this, just in case we exit */
  39.     dumb_kopen,
  40.     dumb_kclose,
  41.     dumb_getc,
  42.     dumb_putc,
  43.     dumb_typahead,
  44.     dumb_flush,
  45.     dumb_move,
  46.     dumb_eeol,
  47.     dumb_eeop,
  48.     dumb_beep,
  49.     dumb_rev,
  50.     dumb_cres,
  51.     null_t_setfor,
  52.     null_t_setback,
  53.     null_t_setpal,
  54.     null_t_scroll,
  55.     null_t_pflush,
  56.     null_t_icursor,
  57.     null_t_title,
  58.     null_t_watchfd,
  59.     null_t_unwatchfd,
  60. };
  61.  
  62. static    int    this_col;
  63. static    int    last_col;
  64.  
  65. static void
  66. flush_blanks(void)
  67. {
  68.     if (last_col > 0) {
  69.         while (last_col++ < this_col)
  70.             (void)putchar(' ');
  71.         last_col = 0;
  72.     }
  73.     TTflush();
  74. }
  75.  
  76. static void
  77. dumb_kopen(void)
  78. {
  79. }
  80.  
  81. static void
  82. dumb_kclose(void)
  83. {
  84. }
  85.  
  86. static int
  87. dumb_getc(void)
  88. {
  89.     flush_blanks();
  90.     return getchar();
  91. }
  92.  
  93. static OUTC_DCL
  94. dumb_putc(OUTC_ARGS)
  95. {
  96.     if (isSpace(c)) {
  97.         if (last_col == 0)
  98.             last_col = this_col;
  99.     } else {
  100.         flush_blanks();
  101.         (void)putchar(c);
  102.     }
  103.     this_col++;
  104.     OUTC_RET c;
  105. }
  106.  
  107. static int
  108. dumb_typahead(void)
  109. {
  110.     return TRUE;
  111. }
  112.  
  113. static void
  114. dumb_flush(void)
  115. {
  116.     (void)fflush(stdout);
  117. }
  118.  
  119. /*ARGSUSED*/
  120. static void
  121. dumb_move(int row GCC_UNUSED, int col)
  122. {
  123.     if (last_col == 0)
  124.         last_col = this_col;
  125.     if (col == 0) {
  126.         putchar('\r');
  127.         if (last_col != 0)
  128.             putchar('\n');
  129.     } else if (last_col > col) {
  130.         while (last_col-- > col)
  131.             putchar('\b');
  132.     } else if (last_col < col) {
  133.         while (last_col++ < col)
  134.             putchar(' ');
  135.     }
  136.     last_col = 0;
  137.     this_col = col;
  138. }
  139.  
  140. static void
  141. dumb_eeol(void)
  142. {
  143. }
  144.  
  145. static void
  146. dumb_eeop(void)
  147. {
  148. }
  149.  
  150. /*ARGSUSED*/
  151. static int
  152. dumb_cres(    /* change screen resolution */
  153. const char * res GCC_UNUSED)
  154. {
  155.     return(FALSE);
  156. }
  157.  
  158. /* ARGSUSED */
  159. static void
  160. dumb_rev(UINT state GCC_UNUSED)
  161. {
  162. }
  163.  
  164. static void
  165. dumb_beep(void)
  166. {
  167.     putchar(BEL);
  168. }
  169.