home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / CMWINTTY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  2.7 KB  |  148 lines

  1. /*
  2.     cmwintty.c
  3.  
  4.     % function that puts chars in a cmap TTY style.
  5.  
  6.     3/28/88 by Ted
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      8/06/89 jmd    Changed interface, now gets passed a string
  15. */
  16.  
  17. #include "oakhead.h"
  18. #include "disppriv.h"
  19. #include "cmwinobj.h"
  20. #include "cmapdecl.h"
  21.  
  22. #include "scancode.h"
  23.  
  24. #include <ctype.h>
  25.  
  26. /* -------------------------------------------------------------------------- */
  27.  
  28. void cmwin_PlotTTY(win, string)
  29.     win_type win;
  30.     char *string;
  31. {
  32.     int     row, col;
  33.     int     orow, ocol;
  34.     ocbox     relcbox, scrollcbox;
  35.  
  36.     boolean build, backspace;
  37.     int          startcol, plen;
  38.     char   *p;
  39.  
  40.     win_GetBox(win, &relcbox);
  41.     win_GetCursorPos(win, &row, &col);
  42.  
  43.     row = (row < 0) ? 0 : row;
  44.     col = (col < 0) ? 0 : col;
  45.  
  46.     while(*string != '\0') {
  47.         orow = row;
  48.         ocol = col;
  49.  
  50.         p = NULL;
  51.         build = TRUE;
  52.         backspace = FALSE;
  53.  
  54.         while(*string != '\0' && build) {
  55.             build = FALSE;
  56.  
  57.             switch (*string) {
  58.             default:
  59.                 build = TRUE;
  60.                 if (p == NULL) {
  61.                     plen = 0;
  62.                     startcol = col;
  63.                     p = string;
  64.                 }
  65.  
  66.                 col += 1;
  67.                 plen++;
  68.                 break;
  69.  
  70.             case '\n':
  71.                 /* newline */
  72.                 col = 0;
  73.                 row += 1;
  74.                 break;
  75.  
  76.             case '\r':
  77.                 /* carriage return */
  78.                 col = 0;
  79.                 break;
  80.  
  81.             case '\f':
  82.                 /* form feed */
  83.                 row += win_GetHeight(win);
  84.                 break;
  85.  
  86.             case '\t':
  87.                 /* tab */
  88.                 col += 4;
  89.                 break;
  90.  
  91.             case '\b':
  92.                 /* backspace */
  93.                 if (col > 0) {
  94.                     col -= 1;
  95.                     backspace = TRUE;
  96.                 }
  97.                 break;
  98.  
  99.             case '\v':
  100.                 /* vertical tab */
  101.                 row -= 1;
  102.                 break;
  103.             }
  104.  
  105.             /* get next character */
  106.             string++;
  107.         }
  108.  
  109.         if (p != NULL) {
  110.             /* output built up string */
  111.             cmwin_DrawString(win, orow, startcol, p, win_GetAttr(win), plen);
  112.         }
  113.  
  114.         if (backspace) {
  115.             cmwin_DrawChar(win, row, col, ' ', win_GetAttr(win));
  116.         }
  117.  
  118.         if (row < relcbox.toprow) {
  119.             row = relcbox.toprow;
  120.         }
  121.         if (col < relcbox.leftcol) {
  122.             col = relcbox.leftcol;
  123.         }
  124.         if (col > relcbox.rightcol) {
  125.             col = relcbox.rightcol;
  126.         }
  127.  
  128.         if (row > relcbox.botrow) {
  129.             /* Scroll the whole cmap above the cursor, not just the visible part */
  130.             scrollcbox.leftcol  = -cmwin_GetColoffs(win);
  131.             scrollcbox.rightcol = scrollcbox.leftcol + cmap_GetWidth(cmwin_GetCmap(win));
  132.             scrollcbox.toprow   = -cmwin_GetRowoffs(win);
  133.             scrollcbox.botrow   = relcbox.botrow;
  134.  
  135.             cmwin_ScrollBoxVt(win, &relcbox, 1);
  136.             orow--;        /* account for cursor scrolling up too */
  137.             row = relcbox.botrow;
  138.         }
  139.  
  140.         if (row != orow || col != ocol) {
  141.             win_SetCursorPos(win, row, col);
  142.         }
  143.  
  144.     }
  145. }
  146. /* -------------------------------------------------------------------------- */
  147.  
  148.