home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / SB_PUT.C < prev    next >
C/C++ Source or Header  |  1990-05-14  |  6KB  |  173 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-90, 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.240.    */
  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:132/491, 1:141/491  */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n132.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.  
  52. #include <stdio.h>
  53. #include <ctype.h>
  54.  
  55. #include "sbuf.h"
  56. #include "com.h"
  57. #include "xfer.h"
  58. #include "zmodem.h"
  59. #include "keybd.h"
  60. #include "sched.h"
  61. #include "externs.h"
  62. #include "prototyp.h"
  63.  
  64. extern BUFFER Sbuf;
  65. extern CELLP Scrnbuf;
  66.  
  67. int sb_putc (win, ch)
  68. REGIONP win;
  69. int ch;
  70. {
  71.    int cmax, rmax;
  72.    int noscroll = 0, puterr = 0;
  73.  
  74.    /* calculate the screen buffer position and limits */
  75.    cmax = win->c1 - win->c0;
  76.    rmax = win->r1 - win->r0;
  77.    Sbuf.row = win->r0 + win->row;
  78.    Sbuf.col = win->c0 + win->col;
  79.  
  80.    /* process the character */
  81.    switch (ch)
  82.       {
  83.       case '\b':
  84.          /* Non destructive backspace */
  85.          if (win->col > 0)
  86.             {
  87.             --(win->col);
  88.             --(Sbuf.col);
  89.             return (SB_OK);
  90.             }
  91.          else
  92.             return (SB_ERR);
  93.  
  94.       case '\r':
  95.          /* clear trailing line segment */
  96.          while (win->col < cmax)
  97.             {
  98.             if (sb_putc (win, ' ') == SB_ERR)
  99.                {
  100.                ++puterr;
  101.                }
  102.             }
  103.          sb_wc (win, ' ', 1);
  104.          break;
  105.  
  106.       case '\t':
  107.          /* convert tabs to spaces */
  108. /*         lim = win->col + 8 - (win->col & 7);
  109.          while (win->col < lim)
  110.             {
  111.             if (sb_putc (win, ' ') == SB_ERR)
  112.                {
  113.                ++puterr;
  114.                }
  115.             }
  116.          break;*/
  117.  
  118.       default:
  119.          (Scrnbuf + Sbuf.row * SB_COLS + Sbuf.col)->b.ch = (unsigned char) ch;
  120.          if (Sbuf.col < Sbuf.lcol[Sbuf.row])
  121.             {
  122.             Sbuf.lcol[Sbuf.row] = Sbuf.col;
  123.             }
  124.          if (Sbuf.col > Sbuf.rcol[Sbuf.row])
  125.             {
  126.             Sbuf.rcol[Sbuf.row] = Sbuf.col;
  127.             }
  128.          break;
  129.       }
  130.  
  131.    /* update the cursor position */
  132.    if (win->col < cmax)
  133.       {
  134.       ++(win->col);
  135.       }
  136.    else if (win->row < rmax)
  137.       {
  138.       win->col = 0;
  139.       ++(win->row);
  140.       }
  141.    else if (win->wflags & SB_SCROLL)
  142.       {
  143.       sb_scrl (win, 1);
  144.       win->col = 0;
  145.       win->row = rmax;
  146.       }
  147.    else
  148.       {
  149.       ++noscroll;
  150.       }
  151.  
  152.    /* update screen buffer position */
  153.    Sbuf.row = win->r0 + win->row;
  154.    Sbuf.col = win->c0 + win->col;
  155.    Sbuf.flags |= SB_DELTA;
  156.  
  157.    return ((noscroll || puterr) ? SB_ERR : SB_OK);
  158. }
  159.  
  160. void sb_puts (win, s)
  161. REGIONP win;
  162. unsigned char *s;
  163. {
  164.    while (*s)
  165.       {
  166.       if (sb_putc (win, *s++) == SB_ERR)
  167.          return; /* (SB_ERR); */
  168.       }
  169.  
  170.    return; /* (SB_OK); */
  171. }
  172.  
  173.