home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / curses-old / addbytes.c next >
Encoding:
C/C++ Source or Header  |  1994-01-30  |  4.1 KB  |  134 lines

  1. /*
  2.  * Copyright (c) 1987 Regents of the University of California.
  3.  * 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    5.4 (Berkeley) 6/1/90";
  36. #endif /* not lint */
  37.  
  38. # include    "curses.ext"
  39.  
  40. /*
  41.  *    This routine adds the character to the current position
  42.  *
  43. waddbytes(register WINDOW *win, register const char *bytes, register int count)
  44.  */
  45. int
  46. waddbytes(WINDOW *win, const char *bytes, int count)
  47. {
  48. #define    SYNCH_OUT()    {win->_cury = y; win->_curx = x;}
  49. #define    SYNCH_IN()    {y = win->_cury; x = win->_curx;}
  50.     register int        x, y;
  51.     register int        newx;
  52.  
  53.     SYNCH_IN();
  54. # ifdef FULLDEBUG
  55.     fprintf(outf, "ADDBYTES('%c') at (%d, %d)\n", c, y, x);
  56. # endif
  57.     while (count--) {
  58.         register int c;
  59.         static char blanks[] = "        ";
  60.  
  61.         c = *bytes++;
  62.         switch (c) {
  63.           case '\t':
  64.             if (waddbytes(win, blanks, 8-(x%8)) == ERR) {
  65.             return ERR;
  66.             }
  67.             SYNCH_IN();
  68.             break;
  69.  
  70.           default:
  71. # ifdef FULLDEBUG
  72.             fprintf(outf, "ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
  73. # endif
  74.             if (win->_flags & _STANDOUT)
  75.                 c |= _STANDOUT;
  76.             {
  77. # ifdef    FULLDEBUG
  78.                 fprintf(outf, "ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
  79. # endif
  80.                 if (win->_y[y][x] != c) {
  81.                     newx = x + win->_ch_off;
  82.                     if (win->_firstch[y] == _NOCHANGE) {
  83.                         win->_firstch[y] =
  84.                                 win->_lastch[y] = newx;
  85.                     } else if (newx < win->_firstch[y])
  86.                         win->_firstch[y] = newx;
  87.                     else if (newx > win->_lastch[y])
  88.                         win->_lastch[y] = newx;
  89. # ifdef FULLDEBUG
  90.                     fprintf(outf, "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
  91.                         win->_firstch[y], win->_lastch[y],
  92.                         win->_firstch[y] - win->_ch_off,
  93.                         win->_lastch[y] - win->_ch_off);
  94. # endif
  95.                 }
  96.             }
  97.             win->_y[y][x++] = c;
  98.             if (x >= win->_maxx) {
  99.                 x = 0;
  100.     newline:
  101.                 if (++y >= win->_maxy)
  102.                     if (win->_scroll) {
  103.                         --y;
  104.                         SYNCH_OUT();
  105.                         scroll(win);
  106.                         SYNCH_IN();
  107.                     }
  108.                     else
  109.                         return ERR;
  110.             }
  111. # ifdef FULLDEBUG
  112.             fprintf(outf, "ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
  113. # endif
  114.             break;
  115.           case '\n':
  116.             SYNCH_OUT();
  117.             wclrtoeol(win);
  118.             SYNCH_IN();
  119.             if (!NONL)
  120.                 x = 0;
  121.             goto newline;
  122.           case '\r':
  123.             x = 0;
  124.             break;
  125.           case '\b':
  126.             if (--x < 0)
  127.                 x = 0;
  128.             break;
  129.         }
  130.     }
  131.     SYNCH_OUT();
  132.     return OK;
  133. }
  134.