home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 287.lha / TY_v1.3 / src / output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  3.9 KB  |  123 lines

  1. /*************************************************************************
  2.  ***                        output.c                     (JJB TEMPLAR) ***
  3.  *** Date modifications begun: 7/8/89.                                 ***
  4.  *** Last modified: 16/8/89.                                           ***
  5.  *************************************************************************/
  6. /*** High level routines for screen output.                            ***
  7.  *************************************************************************/
  8.  
  9. #include "less.h"
  10. #include "win.h"
  11. #include "screen.h"
  12.  
  13. extern int  tty;
  14. extern int  pr_type;
  15. extern int  oldpr;
  16.  
  17. extern int  sc_width, sc_height;
  18. extern int  twiddle;
  19. extern int  fast_line;              /* In option.c */
  20. extern char *line;
  21.  
  22. int     l_start = 0;
  23. static char obuf[1024];
  24. static char *ob = obuf;
  25.  
  26. UBYTE   chmap[32] = {      /* Determines which CTRL-chars to let through */
  27.     1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1};
  28.     /* Currently ESC and TAB are passed through */
  29.  
  30. void    put_line() /*====================================================*/
  31. {                  /* Display line in cur buffer.                        */
  32. register char   *p;              /* Note '\n' must be handled by caller. */
  33. register int    len;
  34.  
  35.     if (!line) {
  36.         if (twiddle) putc('~');
  37.         return;
  38.     }
  39.     len = strlen(line) - l_start;
  40.     if (len <= 0) return;
  41.  
  42.     line += l_start;    /* If l_start zero, no effect. Note that this   *
  43.                          * ignores the problem of skipping ESC-chars,   *
  44.                          * which results in unwanted effects.           */
  45.   /* Very crude right side clip */
  46.     if (len > sc_width + 20) line[len + 20] = 0;
  47.  
  48.     if (fast_line) puts(line);  /* Don't care about special chars */
  49.     else for (p = line;  *p;  p++) {
  50.         if (control_char((UBYTE)(*p))) {
  51.             putc('^');
  52.             putc(carat_char(*p));
  53.         }
  54.         else {
  55.             switch (*p) {
  56.                 case ('~'): ul_enter(); break;
  57.                 case ('`'): ul_exit();  break;
  58.                 default:    putc(*p);
  59.             }
  60.         }
  61.     }
  62.     if (len > sc_width) {       /* May have crashed against right */
  63.         flush();        /* <- annoying to have to do this */
  64.         if (conpos() >= sc_width - 1) puts("$");
  65.     }
  66. }
  67.  
  68. int     control_char(c) /*===============================================*/
  69. register UBYTE  c;      /* Is c a control character? Note unsigned. */
  70. {
  71.     if ((c >= ' ') && (c != 0x7f)) return(0);
  72.     return((c == 0x7f)? 1: (int)chmap[c]);
  73. }
  74.  
  75. int     carat_char(c) /*=================================================*/
  76. int     c;            /* Return ascii for control char (eg: C for ^C)    */
  77. {
  78.     return ((c == 0x7f)? '?': (c | 0x40));
  79. }
  80.  
  81. void    flush() /*=======================================================*/
  82. {
  83.     if (!tty) ttopen();       /* tty: flag to indicate presence of console */
  84.  
  85.     ttflush();                /* flush obuf is different to ttflush obuf */
  86.     tWrite(obuf,(ob-obuf));
  87.     ob = obuf;
  88. }
  89.  
  90. void    putc(c) /*=======================================================*/
  91. int     c;      /* Output char. Write to buffer, flush buffer if full.   */
  92. {
  93.     if (ob >= &obuf[sizeof(obuf)]) flush();
  94.     *ob++ = c;
  95. }
  96.  
  97. void    puts(s) /*=======================================================*/
  98. register char *s;
  99. {
  100.     while (*s) putc(*s++);          /* Ha. */
  101. }
  102.  
  103. char    errmsg[100];
  104.  
  105. void    error(s,rw) /*===================================================*/
  106. char    *s;
  107. int     rw;         /* Really wait? */
  108. {
  109. register int    c;
  110.     flush();        /* Hokay? Necessary for help/about */
  111.     if (!rw) {      /* prompt() handles so_enter, etc */
  112.         oldpr = pr_type;
  113.         pr_type = PR_ERROR;
  114.         strcpy(errmsg,s);
  115.     }
  116.     else {
  117.         SetWindowTitles(Window,s,(char *)-1L);
  118.         while ((c = getc()) != 0x44) bell();    /* Wait for <CR> */
  119.  
  120.      /* if (strlen(s) > sc_width) repaint();     No point if no auto-wrap */
  121.     }
  122. }
  123.