summaryrefslogtreecommitdiffstats
path: root/term-utils/setterm.c
diff options
context:
space:
mode:
authorSami Kerola2014-05-17 21:12:23 +0200
committerSami Kerola2014-05-19 23:45:37 +0200
commitc591be873bc321ec21bdd959a94dad54d9fe36c7 (patch)
tree0a5b1897fad2830d47d1974b68ddec1ec22dee26 /term-utils/setterm.c
parentsetterm: use string utils to numeric parsing (diff)
downloadkernel-qcow2-util-linux-c591be873bc321ec21bdd959a94dad54d9fe36c7.tar.gz
kernel-qcow2-util-linux-c591be873bc321ec21bdd959a94dad54d9fe36c7.tar.xz
kernel-qcow2-util-linux-c591be873bc321ec21bdd959a94dad54d9fe36c7.zip
setterm: move show_tabs() and screendump() functions
Earlier the function was in the middle of option parsing code segment, and screendump() required function prototype. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/setterm.c')
-rw-r--r--term-utils/setterm.c187
1 files changed, 92 insertions, 95 deletions
diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 58b52ca89..533bc0945 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -221,8 +221,6 @@ int opt_ps_mode, opt_pd_min; /* powersave mode/powerdown time */
char opt_sn_name[PATH_MAX] = "screen.dump";
-static void screendump(int vcnum, FILE *F);
-
/* Command line parsing routines.
*
* Note that it is an error for a given option to be invoked more than once.
@@ -442,24 +440,6 @@ static int parse_bfreq(char **argv, char *optarg, int *optind)
return strtos32_or_err(arg, _("argument error"));
}
-static void
-show_tabs(void) {
- int i, co = tigetnum("cols");
-
- if(co > 0) {
- printf("\r ");
- for(i = 10; i < co-2; i+=10)
- printf("%-10d", i);
- putchar('\n');
- for(i = 1; i <= co; i++)
- putchar(i%10+'0');
- putchar('\n');
- for(i = 1; i < co; i++)
- printf("\tT\b");
- putchar('\n');
- }
-}
-
static void __attribute__ ((__noreturn__))
usage(FILE *out) {
/* Print error message about arguments, and the command's syntax. */
@@ -760,6 +740,98 @@ static char *ti_entry(const char *name) {
return buf_ptr;
}
+static void show_tabs(void)
+{
+ int i, co = tigetnum("cols");
+
+ if (co > 0) {
+ printf("\r ");
+ for (i = 10; i < co - 2; i += 10)
+ printf("%-10d", i);
+ putchar('\n');
+ for (i = 1; i <= co; i++)
+ putchar(i % 10 + '0');
+ putchar('\n');
+ for (i = 1; i < co; i++)
+ printf("\tT\b");
+ putchar('\n');
+ }
+}
+
+static void screendump(int vcnum, FILE *F)
+{
+ char infile[MAXPATHLEN];
+ unsigned char header[4];
+ unsigned int rows, cols;
+ int fd;
+ size_t i, j;
+ ssize_t rc;
+ char *inbuf = NULL, *outbuf = NULL, *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) {
+ 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 = xmalloc(rows * cols * 2);
+ outbuf = xmalloc(rows * (cols + 1));
+
+ rc = read(fd, inbuf, rows * cols * 2);
+ if (rc < 0 || (size_t)rc != 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) != (size_t)(q - outbuf)) {
+ warnx(_("Error writing screendump"));
+ goto error;
+ }
+ close(fd);
+ free(inbuf);
+ free(outbuf);
+ return;
+
+ read_error:
+ if (vcnum != 0)
+ warnx(_("Couldn't read %s"), infile);
+ else
+ warnx(_("Couldn't read neither /dev/vcsa0 nor /dev/vcsa"));
+
+ error:
+ if (fd >= 0)
+ close(fd);
+ free(inbuf);
+ free(outbuf);
+ exit(EXIT_FAILURE);
+}
+
static void
perform_sequence(int vcterm) {
/* vcterm: Set if terminal is a virtual console. */
@@ -1024,81 +1096,6 @@ perform_sequence(int vcterm) {
}
-static void
-screendump(int vcnum, FILE * F)
-{
- char infile[MAXPATHLEN];
- unsigned char header[4];
- unsigned int rows, cols;
- int fd;
- size_t i, j;
- ssize_t rc;
- char *inbuf = NULL, *outbuf = NULL, *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) {
- 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 = xmalloc(rows * cols * 2);
- outbuf = xmalloc(rows * (cols + 1));
-
- rc = read(fd, inbuf, rows * cols * 2);
- if (rc < 0 || (size_t) rc != 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) != (size_t) (q - outbuf)) {
- warnx(_("Error writing screendump"));
- goto error;
- }
- close(fd);
- free(inbuf);
- free(outbuf);
- return;
-
-read_error:
- if (vcnum != 0)
- warnx(_("Couldn't read %s"), infile);
- else
- warnx(_("Couldn't read neither /dev/vcsa0 nor /dev/vcsa"));
-
-error:
- if (fd >= 0)
- close(fd);
- free(inbuf);
- free(outbuf);
- exit(EXIT_FAILURE);
-}
-
int
main(int argc, char **argv) {
char *term; /* Terminal type. */