summaryrefslogtreecommitdiffstats
path: root/term-utils/setterm.c
diff options
context:
space:
mode:
authorSami Kerola2011-04-02 22:56:53 +0200
committerKarel Zak2011-04-06 11:19:15 +0200
commita973947c8822c5172d4daf96a415665c3f6b921d (patch)
tree6063b69a1f1058f5f076388e9c74744e491d1496 /term-utils/setterm.c
parentsetterm: mention in man setterm.1 -version and -help switches (diff)
downloadkernel-qcow2-util-linux-a973947c8822c5172d4daf96a415665c3f6b921d.tar.gz
kernel-qcow2-util-linux-a973947c8822c5172d4daf96a415665c3f6b921d.tar.xz
kernel-qcow2-util-linux-a973947c8822c5172d4daf96a415665c3f6b921d.zip
setterm: function screendump coding style fixed
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/setterm.c')
-rw-r--r--term-utils/setterm.c121
1 files changed, 61 insertions, 60 deletions
diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index c0aa53131..f9e7a755a 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -1151,68 +1151,69 @@ perform_sequence(int vcterm) {
}
static void
-screendump(int vcnum, FILE *F) {
- char infile[MAXPATHLEN];
- unsigned char header[4];
- unsigned int rows, cols;
- int fd, i, j;
- char *inbuf, *outbuf, *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) {
+screendump(int vcnum, FILE * F)
+{
+ char infile[MAXPATHLEN];
+ unsigned char header[4];
+ unsigned int rows, cols;
+ int fd, i, j;
+ char *inbuf, *outbuf, *p, *q;
+
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 = malloc(rows*cols*2);
- outbuf = malloc(rows*(cols+1));
- if(!inbuf || !outbuf) {
- fputs(_("Out of memory"), stderr);
- goto error;
- }
- if (read(fd, inbuf, rows*cols*2) != 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;
+ 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 = malloc(rows * cols * 2);
+ outbuf = malloc(rows * (cols + 1));
+ if (!inbuf || !outbuf) {
+ fputs(_("Out of memory"), stderr);
+ goto error;
+ }
+ if (read(fd, inbuf, rows * cols * 2) != 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) != q - outbuf) {
+ warnx(_("Error writing screendump"));
+ goto error;
}
- while(j-- > 0 && q[-1] == ' ')
- q--;
- *q++ = '\n';
- }
- if (fwrite(outbuf, 1, q-outbuf, F) != q-outbuf) {
- warnx(_("Error writing screendump"));
- goto error;
- }
- close(fd);
- return;
-
-read_error:
- warnx(_("Couldn't read %s"), infile);
-error:
- if (fd >= 0)
- close(fd);
- exit(EXIT_FAILURE);
+ close(fd);
+ return;
+
+ read_error:
+ warnx(_("Couldn't read %s"), infile);
+ error:
+ if (fd >= 0)
+ close(fd);
+ exit(EXIT_FAILURE);
}
int