new version from arnold
authorJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 2 May 1985 08:27:20 +0000 (00:27 -0800)
committerJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 2 May 1985 08:27:20 +0000 (00:27 -0800)
SCCS-vsn: lib/libcurses/mvwin.c 1.2
SCCS-vsn: lib/libcurses/newwin.c 1.7
SCCS-vsn: lib/libcurses/overlay.c 1.6
SCCS-vsn: lib/libcurses/overwrite.c 1.4

usr/src/lib/libcurses/mvwin.c
usr/src/lib/libcurses/newwin.c
usr/src/lib/libcurses/overlay.c
usr/src/lib/libcurses/overwrite.c

index 891970c..19d3669 100644 (file)
@@ -3,17 +3,40 @@
 /*
  * relocate the starting position of a window
  *
 /*
  * relocate the starting position of a window
  *
- * %G% (Berkeley) @(#)mvwin.c  1.1
+ * @(#)mvwin.c 1.2 (Berkeley) %G%
  */
 
 mvwin(win, by, bx)
 reg WINDOW     *win;
 reg int                by, bx; {
 
  */
 
 mvwin(win, by, bx)
 reg WINDOW     *win;
 reg int                by, bx; {
 
+       register WINDOW *orig;
+       register int    dy, dx;
+
        if (by + win->_maxy > LINES || bx + win->_maxx > COLS)
                return ERR;
        if (by + win->_maxy > LINES || bx + win->_maxx > COLS)
                return ERR;
-       win->_begy = by;
-       win->_begx = bx;
+       dy = by - win->_begy;
+       dx = bx - win->_begx;
+       orig = win->_orig;
+       if (orig == NULL) {
+               orig = win;
+               do {
+                       win->_begy += dy;
+                       win->_begx += dx;
+                       _swflags_(win);
+                       win = win->_nextp;
+               } while (win != orig);
+       }
+       else {
+               if (by < orig->_begy || win->_maxy + dy > orig->_maxy)
+                       return ERR;
+               if (bx < orig->_begx || win->_maxx + dx > orig->_maxx)
+                       return ERR;
+               win->_begy = by;
+               win->_begx = bx;
+               _swflags_(win);
+               _set_subwin_(orig, win);
+       }
        touchwin(win);
        return OK;
 }
        touchwin(win);
        return OK;
 }
index acf3bbe..9b63b27 100644 (file)
@@ -1,13 +1,14 @@
 /*
  * allocate space for and set up defaults for a new window
  *
 /*
  * allocate space for and set up defaults for a new window
  *
- * %G% (Berkeley) @(#)newwin.c 1.6
+ * @(#)newwin.c        1.7 (Berkeley) %G%
  */
 
 # include      "curses.ext"
 
  */
 
 # include      "curses.ext"
 
-short  *calloc();
-WINDOW *malloc();
+char   *malloc();
+
+# define       SMALLOC (short *) malloc
 
 static WINDOW  *makenew();
 
 
 static WINDOW  *makenew();
 
@@ -20,6 +21,7 @@ int   num_lines, num_cols, begy, begx;
        reg WINDOW      *win;
        reg char        *sp;
        reg int         i, by, bx, nl, nc;
        reg WINDOW      *win;
        reg char        *sp;
        reg int         i, by, bx, nl, nc;
+       reg int         j;
 
        by = begy;
        bx = begx;
 
        by = begy;
        bx = begx;
@@ -32,34 +34,50 @@ int num_lines, num_cols, begy, begx;
                nc = COLS - bx;
        if ((win = makenew(nl, nc, by, bx)) == NULL)
                return ERR;
                nc = COLS - bx;
        if ((win = makenew(nl, nc, by, bx)) == NULL)
                return ERR;
+       if ((win->_firstch = SMALLOC(nl * sizeof win->_firstch[0])) == NULL) {
+               free(win->_y);
+               free(win);
+               return NULL;
+       }
+       if ((win->_lastch = SMALLOC(nl * sizeof win->_lastch[0])) == NULL) {
+               free(win->_y);
+               free(win->_firstch);
+               free(win);
+               return NULL;
+       }
+       win->_nextp = win;
+       for (i = 0; i < nl; i++) {
+               win->_firstch[i] = _NOCHANGE;
+               win->_lastch[i] = _NOCHANGE;
+       }
        for (i = 0; i < nl; i++)
        for (i = 0; i < nl; i++)
