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 10/12] setterm: use string constant rather than #define
Date: Sun, 11 May 2014 20:26:47 +0100	[thread overview]
Message-ID: <1399836409-7769-10-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1399836409-7769-1-git-send-email-kerolasa@iki.fi>

There is no need to repeat same string in compiled code everywhere.

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

diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 01fe27e..ef820b3 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -165,9 +165,6 @@ extern int klogctl(int type, char *buf, int len);
 # define TIOCL_BLANKEDSCREEN	15	/* return which vt was blanked */
 #endif
 
-/* Control sequences. */
-#define ESC "\033"
-
 /* Static variables. */
 
 /* Option flags.  Set if the option is to be invoked. */
@@ -796,6 +793,8 @@ static char *ti_entry(const char *name) {
 
 static void
 perform_sequence(int vcterm) {
+	static const char *ESC = "\033";
+
 	/* vcterm: Set if terminal is a virtual console. */
 
 	int result;
@@ -822,25 +821,25 @@ perform_sequence(int vcterm) {
 	/* -linewrap [on|off]. Vc only (vt102) */
 	if (opt_linewrap && vcterm) {
 		if (opt_li_on)
-			printf("\033[?7h");
+			printf("%s[?7h", ESC);
 		else
-			printf("\033[?7l");
+			printf("%s[?7l", ESC);
 	}
 
 	/* -repeat [on|off]. Vc only (vt102) */
 	if (opt_repeat && vcterm) {
 		if (opt_rep_on)
-			printf("\033[?8h");
+			printf("%s[?8h", ESC);
 		else
-			printf("\033[?8l");
+			printf("%s[?8l", ESC);
 	}
 
 	/* -appcursorkeys [on|off]. Vc only (vt102) */
 	if (opt_appcursorkeys && vcterm) {
 		if (opt_appck_on)
-			printf("\033[?1h");
+			printf("%s[?1h", ESC);
 		else
-			printf("\033[?1l");
+			printf("%s[?1l", ESC);
 	}
 
 	/* -default.  Vc sets default rendition, otherwise clears all
@@ -848,7 +847,7 @@ perform_sequence(int vcterm) {
 	 */
 	if (opt_default) {
 		if (vcterm)
-			printf("\033[0m");
+			printf("%s[0m", ESC);
 		else
 			putp(ti_entry("sgr0"));
 	}
@@ -871,14 +870,14 @@ perform_sequence(int vcterm) {
 	 * Vc only.
 	 */
 	if (opt_ulcolor && vcterm) {
-		printf("\033[1;%d]", opt_ul_color);
+		printf("%s[1;%d]", ESC, opt_ul_color);
 	}
 
 	/* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default.
 	 * Vc only.
 	 */
 	if (opt_hbcolor && vcterm) {
-		printf("\033[2;%d]", opt_hb_color);
+		printf("%s[2;%d]", ESC, opt_hb_color);
 	}
 
 	/* -inversescreen [on|off].  Vc only (vt102).
@@ -886,9 +885,9 @@ perform_sequence(int vcterm) {
 	if (opt_inversescreen) {
 		if (vcterm) {
 			if (opt_invsc_on)
-				printf("\033[?5h");
+				printf("%s[?5h", ESC);
 			else
-				printf("\033[?5l");
+				printf("%s[?5l", ESC);
 		}
 	}
 
@@ -958,7 +957,7 @@ perform_sequence(int vcterm) {
 
 	/* -store.  Vc only. */
 	if (opt_store && vcterm) {
-		printf("\033[8]");
+		printf("%s[8]", ESC);
 	}
 
 	/* -clear [all|rest]. */
@@ -977,7 +976,7 @@ perform_sequence(int vcterm) {
 			show_tabs();
 		else {
 			for(i=0; opt_tb_array[i] > 0; i++)
-				printf("\033[%dG\033H", opt_tb_array[i]);
+				printf("%s[%dG%sH", ESC, opt_tb_array[i], ESC);
 			putchar('\r');
 		}
 	}
@@ -987,10 +986,10 @@ perform_sequence(int vcterm) {
 		int i;
 
 		if (opt_tb_array[0] == -1)
-			printf("\033[3g");
+			printf("%s[3g", ESC);
 		else
 			for(i=0; opt_tb_array[i] > 0; i++)
-				printf("\033[%dG\033[g", opt_tb_array[i]);
+				printf("%s[%dG%s[g", ESC, opt_tb_array[i], ESC);
 		putchar('\r');
 	}
 
@@ -998,16 +997,16 @@ perform_sequence(int vcterm) {
 	if (opt_regtabs && vcterm) {
 		int i;
 
-		printf("\033[3g\r");
+		printf("%s[3g\r", ESC);
 		for(i=opt_rt_len+1; i<=160; i+=opt_rt_len)
-			printf("\033[%dC\033H",opt_rt_len);
+			printf("%s[%dC%sH", ESC, opt_rt_len, ESC);
 		putchar('\r');
 	}
 
 	/* -blank [0-60]. */
 	if (opt_blank && vcterm) {
 		if (opt_bl_min >= 0)
-			printf("\033[9;%d]", opt_bl_min);
+			printf("%s[9;%d]", ESC, opt_bl_min);
 		else if (opt_bl_min == BLANKSCREEN) {
 			char ioctlarg = TIOCL_BLANKSCREEN;
 			if (ioctl(0,TIOCLINUX,&ioctlarg))
@@ -1038,7 +1037,7 @@ perform_sequence(int vcterm) {
 
 	/* -powerdown [0-60]. */
 	if (opt_powerdown) {
-		printf("\033[14;%d]", opt_pd_min);
+		printf("%s[14;%d]", ESC, opt_pd_min);
 	}
 
 	/* -snap [1-NR_CONS]. */
@@ -1077,12 +1076,12 @@ perform_sequence(int vcterm) {
 
 	/* -blength [0-2000] */
 	if (opt_blength && vcterm) {
-		printf("\033[11;%d]", opt_blength_l);
+		printf("%s[11;%d]", ESC, opt_blength_l);
 	}
 
 	/* -bfreq freqnumber */
 	if (opt_bfreq && vcterm) {
-		printf("\033[10;%d]", opt_bfreq_f);
+		printf("%s[10;%d]", ESC, opt_bfreq_f);
 	}
 
 }
-- 
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 ` Sami Kerola [this message]
2014-05-12 12:07   ` [PATCH 10/12] setterm: use string constant rather than #define 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 ` [PATCH 12/12] setterm: convert remaining magic values to symbolic references Sami Kerola
2014-05-12 12:10   ` 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-10-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