aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2013-11-05 16:14:56 -0800
committerPaul Eggert2013-11-05 16:14:56 -0800
commit798aef02223bdfdf4ff383e59590b2a44eaf3a0c (patch)
tree289c91326c8954fbab11e196397d70bb943477f3 /src
parent9e6e98264c0c2684245463689614926bb22a8516 (diff)
downloademacs-798aef02223bdfdf4ff383e59590b2a44eaf3a0c.tar.gz
emacs-798aef02223bdfdf4ff383e59590b2a44eaf3a0c.zip
Integer-related fixes for term.c etc.
* dispextern.h (face_tty_specified_color): New function. * term.c (turn_on_face): Don't rely on undefined behavior when assigning an out-of-range value to 'long'. Simplify test for toggling highlight. (tty_capable_p): Omit last two (unused) args. All callers changed. * term.c (tty_capable_p, tty_menu_display, tty_menu_add_selection) (read_menu_input, tty_menu_activate, tty_menu_show): * xfaces.c (x_supports_face_attributes_p) (tty_supports_face_attributes_p): Use bool for boolean. All callers changed. (tty_supports_face_attributes_p): Omit defaults for color indices; no longer needed. Simplify tail call.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/dispextern.h12
-rw-r--r--src/menu.h4
-rw-r--r--src/term.c102
-rw-r--r--src/xfaces.c26
5 files changed, 69 insertions, 91 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 00ac6f6e28c..6f6b3a26f92 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12013-11-06 Paul Eggert <eggert@cs.ucla.edu>
2
3 Integer-related fixes for term.c etc.
4 * dispextern.h (face_tty_specified_color): New function.
5 * term.c (turn_on_face): Don't rely on undefined behavior when
6 assigning an out-of-range value to 'long'. Simplify
7 test for toggling highlight.
8 (tty_capable_p): Omit last two (unused) args. All callers changed.
9 * term.c (tty_capable_p, tty_menu_display, tty_menu_add_selection)
10 (read_menu_input, tty_menu_activate, tty_menu_show):
11 * xfaces.c (x_supports_face_attributes_p)
12 (tty_supports_face_attributes_p):
13 Use bool for boolean. All callers changed.
14 (tty_supports_face_attributes_p): Omit defaults for color indices;
15 no longer needed. Simplify tail call.
16
12013-11-05 Stefan Monnier <monnier@iro.umontreal.ca> 172013-11-05 Stefan Monnier <monnier@iro.umontreal.ca>
2 18
3 * xdisp.c (prepare_menu_bars): Mark static. 19 * xdisp.c (prepare_menu_bars): Mark static.
diff --git a/src/dispextern.h b/src/dispextern.h
index 32c6a63e62f..d40febd207a 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1720,6 +1720,15 @@ struct face
1720 1720
1721#define FACE_TTY_DEFAULT_BG_COLOR ((unsigned long) -3) 1721#define FACE_TTY_DEFAULT_BG_COLOR ((unsigned long) -3)
1722 1722
1723/* True if COLOR is a specified (i.e., nondefault) foreground or
1724 background color for a tty face. */
1725
1726INLINE bool
1727face_tty_specified_color (unsigned long color)
1728{
1729 return color < FACE_TTY_DEFAULT_BG_COLOR;
1730}
1731
1723/* Non-zero if FACE was realized for unibyte use. */ 1732/* Non-zero if FACE was realized for unibyte use. */
1724 1733
1725#define FACE_UNIBYTE_P(FACE) ((FACE)->charset < 0) 1734#define FACE_UNIBYTE_P(FACE) ((FACE)->charset < 0)
@@ -3489,8 +3498,7 @@ extern int string_cost (const char *);
3489extern int per_line_cost (const char *); 3498extern int per_line_cost (const char *);
3490extern void calculate_costs (struct frame *); 3499extern void calculate_costs (struct frame *);
3491extern void produce_glyphs (struct it *); 3500extern void produce_glyphs (struct it *);
3492extern bool tty_capable_p (struct tty_display_info *, unsigned, 3501extern bool tty_capable_p (struct tty_display_info *, unsigned);
3493 unsigned long, unsigned long);
3494extern void set_tty_color_mode (struct tty_display_info *, struct frame *); 3502extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
3495extern struct terminal *get_named_tty (const char *); 3503extern struct terminal *get_named_tty (const char *);
3496extern void create_tty_output (struct frame *); 3504extern void create_tty_output (struct frame *);
diff --git a/src/menu.h b/src/menu.h
index 17d66290647..cd89f5eecea 100644
--- a/src/menu.h
+++ b/src/menu.h
@@ -51,7 +51,7 @@ extern Lisp_Object ns_menu_show (struct frame *, int, int, bool, bool,
51 Lisp_Object, const char **); 51 Lisp_Object, const char **);
52extern Lisp_Object xmenu_show (struct frame *, int, int, bool, bool, 52extern Lisp_Object xmenu_show (struct frame *, int, int, bool, bool,
53 Lisp_Object, const char **); 53 Lisp_Object, const char **);
54extern Lisp_Object tty_menu_show (struct frame *, int, int, int, int, 54extern Lisp_Object tty_menu_show (struct frame *, int, int, bool, bool,
55 Lisp_Object, int, const char **); 55 Lisp_Object, bool, const char **);
56extern ptrdiff_t menu_item_width (const unsigned char *); 56extern ptrdiff_t menu_item_width (const unsigned char *);
57#endif /* MENU_H */ 57#endif /* MENU_H */
diff --git a/src/term.c b/src/term.c
index 929280865a5..f86d71ac2f4 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1892,55 +1892,18 @@ static void
1892turn_on_face (struct frame *f, int face_id) 1892turn_on_face (struct frame *f, int face_id)
1893{ 1893{
1894 struct face *face = FACE_FROM_ID (f, face_id); 1894 struct face *face = FACE_FROM_ID (f, face_id);
1895 long fg = face->foreground; 1895 unsigned long fg = face->foreground;
1896 long bg = face->background; 1896 unsigned long bg = face->background;
1897 struct tty_display_info *tty = FRAME_TTY (f); 1897 struct tty_display_info *tty = FRAME_TTY (f);
1898 1898
1899 /* Do this first because TS_end_standout_mode may be the same 1899 /* Use reverse video if the face specifies that.
1900 Do this first because TS_end_standout_mode may be the same
1900 as TS_exit_attribute_mode, which turns all appearances off. */ 1901 as TS_exit_attribute_mode, which turns all appearances off. */
1901 if (MAY_USE_WITH_COLORS_P (tty, NC_REVERSE)) 1902 if (MAY_USE_WITH_COLORS_P (tty, NC_REVERSE)
1902 { 1903 && (inverse_video
1903 if (tty->TN_max_colors > 0) 1904 ? fg == FACE_TTY_DEFAULT_FG_COLOR || bg == FACE_TTY_DEFAULT_BG_COLOR
1904 { 1905 : fg == FACE_TTY_DEFAULT_BG_COLOR || bg == FACE_TTY_DEFAULT_FG_COLOR))
1905 if (fg >= 0 && bg >= 0) 1906 tty_toggle_highlight (tty);
1906 {
1907 /* If the terminal supports colors, we can set them
1908 below without using reverse video. The face's fg
1909 and bg colors are set as they should appear on
1910 the screen, i.e. they take the inverse-video'ness
1911 of the face already into account. */
1912 }
1913 else if (inverse_video)
1914 {
1915 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1916 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1917 tty_toggle_highlight (tty);
1918 }
1919 else
1920 {
1921 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1922 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1923 tty_toggle_highlight (tty);
1924 }
1925 }
1926 else
1927 {
1928 /* If we can't display colors, use reverse video
1929 if the face specifies that. */
1930 if (inverse_video)
1931 {
1932 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1933 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1934 tty_toggle_highlight (tty);
1935 }
1936 else
1937 {
1938 if (fg == FACE_TTY_DEFAULT_BG_COLOR
1939 || bg == FACE_TTY_DEFAULT_FG_COLOR)
1940 tty_toggle_highlight (tty);
1941 }
1942 }
1943 }
1944 1907
1945 if (face->tty_bold_p && MAY_USE_WITH_COLORS_P (tty, NC_BOLD)) 1908 if (face->tty_bold_p && MAY_USE_WITH_COLORS_P (tty, NC_BOLD))
1946 OUTPUT1_IF (tty, tty->TS_enter_bold_mode); 1909 OUTPUT1_IF (tty, tty->TS_enter_bold_mode);
@@ -1965,7 +1928,7 @@ turn_on_face (struct frame *f, int face_id)
1965 char *p; 1928 char *p;
1966 1929
1967 ts = tty->standout_mode ? tty->TS_set_background : tty->TS_set_foreground; 1930 ts = tty->standout_mode ? tty->TS_set_background : tty->TS_set_foreground;
1968 if (fg >= 0 && ts) 1931 if (face_tty_specified_color (fg) && ts)
1969 { 1932 {
1970 p = tparam (ts, NULL, 0, fg, 0, 0, 0); 1933 p = tparam (ts, NULL, 0, fg, 0, 0, 0);
1971 OUTPUT (tty, p); 1934 OUTPUT (tty, p);
@@ -1973,7 +1936,7 @@ turn_on_face (struct frame *f, int face_id)
1973 } 1936 }
1974 1937
1975 ts = tty->standout_mode ? tty->TS_set_foreground : tty->TS_set_background; 1938 ts = tty->standout_mode ? tty->TS_set_foreground : tty->TS_set_background;
1976 if (bg >= 0 && ts) 1939 if (face_tty_specified_color (bg) && ts)
1977 { 1940 {
1978 p = tparam (ts, NULL, 0, bg, 0, 0, 0); 1941 p = tparam (ts, NULL, 0, bg, 0, 0, 0);
1979 OUTPUT (tty, p); 1942 OUTPUT (tty, p);
@@ -2027,12 +1990,10 @@ turn_off_face (struct frame *f, int face_id)
2027 1990
2028 1991
2029/* Return true if the terminal on frame F supports all of the 1992/* Return true if the terminal on frame F supports all of the
2030 capabilities in CAPS simultaneously, with foreground and background 1993 capabilities in CAPS simultaneously. */
2031 colors FG and BG. */
2032 1994
2033bool 1995bool
2034tty_capable_p (struct tty_display_info *tty, unsigned int caps, 1996tty_capable_p (struct tty_display_info *tty, unsigned int caps)
2035 unsigned long fg, unsigned long bg)
2036{ 1997{
2037#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \ 1998#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2038 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \ 1999 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
@@ -2867,7 +2828,8 @@ tty_menu_search_pane (tty_menu *menu, int pane)
2867 { 2828 {
2868 if (pane == menu->panenumber[i]) 2829 if (pane == menu->panenumber[i])
2869 return menu->submenu[i]; 2830 return menu->submenu[i];
2870 if ((try = tty_menu_search_pane (menu->submenu[i], pane))) 2831 try = tty_menu_search_pane (menu->submenu[i], pane);
2832 if (try)
2871 return try; 2833 return try;
2872 } 2834 }
2873 return (tty_menu *) 0; 2835 return (tty_menu *) 0;
@@ -2920,7 +2882,7 @@ mouse_get_xy (int *x, int *y)
2920 2882
2921static void 2883static void
2922tty_menu_display (tty_menu *menu, int x, int y, int pn, int *faces, 2884tty_menu_display (tty_menu *menu, int x, int y, int pn, int *faces,
2923 int mx, int my, int first_item, int disp_help) 2885 int mx, int my, int first_item, bool disp_help)
2924{ 2886{
2925 int i, face, width, enabled, mousehere, row, col; 2887 int i, face, width, enabled, mousehere, row, col;
2926 struct frame *sf = SELECTED_FRAME (); 2888 struct frame *sf = SELECTED_FRAME ();
@@ -2997,16 +2959,19 @@ tty_menu_add_pane (tty_menu *menu, const char *txt)
2997 2959
2998/* Create a new item in a menu pane. */ 2960/* Create a new item in a menu pane. */
2999 2961
3000static int 2962static bool
3001tty_menu_add_selection (tty_menu *menu, int pane, 2963tty_menu_add_selection (tty_menu *menu, int pane,
3002 char *txt, int enable, char const *help_text) 2964 char *txt, bool enable, char const *help_text)
3003{ 2965{
3004 int len; 2966 int len;
3005 unsigned char *p; 2967 unsigned char *p;
3006 2968
3007 if (pane) 2969 if (pane)
3008 if (!(menu = tty_menu_search_pane (menu, pane))) 2970 {
3009 return TTYM_FAILURE; 2971 menu = tty_menu_search_pane (menu, pane);
2972 if (! menu)
2973 return 0;
2974 }
3010 tty_menu_make_room (menu); 2975 tty_menu_make_room (menu);
3011 menu->submenu[menu->count] = (tty_menu *) 0; 2976 menu->submenu[menu->count] = (tty_menu *) 0;
3012 menu->text[menu->count] = txt; 2977 menu->text[menu->count] = txt;
@@ -3027,7 +2992,7 @@ tty_menu_add_selection (tty_menu *menu, int pane,
3027 if (len > menu->width) 2992 if (len > menu->width)
3028 menu->width = len; 2993 menu->width = len;
3029 2994
3030 return TTYM_SUCCESS; 2995 return 1;
3031} 2996}
3032 2997
3033/* Decide where the menu would be placed if requested at (X,Y). */ 2998/* Decide where the menu would be placed if requested at (X,Y). */
@@ -3155,7 +3120,7 @@ read_menu_input (struct frame *sf, int *x, int *y, int min_y, int max_y,
3155 else 3120 else
3156 { 3121 {
3157 Lisp_Object cmd; 3122 Lisp_Object cmd;
3158 int usable_input = 1; 3123 bool usable_input = 1;
3159 mi_result st = MI_CONTINUE; 3124 mi_result st = MI_CONTINUE;
3160 struct tty_display_info *tty = FRAME_TTY (sf); 3125 struct tty_display_info *tty = FRAME_TTY (sf);
3161 Lisp_Object saved_mouse_tracking = do_mouse_tracking; 3126 Lisp_Object saved_mouse_tracking = do_mouse_tracking;
@@ -3215,10 +3180,11 @@ static int
3215tty_menu_activate (tty_menu *menu, int *pane, int *selidx, 3180tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3216 int x0, int y0, char **txt, 3181 int x0, int y0, char **txt,
3217 void (*help_callback)(char const *, int, int), 3182 void (*help_callback)(char const *, int, int),
3218 int kbd_navigation) 3183 bool kbd_navigation)
3219{ 3184{
3220 struct tty_menu_state *state; 3185 struct tty_menu_state *state;
3221 int statecount, x, y, i, leave, onepane; 3186 int statecount, x, y, i;
3187 bool leave, onepane;
3222 int result IF_LINT (= 0); 3188 int result IF_LINT (= 0);
3223 int title_faces[4]; /* face to display the menu title */ 3189 int title_faces[4]; /* face to display the menu title */
3224 int faces[4], buffers_num_deleted = 0; 3190 int faces[4], buffers_num_deleted = 0;
@@ -3285,7 +3251,8 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx,
3285 tty_hide_cursor (tty); 3251 tty_hide_cursor (tty);
3286 if (buffers_num_deleted) 3252 if (buffers_num_deleted)
3287 menu->text[0][7] = ' '; 3253 menu->text[0][7] = ' ';
3288 if ((onepane = menu->count == 1 && menu->submenu[0])) 3254 onepane = menu->count == 1 && menu->submenu[0];
3255 if (onepane)
3289 { 3256 {
3290 menu->width = menu->submenu[0]->width; 3257 menu->width = menu->submenu[0]->width;
3291 state[0].menu = menu->submenu[0]; 3258 state[0].menu = menu->submenu[0];
@@ -3585,8 +3552,8 @@ tty_menu_new_item_coords (struct frame *f, int which, int *x, int *y)
3585} 3552}
3586 3553
3587Lisp_Object 3554Lisp_Object
3588tty_menu_show (struct frame *f, int x, int y, int for_click, int keymaps, 3555tty_menu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
3589 Lisp_Object title, int kbd_navigation, const char **error_name) 3556 Lisp_Object title, bool kbd_navigation, const char **error_name)
3590{ 3557{
3591 tty_menu *menu; 3558 tty_menu *menu;
3592 int pane, selidx, lpane, status; 3559 int pane, selidx, lpane, status;
@@ -3709,9 +3676,8 @@ tty_menu_show (struct frame *f, int x, int y, int for_click, int keymaps,
3709 item_data = SSDATA (item_name); 3676 item_data = SSDATA (item_name);
3710 3677
3711 if (lpane == TTYM_FAILURE 3678 if (lpane == TTYM_FAILURE
3712 || (tty_menu_add_selection (menu, lpane, item_data, 3679 || (! tty_menu_add_selection (menu, lpane, item_data,
3713 !NILP (enable), help_string) 3680 !NILP (enable), help_string)))
3714 == TTYM_FAILURE))
3715 { 3681 {
3716 tty_menu_destroy (menu); 3682 tty_menu_destroy (menu);
3717 *error_name = "Can't add selection to menu"; 3683 *error_name = "Can't add selection to menu";
diff --git a/src/xfaces.c b/src/xfaces.c
index 6845e5c3c65..30658f9c4a8 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4711,7 +4711,7 @@ DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,
4711 4711
4712#ifdef HAVE_WINDOW_SYSTEM 4712#ifdef HAVE_WINDOW_SYSTEM
4713 4713
4714/* Return non-zero if all the face attributes in ATTRS are supported 4714/* Return true if all the face attributes in ATTRS are supported
4715 on the window-system frame F. 4715 on the window-system frame F.
4716 4716
4717 The definition of `supported' is somewhat heuristic, but basically means 4717 The definition of `supported' is somewhat heuristic, but basically means
@@ -4721,7 +4721,7 @@ DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,
4721 \(1) different in appearance than the default face, and 4721 \(1) different in appearance than the default face, and
4722 \(2) `close in spirit' to what the attributes specify, if not exact. */ 4722 \(2) `close in spirit' to what the attributes specify, if not exact. */
4723 4723
4724static int 4724static bool
4725x_supports_face_attributes_p (struct frame *f, 4725x_supports_face_attributes_p (struct frame *f,
4726 Lisp_Object attrs[LFACE_VECTOR_SIZE], 4726 Lisp_Object attrs[LFACE_VECTOR_SIZE],
4727 struct face *def_face) 4727 struct face *def_face)
@@ -4811,7 +4811,7 @@ x_supports_face_attributes_p (struct frame *f,
4811 4811
4812#endif /* HAVE_WINDOW_SYSTEM */ 4812#endif /* HAVE_WINDOW_SYSTEM */
4813 4813
4814/* Return non-zero if all the face attributes in ATTRS are supported 4814/* Return true if all the face attributes in ATTRS are supported
4815 on the tty frame F. 4815 on the tty frame F.
4816 4816
4817 The definition of `supported' is somewhat heuristic, but basically means 4817 The definition of `supported' is somewhat heuristic, but basically means
@@ -4827,7 +4827,7 @@ x_supports_face_attributes_p (struct frame *f,
4827 will _not_ be satisfied by the tty display code's automatic 4827 will _not_ be satisfied by the tty display code's automatic
4828 substitution of a `dim' face for italic. */ 4828 substitution of a `dim' face for italic. */
4829 4829
4830static int 4830static bool
4831tty_supports_face_attributes_p (struct frame *f, 4831tty_supports_face_attributes_p (struct frame *f,
4832 Lisp_Object attrs[LFACE_VECTOR_SIZE], 4832 Lisp_Object attrs[LFACE_VECTOR_SIZE],
4833 struct face *def_face) 4833 struct face *def_face)
@@ -4921,12 +4921,6 @@ tty_supports_face_attributes_p (struct frame *f,
4921 4921
4922 /* Color testing. */ 4922 /* Color testing. */
4923 4923
4924 /* Default the color indices in FG_TTY_COLOR and BG_TTY_COLOR, since
4925 we use them when calling `tty_capable_p' below, even if the face
4926 specifies no colors. */
4927 fg_tty_color.pixel = FACE_TTY_DEFAULT_FG_COLOR;
4928 bg_tty_color.pixel = FACE_TTY_DEFAULT_BG_COLOR;
4929
4930 /* Check if foreground color is close enough. */ 4924 /* Check if foreground color is close enough. */
4931 fg = attrs[LFACE_FOREGROUND_INDEX]; 4925 fg = attrs[LFACE_FOREGROUND_INDEX];
4932 if (STRINGP (fg)) 4926 if (STRINGP (fg))
@@ -4992,14 +4986,7 @@ tty_supports_face_attributes_p (struct frame *f,
4992 4986
4993 /* See if the capabilities we selected above are supported, with the 4987 /* See if the capabilities we selected above are supported, with the
4994 given colors. */ 4988 given colors. */
4995 if (test_caps != 0 && 4989 return tty_capable_p (FRAME_TTY (f), test_caps);
4996 ! tty_capable_p (FRAME_TTY (f), test_caps, fg_tty_color.pixel,
4997 bg_tty_color.pixel))
4998 return 0;
4999
5000
5001 /* Hmmm, everything checks out, this terminal must support this face. */
5002 return 1;
5003} 4990}
5004 4991
5005 4992
@@ -5024,7 +5011,8 @@ satisfied by the tty display code's automatic substitution of a `dim'
5024face for italic. */) 5011face for italic. */)
5025 (Lisp_Object attributes, Lisp_Object display) 5012 (Lisp_Object attributes, Lisp_Object display)
5026{ 5013{
5027 int supports = 0, i; 5014 bool supports = 0;
5015 int i;
5028 Lisp_Object frame; 5016 Lisp_Object frame;
5029 struct frame *f; 5017 struct frame *f;
5030 struct face *def_face; 5018 struct face *def_face;