summaryrefslogtreecommitdiffstats
path: root/term-utils/setterm.c
diff options
context:
space:
mode:
authorSami Kerola2014-05-18 10:54:12 +0200
committerSami Kerola2014-05-19 23:45:38 +0200
commitdcc2fe2903a6c85e93b81432640dbdf413ebad03 (patch)
tree66b231627309142883fa310de7ab92fa2c8b0901 /term-utils/setterm.c
parentsetterm: add option control structure (diff)
downloadkernel-qcow2-util-linux-dcc2fe2903a6c85e93b81432640dbdf413ebad03.tar.gz
kernel-qcow2-util-linux-dcc2fe2903a6c85e93b81432640dbdf413ebad03.tar.xz
kernel-qcow2-util-linux-dcc2fe2903a6c85e93b81432640dbdf413ebad03.zip
setterm: add init_terminal() to make main() shorter
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/setterm.c')
-rw-r--r--term-utils/setterm.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/term-utils/setterm.c b/term-utils/setterm.c
index 83cfbd55c..bf5619841 100644
--- a/term-utils/setterm.c
+++ b/term-utils/setterm.c
@@ -1051,45 +1051,47 @@ static void perform_sequence(struct setterm_control *ctl)
}
-int main(int argc, char **argv)
+static void init_terminal(struct setterm_control *ctl)
{
- struct setterm_control ctl = { 0 };
int term_errno;
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
- atexit(close_stdout);
-
- if (argc < 2)
- usage(stderr);
-
- /* Parse arguments. */
- parse_option(&ctl, argc, argv);
-
- /* Find out terminal name. */
- if (!ctl.opt_te_terminal_name) {
- ctl.opt_te_terminal_name = getenv("TERM");
- if (ctl.opt_te_terminal_name == NULL)
+ if (!ctl->opt_te_terminal_name) {
+ ctl->opt_te_terminal_name = getenv("TERM");
+ if (ctl->opt_te_terminal_name == NULL)
errx(EXIT_FAILURE, _("$TERM is not defined."));
}
/* Find terminfo entry. */
- if (setupterm(ctl.opt_te_terminal_name, 1, &term_errno))
- switch(term_errno) {
+ if (setupterm(ctl->opt_te_terminal_name, STDOUT_FILENO, &term_errno))
+ switch (term_errno) {
case -1:
errx(EXIT_FAILURE, _("terminfo database cannot be found"));
case 0:
- errx(EXIT_FAILURE, _("%s: unknown terminal type"), ctl.opt_te_terminal_name);
+ errx(EXIT_FAILURE, _("%s: unknown terminal type"), ctl->opt_te_terminal_name);
case 1:
errx(EXIT_FAILURE, _("terminal is hardcopy"));
}
/* See if the terminal is a virtual console terminal. */
- ctl.vcterm = (!strncmp(ctl.opt_te_terminal_name, "con", 3) ||
- !strncmp(ctl.opt_te_terminal_name, "linux", 5));
+ ctl->vcterm = (!strncmp(ctl->opt_te_terminal_name, "con", 3) ||
+ !strncmp(ctl->opt_te_terminal_name, "linux", 5));
+}
+
- /* Perform the selected options. */
+int main(int argc, char **argv)
+{
+ struct setterm_control ctl = { 0 };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+ atexit(close_stdout);
+
+ if (argc < 2)
+ usage(stderr);
+
+ parse_option(&ctl, argc, argv);
+ init_terminal(&ctl);
perform_sequence(&ctl);
return EXIT_SUCCESS;