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 04/17] setterm: move show_tabs() and screendump() functions
Date: Sun, 18 May 2014 15:05:28 +0100	[thread overview]
Message-ID: <1400421941-14244-5-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1400421941-14244-1-git-send-email-kerolasa@iki.fi>

Earlier the function was in the middle of option parsing code segment,
and screendump() required function prototype.

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

diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index c4753d0..734d275 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -221,8 +221,6 @@ int opt_ps_mode, opt_pd_min;	/* powersave mode/powerdown time */
 
 char opt_sn_name[PATH_MAX] = "screen.dump";
 
-static void screendump(int vcnum, FILE *F);
-
 /* Command line parsing routines.
  *
  * Note that it is an error for a given option to be invoked more than once.
@@ -451,24 +449,6 @@ static int parse_bfreq(char **argv, char *optarg, int *optind)
 	return strtoint_or_err(arg);
 }
 
-static void
-show_tabs(void) {
-	int i, co = tigetnum("cols");
-
-	if(co > 0) {
-		printf("\r         ");
-		for(i = 10; i < co-2; i+=10)
-			printf("%-10d", i);
-		putchar('\n');
-		for(i = 1; i <= co; i++)
-			putchar(i%10+'0');
-		putchar('\n');
-		for(i = 1; i < co; i++)
-			printf("\tT\b");
-		putchar('\n');
-	}
-}
-
 static void __attribute__ ((__noreturn__))
 usage(FILE *out) {
 /* Print error message about arguments, and the command's syntax. */
@@ -769,6 +749,98 @@ static char *ti_entry(const char *name) {
 	return buf_ptr;
 }
 
