+2013-10-08 Paul Eggert <eggert@cs.ucla.edu>
+
+ Fix minor problems found by static checking.
+ * dispnew.c (save_current_matrix): Omit unnecessary casts.
+ * dispnew.c (update_frame_with_menu): Mark debug local as used.
+ * keyboard.c, keyboard.h (Qmouse_movement): Now static.
+ * keyboard.c (read_menu_command): Remove unused local.
+ * lisp.h (read_menu_command): New decl.
+ * menu.c, menu.h (menu_item_width): Arg is now unsigned char *, for
+ benefit of STRING_CHAR_AND_LENGTH. All uses changed.
+ Return ptrdiff_t, not int.
+ * term.c (tty_menu_struct): 'allocated' member is now ptrdiff_t,
+ not int, for benefit of xpalloc.
+ (tty_menu_create, tty_menu_make_room): Simplify by using xzalloc
+ and xpalloc.
+ (have_menus_p): Remove; unused.
+ (tty_menu_add_pane, tty_menu_add_selection): Change signedness of
+ local char * pointer to pacify STRING_CHAR_AND_LENGTH.
+ (tty_menu_add_selection, tty_menu_locate, tty_meny_destroy):
+ Now static.
+ (save_and_enable_current_matrix): Omit unnecessary casts.
+ (read_menu_input): Omit local extern decl (now in lisp.h).
+ Don't access uninitialized storage if mouse_get_xy fails.
+ (tty_menu_activate): Mark local as initialized, for lint.
+ (tty_menu_activate, tty_meny_show): Remove unused locals.
+
2013-10-08 Eli Zaretskii <eliz@gnu.org>
Support menus on text-mode terminals.
char **text;
struct tty_menu_struct **submenu;
int *panenumber; /* Also used as enabled flag. */
- int allocated;
+ ptrdiff_t allocated;
int panecount;
int width;
const char **help_text;
static tty_menu *
tty_menu_create (void)
{
- tty_menu *menu;
-
- menu = (tty_menu *) xmalloc (sizeof (tty_menu));
- menu->allocated = menu->count = menu->panecount = menu->width = 0;
- return menu;
+ return xzalloc (sizeof *tty_menu_create ());
}
/* Allocate some (more) memory for MENU ensuring that there is room for one
- for item. */
+ more item. */
static void
tty_menu_make_room (tty_menu *menu)
{
- if (menu->allocated == 0)
- {
- int count = menu->allocated = 10;
- menu->text = (char **) xmalloc (count * sizeof (char *));
- menu->submenu = (tty_menu **) xmalloc (count * sizeof (tty_menu *));
- menu->panenumber = (int *) xmalloc (count * sizeof (int));
- menu->help_text = (const char **) xmalloc (count * sizeof (char *));
- }
- else if (menu->allocated == menu->count)
+ if (menu->allocated == menu->count)
{
- int count = menu->allocated = menu->allocated + 10;
- menu->text
- = (char **) xrealloc (menu->text, count * sizeof (char *));
- menu->submenu
- = (tty_menu **) xrealloc (menu->submenu, count * sizeof (tty_menu *));
- menu->panenumber
- = (int *) xrealloc (menu->panenumber, count * sizeof (int));
- menu->help_text
- = (const char **) xrealloc (menu->help_text, count * sizeof (char *));
+ ptrdiff_t allocated = menu->allocated;
+ menu->text = xpalloc (menu->text, &allocated, 1, -1, sizeof *menu->text);
+ menu->text = xrealloc (menu->text, allocated * sizeof *menu->text);
+ menu->submenu = xrealloc (menu->submenu,
+ allocated * sizeof *menu->submenu);
+ menu->panenumber = xrealloc (menu->panenumber,
+ allocated * sizeof *menu->panenumber);
+ menu->help_text = xrealloc (menu->help_text,
+ allocated * sizeof *menu->help_text);
+ menu->allocated = allocated;
}
}
/* --------------------------- X Menu emulation ---------------------- */
-/* Report availability of menus. */
-
-int
-have_menus_p (void) { return 1; }
-
/* Create a new pane and place it on the outer-most level. */
static int
tty_menu_add_pane (tty_menu *menu, const char *txt)
{
int len;
- const char *p;
+ const unsigned char *p;
tty_menu_make_room (menu);
menu->submenu[menu->count] = tty_menu_create ();
menu->count++;
/* Update the menu width, if necessary. */
- for (len = 0, p = txt; *p; )
+ for (len = 0, p = (unsigned char *) txt; *p; )
{
int ch_len;
int ch = STRING_CHAR_AND_LENGTH (p, ch_len);
/* Create a new item in a menu pane. */
-int
+static int
tty_menu_add_selection (tty_menu *menu, int pane,
char *txt, int enable, char const *help_text)
{
int len;
- char *p;
+ unsigned char *p;
if (pane)
if (!(menu = tty_menu_search_pane (menu, pane)))
menu->count++;
/* Update the menu width, if necessary. */
- for (len = 0, p = txt; *p; )
+ for (len = 0, p = (unsigned char *) txt; *p; )
{
int ch_len;
int ch = STRING_CHAR_AND_LENGTH (p, ch_len);
/* Decide where the menu would be placed if requested at (X,Y). */
-void
+static void
tty_menu_locate (tty_menu *menu, int x, int y,
int *ulx, int *uly, int *width, int *height)
{
if (from->used[LEFT_MARGIN_AREA])
{
nbytes = from->used[LEFT_MARGIN_AREA] * sizeof (struct glyph);
- to->glyphs[LEFT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
+ to->glyphs[LEFT_MARGIN_AREA] = xmalloc (nbytes);
memcpy (to->glyphs[LEFT_MARGIN_AREA],
from->glyphs[LEFT_MARGIN_AREA], nbytes);
to->used[LEFT_MARGIN_AREA] = from->used[LEFT_MARGIN_AREA];
if (from->used[RIGHT_MARGIN_AREA])
{
nbytes = from->used[RIGHT_MARGIN_AREA] * sizeof (struct glyph);
- to->glyphs[RIGHT_MARGIN_AREA] = (struct glyph *) xmalloc (nbytes);
+ to->glyphs[RIGHT_MARGIN_AREA] = xmalloc (nbytes);
memcpy (to->glyphs[RIGHT_MARGIN_AREA],
from->glyphs[RIGHT_MARGIN_AREA], nbytes);
to->used[RIGHT_MARGIN_AREA] = from->used[RIGHT_MARGIN_AREA];
}
else
{
- extern Lisp_Object read_menu_command (void);
Lisp_Object cmd;
int usable_input = 1;
int st = 0;
if (EQ (cmd, Qt) || EQ (cmd, Qtty_menu_exit))
return -1;
if (EQ (cmd, Qtty_menu_mouse_movement))
- {
- int mx, my;
-
- mouse_get_xy (&mx, &my);
- *x = mx;
- *y = my;
- }
+ mouse_get_xy (x, y);
else if (EQ (cmd, Qtty_menu_next_menu))
{
usable_input = 0;
int kbd_navigation)
{
struct tty_menu_state *state;
- int statecount, x, y, i, b, leave, result, onepane;
+ int statecount, x, y, i, leave, onepane;
+ int result IF_LINT (= 0);
int title_faces[4]; /* face to display the menu title */
int faces[4], buffers_num_deleted = 0;
struct frame *sf = SELECTED_FRAME ();
struct tty_display_info *tty = FRAME_TTY (sf);
bool first_time;
- Lisp_Object saved_echo_area_message, selectface;
+ Lisp_Object selectface;
/* Don't allow non-positive x0 and y0, lest the menu will wrap
around the display. */
/* Dispose of a menu. */
-void
+static void
tty_menu_destroy (tty_menu *menu)
{
int i;
if (ix <= *x
/* We use <= so the blank between 2 items on a TTY is
considered part of the previous item. */
- && *x <= ix + menu_item_width (SSDATA (str)))
+ && *x <= ix + menu_item_width (SDATA (str)))
{
/* Found current item. Now compute the X coordinate of
the previous or next item. */
int dispwidth, dispheight;
int i, j, lines, maxlines;
int maxwidth;
- int dummy_int;
- unsigned int dummy_uint;
ptrdiff_t specpdl_count = SPECPDL_INDEX ();
if (! FRAME_TERMCAP_P (f))