diff options
author | Sami Kerola | 2014-05-18 15:55:23 +0200 |
---|---|---|
committer | Sami Kerola | 2014-05-19 23:54:24 +0200 |
commit | 7a20c8a18855d9b0162fee18d5b453a395b0c361 (patch) | |
tree | 370c99ef4be37d3f6b82812b568a5e29662a7e04 /term-utils/setterm.c | |
parent | setterm: mark some options to be exclusive with each other (diff) | |
download | kernel-qcow2-util-linux-7a20c8a18855d9b0162fee18d5b453a395b0c361.tar.gz kernel-qcow2-util-linux-7a20c8a18855d9b0162fee18d5b453a395b0c361.tar.xz kernel-qcow2-util-linux-7a20c8a18855d9b0162fee18d5b453a395b0c361.zip |
setterm: add set_blanking() action
This make over long perform_sequence() function a little bit shorter.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/setterm.c')
-rw-r--r-- | term-utils/setterm.c | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/term-utils/setterm.c b/term-utils/setterm.c index d2fb596a0..a13161379 100644 --- a/term-utils/setterm.c +++ b/term-utils/setterm.c @@ -733,6 +733,40 @@ static int open_snapshot_device(struct setterm_control *ctl) return fd; } +static void set_blanking(struct setterm_control *ctl) +{ + char ioctlarg; + int ret; + + if (0 <= ctl->opt_bl_min) { + printf("\033[9;%d]", ctl->opt_bl_min); + return; + } + switch (ctl->opt_bl_min) { + case BLANKSCREEN: + ioctlarg = TIOCL_BLANKSCREEN; + if (ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg)) + warn(_("cannot force blank")); + break; + case UNBLANKSCREEN: + ioctlarg = TIOCL_UNBLANKSCREEN; + if (ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg)) + warn(_("cannot force unblank")); + break; + case BLANKEDSCREEN: + ioctlarg = TIOCL_BLANKEDSCREEN; + ret = ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg); + if (ret < 0) + warn(_("cannot get blank status")); + else + printf("%d\n", ret); + break; + default: /* should be impossible to reach */ + abort(); + } + return; +} + static void screendump(struct setterm_control *ctl) { unsigned char header[4]; @@ -960,27 +994,8 @@ static void perform_sequence(struct setterm_control *ctl) } /* -blank [0-60]. */ - if (ctl->opt_blank && vc_only(ctl, "--blank")) { - if (ctl->opt_bl_min >= 0) - printf("\033[9;%d]", ctl->opt_bl_min); - else if (ctl->opt_bl_min == BLANKSCREEN) { - char ioctlarg = TIOCL_BLANKSCREEN; - if (ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg)) - warn(_("cannot force blank")); - } else if (ctl->opt_bl_min == UNBLANKSCREEN) { - char ioctlarg = TIOCL_UNBLANKSCREEN; - if (ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg)) - warn(_("cannot force unblank")); - } else if (ctl->opt_bl_min == BLANKEDSCREEN) { - char ioctlarg = TIOCL_BLANKEDSCREEN; - int ret; - ret = ioctl(STDIN_FILENO, TIOCLINUX, &ioctlarg); - if (ret < 0) - warn(_("cannot get blank status")); - else - printf("%d\n", ret); - } - } + if (ctl->opt_blank && vc_only(ctl, "--blank")) + set_blanking(ctl); /* -powersave [on|vsync|hsync|powerdown|off] (console) */ if (ctl->opt_powersave) { |