Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src/lib Pull up revisions:



details:   https://anonhg.NetBSD.org/src/rev/ddde8de1980c
branches:  netbsd-6
changeset: 774395:ddde8de1980c
user:      jdc <jdc%NetBSD.org@localhost>
date:      Thu Aug 09 06:46:37 2012 +0000

description:
Pull up revisions:
  src/lib/libcurses/get_wch.c revision 1.10
  src/lib/libmenu/internals.c revisions 1.14,1.15
(requested by blymn in ticket #459).

* Size argument for memset when clearing cbuf was wrong, cbuf is an array
  of char not int so memset was stomping memory past the end of the array.
  Use sizeof properly to correctly determine the amount of memory to clear.

Extraneous whitespace removal.

* Corrected menu drawing when O_ROWMAJOR is not set
* Corrected menu item neighbour calculation so it works when O_ROWMAJOR
  is set and unset.  This corrects item navigation which was previously
  broken when O_ROWMAJOR was not set.

This resolves lib/46620.

diffstat:

 lib/libcurses/get_wch.c |    6 +-
 lib/libmenu/internals.c |  431 +++++++++++++++++++++++++++--------------------
 2 files changed, 246 insertions(+), 191 deletions(-)

diffs (truncated from 655 to 300 lines):

diff -r a003cb5f3fbd -r ddde8de1980c lib/libcurses/get_wch.c
--- a/lib/libcurses/get_wch.c   Thu Aug 09 06:36:42 2012 +0000
+++ b/lib/libcurses/get_wch.c   Thu Aug 09 06:46:37 2012 +0000
@@ -1,4 +1,4 @@
-/*   $NetBSD: get_wch.c,v 1.9 2010/12/16 17:42:28 wiz Exp $ */
+/*   $NetBSD: get_wch.c,v 1.9.8.1 2012/08/09 06:46:37 jdc Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation Inc.
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: get_wch.c,v 1.9 2010/12/16 17:42:28 wiz Exp $");
+__RCSID("$NetBSD: get_wch.c,v 1.9.8.1 2012/08/09 06:46:37 jdc Exp $");
 #endif                                           /* not lint */
 
 #include <string.h>
@@ -67,7 +67,7 @@
 __init_get_wch(SCREEN *screen)
 {
        wstate = INKEY_NORM;
-       memset( &screen->cbuf, 0, MAX_CBUF_SIZE * sizeof( int ));
+       memset( &screen->cbuf, 0, sizeof(screen->cbuf));
        screen->cbuf_head = screen->cbuf_tail = screen->cbuf_cur = 0;
 }
 #endif /* HAVE_WCHAR */
diff -r a003cb5f3fbd -r ddde8de1980c lib/libmenu/internals.c
--- a/lib/libmenu/internals.c   Thu Aug 09 06:36:42 2012 +0000
+++ b/lib/libmenu/internals.c   Thu Aug 09 06:46:37 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: internals.c,v 1.13 2006/11/24 19:46:58 christos Exp $  */
+/*     $NetBSD: internals.c,v 1.13.42.1 2012/08/09 06:46:37 jdc Exp $  */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn (blymn%baea.com.au@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: internals.c,v 1.13 2006/11/24 19:46:58 christos Exp $");
+__RCSID("$NetBSD: internals.c,v 1.13.42.1 2012/08/09 06:46:37 jdc Exp $");
 
 #include <menu.h>
 #include <ctype.h>
@@ -37,9 +37,7 @@
 
 /* internal function prototypes */
 static void
-_menui_calc_neighbours(MENU *menu, int item_no, int cycle, int item_rows,
-                      int item_cols, ITEM **next, ITEM **prev,
-                       ITEM **major_next, ITEM **major_prev);
+_menui_calc_neighbours(MENU *menu, int item_no);
 static void _menui_redraw_menu(MENU *menu, int old_top_row, int old_cur_item);
 
   /*
@@ -52,9 +50,8 @@
 int
 _menui_stitch_items(MENU *menu)
 {
-       int i, cycle, row_major;
+       int i, row_major;
 
-       cycle = ((menu->opts & O_NONCYCLIC) != O_NONCYCLIC);
        row_major = ((menu->opts & O_ROWMAJOR) == O_ROWMAJOR);
 
        if (menu->posted == 1)
@@ -62,41 +59,14 @@
        if (menu->items == NULL)
                return E_BAD_ARGUMENT;
 
-       if (row_major) {
-               menu->item_rows = menu->item_count / menu->cols;
-               menu->item_cols = menu->cols;
-               if (menu->item_count > (menu->item_rows * menu->item_cols))
-                       menu->item_rows += 1;
-       } else {
-               menu->item_cols = menu->item_count / menu->rows;
-               menu->item_rows = menu->rows;
-               if (menu->item_count > (menu->item_rows * menu->item_cols))
-                       menu->item_cols += 1;
-       }
-       
+       menu->item_rows = menu->item_count / menu->cols;
+       menu->item_cols = menu->cols;
+       if (menu->item_count > (menu->item_rows * menu->item_cols))
+               menu->item_rows += 1;
 
        _menui_max_item_size(menu);
 
        for (i = 0; i < menu->item_count; i++) {
-                 /* Calculate the neighbours.  The ugliness here deals with
-                  * the differing menu layout styles.  The layout affects
-                  * the neighbour calculation so we change the arguments
-                  * around depending on the layout style.
-                  */
-               _menui_calc_neighbours(menu, i, cycle,
-                                       (row_major) ? menu->item_rows
-                                       : menu->item_cols,
-                                       (row_major) ? menu->item_cols
-                                       : menu->item_rows,
-                                       (row_major) ? &menu->items[i]->right
-                                       : &menu->items[i]->down,
-                                       (row_major) ? &menu->items[i]->left
-                                       : &menu->items[i]->up,
-                                       (row_major) ? &menu->items[i]->down
-                                       : &menu->items[i]->right,
-                                       (row_major) ? &menu->items[i]->up
-                                       : &menu->items[i]->left);
-               
                  /* fill in the row and column value of the item */
                if (row_major) {
                        menu->items[i]->row = i / menu->item_cols;
@@ -105,125 +75,200 @@
                        menu->items[i]->row = i % menu->item_rows;
                        menu->items[i]->col = i / menu->item_rows;
                }
+
+               _menui_calc_neighbours(menu, i);
        }
-       
+
        return E_OK;
 }
 
   /*
-   * Calculate the neighbours for an item in menu.  This routine deliberately
-   * does not refer to up/down/left/right as these concepts depend on the menu
-   * layout style (row major or not).  By arranging the arguments in the right
-   * order the caller can generate the neighbours for either menu layout style.
+   * Calculate the neighbours for an item in menu.
    */
 static void
