Linux console tools development discussion
 help / color / mirror / Atom feed
From: Felix Janda <felix.janda@posteo.de>
To: kbd@lists.altlinux.org
Subject: [kbd] [PATCH 4/5] setvtrgb: inline set_colormap
Date: Wed, 22 Apr 2015 21:06:40 +0200
Message-ID: <20150422190640.GD3170@euler> (raw)

---
 src/setvtrgb.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/src/setvtrgb.c b/src/setvtrgb.c
index 94501ef..3fa03a7 100644
--- a/src/setvtrgb.c
+++ b/src/setvtrgb.c
@@ -54,18 +54,6 @@ usage(int code)
 }
 
 static void
-set_colormap(unsigned char *colormap)
-{
-	int fd = getfd(NULL);
-
-	/* Apply the color map to the tty via ioctl */
-	if (ioctl(fd, PIO_CMAP, colormap) == -1)
-		error(EXIT_FAILURE, errno, "ioctl");
-
-	close(fd);
-}
-
-static void
 parse_file(FILE *fd, const char *filename)
 {
 	int c;
@@ -100,9 +88,10 @@ parse_file(FILE *fd, const char *filename)
 
 int
 main(int argc, char **argv) {
-	int c;
+	int c, fd;
 	const char *file;
-	FILE *fd;
+	unsigned char *colormap = cmap;
+	FILE *f;
 
 	set_progname(argv[0]);
 
@@ -127,21 +116,26 @@ main(int argc, char **argv) {
 	file = argv[optind];
 
 	if (!strcmp(file, "vga")) {
-		set_colormap(vga_colors);
-		return EXIT_SUCCESS;
+		colormap = vga_colors;
 
 	} else if (!strcmp(file, "-")) {
 		parse_file(stdin, "stdin");
 
 	} else {
-		if ((fd = fopen(file, "r")) == NULL)
+		if ((f = fopen(file, "r")) == NULL)
 			error(EXIT_FAILURE, errno, "fopen");
 
-		parse_file(fd, file);
-		fclose(fd);
+		parse_file(f, file);
+		fclose(f);
 	}
 
-	set_colormap(cmap);
+	fd = getfd(NULL);
+
+	/* Apply the color map to the tty via ioctl */
+	if (ioctl(fd, PIO_CMAP, colormap) == -1)
+		error(EXIT_FAILURE, errno, "ioctl");
+
+	close(fd);
 
 	return EXIT_SUCCESS;
 }
-- 
2.0.5


                 reply	other threads:[~2015-04-22 19:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20150422190640.GD3170@euler \
    --to=felix.janda@posteo.de \
    --cc=kbd@lists.altlinux.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

Linux console tools development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/kbd/0 kbd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kbd kbd/ http://lore.altlinux.org/kbd \
		kbd@lists.altlinux.org kbd@lists.altlinux.ru kbd@lists.altlinux.com
	public-inbox-index kbd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.kbd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git