home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / SB_PUT.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  7KB  |  182 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*       Routines for putting lines of text in windows for BinkleyTerm      */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*   This module is derived from code developed by Augie Hansen in his      */
  43. /*   book "Proficient C" published by Microsoft Press.  Mr. Hansen was      */
  44. /*   kind enough to give us verbal permission to use his routines, and      */
  45. /*   Bob, Vince and Alan (and all our full screen users) are grateful.      */
  46. /*   If you decide to use this code in some package you are doing, give     */
  47. /*   some thought to going out and buying the book. He deserves that.       */
  48. /*                                                                          */
  49. /*--------------------------------------------------------------------------*/
  50.  
  51. /* Include this file before any other includes or defines! */
  52.  
  53. #include "includes.h"
  54.  
  55. extern BUFFER Sbuf;
  56. extern CELLP Scrnbuf;
  57.  
  58. int sb_putc (REGIONP win, int ch)
  59. {
  60.    int cmax, rmax;
  61.    int noscroll = 0, puterr = 0;
  62.  
  63. #ifdef MILQ
  64.    RECT                 Rect;
  65. #endif
  66.  
  67.    /* calculate the screen buffer position and limits */
  68.  
  69. #ifdef MILQ
  70.    GetClientRect( win->hWnd, &Rect );
  71.    cmax = Rect.right - Rect.left;
  72.    rmax = Rect.bottom - Rect.top;
  73.    Sbuf.row = Rect.top + win->row;
  74.    Sbuf.col = Rect.left + win->col;
  75. #else
  76.    cmax = win->c1 - win->c0;
  77.    rmax = win->r1 - win->r0;
  78.    Sbuf.row = win->r0 + win->row;
  79.    Sbuf.col = win->c0 + win->col;
  80. #endif
  81.  
  82.    /* process the character */
  83.    switch (ch)
  84.       {
  85.       case '\b':
  86.          /* Non destructive backspace */
  87.          if (win->col > 0)
  88.             {
  89.             --(win->col);
  90.             --(Sbuf.col);
  91.             return (SB_OK);
  92.             }
  93.          else
  94.             return (SB_ERR);
  95.  
  96.       case '\r':
  97.          /* clear trailing line segment */
  98.          while (win->col < cmax)
  99.             {
  100.             if (sb_putc (win, ' ') == SB_ERR)
  101.                {
  102.                ++puterr;
  103.                }
  104.             }
  105.          sb_wc (win, ' ', 1);
  106.          break;
  107.  
  108. #ifdef TABEXP
  109.       case '\t':
  110.          /* convert tabs to spaces */
  111.          lim = win->col + 8 - (win->col & 7);
  112.          while (win->col < lim)
  113.             {
  114.             if (sb_putc (win, ' ') == SB_ERR)
  115.                {
  116.                ++puterr;
  117.                }
  118.             }
  119.          break;
  120. #endif /* TABEXP */
  121.  
  122.       default:
  123. #ifndef MILQ
  124.          (Scrnbuf + Sbuf.row * SB_COLS + Sbuf.col)->b.ch = (unsigned char) ch;
  125. #endif
  126.  
  127. #ifdef MILQ
  128.          WinPutc( win->hWnd, win->row - 1, win->col - 1, ch, SYSTEM_COLOR );
  129. #endif
  130.          if (Sbuf.col < Sbuf.lcol[Sbuf.row])
  131.             {
  132.             Sbuf.lcol[Sbuf.row] = Sbuf.col;
  133.             }
  134.          if (Sbuf.col > Sbuf.rcol[Sbuf.row])
  135.             {
  136.             Sbuf.rcol[Sbuf.row] = Sbuf.col;
  137.             }
  138.          break;
  139.       }
  140.  
  141.    /* update the cursor position */
  142.    if (win->col < cmax)
  143.       {
  144.       ++(win->col);
  145.       }
  146.    else if (win->row < rmax)
  147.       {
  148.       win->col = 0;
  149.       ++(win->row);
  150.       }
  151.    else if (win->wflags & SB_SCROLL)
  152.       {
  153.       sb_scrl (win, 1);
  154.       win->col = 0;
  155.       win->row = rmax;
  156.       }
  157.    else
  158.       {
  159.       ++noscroll;
  160.       }
  161.  
  162.    /* update screen buffer position */
  163.    Sbuf.row = win->r0 + win->row;
  164.    Sbuf.col = win->c0 + win->col;
  165.    Sbuf.flags |= SB_DELTA;
  166.  
  167.    return ((noscroll || puterr) ? SB_ERR : SB_OK);
  168. }
  169.  
  170. #ifndef MILQ
  171. void sb_puts (REGIONP win, char *s)
  172. {
  173.    while (*s)
  174.       {
  175.       if (sb_putc (win, *s++) == SB_ERR)
  176.          return; /* (SB_ERR); */
  177.       }
  178.  
  179.    return; /* (SB_OK); */
  180. }
  181. #endif
  182.