-_menui_calc_neighbours(MENU *menu, int item_no, int cycle, int item_rows,
-                      int item_cols, ITEM **next, ITEM **prev,
-                      ITEM **major_next, ITEM **major_prev)
+_menui_calc_neighbours(MENU *menu, int item_no)
 {
-       int neighbour;
+       int neighbour, cycle, row_major, edge;
+       ITEM *item;
 
-       if (item_rows < 2) {
+       row_major = ((menu->opts & O_ROWMAJOR) == O_ROWMAJOR);
+       cycle = ((menu->opts & O_NONCYCLIC) != O_NONCYCLIC);
+       item = menu->items[item_no];
+
+       if (menu->item_rows < 2) {
                if (cycle) {
-                       *major_next = menu->items[item_no];
-                       *major_prev = menu->items[item_no];
+                       item->up = item;
+                       item->down = item;
                } else {
-                       *major_next = NULL;
-                       *major_prev = NULL;
+                       item->up = NULL;
+                       item->down = NULL;
                }
        } else {
-               neighbour = item_no + item_cols;
-               if (neighbour >= menu->item_count) {
-                       if (cycle) {
-                               if (item_rows == 2) {
-                                       neighbour = item_no - item_cols;
-                                       if (neighbour < 0)
-                                               neighbour = item_no;
-                                       *major_next = menu->items[neighbour];
-                               } else {
-                                       *major_next =
-                                               menu->items[item_no % item_cols];
-                               }
+
+               /* up */
+               if (menu->item_cols < 2) {
+                       if (item_no == 0) {
+                               if (cycle)
+                                       item->up =
+                                           menu->items[menu->item_count - 1];
+                               else
+                                       item->up = NULL;
                        } else
-                               *major_next = NULL;
-               } else
-                       *major_next = menu->items[neighbour];
-               
-               
-               neighbour = item_no - item_cols;
-               if (neighbour < 0) {
-                       if (cycle) {
-                               if (item_rows == 2) {
-                                       neighbour = item_no + item_cols;
+                               item->up = menu->items[item_no - 1];
+               } else {
+                       edge = 0;
+                       if (row_major) {
+                               if (item->row == 0) {
+                                       neighbour =
+                                       (menu->item_rows - 1) * menu->item_cols
+                                               + item->col;
+                                       if (neighbour >= menu->item_count)
+                                               neighbour -= menu->item_cols;
+                                       edge = 1;
+                               } else
+                                       neighbour = item_no - menu->item_cols;
+                       } else {
+                               if (item->row == 0) {
+                                       neighbour = menu->item_rows * item->col
+                                               + menu->item_rows - 1;
                                        if (neighbour >= menu->item_count)
-                                               neighbour = item_no;
-                                       *major_prev = menu->items[neighbour];
+                                               neighbour = menu->item_count - 1;
+                                       edge = 1;
+                               } else
+                                       neighbour = item_no - 1;
+                       }
+
+
+                       item->up = menu->items[neighbour];
+                       if ((!cycle) && (edge == 1))
+                               item->up = NULL;
+               }
+
+               /* Down */
+               if (menu->item_cols < 2) {
+                       if (item_no == (menu->item_count - 1)) {
+                               if (cycle)
+                                       item->down = menu->items[0];
+                               else
+                                       item->down = NULL;
+                       } else
+                               item->down = menu->items[item_no + 1];
+               } else {
+                       edge = 0;
+                       if (row_major) {
+                               if (item->row == menu->item_rows - 1) {
+                                       neighbour = item->col;
+                                       edge = 1;
                                } else {
-                                       neighbour = item_no +
-                                               (item_rows - 1) * item_cols;
+                                       neighbour = item_no + menu->item_cols;
+                                       if (neighbour >= menu->item_count) {
+                                               neighbour = item->col;
+                                               edge = 1;
+                                       }
+                               }
+                       } else {
+                               if (item->row == menu->item_rows - 1) {
+                                       neighbour = item->col * menu->item_rows;
+                                       edge = 1;
+                               } else {
+                                       neighbour = item_no + 1;
+                                       if (neighbour >= menu->item_count) {
+                                               neighbour = item->col
+                                                   * menu->item_rows;
+                                               edge = 1;
+                                       }
+                               }
+                       }
 
-                                       if (neighbour >= menu->item_count)
-                                               neighbour = item_no +
-                                                       (item_rows - 2)
-                                                       * item_cols;
-                                       
-                                       *major_prev = menu->items[neighbour];
-                               }
-                       } else
-                               *major_prev = NULL;
-               } else
-                       *major_prev = menu->items[neighbour];
+                       item->down = menu->items[neighbour];
+                       if ((!cycle) && (edge == 1))
+                               item->down = NULL;
+               }
        }
-       
-       if ((item_no % item_cols) == 0) {
+
+       if (menu->item_cols < 2) {
                if (cycle) {
-                       if (item_cols  < 2) {
-                               *prev = menu->items[item_no];
-                       } else {
-                               neighbour = item_no + item_cols - 1;
-                               if (neighbour >= menu->item_count) {
-                                       if (item_cols == 2) {
-                                               *prev = menu->items[item_no];
-                                       } else {
-                                               *prev = menu->items[menu->item_count - 1];
-                                       }
+                       item->left = item;
+                       item->right = item;
+               } else {
+                       item->left = NULL;
+                       item->right = NULL;
+               }
+       } else {



Home | Main Index | Thread Index | Old Index