home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libcurses-8.3-src.lha / libcurses-8.3 / addbytes.c next >
Encoding:
C/C++ Source or Header  |  1995-01-11  |  4.4 KB  |  149 lines

  1. /*
  2.  * Copyright (c) 1987, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)addbytes.c    8.3 (Berkeley) 3/19/94";
  36. #endif    /* not lint */
  37.  
  38. #include <curses.h>
  39.  
  40. #define    SYNCH_IN    {y = win->cury; x = win->curx;}
  41. #define    SYNCH_OUT    {win->cury = y; win->curx = x;}
  42.  
  43. /*
  44.  * waddbytes --
  45.  *    Add the character to the current position in the given window.
  46.  */
  47. int
  48. __waddbytes(win, bytes, count, so)
  49.     register WINDOW *win;
  50.     register const char *bytes;
  51.     register int count;
  52.     int so;
  53. {
  54.     static char blanks[] = "        ";
  55.     register int c, newx, x, y;
  56.     char stand;
  57.     __LINE *lp;
  58.  
  59.     DBUG_ENTER ("waddbytes");
  60.     DBUG_PRINT ("addbytes", ("add %d characters to window", count));
  61.     DBUG_PRINT ("addbytes", ("standout flag is %d", so));
  62.     SYNCH_IN;
  63.  
  64.     while (count--) {
  65.         c = *bytes++;
  66.         DBUG_PRINT ("waddbytes", ("add '%c' at (%d, %d)", c, y, x));
  67.         switch (c) {
  68.         case '\t':
  69.             SYNCH_OUT;
  70.             if (waddbytes(win, blanks, 8 - (x % 8)) == ERR)
  71.                 DBUG_RETURN (ERR);
  72.             SYNCH_IN;
  73.             break;
  74.  
  75.         default:
  76.             lp = win->lines[y];
  77.             if (lp->flags & __ISPASTEOL) {
  78.                 lp->flags &= ~__ISPASTEOL;
  79. newline:            if (y == win->maxy - 1) {
  80.                     if (win->flags & __SCROLLOK) {
  81.                         SYNCH_OUT;
  82.                         scroll(win);
  83.                         SYNCH_IN;
  84.                         lp = win->lines[y];
  85.                             x = 0;
  86.                     } else
  87.                         DBUG_RETURN (ERR);
  88.                 } else {
  89.                     y++;
  90.                     lp = win->lines[y];
  91.                     x = 0;
  92.                 }
  93.                 if (c == '\n')
  94.                     break;
  95.             }
  96.                 
  97.             stand = '\0';
  98.             if (win->flags & __WSTANDOUT || so)
  99.                 stand |= __STANDOUT;
  100.             DBUG_PRINT ("waddbytes", ("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d",
  101.                           y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp));
  102.             if (lp->line[x].ch != c || 
  103.                 !(lp->line[x].attr & stand)) {
  104.                 newx = x + win->ch_off;
  105.                 if (!(lp->flags & __ISDIRTY)) {
  106.                     lp->flags |= __ISDIRTY;
  107.                     *lp->firstchp = *lp->lastchp = newx;
  108.                 }
  109.                 else if (newx < *lp->firstchp)
  110.                     *lp->firstchp = newx;
  111.                 else if (newx > *lp->lastchp)
  112.                     *lp->lastchp = newx;
  113.                 DBUG_PRINT ("waddbytes", ("ADDBYTES: change gives f/l: %d/%d [%d/%d]",
  114.                               *lp->firstchp, *lp->lastchp,
  115.                               *lp->firstchp - win->ch_off,
  116.                               *lp->lastchp - win->ch_off));
  117.             }
  118.             lp->line[x].ch = c;
  119.             if (stand)
  120.                 lp->line[x].attr |= __STANDOUT;
  121.             else
  122.                 lp->line[x].attr &= ~__STANDOUT;
  123.             if (x == win->maxx - 1)
  124.                 lp->flags |= __ISPASTEOL;
  125.             else
  126.                 x++;
  127.             DBUG_PRINT ("waddbytes", ("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d",
  128.                           y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp));
  129.             break;
  130.         case '\n':
  131.             SYNCH_OUT;
  132.             wclrtoeol(win);
  133.             SYNCH_IN;
  134.             if (!NONL)
  135.                 x = 0;
  136.             goto newline;
  137.         case '\r':
  138.             x = 0;
  139.             break;
  140.         case '\b':
  141.             if (--x < 0)
  142.                 x = 0;
  143.             break;
  144.         }
  145.     }
  146.     SYNCH_OUT;
  147.     DBUG_RETURN (OK);
  148. }
  149.