]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/setterm.c
1 /* setterm.c, set terminal attributes.
3 * Copyright (C) 1990 Gordon Irlam (gordoni@cs.ua.oz.au). Conditions of use,
4 * modification, and redistribution are contained in the file COPYRIGHT that
5 * forms part of this distribution.
7 * Adaption to Linux by Peter MacDonald.
9 * Enhancements by Mika Liljeberg (liljeber@cs.Helsinki.FI)
11 * Beep modifications by Christophe Jolif (cjolif@storm.gatelink.fr.net)
13 * Sanity increases by Cafeine Addict [sic].
15 * Powersave features by todd j. derr <tjd@wordsmith.org>
17 * Converted to terminfo by Kars de Jong (jongk@cs.utwente.nl)
19 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
20 * - added Native Language Support
26 * [ -term terminal_name ]
29 * [ -cursor [on|off] ]
30 * [ -repeat [on|off] ]
31 * [ -appcursorkeys [on|off] ]
32 * [ -linewrap [on|off] ]
34 * [ -softscroll [on|off] ]
36 * [ -foreground black|red|green|yellow|blue|magenta|cyan|white|default ]
37 * [ -background black|red|green|yellow|blue|magenta|cyan|white|default ]
38 * [ -ulcolor black|grey|red|green|yellow|blue|magenta|cyan|white ]
39 * [ -ulcolor bright red|green|yellow|blue|magenta|cyan|white ]
40 * [ -hbcolor black|grey|red|green|yellow|blue|magenta|cyan|white ]
41 * [ -hbcolor bright red|green|yellow|blue|magenta|cyan|white ]
42 * [ -inversescreen [on|off] ]
44 * [ -half-bright [on|off] ]
46 * [ -reverse [on|off] ]
47 * [ -underline [on|off] ]
49 * [ -clear [ all|rest ] ]
50 * [ -tabs [tab1 tab2 tab3 ... ] ] (tabn = 1-160)
51 * [ -clrtabs [ tab1 tab2 tab3 ... ] (tabn = 1-160)
52 * [ -regtabs [1-160] ]
53 * [ -blank [0-60|force|poke|] ]
54 * [ -dump [1-NR_CONS ] ]
55 * [ -append [1-NR_CONS ] ]
56 * [ -file dumpfilename ]
57 * [ -standout [attr] ]
60 * [ -powersave [on|vsync|hsync|powerdown|off] ]
61 * [ -powerdown [0-60] ]
62 * [ -blength [0-2000] ]
68 * Setterm writes to standard output a character string that will
69 * invoke the specified terminal capabilities. Where possibile
70 * terminfo is consulted to find the string to use. Some options
71 * however do not correspond to a terminfo capability. In this case if
72 * the terminal type is "con*", or "linux*" the string that invokes
73 * the specified capabilities on the PC Linux virtual console driver
74 * is output. Options that are not implemented by the terminal are
77 * The following options are non-obvious.
79 * -term can be used to override the TERM environment variable.
81 * -reset displays the terminal reset string, which typically resets the
82 * terminal to its power on state.
84 * -initialize displays the terminal initialization string, which typically
85 * sets the terminal's rendering options, and other attributes to the
88 * -default sets the terminal's rendering options to the default values.
90 * -store stores the terminal's current rendering options as the default
101 #ifndef NCURSES_CONST
102 #define NCURSES_CONST const /* define before including term.h */
106 #ifdef HAVE_NCURSES_H
108 #elif defined(HAVE_NCURSES_NCURSES_H)
109 #include <ncurses/ncurses.h>
112 #include <sys/param.h> /* for MAXPATHLEN */
113 #include <sys/ioctl.h>
114 #include <sys/time.h>
115 #ifdef HAVE_LINUX_TIOCL_H
116 #include <linux/tiocl.h>
123 #if __GNU_LIBRARY__ < 5
125 # include <linux/unistd.h>
126 #define __NR_klogctl __NR_syslog
127 _syscall3(int, klogctl
, int, type
, char*, buf
, int, len
);
128 #else /* __alpha__ */
129 #define klogctl syslog
132 extern int klogctl(int type
, char *buf
, int len
);
136 /* Keyboard types. */
155 #define BLANKSCREEN -1
156 #define UNBLANKSCREEN -2
157 #define BLANKEDSCREEN -3
159 /* <linux/tiocl.h> fallback */
160 #ifndef TIOCL_BLANKSCREEN
161 # define TIOCL_UNBLANKSCREEN 4 /* unblank screen */
162 # define TIOCL_SETVESABLANK 10 /* set vesa blanking mode */
163 # define TIOCL_BLANKSCREEN 14 /* keep screen blank even if a key is pressed */
164 # define TIOCL_BLANKEDSCREEN 15 /* return which vt was blanked */
167 /* Control sequences. */
172 /* Static variables. */
174 /* Option flags. Set if the option is to be invoked. */
175 int opt_term
, opt_reset
, opt_initialize
, opt_cursor
;
176 int opt_linewrap
, opt_snow
, opt_softscroll
, opt_default
, opt_foreground
;
177 int opt_background
, opt_bold
, opt_blink
, opt_reverse
, opt_underline
;
178 int opt_store
, opt_clear
, opt_blank
, opt_snap
, opt_snapfile
, opt_standout
;
179 int opt_append
, opt_ulcolor
, opt_hbcolor
, opt_halfbright
, opt_repeat
;
180 int opt_tabs
, opt_clrtabs
, opt_regtabs
, opt_appcursorkeys
, opt_inversescreen
;
181 int opt_msg
, opt_msglevel
, opt_powersave
, opt_powerdown
;
182 int opt_blength
, opt_bfreq
;
184 /* Option controls. The variable names have been contracted to ensure
187 char *opt_te_terminal_name
; /* Terminal name. */
188 int opt_cu_on
, opt_li_on
, opt_sn_on
, opt_so_on
, opt_bo_on
, opt_hb_on
, opt_bl_on
;
189 int opt_re_on
, opt_un_on
, opt_rep_on
, opt_appck_on
, opt_invsc_on
;
190 int opt_msg_on
; /* Boolean switches. */
191 int opt_ke_type
; /* Keyboard type. */
192 int opt_fo_color
, opt_ba_color
; /* Colors. */
193 int opt_ul_color
, opt_hb_color
;
194 int opt_cl_all
; /* Clear all or rest. */
195 int opt_bl_min
; /* Blank screen. */
198 int opt_sn_num
; /* Snap screen. */
200 int opt_rt_len
; /* regular tab length */
201 int opt_tb_array
[161]; /* Array for tab list */
202 int opt_msglevel_num
;
203 int opt_ps_mode
, opt_pd_min
; /* powersave mode/powerdown time */
205 char opt_sn_name
[200] = "screen.dump";
207 static void screendump(int vcnum
, FILE *F
);
209 /* Command line parsing routines.
211 * Note that it is an error for a given option to be invoked more than once.
215 parse_term(int argc
, char **argv
, int *option
, char **opt_term
, int *bad_arg
) {
216 /* argc: Number of arguments for this option. */
217 /* argv: Arguments for this option. */
218 /* option: Term flag to set. */
219 /* opt_term: Terminal name to set. */
220 /* bad_arg: Set to true if an error is detected. */
222 /* Parse a -term specification. */
224 if (argc
!= 1 || *option
)
232 parse_none(int argc
, char **argv
, int *option
, int *bad_arg
) {
233 /* argc: Number of arguments for this option. */
234 /* argv: Arguments for this option. */
235 /* option: Term flag to set. */
236 /* bad_arg: Set to true if an error is detected. */
238 /* Parse a parameterless specification. */
240 if (argc
!= 0 || *option
)
246 parse_switch(int argc
, char **argv
, int *option
, int *opt_on
, int *bad_arg
) {
247 /* argc: Number of arguments for this option. */
248 /* argv: Arguments for this option. */
249 /* option: Option flag to set. */
250 /* opt_on: Boolean option switch to set or reset. */
251 /* bad_arg: Set to true if an error is detected. */
253 /* Parse a boolean (on/off) specification. */
255 if (argc
> 1 || *option
)
259 if (strcmp(argv
[0], "on") == 0)
261 else if (strcmp(argv
[0], "off") == 0)
271 par_color(int argc
, char **argv
, int *option
, int *opt_color
, int *bad_arg
) {
272 /* argc: Number of arguments for this option. */
273 /* argv: Arguments for this option. */
274 /* option: Color flag to set. */
275 /* opt_color: Color to set. */
276 /* bad_arg: Set to true if an error is detected. */
278 /* Parse a -foreground or -background specification. */
280 if (argc
!= 1 || *option
)
284 if (strcmp(argv
[0], "black") == 0)
286 else if (strcmp(argv
[0], "red") == 0)
288 else if (strcmp(argv
[0], "green") == 0)
290 else if (strcmp(argv
[0], "yellow") == 0)
292 else if (strcmp(argv
[0], "blue") == 0)
294 else if (strcmp(argv
[0], "magenta") == 0)
295 *opt_color
= MAGENTA
;
296 else if (strcmp(argv
[0], "cyan") == 0)
298 else if (strcmp(argv
[0], "white") == 0)
300 else if (strcmp(argv
[0], "default") == 0)
301 *opt_color
= DEFAULT
;
302 else if (isdigit(argv
[0][0]))
303 *opt_color
= atoi(argv
[0]);
307 if(*opt_color
< 0 || *opt_color
> 9 || *opt_color
== 8)
313 par_color2(int argc
, char **argv
, int *option
, int *opt_color
, int *bad_arg
) {
314 /* argc: Number of arguments for this option. */
315 /* argv: Arguments for this option. */
316 /* option: Color flag to set. */
317 /* opt_color: Color to set. */
318 /* bad_arg: Set to true if an error is detected. */
320 /* Parse a -ulcolor or -hbcolor specification. */
322 if (!argc
|| argc
> 2 || *option
)
327 if (strcmp(argv
[0], "bright") == 0)
335 if (strcmp(argv
[argc
-1], "black") == 0) {
340 } else if (strcmp(argv
[argc
-1], "grey") == 0) {
345 } else if (strcmp(argv
[argc
-1], "red") == 0)
347 else if (strcmp(argv
[argc
-1], "green") == 0)
349 else if (strcmp(argv
[argc
-1], "yellow") == 0)
350 *opt_color
|= YELLOW
;
351 else if (strcmp(argv
[argc
-1], "blue") == 0)
353 else if (strcmp(argv
[argc
-1], "magenta") == 0)
354 *opt_color
|= MAGENTA
;
355 else if (strcmp(argv
[argc
-1], "cyan") == 0)
357 else if (strcmp(argv
[argc
-1], "white") == 0)
359 else if (isdigit(argv
[argc
-1][0]))
360 *opt_color
= atoi(argv
[argc
-1]);
363 if(*opt_color
< 0 || *opt_color
> 15)
369 parse_clear(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
370 /* argc: Number of arguments for this option. */
371 /* argv: Arguments for this option. */
372 /* option: Clear flag to set. */
373 /* opt_all: Clear all switch to set or reset. */
374 /* bad_arg: Set to true if an error is detected. */
376 /* Parse a -clear specification. */
378 if (argc
> 1 || *option
)
382 if (strcmp(argv
[0], "all") == 0)
384 else if (strcmp(argv
[0], "rest") == 0)
394 parse_blank(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
395 /* argc: Number of arguments for this option. */
396 /* argv: Arguments for this option. */
397 /* option: Clear flag to set. */
398 /* opt_all: Clear all switch to set or reset. */
399 /* bad_arg: Set to true if an error is detected. */
401 /* Parse a -blank specification. */
403 if (argc
> 1 || *option
)
407 if (!strcmp(argv
[0], "force"))
408 *opt_all
= BLANKSCREEN
;
409 else if (!strcmp(argv
[0], "poke"))
410 *opt_all
= UNBLANKSCREEN
;
412 *opt_all
= atoi(argv
[0]);
413 if ((*opt_all
> 60) || (*opt_all
< 0))
417 *opt_all
= BLANKEDSCREEN
;
422 parse_powersave(int argc
, char **argv
, int *option
, int *opt_mode
, int *bad_arg
) {
423 /* argc: Number of arguments for this option. */
424 /* argv: Arguments for this option. */
425 /* option: powersave flag to set. */
426 /* opt_mode: Powersaving mode, defined in vesa_blank.c */
427 /* bad_arg: Set to true if an error is detected. */
429 /* Parse a -powersave mode specification. */
431 if (argc
> 1 || *option
)
435 if (strcmp(argv
[0], "on") == 0)
437 else if (strcmp(argv
[0], "vsync") == 0)
439 else if (strcmp(argv
[0], "hsync") == 0)
441 else if (strcmp(argv
[0], "powerdown") == 0)
443 else if (strcmp(argv
[0], "off") == 0)
454 parse_standout(int argc
, char *argv
, int *option
, int *opt_all
, int *bad_arg
) {
455 /* argc: Number of arguments for this option. */
456 /* argv: Arguments for this option. */
457 /* option: Clear flag to set. */
458 /* opt_all: Clear all switch to set or reset. */
459 /* bad_arg: Set to true if an error is detected. */
461 /* Parse a -standout specification. */
463 if (argc
> 1 || *option
)
467 *opt_all
= atoi(argv
[0]);
474 parse_msglevel(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
475 /* argc: Number of arguments for this option. */
476 /* argv: Arguments for this option. */
477 /* option: Clear flag to set. */
478 /* opt_all: Clear all switch to set or reset. */
479 /* bad_arg: Set to true if an error is detected. */
481 if (argc
> 1 || *option
)
485 *opt_all
= atoi(argv
[0]);
486 if (*opt_all
< 0 || *opt_all
> 8)
494 parse_snap(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
495 /* argc: Number of arguments for this option. */
496 /* argv: Arguments for this option. */
497 /* option: Clear flag to set. */
498 /* opt_all: Clear all switch to set or reset. */
499 /* bad_arg: Set to true if an error is detected. */
501 /* Parse a -dump or -append specification. */
503 if (argc
> 1 || *option
)
507 *opt_all
= atoi(argv
[0]);
516 parse_snapfile(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
517 /* argc: Number of arguments for this option. */
518 /* argv: Arguments for this option. */
519 /* option: Clear flag to set. */
520 /* opt_all: Clear all switch to set or reset. */
521 /* bad_arg: Set to true if an error is detected. */
523 /* Parse a -file specification. */
525 if (argc
!= 1 || *option
)
529 strcpy((char *)opt_all
, argv
[0]);
533 parse_tabs(int argc
, char **argv
, int *option
, int *tab_array
, int *bad_arg
) {
534 /* argc: Number of arguments for this option. */
535 /* argv: Arguments for this option. */
536 /* option: Clear flag to set. */
537 /* tab_array: Array of tabs */
538 /* bad_arg: Set to true if an error is detected. */
540 if (*option
|| argc
> 160)
543 tab_array
[argc
] = -1;
545 tab_array
[argc
] = atoi(argv
[argc
]);
546 if(tab_array
[argc
] < 1 || tab_array
[argc
] > 160) {
554 parse_clrtabs(int argc
, char **argv
, int *option
, int *tab_array
, int *bad_arg
) {
555 /* argc: Number of arguments for this option. */
556 /* argv: Arguments for this option. */
557 /* option: Clear flag to set. */
558 /* tab_array: Array of tabs */
559 /* bad_arg: Set to true if an error is detected. */
561 if (*option
|| argc
> 160)
568 tab_array
[argc
] = -1;
570 tab_array
[argc
] = atoi(argv
[argc
]);
571 if(tab_array
[argc
] < 1 || tab_array
[argc
] > 160) {
579 parse_regtabs(int argc
, char **argv
, int *option
, int *opt_len
, int *bad_arg
) {
580 /* argc: Number of arguments for this option. */
581 /* argv: Arguments for this option. */
582 /* option: Clear flag to set. */
583 /* opt_len: Regular tab length. */
584 /* bad_arg: Set to true if an error is detected. */
586 if (*option
|| argc
> 1)
593 *opt_len
= atoi(argv
[0]);
594 if(*opt_len
< 1 || *opt_len
> 160) {
602 parse_blength(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
603 /* argc: Number of arguments for this option. */
604 /* argv: Arguments for this option. */
605 /* option: Clear flag to set. */
607 /* bad_arg: Set to true if an error is detected. */
609 /* Parse -blength specification. */
611 if (argc
> 1 || *option
)
615 *opt_all
= atoi(argv
[0]);
624 parse_bfreq(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
625 /* argc: Number of arguments for this option. */
626 /* argv: Arguments for this option. */
627 /* option: Clear flag to set. */
629 /* bad_arg: Set to true if an error is detected. */
631 /* Parse -bfreq specification. */
633 if (argc
> 1 || *option
)
637 *opt_all
= atoi(argv
[0]);
646 int i
, co
= tigetnum("cols");
650 for(i
= 10; i
< co
-2; i
+=10)
653 for(i
= 1; i
<= co
; i
++)
656 for(i
= 1; i
< co
; i
++)
663 #define STRCMP(str1,str2) strncmp(str1,str2,strlen(str1))
666 parse_option(char *option
, int argc
, char **argv
, int *bad_arg
) {
667 /* option: Option with leading '-' removed. */
668 /* argc: Number of arguments for this option. */
669 /* argv: Arguments for this option. */
670 /* bad_arg: Set to true if an error is detected. */
672 /* Parse a single specification. */
674 if (STRCMP(option
, "term") == 0)
675 parse_term(argc
, argv
, &opt_term
, &opt_te_terminal_name
, bad_arg
);
676 else if (STRCMP(option
, "reset") == 0)
677 parse_none(argc
, argv
, &opt_reset
, bad_arg
);
678 else if (STRCMP(option
, "initialize") == 0)
679 parse_none(argc
, argv
, &opt_initialize
, bad_arg
);
680 else if (STRCMP(option
, "cursor") == 0)
681 parse_switch(argc
, argv
, &opt_cursor
, &opt_cu_on
, bad_arg
);
682 else if (STRCMP(option
, "repeat") == 0)
683 parse_switch(argc
, argv
, &opt_repeat
, &opt_rep_on
, bad_arg
);
684 else if (STRCMP(option
, "appcursorkeys") == 0)
685 parse_switch(argc
, argv
, &opt_appcursorkeys
, &opt_appck_on
, bad_arg
);
686 else if (STRCMP(option
, "linewrap") == 0)
687 parse_switch(argc
, argv
, &opt_linewrap
, &opt_li_on
, bad_arg
);
689 else if (STRCMP(option
, "snow") == 0)
690 parse_switch(argc
, argv
, &opt_snow
, &opt_sn_on
, bad_arg
);
691 else if (STRCMP(option
, "softscroll") == 0)
692 parse_switch(argc
, argv
, &opt_softscroll
, &opt_so_on
, bad_arg
);
694 else if (STRCMP(option
, "default") == 0)
695 parse_none(argc
, argv
, &opt_default
, bad_arg
);
696 else if (STRCMP(option
, "foreground") == 0)
697 par_color(argc
, argv
, &opt_foreground
, &opt_fo_color
, bad_arg
);
698 else if (STRCMP(option
, "background") == 0)
699 par_color(argc
, argv
, &opt_background
, &opt_ba_color
, bad_arg
);
700 else if (STRCMP(option
, "ulcolor") == 0)
701 par_color2(argc
, argv
, &opt_ulcolor
, &opt_ul_color
, bad_arg
);
702 else if (STRCMP(option
, "hbcolor") == 0)
703 par_color2(argc
, argv
, &opt_hbcolor
, &opt_hb_color
, bad_arg
);
704 else if (STRCMP(option
, "inversescreen") == 0)
705 parse_switch(argc
, argv
, &opt_inversescreen
, &opt_invsc_on
, bad_arg
);
706 else if (STRCMP(option
, "bold") == 0)
707 parse_switch(argc
, argv
, &opt_bold
, &opt_bo_on
, bad_arg
);
708 else if (STRCMP(option
, "half-bright") == 0)
709 parse_switch(argc
, argv
, &opt_halfbright
, &opt_hb_on
, bad_arg
);
710 else if (STRCMP(option
, "blink") == 0)
711 parse_switch(argc
, argv
, &opt_blink
, &opt_bl_on
, bad_arg
);
712 else if (STRCMP(option
, "reverse") == 0)
713 parse_switch(argc
, argv
, &opt_reverse
, &opt_re_on
, bad_arg
);
714 else if (STRCMP(option
, "underline") == 0)
715 parse_switch(argc
, argv
, &opt_underline
, &opt_un_on
, bad_arg
);
716 else if (STRCMP(option
, "store") == 0)
717 parse_none(argc
, argv
, &opt_store
, bad_arg
);
718 else if (STRCMP(option
, "clear") == 0)
719 parse_clear(argc
, argv
, &opt_clear
, &opt_cl_all
, bad_arg
);
720 else if (STRCMP(option
, "tabs") == 0)
721 parse_tabs(argc
, argv
, &opt_tabs
, opt_tb_array
, bad_arg
);
722 else if (STRCMP(option
, "clrtabs") == 0)
723 parse_clrtabs(argc
, argv
, &opt_clrtabs
, opt_tb_array
, bad_arg
);
724 else if (STRCMP(option
, "regtabs") == 0)
725 parse_regtabs(argc
, argv
, &opt_regtabs
, &opt_rt_len
, bad_arg
);
726 else if (STRCMP(option
, "blank") == 0)
727 parse_blank(argc
, argv
, &opt_blank
, &opt_bl_min
, bad_arg
);
728 else if (STRCMP(option
, "dump") == 0)
729 parse_snap(argc
, argv
, &opt_snap
, &opt_sn_num
, bad_arg
);
730 else if (STRCMP(option
, "append") == 0)
731 parse_snap(argc
, argv
, &opt_append
, &opt_sn_num
, bad_arg
);
732 else if (STRCMP(option
, "file") == 0)
733 parse_snapfile(argc
, argv
, &opt_snapfile
, (int *)opt_sn_name
, bad_arg
);
734 else if (STRCMP(option
, "msg") == 0)
735 parse_switch(argc
, argv
, &opt_msg
, &opt_msg_on
, bad_arg
);
736 else if (STRCMP(option
, "msglevel") == 0)
737 parse_msglevel(argc
, argv
, &opt_msglevel
, &opt_msglevel_num
, bad_arg
);
738 else if (STRCMP(option
, "powersave") == 0)
739 parse_powersave(argc
, argv
, &opt_powersave
, &opt_ps_mode
, bad_arg
);
740 else if (STRCMP(option
, "powerdown") == 0)
741 parse_blank(argc
, argv
, &opt_powerdown
, &opt_pd_min
, bad_arg
);
742 else if (STRCMP(option
, "blength") == 0)
743 parse_blength(argc
, argv
, &opt_blength
, &opt_blength_l
, bad_arg
);
744 else if (STRCMP(option
, "bfreq") == 0)
745 parse_bfreq(argc
, argv
, &opt_bfreq
, &opt_bfreq_f
, bad_arg
);
747 else if (STRCMP(option
, "standout") == 0)
748 parse_standout(argc
, argv
, &opt_standout
, &opt_st_attr
, bad_arg
);
754 /* End of command line parsing routines. */
757 usage(char *prog_name
) {
758 /* Print error message about arguments, and the command's syntax. */
760 fprintf(stderr
, _("%s: Argument error, usage\n"), prog_name
);
761 fprintf(stderr
, "\n");
762 fprintf(stderr
, "%s\n", prog_name
);
763 fprintf(stderr
, _(" [ -term terminal_name ]\n"));
764 fprintf(stderr
, _(" [ -reset ]\n"));
765 fprintf(stderr
, _(" [ -initialize ]\n"));
766 fprintf(stderr
, _(" [ -cursor [on|off] ]\n"));
768 fprintf(stderr
, _(" [ -snow [on|off] ]\n"));
769 fprintf(stderr
, _(" [ -softscroll [on|off] ]\n"));
771 fprintf(stderr
, _(" [ -repeat [on|off] ]\n"));
772 fprintf(stderr
, _(" [ -appcursorkeys [on|off] ]\n"));
773 fprintf(stderr
, _(" [ -linewrap [on|off] ]\n"));
774 fprintf(stderr
, _(" [ -default ]\n"));
775 fprintf(stderr
, _(" [ -foreground black|blue|green|cyan"));
776 fprintf(stderr
, _("|red|magenta|yellow|white|default ]\n"));
777 fprintf(stderr
, _(" [ -background black|blue|green|cyan"));
778 fprintf(stderr
, _("|red|magenta|yellow|white|default ]\n"));
779 fprintf(stderr
, _(" [ -ulcolor black|grey|blue|green|cyan"));
780 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
781 fprintf(stderr
, _(" [ -ulcolor bright blue|green|cyan"));
782 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
783 fprintf(stderr
, _(" [ -hbcolor black|grey|blue|green|cyan"));
784 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
785 fprintf(stderr
, _(" [ -hbcolor bright blue|green|cyan"));
786 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
788 fprintf(stderr
, _(" [ -standout [ attr ] ]\n"));
790 fprintf(stderr
, _(" [ -inversescreen [on|off] ]\n"));
791 fprintf(stderr
, _(" [ -bold [on|off] ]\n"));
792 fprintf(stderr
, _(" [ -half-bright [on|off] ]\n"));
793 fprintf(stderr
, _(" [ -blink [on|off] ]\n"));
794 fprintf(stderr
, _(" [ -reverse [on|off] ]\n"));
795 fprintf(stderr
, _(" [ -underline [on|off] ]\n"));
796 fprintf(stderr
, _(" [ -store ]\n"));
797 fprintf(stderr
, _(" [ -clear [all|rest] ]\n"));
798 fprintf(stderr
, _(" [ -tabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"));
799 fprintf(stderr
, _(" [ -clrtabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"));
800 fprintf(stderr
, _(" [ -regtabs [1-160] ]\n"));
801 fprintf(stderr
, _(" [ -blank [0-60|force|poke] ]\n"));
802 fprintf(stderr
, _(" [ -dump [1-NR_CONSOLES] ]\n"));
803 fprintf(stderr
, _(" [ -append [1-NR_CONSOLES] ]\n"));
804 fprintf(stderr
, _(" [ -file dumpfilename ]\n"));
805 fprintf(stderr
, _(" [ -msg [on|off] ]\n"));
806 fprintf(stderr
, _(" [ -msglevel [0-8] ]\n"));
807 fprintf(stderr
, _(" [ -powersave [on|vsync|hsync|powerdown|off] ]\n"));
808 fprintf(stderr
, _(" [ -powerdown [0-60] ]\n"));
809 fprintf(stderr
, _(" [ -blength [0-2000] ]\n"));
810 fprintf(stderr
, _(" [ -bfreq freqnumber ]\n"));
813 static char *ti_entry(const char *name
) {
814 /* name: Terminfo capability string to lookup. */
816 /* Return the specified terminfo string, or an empty string if no such terminfo
822 if ((buf_ptr
= tigetstr((char *)name
)) == (char *)-1)
828 perform_sequence(int vcterm
) {
829 /* vcterm: Set if terminal is a virtual console. */
832 /* Perform the selected options. */
836 putp(ti_entry("rs1"));
840 if (opt_initialize
) {
841 putp(ti_entry("is2"));
844 /* -cursor [on|off]. */
847 putp(ti_entry("cnorm"));
849 putp(ti_entry("civis"));
852 /* -linewrap [on|off]. Vc only (vt102) */
853 if (opt_linewrap
&& vcterm
) {
860 /* -repeat [on|off]. Vc only (vt102) */
861 if (opt_repeat
&& vcterm
) {
868 /* -appcursorkeys [on|off]. Vc only (vt102) */
869 if (opt_appcursorkeys
&& vcterm
) {
877 /* -snow [on|off]. Vc only. */
878 if (opt_snow
&& vcterm
) {
880 printf("%s%s%s", DCS
, "snow.on", ST
);
882 printf("%s%s%s", DCS
, "snow.off", ST
);
885 /* -softscroll [on|off]. Vc only. */
886 if (opt_softscroll
&& vcterm
) {
888 printf("%s%s%s", DCS
, "softscroll.on", ST
);
890 printf("%s%s%s", DCS
, "softscroll.off", ST
);
894 /* -default. Vc sets default rendition, otherwise clears all
901 putp(ti_entry("sgr0"));
904 /* -foreground black|red|green|yellow|blue|magenta|cyan|white|default.
907 if (opt_foreground
&& vcterm
) {
908 printf("%s%s%c%s", ESC
, "[3", '0' + opt_fo_color
, "m");
911 /* -background black|red|green|yellow|blue|magenta|cyan|white|default.
914 if (opt_background
&& vcterm
) {
915 printf("%s%s%c%s", ESC
, "[4", '0' + opt_ba_color
, "m");
918 /* -ulcolor black|red|green|yellow|blue|magenta|cyan|white|default.
921 if (opt_ulcolor
&& vcterm
) {
922 printf("\033[1;%d]", opt_ul_color
);
925 /* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default.
928 if (opt_hbcolor
&& vcterm
) {
929 printf("\033[2;%d]", opt_hb_color
);
932 /* -inversescreen [on|off]. Vc only (vt102).
934 if (opt_inversescreen
) {
943 /* -bold [on|off]. Vc behaves as expected, otherwise off turns off
948 putp(ti_entry("bold"));
951 printf("%s%s", ESC
, "[22m");
953 putp(ti_entry("sgr0"));
957 /* -half-bright [on|off]. Vc behaves as expected, otherwise off turns off
960 if (opt_halfbright
) {
962 putp(ti_entry("dim"));
965 printf("%s%s", ESC
, "[22m");
967 putp(ti_entry("sgr0"));
971 /* -blink [on|off]. Vc behaves as expected, otherwise off turns off
976 putp(ti_entry("blink"));
979 printf("%s%s", ESC
, "[25m");
981 putp(ti_entry("sgr0"));
985 /* -reverse [on|off]. Vc behaves as expected, otherwise off turns
986 * off all attributes.
990 putp(ti_entry("rev"));
993 printf("%s%s", ESC
, "[27m");
995 putp(ti_entry("sgr0"));
999 /* -underline [on|off]. */
1000 if (opt_underline
) {
1002 putp(ti_entry("smul"));
1004 putp(ti_entry("rmul"));
1007 /* -store. Vc only. */
1008 if (opt_store
&& vcterm
) {
1012 /* -clear [all|rest]. */
1015 putp(ti_entry("clear"));
1017 putp(ti_entry("ed"));
1020 /* -tabs Vc only. */
1021 if (opt_tabs
&& vcterm
) {
1024 if (opt_tb_array
[0] == -1)
1027 for(i
=0; opt_tb_array
[i
] > 0; i
++)
1028 printf("\033[%dG\033H", opt_tb_array
[i
]);
1033 /* -clrtabs Vc only. */
1034 if (opt_clrtabs
&& vcterm
) {
1037 if (opt_tb_array
[0] == -1)
1040 for(i
=0; opt_tb_array
[i
] > 0; i
++)
1041 printf("\033[%dG\033[g", opt_tb_array
[i
]);
1045 /* -regtabs Vc only. */
1046 if (opt_regtabs
&& vcterm
) {
1049 printf("\033[3g\r");
1050 for(i
=opt_rt_len
+1; i
<=160; i
+=opt_rt_len
)
1051 printf("\033[%dC\033H",opt_rt_len
);
1055 /* -blank [0-60]. */
1056 if (opt_blank
&& vcterm
) {
1057 if (opt_bl_min
>= 0)
1058 printf("\033[9;%d]", opt_bl_min
);
1059 else if (opt_bl_min
== BLANKSCREEN
) {
1060 char ioctlarg
= TIOCL_BLANKSCREEN
;
1061 if (ioctl(0,TIOCLINUX
,&ioctlarg
))
1062 fprintf(stderr
,_("cannot force blank\n"));
1063 } else if (opt_bl_min
== UNBLANKSCREEN
) {
1064 char ioctlarg
= TIOCL_UNBLANKSCREEN
;
1065 if (ioctl(0,TIOCLINUX
,&ioctlarg
))
1066 fprintf(stderr
,_("cannot force unblank\n"));
1067 } else if (opt_bl_min
== BLANKEDSCREEN
) {
1068 char ioctlarg
= TIOCL_BLANKEDSCREEN
;
1070 ret
= ioctl(0,TIOCLINUX
,&ioctlarg
);
1072 fprintf(stderr
,_("cannot get blank status\n"));
1078 /* -powersave [on|vsync|hsync|powerdown|off] (console) */
1079 if (opt_powersave
) {
1081 ioctlarg
[0] = TIOCL_SETVESABLANK
;
1082 ioctlarg
[1] = opt_ps_mode
;
1083 if (ioctl(0,TIOCLINUX
,ioctlarg
))
1084 fprintf(stderr
,_("cannot (un)set powersave mode\n"));
1087 /* -powerdown [0-60]. */
1088 if (opt_powerdown
) {
1089 printf("\033[14;%d]", opt_pd_min
);
1093 /* -standout [num]. */
1098 /* -snap [1-NR_CONS]. */
1099 if (opt_snap
|| opt_append
) {
1102 F
= fopen(opt_sn_name
, opt_snap
? "w" : "a");
1104 perror(opt_sn_name
);
1105 fprintf(stderr
,("setterm: can not open dump file %s for output\n"),
1109 screendump(opt_sn_num
, F
);
1113 /* -msg [on|off]. */
1114 if (opt_msg
&& vcterm
) {
1116 /* 7 -- Enable printk's to console */
1117 result
= klogctl(7, NULL
, 0);
1119 /* 6 -- Disable printk's to console */
1120 result
= klogctl(6, NULL
, 0);
1123 printf(_("klogctl error: %s\n"), strerror(errno
));
1126 /* -msglevel [0-8] */
1127 if (opt_msglevel
&& vcterm
) {
1128 /* 8 -- Set level of messages printed to console */
1129 result
= klogctl(8, NULL
, opt_msglevel_num
);
1131 printf(_("klogctl error: %s\n"), strerror(errno
));
1134 /* -blength [0-2000] */
1135 if (opt_blength
&& vcterm
) {
1136 printf("\033[11;%d]", opt_blength_l
);
1139 /* -bfreq freqnumber */
1140 if (opt_bfreq
&& vcterm
) {
1141 printf("\033[10;%d]", opt_bfreq_f
);
1147 screendump(int vcnum
, FILE *F
) {
1148 char infile
[MAXPATHLEN
];
1149 unsigned char header
[4];
1150 unsigned int rows
, cols
;
1152 char *inbuf
, *outbuf
, *p
, *q
;
1154 sprintf(infile
, "/dev/vcsa%d", vcnum
);
1155 fd
= open(infile
, O_RDONLY
);
1156 if (fd
< 0 && vcnum
== 0) {
1157 /* vcsa0 is often called vcsa */
1158 sprintf(infile
, "/dev/vcsa");
1159 fd
= open(infile
, O_RDONLY
);
1162 /* try devfs name - for zero vcnum just /dev/vcc/a */
1163 /* some gcc's warn for %.u - add 0 */
1164 sprintf(infile
, "/dev/vcc/a%.0u", vcnum
);
1165 fd
= open(infile
, O_RDONLY
);
1168 sprintf(infile
, "/dev/vcsa%d", vcnum
);
1171 if (read(fd
, header
, 4) != 4)
1175 if (rows
* cols
== 0)
1177 inbuf
= malloc(rows
*cols
*2);
1178 outbuf
= malloc(rows
*(cols
+1));
1179 if(!inbuf
|| !outbuf
) {
1180 fputs(_("Out of memory"), stderr
);
1183 if (read(fd
, inbuf
, rows
*cols
*2) != rows
*cols
*2)
1187 for(i
=0; i
<rows
; i
++) {
1188 for(j
=0; j
<cols
; j
++) {
1192 while(j
-- > 0 && q
[-1] == ' ')
1196 if (fwrite(outbuf
, 1, q
-outbuf
, F
) != q
-outbuf
) {
1197 fprintf(stderr
, _("Error writing screendump\n"));
1204 fprintf(stderr
, _("Couldn't read %s\n"), infile
);
1212 main(int argc
, char **argv
) {
1213 int bad_arg
= FALSE
; /* Set if error in arguments. */
1215 char *term
; /* Terminal type. */
1216 int vcterm
; /* Set if terminal is a virtual console. */
1218 setlocale(LC_ALL
, "");
1219 bindtextdomain(PACKAGE
, LOCALEDIR
);
1220 textdomain(PACKAGE
);
1225 /* Parse arguments. */
1227 for (arg
= 1; arg
< argc
;) {
1228 if (*argv
[arg
] == '-') {
1230 /* Parse a single option. */
1232 for (modifier
= arg
+ 1; modifier
< argc
; modifier
++) {
1233 if (*argv
[modifier
] == '-') break;
1235 parse_option(argv
[arg
] + 1, modifier
- arg
- 1,
1236 &argv
[arg
+ 1], &bad_arg
);
1244 /* Display syntax message if error in arguments. */
1251 /* Find out terminal name. */
1254 term
= opt_te_terminal_name
;
1256 term
= getenv("TERM");
1258 fprintf(stderr
, _("%s: $TERM is not defined.\n"),
1264 /* Find terminfo entry. */
1266 setupterm(term
, 1, (int *)0);
1268 /* See if the terminal is a virtual console terminal. */
1270 vcterm
= (!strncmp(term
, "con", 3) || !strncmp(term
, "linux", 5));
1272 /* Perform the selected options. */
1274 perform_sequence(vcterm
);