setterm: convert remaining magic values to symbolic references

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Sami Kerola 2014-05-11 20:26:49 +01:00 committed by Karel Zak
parent 010f219d5f
commit 3393c136a2
1 changed files with 47 additions and 20 deletions

View File

@ -171,6 +171,33 @@ enum {
};
#endif
/* Powersave modes */
enum {
VESA_BLANK_MODE_OFF = 0,
VESA_BLANK_MODE_SUSPENDV,
VESA_BLANK_MODE_SUSPENDH,
VESA_BLANK_MODE_POWERDOWN
};
/* klogctl() actions */
enum {
SYSLOG_ACTION_CONSOLE_OFF = 6,
SYSLOG_ACTION_CONSOLE_ON = 7,
SYSLOG_ACTION_CONSOLE_LEVEL = 8
};
/* Console log levels */
enum {
CONSOLE_LEVEL_MIN = 1,
CONSOLE_LEVEL_MAX = 8
};
/* Various numbers */
#define DEFAULT_TAB_LEN 8
#define BLANK_MAX 60
#define TABS_MAX 160
#define BLENGTH_MAX 2000
/* Option flags. Set if the option is to be invoked. */
int opt_term, opt_reset, opt_initialize, opt_cursor;
int opt_linewrap, opt_default, opt_foreground;
@ -196,7 +223,7 @@ int opt_blength_l;
int opt_bfreq_f;
int opt_sn_num; /* Snap screen. */
int opt_rt_len; /* regular tab length */
int opt_tb_array[161]; /* Array for tab list */
int opt_tb_array[TABS_MAX + 1]; /* Array for tab list */
int opt_msglevel_num;
int opt_ps_mode, opt_pd_min; /* powersave mode/powerdown time */
@ -408,7 +435,7 @@ parse_blank(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
*opt_all = UNBLANKSCREEN;
else {
*opt_all = atoi(argv[0]);
if ((*opt_all > 60) || (*opt_all < 0))
if (*opt_all < 0 || BLANK_MAX < *opt_all)
*bad_arg = TRUE;
}
} else {
@ -431,19 +458,19 @@ parse_powersave(int argc, char **argv, int *option, int *opt_mode, int *bad_arg)
*option = TRUE;
if (argc == 1) {
if (strcmp(argv[0], "on") == 0)
*opt_mode = 1;
*opt_mode = VESA_BLANK_MODE_SUSPENDV;
else if (strcmp(argv[0], "vsync") == 0)
*opt_mode = 1;
*opt_mode = VESA_BLANK_MODE_SUSPENDV;
else if (strcmp(argv[0], "hsync") == 0)
*opt_mode = 2;
*opt_mode = VESA_BLANK_MODE_SUSPENDH;
else if (strcmp(argv[0], "powerdown") == 0)
*opt_mode = 3;
*opt_mode = VESA_BLANK_MODE_POWERDOWN;
else if (strcmp(argv[0], "off") == 0)
*opt_mode = 0;
*opt_mode = VESA_BLANK_MODE_OFF;
else
*bad_arg = TRUE;
} else {
*opt_mode = 0;
*opt_mode = VESA_BLANK_MODE_OFF;
}
}
@ -460,7 +487,7 @@ parse_msglevel(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
*option = TRUE;
if (argc == 1) {
*opt_all = atoi(argv[0]);
if (*opt_all < 0 || *opt_all > 8)
if (*opt_all < CONSOLE_LEVEL_MIN || CONSOLE_LEVEL_MAX < *opt_all)
*bad_arg = TRUE;
} else {
*opt_all = -1;
@ -515,13 +542,13 @@ parse_tabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg) {
/* tab_array: Array of tabs */
/* bad_arg: Set to true if an error is detected. */
if (*option || argc > 160)
if (*option || TABS_MAX < argc)
*bad_arg = TRUE;
*option = TRUE;
tab_array[argc] = -1;
while(argc--) {
tab_array[argc] = atoi(argv[argc]);
if(tab_array[argc] < 1 || tab_array[argc] > 160) {
if (tab_array[argc] < 1 || TABS_MAX < tab_array[argc]) {
*bad_arg = TRUE;
return;
}
@ -536,7 +563,7 @@ parse_clrtabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg)
/* tab_array: Array of tabs */
/* bad_arg: Set to true if an error is detected. */
if (*option || argc > 160)
if (*option || TABS_MAX < argc)
*bad_arg = TRUE;
*option = TRUE;
if(argc == 0) {
@ -546,7 +573,7 @@ parse_clrtabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg)
tab_array[argc] = -1;
while(argc--) {
tab_array[argc] = atoi(argv[argc]);
if(tab_array[argc] < 1 || tab_array[argc] > 160) {
if(tab_array[argc] < 1 || TABS_MAX < tab_array[argc]) {
*bad_arg = TRUE;
return;
}
@ -565,11 +592,11 @@ parse_regtabs(int argc, char **argv, int *option, int *opt_len, int *bad_arg) {
*bad_arg = TRUE;
*option = TRUE;
if(argc == 0) {
*opt_len = 8;
*opt_len = DEFAULT_TAB_LEN;
return;
}
*opt_len = atoi(argv[0]);
if(*opt_len < 1 || *opt_len > 160) {
if(*opt_len < 1 || TABS_MAX < *opt_len) {
*bad_arg = TRUE;
return;
}
@ -591,7 +618,7 @@ parse_blength(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
*option = TRUE;
if (argc == 1) {
*opt_all = atoi(argv[0]);
if (*opt_all > 2000)
if (BLENGTH_MAX < *opt_all)
*bad_arg = TRUE;
} else {
*opt_all = 0;
@ -971,7 +998,7 @@ perform_sequence(int vcterm) {
int i;
fputs("\033[3g\r", stdout);
for(i=opt_rt_len+1; i<=160; i+=opt_rt_len)
for(i=opt_rt_len+1; i<=TABS_MAX; i+=opt_rt_len)
printf("\033[%dC\033H",opt_rt_len);
putchar('\r');
}
@ -1030,10 +1057,10 @@ perform_sequence(int vcterm) {
if (opt_msg && vcterm) {
if (opt_msg_on)
/* 7 -- Enable printk's to console */
result = klogctl(7, NULL, 0);
result = klogctl(SYSLOG_ACTION_CONSOLE_ON, NULL, 0);
else
/* 6 -- Disable printk's to console */
result = klogctl(6, NULL, 0);
result = klogctl(SYSLOG_ACTION_CONSOLE_OFF, NULL, 0);
if (result != 0)
warn(_("klogctl error"));
@ -1042,7 +1069,7 @@ perform_sequence(int vcterm) {
/* -msglevel [0-8] */
if (opt_msglevel && vcterm) {
/* 8 -- Set level of messages printed to console */
result = klogctl(8, NULL, opt_msglevel_num);
result = klogctl(SYSLOG_ACTION_CONSOLE_LEVEL, NULL, opt_msglevel_num);
if (result != 0)
warn(_("klogctl error"));
}