BSD 4_4_Lite2 release
[unix-history] / usr / src / lib / libcurses / addbytes.c
index 32d077d..6dd8bf9 100644 (file)
@@ -1,31 +1,45 @@
 /*
 /*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1987, 1993, 1994
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)addbytes.c 5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include <curses.h>
-#include <termios.h>
+#include "curses.h"
 
 #define        SYNCH_IN        {y = win->cury; x = win->curx;}
 #define        SYNCH_OUT       {win->cury = y; win->curx = x;}
 
 
 #define        SYNCH_IN        {y = win->cury; x = win->curx;}
 #define        SYNCH_OUT       {win->cury = y; win->curx = x;}
 
-int
-waddbytes(win, bytes, count)
-       WINDOW *win;
-       char *bytes;
-       int count;
-{
-       __waddbytes(win, bytes, count, 0);
-}
-
-
-
 /*
  * waddbytes --
  *     Add the character to the current position in the given window.
 /*
  * waddbytes --
  *     Add the character to the current position in the given window.
@@ -33,7 +47,7 @@ waddbytes(win, bytes, count)
 int
 __waddbytes(win, bytes, count, so)
        register WINDOW *win;
 int
 __waddbytes(win, bytes, count, so)
        register WINDOW *win;
-       register char *bytes;
+       register const char *bytes;
        register int count;
        int so;
 {
        register int count;
        int so;
 {
@@ -45,7 +59,7 @@ __waddbytes(win, bytes, count, so)
        SYNCH_IN;
 
 #ifdef DEBUG
        SYNCH_IN;
 
 #ifdef DEBUG
-       __TRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x);
+       __CTRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x);
 #endif
        while (count--) {
                c = *bytes++;
 #endif
        while (count--) {
                c = *bytes++;
@@ -59,7 +73,7 @@ __waddbytes(win, bytes, count, so)
 
                default:
 #ifdef DEBUG
 
                default:
 #ifdef DEBUG
-       __TRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
+       __CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
 #endif
                        
                        lp = win->lines[y];
 #endif
                        
                        lp = win->lines[y];
@@ -72,19 +86,22 @@ newline:                    if (y == win->maxy - 1) {
                                                SYNCH_IN;
                                                lp = win->lines[y];
                                                x = 0;
                                                SYNCH_IN;
                                                lp = win->lines[y];
                                                x = 0;
-                                       } 
+                                       } else
+                                               return (ERR);
                                } else {
                                        y++;
                                        lp = win->lines[y];
                                        x = 0;
                                }
                                } else {
                                        y++;
                                        lp = win->lines[y];
                                        x = 0;
                                }
+                               if (c == '\n')
+                                       break;
                        }
                                
                        stand = '\0';
                        if (win->flags & __WSTANDOUT || so)
                                stand |= __STANDOUT;
 #ifdef DEBUG
                        }
                                
                        stand = '\0';
                        if (win->flags & __WSTANDOUT || so)
                                stand |= __STANDOUT;
 #ifdef DEBUG
-       __TRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n",
+       __CTRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n",
            y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
 #endif
                        if (lp->line[x].ch != c || 
            y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
 #endif
                        if (lp->line[x].ch != c || 
@@ -99,7 +116,7 @@ newline:                     if (y == win->maxy - 1) {
                                else if (newx > *lp->lastchp)
                                        *lp->lastchp = newx;
 #ifdef DEBUG
                                else if (newx > *lp->lastchp)
                                        *lp->lastchp = newx;
 #ifdef DEBUG
-       __TRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
+       __CTRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
            *lp->firstchp, *lp->lastchp,
            *lp->firstchp - win->ch_off,
            *lp->lastchp - win->ch_off);
            *lp->firstchp, *lp->lastchp,
            *lp->firstchp - win->ch_off,
            *lp->lastchp - win->ch_off);
@@ -115,7 +132,7 @@ newline:                    if (y == win->maxy - 1) {
                        else
                                x++;
 #ifdef DEBUG
                        else
                                x++;
 #ifdef DEBUG
-       __TRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n",
+       __CTRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n",
            y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
 #endif
                        break;
            y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
 #endif
                        break;
@@ -123,7 +140,7 @@ newline:                    if (y == win->maxy - 1) {
                        SYNCH_OUT;
                        wclrtoeol(win);
                        SYNCH_IN;
                        SYNCH_OUT;
                        wclrtoeol(win);
                        SYNCH_IN;
-                       if (origtermio.c_oflag & ONLCR)
+                       if (!NONL)
                                x = 0;
                        goto newline;
                case '\r':
                                x = 0;
                        goto newline;
                case '\r':
@@ -138,4 +155,3 @@ newline:                    if (y == win->maxy - 1) {
        SYNCH_OUT;
        return (OK);
 }
        SYNCH_OUT;
        return (OK);
 }