home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / EDITOR / NVI179B / NVI179B.ZIP / curses / addbytes.c next >
C/C++ Source or Header  |  1996-03-06  |  4KB  |  160 lines

  1. /*
  2.  * Copyright (c) 1987, 1993, 1994
  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. #include "config.h"
  35.  
  36. #ifndef lint
  37. static const char sccsid[] = "@(#)addbytes.c    8.4 (Berkeley) 5/4/94";
  38. #endif    /* not lint */
  39.  
  40. #include "curses.h"
  41.  
  42. #define    SYNCH_IN    {y = win->cury; x = win->curx;}
  43. #define    SYNCH_OUT    {win->cury = y; win->curx = x;}
  44.  
  45. /*
  46.  * waddbytes --
  47.  *    Add the character to the current position in the given window.
  48.  */
  49. int
  50. __waddbytes(win, bytes, count, so)
  51.     register WINDOW *win;
  52.     register const char *bytes;
  53.     register int count;
  54.     int so;
  55. {
  56.     static char blanks[] = "        ";
  57.     register int c, newx, x, y;
  58.     char stand;
  59.     __LINE *lp;
  60.  
  61.     SYNCH_IN;
  62.  
  63. #ifdef CURSES_DEBUG
  64.     __CTRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x);
  65. #endif
  66.     while (count--) {
  67.         c = *bytes++;
  68.         switch (c) {
  69.         case '\t':
  70.             SYNCH_OUT;
  71.             if (waddbytes(win, blanks, 8 - (x % 8)) == ERR)
  72.                 return (ERR);
  73.             SYNCH_IN;
  74.             break;
  75.  
  76.         default:
  77. #ifdef CURSES_DEBUG
  78.     __CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
  79. #endif
  80.             
  81.             lp = win->lines[y];
  82.             if (lp->flags & __ISPASTEOL) {
  83.                 lp->flags &= ~__ISPASTEOL;
  84. newline:            if (y == win->maxy - 1) {
  85.                     if (win->flags & __SCROLLOK) {
  86.                         SYNCH_OUT;
  87.                         scroll(win);
  88.                         SYNCH_IN;
  89.                         lp = win->lines[y];
  90.                             x = 0;
  91.                     } else
  92.                         return (ERR);
  93.                 } else {
  94.                     y++;
  95.                     lp = win->lines[y];
  96.                     x = 0;
  97.                 }
  98.                 if (c == '\n')
  99.                     break;
  100.             }
  101.                 
  102.             stand = '\0';
  103.             if (win->flags & __WSTANDOUT || so)
  104.                 stand |= __STANDOUT;
  105. #ifdef CURSES_DEBUG
  106.     __CTRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n",
  107.         y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
  108. #endif
  109.             if (lp->line[x].ch != c || 
  110.                 !(lp->line[x].attr & stand)) {
  111.                 newx = x + win->ch_off;
  112.                 if (!(lp->flags & __ISDIRTY)) {
  113.                     lp->flags |= __ISDIRTY;
  114.                     *lp->firstchp = *lp->lastchp = newx;
  115.                 }
  116.                 else if (newx < *lp->firstchp)
  117.                     *lp->firstchp = newx;
  118.                 else if (newx > *lp->lastchp)
  119.                     *lp->lastchp = newx;
  120. #ifdef CURSES_DEBUG
  121.     __CTRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
  122.         *lp->firstchp, *lp->lastchp,
  123.         *lp->firstchp - win->ch_off,
  124.         *lp->lastchp - win->ch_off);
  125. #endif
  126.             }
  127.             lp->line[x].ch = c;
  128.             if (stand)
  129.                 lp->line[x].attr |= __STANDOUT;
  130.             else
  131.                 lp->line[x].attr &= ~__STANDOUT;
  132.             if (x == win->maxx - 1)
  133.                 lp->flags |= __ISPASTEOL;
  134.             else
  135.                 x++;
  136. #ifdef CURSES_DEBUG
  137.     __CTRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n",
  138.         y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
  139. #endif
  140.             break;
  141.         case '\n':
  142.             SYNCH_OUT;
  143.             wclrtoeol(win);
  144.             SYNCH_IN;
  145.             if (!NONL)
  146.                 x = 0;
  147.             goto newline;
  148.         case '\r':
  149.             x = 0;
  150.             break;
  151.         case '\b':
  152.             if (--x < 0)
  153.                 x = 0;
  154.             break;
  155.         }
  156.     }
  157.     SYNCH_OUT;
  158.     return (OK);
  159. }
  160.