-               if ((win->_y[i] = (char *) calloc(nc, sizeof (char))) == NULL) {
-                       reg int         j;
-
+               if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) {
                        for (j = 0; j < i; j++)
                        for (j = 0; j < i; j++)
-                               cfree(win->_y[j]);
-                       cfree(win->_firstch);
-                       cfree(win->_lastch);
-                       cfree(win->_y);
-                       cfree(win);
+                               free(win->_y[j]);
+                       free(win->_firstch);
+                       free(win->_lastch);
+                       free(win->_y);
+                       free(win);
                        return ERR;
                }
                else
                        for (sp = win->_y[i]; sp < win->_y[i] + nc; )
                                *sp++ = ' ';
                        return ERR;
                }
                else
                        for (sp = win->_y[i]; sp < win->_y[i] + nc; )
                                *sp++ = ' ';
-       win->_nextp = win;
+       win->_ch_off = 0;
+# ifdef DEBUG
+       fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off);
+# endif
        return win;
 }
 
 WINDOW *
 subwin(orig, num_lines, num_cols, begy, begx)
 reg WINDOW     *orig;
        return win;
 }
 
 WINDOW *
 subwin(orig, num_lines, num_cols, begy, begx)
 reg WINDOW     *orig;
-int            num_lines, num_cols, begy, begx; {
-
+int            num_lines, num_cols, begy, begx;
+{
        reg int         i;
        reg WINDOW      *win;
        reg int         by, bx, nl, nc;
        reg int         i;
        reg WINDOW      *win;
        reg int         by, bx, nl, nc;
-       reg int         j, k;
 
        by = begy;
        bx = begx;
 
        by = begy;
        bx = begx;
@@ -74,31 +92,42 @@ int         num_lines, num_cols, begy, begx; {
 # endif
        if (by < orig->_begy || bx < orig->_begx
            || by + nl > orig->_maxy + orig->_begy
 # endif
        if (by < orig->_begy || bx < orig->_begx
            || by + nl > orig->_maxy + orig->_begy
-           || bx + nc > orig->_maxx + orig->_begx) {
-# ifdef        DEBUG
-               fprintf(stderr, "returning ERR (1)\n");
-               fprintf(stderr, "SUBWIN(begx = %d, begy = %d,maxx = %d, maxy = %d, nl = %d, nc = %d, by = %d, bx = %d)\n", orig->_begx,orig->_begy,orig->_maxx,orig->_maxy, nl, nc, by, bx);
-# endif
+           || bx + nc > orig->_maxx + orig->_begx)
                return ERR;
                return ERR;
-       }
        if (nl == 0)
                nl = orig->_maxy + orig->_begy - by;
        if (nc == 0)
                nc = orig->_maxx + orig->_begx - bx;
        if (nl == 0)
                nl = orig->_maxy + orig->_begy - by;
        if (nc == 0)
                nc = orig->_maxx + orig->_begx - bx;
-       if ((win = makenew(nl, nc, by, bx)) == NULL) {
-               fprintf(stderr, "returning ERR (2)\n");
+       if ((win = makenew(nl, nc, by, bx)) == NULL)
                return ERR;
                return ERR;
-       }
-       j = by - orig->_begy;
-       k = bx - orig->_begx;
-       for (i = 0; i < nl; i++)
-               win->_y[i] = &orig->_y[j++][k];
        win->_nextp = orig->_nextp;
        orig->_nextp = win;
        win->_orig = orig;
        win->_nextp = orig->_nextp;
        orig->_nextp = win;
        win->_orig = orig;
+       _set_subwin_(orig, win);
        return win;
 }
 
        return win;
 }
 
+/*
+ * this code is shared with mvwin()
+ */
+_set_subwin_(orig, win)
+register WINDOW        *orig, *win;
+{
+       register int    i, j, k;
+
+       j = win->_begy - orig->_begy;
+       k = win->_begx - orig->_begx;
+       win->_ch_off = k;
+# ifdef DEBUG
+       fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off);
+# endif
+       win->_firstch = &orig->_firstch[j];
+       win->_lastch = &orig->_lastch[j];
+       for (i = 0; i < win->_maxy; i++, j++)
+               win->_y[i] = &orig->_y[j][k];
+
+}
+
 /*
  *     This routine sets up a window buffer and returns a pointer to it.
  */
 /*
  *     This routine sets up a window buffer and returns a pointer to it.
  */
