aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
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/term.c
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/term.c')
-rw-r--r--src/term.c102
1 files changed, 34 insertions, 68 deletions
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";