public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 12/12] setterm: convert remaining magic values to symbolic references
Date: Sun, 11 May 2014 20:26:49 +0100	[thread overview]
Message-ID: <1399836409-7769-12-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1399836409-7769-1-git-send-email-kerolasa@iki.fi>

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 term-utils/setterm.c | 65 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 20 deletions(-)

diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 2de555e..5950d2a 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -171,6 +171,31 @@ 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
+};
+
+/* Various numbers  */
+enum {
+	CONSOLE_LEVEL_MIN = 1,
+	CONSOLE_LEVEL_MAX = 8,
+	DEFAULT_TAB_LEN = 8,
+	BLANK_MAX = 60,
+	TABS_MAX = 160,
+	BLENGTH_MAX = 2000,
+};
+
 /* Static variables. */
 
 /* Option flags.  Set if the option is to be invoked. */
@@ -198,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 */
 
@@ -410,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 {
@@ -433,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;
 	}
 }
 
@@ -462,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;
@@ -517,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;
 		}
@@ -538,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) {
@@ -548,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;
 		}
@@ -567,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;
 	}
@@ -593,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;
@@ -1004,7 +1029,7 @@ perform_sequence(int vcterm) {
 		int i;
 
 		printf("%s[3g\r", ESC);
-		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("%s[%dC%sH", ESC, opt_rt_len, ESC);
 		putchar('\r');
 	}
@@ -1063,10 +1088,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"));
@@ -1075,7 +1100,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"));
 	}
-- 
1.9.2


  parent reply	other threads:[~2014-05-11 19:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-11 19:26 [PATCH 01/12] tests: check /proc availability, and go-around if it is incomplete Sami Kerola
2014-05-11 19:26 ` [PATCH 02/12] cytune: remove from util-linux Sami Kerola
2014-05-12 12:11   ` Karel Zak
2014-05-11 19:26 ` [PATCH 03/12] blkid: remove unused variable Sami Kerola
2014-05-11 19:26 ` [PATCH 04/12] logger: fail when io vector number exceeds maximum Sami Kerola
2014-05-11 19:26 ` [PATCH 05/12] logger: check numeric priority and facility input values Sami Kerola
2014-05-11 19:26 ` [PATCH 06/12] build-sys: remove unnecessary void casts Sami Kerola
2014-05-11 19:26 ` [PATCH 07/12] term-utils: avoid error message string length couting errors Sami Kerola
2014-05-12 12:05   ` Karel Zak
2014-05-11 19:26 ` [PATCH 08/12] wall: replace magic number by named value Sami Kerola
2014-05-11 19:26 ` [PATCH 09/12] setterm: remove unused code Sami Kerola
2014-05-11 19:26 ` [PATCH 10/12] setterm: use string constant rather than #define Sami Kerola
2014-05-12 12:07   ` Karel Zak
2014-05-11 19:26 ` [PATCH 11/12] setterm: convert various constant number definitions to enums Sami Kerola
2014-05-11 19:26 ` Sami Kerola [this message]
2014-05-12 12:10   ` [PATCH 12/12] setterm: convert remaining magic values to symbolic references Karel Zak
2014-05-12 14:53     ` Sami Kerola
2014-05-12  7:05 ` [PATCH 01/12] tests: check /proc availability, and go-around if it is incomplete Bernhard Voelker
2014-05-12  9:13   ` Sami Kerola
2014-05-12 11:06   ` Karel Zak
2014-05-12 12:01 ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399836409-7769-12-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox