]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setterm: function screendump coding style fixed
authorSami Kerola <kerolasa@iki.fi>
Sat, 2 Apr 2011 20:56:53 +0000 (22:56 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Apr 2011 09:19:15 +0000 (11:19 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
term-utils/setterm.c

index c0aa531319fb578d66d5627aff78529287174948..f9e7a755ac50f69a2c271cfe88ab11591bb7c66b 100644 (file)
@@ -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