home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / CMWINTTY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-28  |  2.7 KB  |  147 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.2
  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.      3/28/90 jmd    ansi-fied
  16. */
  17.  
  18. #include "oakhead.h"
  19. #include "disppriv.h"
  20. #include "cmwinobj.h"
  21. #include "cmapdecl.h"
  22.  
  23. #include "scancode.h"
  24.  
  25. #include <ctype.h>
  26.  
  27. /* -------------------------------------------------------------------------- */
  28.  
  29. void cmwin_PlotTTY(win_type win, char *string)
  30. {
  31.     int     row, col;
  32.     int     orow, ocol;
  33.     ocbox     relcbox, scrollcbox;
  34.  
  35.     boolean build, backspace;
  36.     int          startcol, plen;
  37.     char   *p;
  38.  
  39.     win_GetBox(win, &relcbox);
  40.     win_GetCursorPos(win, &row, &col);
  41.  
  42.     row = (row < 0) ? 0 : row;
  43.     col = (col < 0) ? 0 : col;
  44.  
  45.     while(*string != '\0') {
  46.         orow = row;
  47.         ocol = col;
  48.  
  49.         p = NULL;
  50.         build = TRUE;
  51.         backspace = FALSE;
  52.  
  53.         while(*string != '\0' && build) {
  54.             build = FALSE;
  55.  
  56.             switch (*string) {
  57.             default:
  58.                 build = TRUE;
  59.                 if (p == NULL) {
  60.                     plen = 0;
  61.                     startcol = col;
  62.                     p = string;
  63.                 }
  64.  
  65.                 col += 1;
  66.                 plen++;
  67.                 break;
  68.  
  69.             case '\n':
  70.                 /* newline */
  71.                 col = 0;
  72.                 row += 1;
  73.                 break;
  74.  
  75.             case '\r':
  76.                 /* carriage return */
  77.                 col = 0;
  78.                 break;
  79.  
  80.             case '\f':
  81.                 /* form feed */
  82.                 row += win_GetHeight(win);
  83.                 break;
  84.  
  85.             case '\t':
  86.                 /* tab */
  87.                 col += 4;
  88.                 break;
  89.  
  90.             case '\b':
  91.                 /* backspace */
  92.                 if (col > 0) {
  93.                     col -= 1;
  94.                     backspace = TRUE;
  95.                 }
  96.                 break;
  97.  
  98.             case '\v':
  99.                 /* vertical tab */
  100.                 row -= 1;
  101.                 break;
  102.             }
  103.  
  104.             /* get next character */
  105.             string++;
  106.         }
  107.  
  108.         if (p != NULL) {
  109.             /* output built up string */
  110.             cmwin_DrawString(win, orow, startcol, p, win_GetAttr(win), plen);
  111.         }
  112.  
  113.         if (backspace) {
  114.             cmwin_DrawChar(win, row, col, ' ', win_GetAttr(win));
  115.         }
  116.  
  117.         if (row < relcbox.toprow) {
  118.             row = relcbox.toprow;
  119.         }
  120.         if (col < relcbox.leftcol) {
  121.             col = relcbox.leftcol;
  122.         }
  123.         if (col > relcbox.rightcol) {
  124.             col = relcbox.rightcol;
  125.         }
  126.  
  127.         if (row > relcbox.botrow) {
  128.             /* Scroll the whole cmap above the cursor, not just the visible part */
  129.             scrollcbox.leftcol  = -cmwin_GetColoffs(win);
  130.             scrollcbox.rightcol = scrollcbox.leftcol + cmap_GetWidth(cmwin_GetCmap(win));
  131.             scrollcbox.toprow   = -cmwin_GetRowoffs(win);
  132.             scrollcbox.botrow   = relcbox.botrow;
  133.  
  134.             cmwin_ScrollBoxVt(win, &relcbox, 1);
  135.             orow--;        /* account for cursor scrolling up too */
  136.             row = relcbox.botrow;
  137.         }
  138.  
  139.         if (row != orow || col != ocol) {
  140.             win_SetCursorPos(win, row, col);
  141.         }
  142.  
  143.     }
  144. }
  145. /* -------------------------------------------------------------------------- */
  146.  
  147.