From a973947c8822c5172d4daf96a415665c3f6b921d Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 2 Apr 2011 22:56:53 +0200 Subject: setterm: function screendump coding style fixed Signed-off-by: Sami Kerola --- term-utils/setterm.c | 121 ++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 60 deletions(-) (limited to 'term-utils') 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 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 -- cgit v1.2.3-55-g7522