]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/movewindow.c
ncurses 5.9 - patch 20121215
[ncurses.git] / test / movewindow.c
index 7905a9356b7b493019874066edf1bf118e8363aa..612cb8823cb75cbabb200f2f9701654a5a72d1e2 100644 (file)
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: movewindow.c,v 1.34 2012/02/05 01:16:47 tom Exp $
+ * $Id: movewindow.c,v 1.38 2012/12/15 18:36:40 tom Exp $
  *
  * Demonstrate move functions for windows and derived windows from the curses
  * library.
  *
  * Demonstrate move functions for windows and derived windows from the curses
  * library.
@@ -79,6 +79,14 @@ static void tail_line(CONST_FMT char *fmt,...) GCC_PRINTFLIKE(1, 2);
 static unsigned num_windows;
 static FRAME *all_windows;
 
 static unsigned num_windows;
 static FRAME *all_windows;
 
+static void
+failed(const char *s)
+{
+    perror(s);
+    endwin();
+    ExitProgram(EXIT_FAILURE);
+}
+
 static void
 message(int lineno, CONST_FMT char *fmt, va_list argp)
 {
 static void
 message(int lineno, CONST_FMT char *fmt, va_list argp)
 {
@@ -198,7 +206,6 @@ selectcell(WINDOW *parent,
                        i = event.y - uli;
                        j = event.x - ulj;
                    }
                        i = event.y - uli;
                        j = event.x - ulj;
                    }
-                   moved = TRUE;
                } else {
                    beep();
                    break;
                } else {
                    beep();
                    break;
@@ -211,8 +218,16 @@ selectcell(WINDOW *parent,
            res.x = ulj + j;
            return (&res);
        }
            res.x = ulj + j;
            return (&res);
        }
-       i %= si;
-       j %= sj;
+
+       if (si <= 0)
+           i = 0;
+       else
+           i %= si;
+
+       if (sj <= 0)
+           j = 0;
+       else
+           j %= sj;
 
        /*
         * If the caller can handle continuous movement, return the result.
 
        /*
         * If the caller can handle continuous movement, return the result.
@@ -306,6 +321,8 @@ add_window(WINDOW *parent, WINDOW *child)
     keypad(child, TRUE);
     if (need > have) {
        all_windows = typeRealloc(FRAME, need, all_windows);
     keypad(child, TRUE);
     if (need > have) {
        all_windows = typeRealloc(FRAME, need, all_windows);
+       if (!all_windows)
+           failed("add_window");
     }
     all_windows[num_windows].parent = parent;
     all_windows[num_windows].child = child;
     }
     all_windows[num_windows].parent = parent;
     all_windows[num_windows].child = child;
@@ -542,7 +559,7 @@ fill_with_pattern(WINDOW *win)
     getmaxyx(win, y1, x1);
     for (y = 0; y < y1; ++y) {
        for (x = 0; x < x1; ++x) {
     getmaxyx(win, y1, x1);
     for (y = 0; y < y1; ++y) {
        for (x = 0; x < x1; ++x) {
-           MvWAddCh(win, y, x, ch);
+           MvWAddCh(win, y, x, (chtype) ch);
            if (++ch > 'z')
                ch = 'a';
        }
            if (++ch > 'z')
                ch = 'a';
        }