File: setpalette.c

package info (click to toggle)
kbd 2.0.4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 14,136 kB
  • sloc: sh: 12,838; ansic: 12,531; pascal: 472; lex: 466; makefile: 394; yacc: 356; perl: 126; sed: 16
file content (49 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include "getfd.h"
#include "version.h"
#include "kbd_error.h"

int main(int argc, char **argv)
{
	int fd, indx, red, green, blue;
	unsigned char cmap[48];

	set_progname(argv[0]);

	if (argc != 5) {
		fprintf(stderr, "usage: %s index red green blue\n", progname);
		exit(EXIT_FAILURE);
	}

	indx  = atoi(argv[1]);
	red   = atoi(argv[2]);
	green = atoi(argv[3]);
	blue  = atoi(argv[4]);

	if (indx < 0 || red < 0 || green < 0 || blue < 0 ||
	    indx > 15 || red > 255 || green > 255 || blue > 255) {
		fprintf(stderr, "indx must be in 0..15, colors in 0..255\n");
		exit(EXIT_FAILURE);
	}

	if ((fd = getfd(NULL)) < 0)
		kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));

	if (ioctl(fd, GIO_CMAP, cmap))
		kbd_error(EXIT_FAILURE, errno, "ioctl GIO_CMAP");

	cmap[3 * indx]     = red;
	cmap[3 * indx + 1] = green;
	cmap[3 * indx + 2] = blue;

	if (ioctl(fd, PIO_CMAP, cmap))
		kbd_error(EXIT_FAILURE, errno, "ioctl PIO_CMAP");

	return EXIT_SUCCESS;
}