+static void show_tabs(void)
+{
+	int i, co = tigetnum("cols");
+
+	if (co > 0) {
+		printf("\r         ");
+		for (i = 10; i < co - 2; i += 10)
+			printf("%-10d", i);
+		putchar('\n');
+		for (i = 1; i <= co; i++)
+			putchar(i % 10 + '0');
+		putchar('\n');
+		for (i = 1; i < co; i++)
+			printf("\tT\b");
+		putchar('\n');
+	}
+}
+
+static void screendump(int vcnum, FILE *F)
+{
+	char infile[MAXPATHLEN];
+	unsigned char header[4];
+	unsigned int rows, cols;
+	int fd;
+	size_t i, j;
+	ssize_t rc;
+	char *inbuf = NULL, *outbuf = NULL, *p, *q;
+
+	sprintf(infile, "/dev/vcsa%d", vcnum);
+	fd = open(infile, O_RDONLY);
+	if (fd < 0 && vcnum == 0) {
+		/* vcsa0 is often called vcsa */
+		sprintf(infile, "/dev/vcsa");
+		fd = open(infile, O_RDONLY);
+	}
+	if (fd < 0) {
+		/* try devfs name - for zero vcnum just /dev/vcc/a */
+		/* some gcc's warn for %.u - add 0 */
+		sprintf(infile, "/dev/vcc/a%.0u", vcnum);
+		fd = open(infile, O_RDONLY);
+	}
+	if (fd < 0) {
+		sprintf(infile, "/dev/vcsa%d", vcnum);
+		goto read_error;
+	}
+	if (read(fd, header, 4) != 4)
+		goto read_error;
+	rows = header[0];
+	cols = header[1];
+	if (rows * cols == 0)
+		goto read_error;
+
+	inbuf = xmalloc(rows * cols * 2);
+	outbuf = xmalloc(rows * (cols + 1));
+
+	rc = read(fd, inbuf, rows * cols * 2);
+	if (rc < 0 || (size_t)rc != rows * cols * 2)
+		goto read_error;
+	p = inbuf;
+	q = outbuf;
+	for (i = 0; i < rows; i++) {
+		for (j = 0; j < cols; j++) {
+			*q++ = *p;
+			p += 2;
+		}
+		while (j-- > 0 && q[-1] == ' ')
+			q--;
+		*q++ = '\n';
+	}
+	if (fwrite(outbuf, 1, q - outbuf, F) != (size_t)(q - outbuf)) {
+		warnx(_("Error writing screendump"));
+		goto error;
+	}
+	close(fd);
+	free(inbuf);
+	free(outbuf);
+	return;
+
+ read_error:
+	if (vcnum != 0)
+		warnx(_("Couldn't read %s"), infile);
+	else
+		warnx(_("Couldn't read neither /dev/vcsa0 nor /dev/vcsa"));
+
+ error:
+	if (fd >= 0)
+		close(fd);
+	free(inbuf);
+	free(outbuf);
+	exit(EXIT_FAILURE);
+}
+
 static void
 perform_sequence(int vcterm) {
 	/* vcterm: Set if terminal is a virtual console. */
@@ -1033,81 +1105,6 @@ perform_sequence(int vcterm) {
 
 }
 
-static void
-screendump(int vcnum, FILE * F)
-{
-	char infile[MAXPATHLEN];
-	unsigned char header[4];
-	unsigned int rows, cols;
-	int fd;
-	size_t i, j;
-	ssize_t rc;
-	char *inbuf = NULL, *outbuf = NULL, *p, *q;
-
-	sprintf(infile, "/dev/vcsa%d", vcnum);
-	fd = open(infile, O_RDONLY);
-	if (fd < 0 && vcnum == 0) {
-		/* vcsa0 is often called vcsa */
-		sprintf(infile, "/dev/vcsa");
-		fd = open(infile, O_RDONLY);
-	}
-	if (fd < 0) {
-		/* try devfs name - for zero vcnum just /dev/vcc/a */
-		/* some gcc's warn for %.u - add 0 */
-		sprintf(infile, "/dev/vcc/a%.0u", vcnum);
-		fd = open(infile, O_RDONLY);
-	}
-	if (fd < 0) {
-		sprintf(infile, "/dev/vcsa%d", vcnum);
-		goto read_error;
-	}
-	if (read(fd, header, 4) != 4)
-		goto read_error;
-	rows = header[0];
-	cols = header[1];
-	if (rows * cols == 0)
-		goto read_error;
-
-	inbuf = xmalloc(rows * cols * 2);
-	outbuf = xmalloc(rows * (cols + 1));
-
-	rc = read(fd, inbuf, rows * cols * 2);
-	if (rc < 0 || (size_t) rc != rows * cols * 2)
-		goto read_error;
-	p = inbuf;
-	q = outbuf;
-	for (i = 0; i < rows; i++) {
-		for (j = 0; j < cols; j++) {
-			*q++ = *p;
-			p += 2;
-		}
-		while (j-- > 0 && q[-1] == ' ')
-			q--;
-		*q++ = '\n';
-	}
-	if (fwrite(outbuf, 1, q - outbuf, F) != (size_t) (q - outbuf)) {
-		warnx(_("Error writing screendump"));
-		goto error;
-	}
-	close(fd);
-	free(inbuf);
-	free(outbuf);
-	return;
-
-read_error:
-	if (vcnum != 0)
-		warnx(_("Couldn't read %s"), infile);
-	else
-		warnx(_("Couldn't read neither /dev/vcsa0 nor /dev/vcsa"));
-
-error:
-	if (fd >= 0)
-		close(fd);
-	free(inbuf);
-	free(outbuf);
-	exit(EXIT_FAILURE);
-}
-
 int
 main(int argc, char **argv) {
 	char *term;			/* Terminal type. */
-- 
1.9.2


  parent reply	other threads:[~2014-05-18 14:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-18 14:05 [PATCH 00/17] pull: almost complete setterm refactoring Sami Kerola
2014-05-18 14:05 ` [PATCH 01/17] setterm: clean up includes Sami Kerola
2014-05-18 14:05 ` [PATCH 02/17] setterm: use getopt_long_only() for option parsing Sami Kerola
2014-05-19  9:29   ` Karel Zak
2014-05-18 14:05 ` [PATCH 03/17] setterm: use string utils to numeric parsing Sami Kerola
2014-05-19  9:24   ` Karel Zak
2014-05-18 14:05 ` Sami Kerola [this message]
2014-05-18 14:05 ` [PATCH 05/17] setterm: remove usage comment segment Sami Kerola
2014-05-18 14:05 ` [PATCH 06/17] setterm: add option control structure Sami Kerola
2014-05-19  9:38   ` Karel Zak
2014-05-19  9:48   ` Karel Zak
2014-05-18 14:05 ` [PATCH 07/17] setterm: add init_terminal() to make main() shorter Sami Kerola
2014-05-18 14:05 ` [PATCH 08/17] setterm: clean up screendump() Sami Kerola
2014-05-18 14:05 ` [PATCH 09/17] setterm: remove devfs and /dev/vcsa0 support Sami Kerola
2014-05-19  9:52   ` Karel Zak
2014-05-18 14:05 ` [PATCH 10/17] setterm: make -msglevel 0 to work as is did earlier Sami Kerola
2014-05-18 14:05 ` [PATCH 11/17] setterm: correct usage() bright color argument Sami Kerola
2014-05-19  9:57   ` Karel Zak
2014-05-18 14:05 ` [PATCH 12/17] setterm: improve perform_sequence() coding style Sami Kerola
2014-05-18 14:05 ` [PATCH 13/17] setterm: tell user when options does not effect Sami Kerola
2014-05-19 10:02   ` Karel Zak
2014-05-18 14:05 ` [PATCH 14/17] setterm: improve error messages Sami Kerola
2014-05-18 14:05 ` [PATCH 15/17] setterm: various visual terminal effects are not console specific Sami Kerola
2014-05-18 14:05 ` [PATCH 16/17] setterm: mark some options to be exclusive with each other Sami Kerola
2014-05-18 14:05 ` [PATCH 17/17] setterm: add set_blanking() action Sami Kerola
2014-05-19 21:51 ` [PATCH 00/17] pull: almost complete setterm refactoring Sami Kerola
2014-05-20  8:11   ` Benno Schulenberg
2014-05-20 10:02     ` 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=1400421941-14244-5-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