@@ -118,46 +147,27 @@ int       num_lines, num_cols, begy, begx; {
 # ifdef        DEBUG
        fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
 # endif
 # ifdef        DEBUG
        fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
 # endif
-       if ((win = (WINDOW *) calloc(1, sizeof (WINDOW))) == NULL)
+       if ((win = (WINDOW *) malloc(sizeof *win)) == NULL)
                return NULL;
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: nl = %d\n", nl);
 # endif
                return NULL;
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: nl = %d\n", nl);
 # endif
-       if ((win->_y = (char **) calloc(nl, sizeof (char *))) == NULL) {
-               cfree(win);
-               return NULL;
-       }
-       if ((win->_firstch = calloc(nl, sizeof (short))) == NULL) {
-               cfree(win);
-               cfree(win->_y);
-               return NULL;
-       }
-       if ((win->_lastch = calloc(nl, sizeof (short))) == NULL) {
-               cfree(win);
-               cfree(win->_y);
-               cfree(win->_firstch);
+       if ((win->_y = (char **) malloc(nl * sizeof win->_y[0])) == NULL) {
+               free(win);
                return NULL;
        }
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: nc = %d\n", nc);
 # endif
        win->_cury = win->_curx = 0;
                return NULL;
        }
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: nc = %d\n", nc);
 # endif
        win->_cury = win->_curx = 0;
-       win->_clear = (nl == LINES && nc == COLS);
+       win->_clear = FALSE;
        win->_maxy = nl;
        win->_maxx = nc;
        win->_begy = by;
        win->_begx = bx;
        win->_flags = 0;
        win->_scroll = win->_leave = FALSE;
        win->_maxy = nl;
        win->_maxx = nc;
        win->_begy = by;
        win->_begx = bx;
        win->_flags = 0;
        win->_scroll = win->_leave = FALSE;
-       for (i = 0; i < nl; i++)
-               win->_firstch[i] = win->_lastch[i] = _NOCHANGE;
-       if (bx + nc == COLS) {
-               win->_flags |= _ENDLINE;
-               if (bx == 0 && nl == LINES && by == 0)
-                       win->_flags |= _FULLWIN;
-               if (by + nl == LINES)
-                       win->_flags |= _SCROLLWIN;
-       }
+       _swflags_(win);
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
        fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
 # ifdef DEBUG
        fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
        fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
@@ -170,3 +180,20 @@ int        num_lines, num_cols, begy, begx; {
 # endif
        return win;
 }
 # endif
        return win;
 }
