speakup: document the usage of enum values

The cursor tracking modes enum, the edge enum, and the read_all commands
enum should be used as such in the source code, to make it more readable
and make gcc catch missing values in switches.

Also, some values of enums are coupled with others, we at least need to
document these.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Link: https://lore.kernel.org/r/20201102095945.ap4pdff2dn47hijh@function
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Samuel Thibault 2020-11-02 10:59:45 +01:00 committed by Greg Kroah-Hartman
parent a79db45fa5
commit 5081559447
2 changed files with 43 additions and 35 deletions

View File

@ -23,12 +23,15 @@ enum msg_index_t {
MSG_OFF = MSG_STATUS_START, MSG_OFF = MSG_STATUS_START,
MSG_ON, MSG_ON,
MSG_NO_WINDOW, MSG_NO_WINDOW,
/* These must be ordered the same as enum cursor_track */
MSG_CURSOR_MSGS_START, MSG_CURSOR_MSGS_START,
MSG_CURSORING_OFF = MSG_CURSOR_MSGS_START, MSG_CURSORING_OFF = MSG_CURSOR_MSGS_START,
MSG_CURSORING_ON, MSG_CURSORING_ON,
MSG_HIGHLIGHT_TRACKING, MSG_HIGHLIGHT_TRACKING,
MSG_READ_WINDOW, MSG_READ_WINDOW,
MSG_READ_ALL, MSG_READ_ALL,
MSG_EDIT_DONE, MSG_EDIT_DONE,
MSG_WINDOW_ALREADY_SET, MSG_WINDOW_ALREADY_SET,
MSG_END_BEFORE_START, MSG_END_BEFORE_START,
@ -41,11 +44,14 @@ enum msg_index_t {
MSG_LEAVING_HELP, MSG_LEAVING_HELP,
MSG_IS_UNASSIGNED, MSG_IS_UNASSIGNED,
MSG_HELP_INFO, MSG_HELP_INFO,
/* These must be ordered the same as enum edge */
MSG_EDGE_MSGS_START, MSG_EDGE_MSGS_START,
MSG_EDGE_TOP = MSG_EDGE_MSGS_START, MSG_EDGE_TOP = MSG_EDGE_MSGS_START,
MSG_EDGE_BOTTOM, MSG_EDGE_BOTTOM,
MSG_EDGE_LEFT, MSG_EDGE_LEFT,
MSG_EDGE_RIGHT, MSG_EDGE_RIGHT,
MSG_NUMBER, MSG_NUMBER,
MSG_SPACE, MSG_SPACE,
MSG_START, /* A little confusing, given our convention. */ MSG_START, /* A little confusing, given our convention. */

View File

@ -90,19 +90,18 @@ const u_char spk_key_defaults[] = {
#include "speakupmap.h" #include "speakupmap.h"
}; };
/* Speakup Cursor Track Variables */ /* cursor track modes, must be ordered same as cursor_msgs in enum msg_index_t */
static int cursor_track = 1, prev_cursor_track = 1; enum cursor_track {
/* cursor track modes, must be ordered same as cursor_msgs */
enum {
CT_Off = 0, CT_Off = 0,
CT_On, CT_On,
CT_Highlight, CT_Highlight,
CT_Window, CT_Window,
CT_Max CT_Max,
read_all_mode = CT_Max,
}; };
#define read_all_mode CT_Max /* Speakup Cursor Track Variables */
static enum cursor_track cursor_track = 1, prev_cursor_track = 1;
static struct tty_struct *tty; static struct tty_struct *tty;
@ -405,15 +404,17 @@ static void say_attributes(struct vc_data *vc)
synth_printf("%s\n", spk_msg_get(MSG_COLORS_START + bg)); synth_printf("%s\n", spk_msg_get(MSG_COLORS_START + bg));
} }
enum { /* must be ordered same as edge_msgs in enum msg_index_t */
edge_top = 1, enum edge {
edge_none = 0,
edge_top,
edge_bottom, edge_bottom,
edge_left, edge_left,
edge_right, edge_right,
edge_quiet edge_quiet
}; };
static void announce_edge(struct vc_data *vc, int msg_id) static void announce_edge(struct vc_data *vc, enum edge msg_id)
{ {
if (spk_bleeps & 1) if (spk_bleeps & 1)
bleep(spk_y); bleep(spk_y);
@ -608,7 +609,8 @@ static void say_prev_word(struct vc_data *vc)
{ {
u_char temp; u_char temp;
u16 ch; u16 ch;
u_short edge_said = 0, last_state = 0, state = 0; enum edge edge_said = edge_none;
u_short last_state = 0, state = 0;
spk_parked |= 0x01; spk_parked |= 0x01;
@ -653,7 +655,7 @@ static void say_prev_word(struct vc_data *vc)
} }
if (spk_x == 0 && edge_said == edge_quiet) if (spk_x == 0 && edge_said == edge_quiet)
edge_said = edge_left; edge_said = edge_left;
if (edge_said > 0 && edge_said < edge_quiet) if (edge_said > edge_none && edge_said < edge_quiet)
announce_edge(vc, edge_said); announce_edge(vc, edge_said);
say_word(vc); say_word(vc);
} }
@ -662,7 +664,8 @@ static void say_next_word(struct vc_data *vc)
{ {
u_char temp; u_char temp;
u16 ch; u16 ch;
u_short edge_said = 0, last_state = 2, state = 0; enum edge edge_said = edge_none;
u_short last_state = 2, state = 0;
spk_parked |= 0x01; spk_parked |= 0x01;
if (spk_x == vc->vc_cols - 1 && spk_y == vc->vc_rows - 1) { if (spk_x == vc->vc_cols - 1 && spk_y == vc->vc_rows - 1) {
@ -694,7 +697,7 @@ static void say_next_word(struct vc_data *vc)
spk_pos += 2; spk_pos += 2;
last_state = state; last_state = state;
} }
if (edge_said > 0) if (edge_said > edge_none)
announce_edge(vc, edge_said); announce_edge(vc, edge_said);
say_word(vc); say_word(vc);
} }
@ -1366,31 +1369,30 @@ static void speakup_deallocate(struct vc_data *vc)
speakup_console[vc_num] = NULL; speakup_console[vc_num] = NULL;
} }
static u_char is_cursor; enum read_all_command {
static u_long old_cursor_pos, old_cursor_x, old_cursor_y; RA_NEXT_SENT = KVAL(K_DOWN)+1,
static int cursor_con; RA_PREV_LINE = KVAL(K_LEFT)+1,
RA_NEXT_LINE = KVAL(K_RIGHT)+1,
static void reset_highlight_buffers(struct vc_data *); RA_PREV_SENT = KVAL(K_UP)+1,
static int read_all_key;
static int in_keyboard_notifier;
static void start_read_all_timer(struct vc_data *vc, int command);
enum {
RA_NOTHING,
RA_NEXT_SENT,
RA_PREV_LINE,
RA_NEXT_LINE,
RA_PREV_SENT,
RA_DOWN_ARROW, RA_DOWN_ARROW,
RA_TIMER, RA_TIMER,
RA_FIND_NEXT_SENT, RA_FIND_NEXT_SENT,
RA_FIND_PREV_SENT, RA_FIND_PREV_SENT,
}; };
static void kbd_fakekey2(struct vc_data *vc, int command) static u_char is_cursor;
static u_long old_cursor_pos, old_cursor_x, old_cursor_y;
static int cursor_con;
static void reset_highlight_buffers(struct vc_data *);
static enum read_all_command read_all_key;
static int in_keyboard_notifier;
static void start_read_all_timer(struct vc_data *vc, enum read_all_command command);
static void kbd_fakekey2(struct vc_data *vc, enum read_all_command command)
{ {
del_timer(&cursor_timer); del_timer(&cursor_timer);
speakup_fake_down_arrow(); speakup_fake_down_arrow();
@ -1427,7 +1429,7 @@ static void stop_read_all(struct vc_data *vc)
spk_do_flush(); spk_do_flush();
} }
static void start_read_all_timer(struct vc_data *vc, int command) static void start_read_all_timer(struct vc_data *vc, enum read_all_command command)
{ {
struct var_t *cursor_timeout; struct var_t *cursor_timeout;
@ -1438,7 +1440,7 @@ static void start_read_all_timer(struct vc_data *vc, int command)
jiffies + msecs_to_jiffies(cursor_timeout->u.n.value)); jiffies + msecs_to_jiffies(cursor_timeout->u.n.value));
} }
static void handle_cursor_read_all(struct vc_data *vc, int command) static void handle_cursor_read_all(struct vc_data *vc, enum read_all_command command)
{ {
int indcount, sentcount, rv, sn; int indcount, sentcount, rv, sn;