home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / curses / src / waddstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-30  |  5.0 KB  |  143 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : waddstr.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Adds a string to the display buffer.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log:    waddstr.c,v $
  41.  * Revision 1.6  92/06/21  01:12:54  sie
  42.  * Indentation.
  43.  * 
  44.  * Revision 1.5  92/06/10  23:44:49  sie
  45.  * Added serial support.
  46.  * 
  47.  * Revision 1.4  92/01/25  23:55:34  sie
  48.  * Used define for TABSIZE rather than a hard coded 8.
  49.  * 
  50.  * Revision 1.3  91/12/28  22:45:23  sie
  51.  * changed attrs to UBYTE from short + some tidying up.
  52.  * 
  53.  * Revision 1.2  91/12/28  14:01:00  sie
  54.  * Removed WinStat.
  55.  * Renamed LineElement as lnel.
  56.  * 
  57.  * Revision 1.1  91/09/28  18:09:36  sie
  58.  * Initial revision
  59.  * 
  60.  *
  61.  */
  62.  
  63. static char *rcsid = "$Header: SRC:lib/curses/src/RCS/waddstr.c,v 1.6 92/06/21 01:12:54 sie Exp $";
  64.  
  65. #include "acurses.h"
  66.  
  67.  
  68. waddstr(WINDOW *WinPtr, char *Str)
  69. {
  70.   if(!*Str)
  71.     return OK;
  72.   
  73.   WinPtr->LnArry[WinPtr->_cury].Touched = TRUE;
  74.   WinPtr->LnArry[WinPtr->_cury].StartCol = min(WinPtr->LnArry[WinPtr->_cury].StartCol, WinPtr->_curx);
  75.   if(WinPtr->ParentWin) {
  76.     WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].Touched = TRUE;
  77.     WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].StartCol = min(WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].StartCol, WinPtr->_curx + WinPtr->_begx);
  78.   }
  79.   while(*Str) {
  80.     switch(*Str) {
  81.     case '\t':
  82.       do {
  83.     WinPtr->LnArry[WinPtr->_cury].Line[WinPtr->_curx] = ' ';
  84.     WinPtr->LnArry[WinPtr->_cury].ATTRS[WinPtr->_curx++] = WinPtr->_attrs;
  85.       } while(WinPtr->_curx % TABSIZE);
  86.       break;
  87.     case '\n':
  88.       WinPtr->LnArry[WinPtr->_cury].EndCol = max(WinPtr->LnArry[WinPtr->_cury].EndCol, WinPtr->_curx - 1);
  89.       wclrtoeol(WinPtr);
  90.       if(WinPtr->ParentWin)
  91.     WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol=max(WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol,WinPtr->_curx+WinPtr->_begx-1);
  92.       WinPtr->_curx=0;
  93.       WinPtr->_cury++;
  94.       if(WinPtr->_cury > WinPtr->ScrollBot) {
  95.     if(WinPtr->_scroll)
  96.       scroll(WinPtr);
  97.     WinPtr->_cury = WinPtr->ScrollBot;
  98.       }
  99.       if(*(Str + 1)) {  /* If there is more then touch this line too */
  100.     WinPtr->LnArry[WinPtr->_cury].Touched = TRUE;
  101.     WinPtr->LnArry[WinPtr->_cury].StartCol = min(WinPtr->LnArry[WinPtr->_cury].StartCol, WinPtr->_curx);
  102.     if(WinPtr->ParentWin) {
  103.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].Touched = TRUE;
  104.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].StartCol = min(WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].StartCol, WinPtr->_curx+WinPtr->_begx);
  105.     }
  106.       }
  107.     break;
  108.     default:
  109.       WinPtr->LnArry[WinPtr->_cury].Line[WinPtr->_curx] = *Str;
  110.       WinPtr->LnArry[WinPtr->_cury].ATTRS[WinPtr->_curx] = WinPtr->_attrs;
  111.       WinPtr->_curx++;
  112.       break;
  113.     } /* switch */
  114.     if(WinPtr->_curx > WinPtr->_maxx) {    /* If gone off end of line */
  115.       WinPtr->LnArry[WinPtr->_cury].EndCol = WinPtr->_maxx;
  116.       WinPtr->_curx = 0;
  117.       WinPtr->_cury++;
  118.       if(WinPtr->_scroll) {
  119.     if(WinPtr->_cury > WinPtr->ScrollBot) {
  120.       scroll(WinPtr);
  121.       WinPtr->_cury = WinPtr->ScrollBot;
  122.     }
  123.       }
  124.     if(WinPtr->_cury > WinPtr->_maxy)
  125.     WinPtr->_cury = WinPtr->_maxy;
  126.       if(*(Str + 1)) {  /* If there is more then touch this line too */
  127.     WinPtr->LnArry[WinPtr->_cury].Touched = TRUE;
  128.     WinPtr->LnArry[WinPtr->_cury].StartCol = WinPtr->_begx;
  129.     if(WinPtr->ParentWin) {
  130.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].Touched=TRUE;
  131.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].StartCol=
  132.         min(WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].StartCol, WinPtr->_begx);
  133.     }
  134.       }
  135.     } /* if gone off end of line */
  136.   Str++;
  137. } /* while (*Str) */
  138.   WinPtr->LnArry[WinPtr->_cury].EndCol = max(WinPtr->LnArry[WinPtr->_cury].EndCol, WinPtr->_curx - 1);
  139.   if(WinPtr->ParentWin)
  140.     WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol = max(WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol, WinPtr->_curx+WinPtr->_begx-1);
  141.   return OK;
  142. }
  143.