+
+_swflags_(win)
+register WINDOW        *win;
+{
+       win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN);
+       if (win->_begx + win->_maxx == COLS) {
+               win->_flags |= _ENDLINE;
+               if (win->_begx == 0) {
+                       if (AL && DL)
+                               win->_flags |= _FULLLINE;
+                       if (win->_maxy == LINES && win->_begy == 0)
+                               win->_flags |= _FULLWIN;
+               }
+               if (win->_begy + win->_maxy == LINES)
+                       win->_flags |= _SCROLLWIN;
+       }
+}
index da0bd54..f4207f2 100644 (file)
@@ -7,7 +7,7 @@
 /*
  *     This routine writes win1 on win2 non-destructively.
  *
 /*
  *     This routine writes win1 on win2 non-destructively.
  *
- * %G% (Berkeley) @(#)overlay.c        1.5
+ * @(#)overlay.c       1.6 (Berkeley) %G%
  */
 overlay(win1, win2)
 reg WINDOW     *win1, *win2; {
  */
 overlay(win1, win2)
 reg WINDOW     *win1, *win2; {
@@ -18,16 +18,29 @@ reg WINDOW  *win1, *win2; {
 # ifdef DEBUG
        fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2);
 # endif
 # ifdef DEBUG
        fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2);
 # endif
-       starty = max(win1->_begy, win2->_begy) - win1->_begy;
-       startx = max(win1->_begx, win2->_begx) - win1->_begx;
-       endy = min(win1->_maxy, win2->_maxy) - win1->_begy - 1;
-       endx = min(win1->_maxx, win2->_maxx) - win1->_begx - 1;
-       for (y = starty; y <= endy; y++) {
-               end = &win1->_y[y][endx];
-               x = startx + win1->_begx;
-               for (sp = &win1->_y[y][startx]; sp <= end; sp++) {
-                       if (!isspace(*sp))
-                               mvwaddch(win2, y + win1->_begy, x, *sp);
+       starty = max(win1->_begy, win2->_begy);
+       startx = max(win1->_begx, win2->_begx);
+       endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
+       endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
+# ifdef DEBUG
+       fprintf(outf, "OVERLAY:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
+# endif
+       if (starty >= endy || startx >= endx)
+               return;
+       x = endx - startx;
+       for (y = starty; y < endy; y++) {
+               bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
+                     &win2->_y[y - win2->_begy][startx - win2->_begx], x);
+               touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
+       }
+       for (y = starty; y < endy; y++) {
+               end = &win1->_y[y - win1->_begy][endx - win1->_begx];
+               x = startx - win2->_begx;
+               for (sp = &win1->_y[y][startx - win1->_begx]; sp < end; sp++) {
+                       if (!isspace(*sp)) {
+                               waddch(win2, y - win2->_begy, x);
+                               waddch(win2, *sp);
+                       }
                        x++;
                }
        }
                        x++;
                }
        }
index dbd29f4..90e4fb1 100644 (file)
@@ -1,31 +1,36 @@
 # include      "curses.ext"
 # include      "curses.ext"
+# include      <ctype.h>
 
 # define       min(a,b)        (a < b ? a : b)
 
 # define       min(a,b)        (a < b ? a : b)
+# define       max(a,b)        (a > b ? a : b)
 
 /*
  *     This routine writes win1 on win2 destructively.
  *
 
 /*
  *     This routine writes win1 on win2 destructively.
  *
- * %G% (Berkeley) @(#)overwrite.c      1.3
+ * @(#)overwrite.c     1.4 (Berkeley) %G%
  */
 overwrite(win1, win2)
 reg WINDOW     *win1, *win2; {
 
  */
 overwrite(win1, win2)
 reg WINDOW     *win1, *win2; {
 
-       reg int         x, y, minx, miny, startx, starty;
+       reg char        *sp, *end;
+       reg int         x, y, endy, endx, starty, startx;
 
 # ifdef DEBUG
 
 # ifdef DEBUG
-       fprintf(outf, "OVERWRITE(0%o, 0%o);\n", win1, win2);
+       fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2);
 # endif
 # endif
-       miny = min(win1->_maxy, win2->_maxy);
-       minx = min(win1->_maxx, win2->_maxx);
+       starty = max(win1->_begy, win2->_begy);
+       startx = max(win1->_begx, win2->_begx);
+       endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
+       endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
+       if (starty >= endy || startx >= endx)
+               return;
 # ifdef DEBUG
 # ifdef DEBUG
-       fprintf(outf, "OVERWRITE:\tminx = %d,  miny = %d\n", minx, miny);
+       fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
 # endif
 # endif
-       starty = win1->_begy - win2->_begy;
-       startx = win1->_begx - win2->_begx;
-       if (startx < 0)
-               startx = 0;
-       for (y = 0; y < miny; y++)
-               if (wmove(win2, y + starty, startx) != ERR)
-                       for (x = 0; x < minx; x++)
-                               waddch(win2, win1->_y[y][x]);
+       x = endx - startx;
+       for (y = starty; y < endy; y++) {
+               bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
+                     &win2->_y[y - win2->_begy][startx - win2->_begx], x);
+               touchline(win2, y, startx - win2->_begx, endx - win2->_begx);
+       }
 }
 }