]>
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] ]
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 */
110 #include <sys/ioctl.h>
111 #include <sys/time.h>
115 /* TCGETS is either defined in termios.h, or here: */
116 #include <asm/ioctls.h>
119 #if __GNU_LIBRARY__ < 5
121 # include <linux/unistd.h>
122 #define __NR_klogctl __NR_syslog
123 _syscall3(int, klogctl
, int, type
, char*, buf
, int, len
);
124 #else /* __alpha__ */
125 #define klogctl syslog
128 extern int klogctl(int type
, char *buf
, int len
);
132 /* General constants. */
138 /* Keyboard types. */
156 /* Control sequences. */
161 /* Static variables. */
163 /* Option flags. Set if the option is to be invoked. */
164 int opt_term
, opt_reset
, opt_initialize
, opt_cursor
;
165 int opt_linewrap
, opt_snow
, opt_softscroll
, opt_default
, opt_foreground
;
166 int opt_background
, opt_bold
, opt_blink
, opt_reverse
, opt_underline
;
167 int opt_store
, opt_clear
, opt_blank
, opt_snap
, opt_snapfile
, opt_standout
;
168 int opt_append
, opt_ulcolor
, opt_hbcolor
, opt_halfbright
, opt_repeat
;
169 int opt_tabs
, opt_clrtabs
, opt_regtabs
, opt_appcursorkeys
, opt_inversescreen
;
170 int opt_msg
, opt_msglevel
, opt_powersave
, opt_powerdown
;
171 int opt_blength
, opt_bfreq
;
173 /* Option controls. The variable names have been contracted to ensure
176 char *opt_te_terminal_name
; /* Terminal name. */
177 int opt_cu_on
, opt_li_on
, opt_sn_on
, opt_so_on
, opt_bo_on
, opt_hb_on
, opt_bl_on
;
178 int opt_re_on
, opt_un_on
, opt_rep_on
, opt_appck_on
, opt_invsc_on
;
179 int opt_msg_on
; /* Boolean switches. */
180 int opt_ke_type
; /* Keyboard type. */
181 int opt_fo_color
, opt_ba_color
; /* Colors. */
182 int opt_ul_color
, opt_hb_color
;
183 int opt_cl_all
; /* Clear all or rest. */
184 int opt_bl_min
; /* Blank screen. */
187 int opt_sn_num
= 0; /* Snap screen. */
189 int opt_rt_len
; /* regular tab length */
190 int opt_tb_array
[161]; /* Array for tab list */
191 int opt_msglevel_num
;
192 int opt_ps_mode
, opt_pd_min
; /* powersave mode/powerdown time */
194 char opt_sn_name
[200] = "screen.dump";
196 static void screendump(int vcnum
, FILE *F
);
198 /* Command line parsing routines.
200 * Note that it is an error for a given option to be invoked more than once.
204 parse_term(int argc
, char **argv
, int *option
, char **opt_term
, int *bad_arg
) {
205 /* argc: Number of arguments for this option. */
206 /* argv: Arguments for this option. */
207 /* option: Term flag to set. */
208 /* opt_term: Terminal name to set. */
209 /* bad_arg: Set to true if an error is detected. */
211 /* Parse a -term specification. */
213 if (argc
!= 1 || *option
)
221 parse_none(int argc
, char **argv
, int *option
, int *bad_arg
) {
222 /* argc: Number of arguments for this option. */
223 /* argv: Arguments for this option. */
224 /* option: Term flag to set. */
225 /* bad_arg: Set to true if an error is detected. */
227 /* Parse a parameterless specification. */
229 if (argc
!= 0 || *option
)
235 parse_switch(int argc
, char **argv
, int *option
, int *opt_on
, int *bad_arg
) {
236 /* argc: Number of arguments for this option. */
237 /* argv: Arguments for this option. */
238 /* option: Option flag to set. */
239 /* opt_on: Boolean option switch to set or reset. */
240 /* bad_arg: Set to true if an error is detected. */
242 /* Parse a boolean (on/off) specification. */
244 if (argc
> 1 || *option
)
248 if (strcmp(argv
[0], "on") == 0)
250 else if (strcmp(argv
[0], "off") == 0)
260 par_color(int argc
, char **argv
, int *option
, int *opt_color
, int *bad_arg
) {
261 /* argc: Number of arguments for this option. */
262 /* argv: Arguments for this option. */
263 /* option: Color flag to set. */
264 /* opt_color: Color to set. */
265 /* bad_arg: Set to true if an error is detected. */
267 /* Parse a -foreground or -background specification. */
269 if (argc
!= 1 || *option
)
273 if (strcmp(argv
[0], "black") == 0)
275 else if (strcmp(argv
[0], "red") == 0)
277 else if (strcmp(argv
[0], "green") == 0)
279 else if (strcmp(argv
[0], "yellow") == 0)
281 else if (strcmp(argv
[0], "blue") == 0)
283 else if (strcmp(argv
[0], "magenta") == 0)
284 *opt_color
= MAGENTA
;
285 else if (strcmp(argv
[0], "cyan") == 0)
287 else if (strcmp(argv
[0], "white") == 0)
289 else if (strcmp(argv
[0], "default") == 0)
290 *opt_color
= DEFAULT
;
291 else if (isdigit(argv
[0][0]))
292 *opt_color
= atoi(argv
[0]);
296 if(*opt_color
< 0 || *opt_color
> 7)
302 par_color2(int argc
, char **argv
, int *option
, int *opt_color
, int *bad_arg
) {
303 /* argc: Number of arguments for this option. */
304 /* argv: Arguments for this option. */
305 /* option: Color flag to set. */
306 /* opt_color: Color to set. */
307 /* bad_arg: Set to true if an error is detected. */
309 /* Parse a -ulcolor or -hbcolor specification. */
311 if (!argc
|| argc
> 2 || *option
)
316 if (strcmp(argv
[0], "bright") == 0)
324 if (strcmp(argv
[argc
-1], "black") == 0) {
329 } else if (strcmp(argv
[argc
-1], "grey") == 0) {
334 } else if (strcmp(argv
[argc
-1], "red") == 0)
336 else if (strcmp(argv
[argc
-1], "green") == 0)
338 else if (strcmp(argv
[argc
-1], "yellow") == 0)
339 *opt_color
|= YELLOW
;
340 else if (strcmp(argv
[argc
-1], "blue") == 0)
342 else if (strcmp(argv
[argc
-1], "magenta") == 0)
343 *opt_color
|= MAGENTA
;
344 else if (strcmp(argv
[argc
-1], "cyan") == 0)
346 else if (strcmp(argv
[argc
-1], "white") == 0)
348 else if (isdigit(argv
[argc
-1][0]))
349 *opt_color
= atoi(argv
[argc
-1]);
352 if(*opt_color
< 0 || *opt_color
> 15)
358 parse_clear(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
359 /* argc: Number of arguments for this option. */
360 /* argv: Arguments for this option. */
361 /* option: Clear flag to set. */
362 /* opt_all: Clear all switch to set or reset. */
363 /* bad_arg: Set to true if an error is detected. */
365 /* Parse a -clear specification. */
367 if (argc
> 1 || *option
)
371 if (strcmp(argv
[0], "all") == 0)
373 else if (strcmp(argv
[0], "rest") == 0)
383 parse_blank(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
384 /* argc: Number of arguments for this option. */
385 /* argv: Arguments for this option. */
386 /* option: Clear flag to set. */
387 /* opt_all: Clear all switch to set or reset. */
388 /* bad_arg: Set to true if an error is detected. */
390 /* Parse a -blank specification. */
392 if (argc
> 1 || *option
)
396 *opt_all
= atoi(argv
[0]);
397 if ((*opt_all
> 60) || (*opt_all
< 0))
405 parse_powersave(int argc
, char **argv
, int *option
, int *opt_mode
, int *bad_arg
) {
406 /* argc: Number of arguments for this option. */
407 /* argv: Arguments for this option. */
408 /* option: powersave flag to set. */
409 /* opt_mode: Powersaving mode, defined in vesa_blank.c */
410 /* bad_arg: Set to true if an error is detected. */
412 /* Parse a -powersave mode specification. */
414 if (argc
> 1 || *option
)
418 if (strcmp(argv
[0], "on") == 0)
420 else if (strcmp(argv
[0], "vsync") == 0)
422 else if (strcmp(argv
[0], "hsync") == 0)
424 else if (strcmp(argv
[0], "powerdown") == 0)
426 else if (strcmp(argv
[0], "off") == 0)
437 parse_standout(int argc
, char *argv
, int *option
, int *opt_all
, int *bad_arg
) {
438 /* argc: Number of arguments for this option. */
439 /* argv: Arguments for this option. */
440 /* option: Clear flag to set. */
441 /* opt_all: Clear all switch to set or reset. */
442 /* bad_arg: Set to true if an error is detected. */
444 /* Parse a -standout specification. */
446 if (argc
> 1 || *option
)
450 *opt_all
= atoi(argv
[0]);
457 parse_msglevel(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
458 /* argc: Number of arguments for this option. */
459 /* argv: Arguments for this option. */
460 /* option: Clear flag to set. */
461 /* opt_all: Clear all switch to set or reset. */
462 /* bad_arg: Set to true if an error is detected. */
464 if (argc
> 1 || *option
)
468 *opt_all
= atoi(argv
[0]);
469 if (*opt_all
< 0 || *opt_all
> 8)
477 parse_snap(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
478 /* argc: Number of arguments for this option. */
479 /* argv: Arguments for this option. */
480 /* option: Clear flag to set. */
481 /* opt_all: Clear all switch to set or reset. */
482 /* bad_arg: Set to true if an error is detected. */
484 /* Parse a -dump or -append specification. */
486 if (argc
> 1 || *option
)
490 *opt_all
= atoi(argv
[0]);
499 parse_snapfile(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
500 /* argc: Number of arguments for this option. */
501 /* argv: Arguments for this option. */
502 /* option: Clear flag to set. */
503 /* opt_all: Clear all switch to set or reset. */
504 /* bad_arg: Set to true if an error is detected. */
506 /* Parse a -file specification. */
508 if (argc
!= 1 || *option
)
512 strcpy((char *)opt_all
, argv
[0]);
516 parse_tabs(int argc
, char **argv
, int *option
, int *tab_array
, int *bad_arg
) {
517 /* argc: Number of arguments for this option. */
518 /* argv: Arguments for this option. */
519 /* option: Clear flag to set. */
520 /* tab_array: Array of tabs */
521 /* bad_arg: Set to true if an error is detected. */
523 if (*option
|| argc
> 160)
526 tab_array
[argc
] = -1;
528 tab_array
[argc
] = atoi(argv
[argc
]);
529 if(tab_array
[argc
] < 1 || tab_array
[argc
] > 160) {
537 parse_clrtabs(int argc
, char **argv
, int *option
, int *tab_array
, int *bad_arg
) {
538 /* argc: Number of arguments for this option. */
539 /* argv: Arguments for this option. */
540 /* option: Clear flag to set. */
541 /* tab_array: Array of tabs */
542 /* bad_arg: Set to true if an error is detected. */
544 if (*option
|| argc
> 160)
551 tab_array
[argc
] = -1;
553 tab_array
[argc
] = atoi(argv
[argc
]);
554 if(tab_array
[argc
] < 1 || tab_array
[argc
] > 160) {
562 parse_regtabs(int argc
, char **argv
, int *option
, int *opt_len
, int *bad_arg
) {
563 /* argc: Number of arguments for this option. */
564 /* argv: Arguments for this option. */
565 /* option: Clear flag to set. */
566 /* opt_len: Regular tab length. */
567 /* bad_arg: Set to true if an error is detected. */
569 if (*option
|| argc
> 1)
576 *opt_len
= atoi(argv
[0]);
577 if(*opt_len
< 1 || *opt_len
> 160) {
585 parse_blength(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
586 /* argc: Number of arguments for this option. */
587 /* argv: Arguments for this option. */
588 /* option: Clear flag to set. */
590 /* bad_arg: Set to true if an error is detected. */
592 /* Parse -blength specification. */
594 if (argc
> 1 || *option
)
598 *opt_all
= atoi(argv
[0]);
607 parse_bfreq(int argc
, char **argv
, int *option
, int *opt_all
, int *bad_arg
) {
608 /* argc: Number of arguments for this option. */
609 /* argv: Arguments for this option. */
610 /* option: Clear flag to set. */
612 /* bad_arg: Set to true if an error is detected. */
614 /* Parse -bfreq specification. */
616 if (argc
> 1 || *option
)
620 *opt_all
= atoi(argv
[0]);
629 int i
, co
= tigetnum("cols");
633 for(i
= 10; i
< co
-2; i
+=10)
636 for(i
= 1; i
<= co
; i
++)
639 for(i
= 1; i
< co
; i
++)
646 #define STRCMP(str1,str2) strncmp(str1,str2,strlen(str1))
649 parse_option(char *option
, int argc
, char **argv
, int *bad_arg
) {
650 /* option: Option with leading '-' removed. */
651 /* argc: Number of arguments for this option. */
652 /* argv: Arguments for this option. */
653 /* bad_arg: Set to true if an error is detected. */
655 /* Parse a single specification. */
657 if (STRCMP(option
, "term") == 0)
658 parse_term(argc
, argv
, &opt_term
, &opt_te_terminal_name
, bad_arg
);
659 else if (STRCMP(option
, "reset") == 0)
660 parse_none(argc
, argv
, &opt_reset
, bad_arg
);
661 else if (STRCMP(option
, "initialize") == 0)
662 parse_none(argc
, argv
, &opt_initialize
, bad_arg
);
663 else if (STRCMP(option
, "cursor") == 0)
664 parse_switch(argc
, argv
, &opt_cursor
, &opt_cu_on
, bad_arg
);
665 else if (STRCMP(option
, "repeat") == 0)
666 parse_switch(argc
, argv
, &opt_repeat
, &opt_rep_on
, bad_arg
);
667 else if (STRCMP(option
, "appcursorkeys") == 0)
668 parse_switch(argc
, argv
, &opt_appcursorkeys
, &opt_appck_on
, bad_arg
);
669 else if (STRCMP(option
, "linewrap") == 0)
670 parse_switch(argc
, argv
, &opt_linewrap
, &opt_li_on
, bad_arg
);
672 else if (STRCMP(option
, "snow") == 0)
673 parse_switch(argc
, argv
, &opt_snow
, &opt_sn_on
, bad_arg
);
674 else if (STRCMP(option
, "softscroll") == 0)
675 parse_switch(argc
, argv
, &opt_softscroll
, &opt_so_on
, bad_arg
);
677 else if (STRCMP(option
, "default") == 0)
678 parse_none(argc
, argv
, &opt_default
, bad_arg
);
679 else if (STRCMP(option
, "foreground") == 0)
680 par_color(argc
, argv
, &opt_foreground
, &opt_fo_color
, bad_arg
);
681 else if (STRCMP(option
, "background") == 0)
682 par_color(argc
, argv
, &opt_background
, &opt_ba_color
, bad_arg
);
683 else if (STRCMP(option
, "ulcolor") == 0)
684 par_color2(argc
, argv
, &opt_ulcolor
, &opt_ul_color
, bad_arg
);
685 else if (STRCMP(option
, "hbcolor") == 0)
686 par_color2(argc
, argv
, &opt_hbcolor
, &opt_hb_color
, bad_arg
);
687 else if (STRCMP(option
, "inversescreen") == 0)
688 parse_switch(argc
, argv
, &opt_inversescreen
, &opt_invsc_on
, bad_arg
);
689 else if (STRCMP(option
, "bold") == 0)
690 parse_switch(argc
, argv
, &opt_bold
, &opt_bo_on
, bad_arg
);
691 else if (STRCMP(option
, "half-bright") == 0)
692 parse_switch(argc
, argv
, &opt_halfbright
, &opt_hb_on
, bad_arg
);
693 else if (STRCMP(option
, "blink") == 0)
694 parse_switch(argc
, argv
, &opt_blink
, &opt_bl_on
, bad_arg
);
695 else if (STRCMP(option
, "reverse") == 0)
696 parse_switch(argc
, argv
, &opt_reverse
, &opt_re_on
, bad_arg
);
697 else if (STRCMP(option
, "underline") == 0)
698 parse_switch(argc
, argv
, &opt_underline
, &opt_un_on
, bad_arg
);
699 else if (STRCMP(option
, "store") == 0)
700 parse_none(argc
, argv
, &opt_store
, bad_arg
);
701 else if (STRCMP(option
, "clear") == 0)
702 parse_clear(argc
, argv
, &opt_clear
, &opt_cl_all
, bad_arg
);
703 else if (STRCMP(option
, "tabs") == 0)
704 parse_tabs(argc
, argv
, &opt_tabs
, opt_tb_array
, bad_arg
);
705 else if (STRCMP(option
, "clrtabs") == 0)
706 parse_clrtabs(argc
, argv
, &opt_clrtabs
, opt_tb_array
, bad_arg
);
707 else if (STRCMP(option
, "regtabs") == 0)
708 parse_regtabs(argc
, argv
, &opt_regtabs
, &opt_rt_len
, bad_arg
);
709 else if (STRCMP(option
, "blank") == 0)
710 parse_blank(argc
, argv
, &opt_blank
, &opt_bl_min
, bad_arg
);
711 else if (STRCMP(option
, "dump") == 0)
712 parse_snap(argc
, argv
, &opt_snap
, &opt_sn_num
, bad_arg
);
713 else if (STRCMP(option
, "append") == 0)
714 parse_snap(argc
, argv
, &opt_append
, &opt_sn_num
, bad_arg
);
715 else if (STRCMP(option
, "file") == 0)
716 parse_snapfile(argc
, argv
, &opt_snapfile
, (int *)opt_sn_name
, bad_arg
);
717 else if (STRCMP(option
, "msg") == 0)
718 parse_switch(argc
, argv
, &opt_msg
, &opt_msg_on
, bad_arg
);
719 else if (STRCMP(option
, "msglevel") == 0)
720 parse_msglevel(argc
, argv
, &opt_msglevel
, &opt_msglevel_num
, bad_arg
);
721 else if (STRCMP(option
, "powersave") == 0)
722 parse_powersave(argc
, argv
, &opt_powersave
, &opt_ps_mode
, bad_arg
);
723 else if (STRCMP(option
, "powerdown") == 0)
724 parse_blank(argc
, argv
, &opt_powerdown
, &opt_pd_min
, bad_arg
);
725 else if (STRCMP(option
, "blength") == 0)
726 parse_blength(argc
, argv
, &opt_blength
, &opt_blength_l
, bad_arg
);
727 else if (STRCMP(option
, "bfreq") == 0)
728 parse_bfreq(argc
, argv
, &opt_bfreq
, &opt_bfreq_f
, bad_arg
);
730 else if (STRCMP(option
, "standout") == 0)
731 parse_standout(argc
, argv
, &opt_standout
, &opt_st_attr
, bad_arg
);
737 /* End of command line parsing routines. */
740 usage(char *prog_name
) {
741 /* Print error message about arguments, and the command's syntax. */
743 fprintf(stderr
, _("%s: Argument error, usage\n"), prog_name
);
744 fprintf(stderr
, "\n");
745 fprintf(stderr
, "%s\n", prog_name
);
746 fprintf(stderr
, _(" [ -term terminal_name ]\n"));
747 fprintf(stderr
, _(" [ -reset ]\n"));
748 fprintf(stderr
, _(" [ -initialize ]\n"));
749 fprintf(stderr
, _(" [ -cursor [on|off] ]\n"));
751 fprintf(stderr
, _(" [ -snow [on|off] ]\n"));
752 fprintf(stderr
, _(" [ -softscroll [on|off] ]\n"));
754 fprintf(stderr
, _(" [ -repeat [on|off] ]\n"));
755 fprintf(stderr
, _(" [ -appcursorkeys [on|off] ]\n"));
756 fprintf(stderr
, _(" [ -linewrap [on|off] ]\n"));
757 fprintf(stderr
, _(" [ -default ]\n"));
758 fprintf(stderr
, _(" [ -foreground black|blue|green|cyan"));
759 fprintf(stderr
, _("|red|magenta|yellow|white|default ]\n"));
760 fprintf(stderr
, _(" [ -background black|blue|green|cyan"));
761 fprintf(stderr
, _("|red|magenta|yellow|white|default ]\n"));
762 fprintf(stderr
, _(" [ -ulcolor black|grey|blue|green|cyan"));
763 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
764 fprintf(stderr
, _(" [ -ulcolor bright blue|green|cyan"));
765 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
766 fprintf(stderr
, _(" [ -hbcolor black|grey|blue|green|cyan"));
767 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
768 fprintf(stderr
, _(" [ -hbcolor bright blue|green|cyan"));
769 fprintf(stderr
, _("|red|magenta|yellow|white ]\n"));
771 fprintf(stderr
, _(" [ -standout [ attr ] ]\n"));
773 fprintf(stderr
, _(" [ -inversescreen [on|off] ]\n"));
774 fprintf(stderr
, _(" [ -bold [on|off] ]\n"));
775 fprintf(stderr
, _(" [ -half-bright [on|off] ]\n"));
776 fprintf(stderr
, _(" [ -blink [on|off] ]\n"));
777 fprintf(stderr
, _(" [ -reverse [on|off] ]\n"));
778 fprintf(stderr
, _(" [ -underline [on|off] ]\n"));
779 fprintf(stderr
, _(" [ -store ]\n"));
780 fprintf(stderr
, _(" [ -clear [all|rest] ]\n"));
781 fprintf(stderr
, _(" [ -tabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"));
782 fprintf(stderr
, _(" [ -clrtabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"));
783 fprintf(stderr
, _(" [ -regtabs [1-160] ]\n"));
784 fprintf(stderr
, _(" [ -blank [0-60] ]\n"));
785 fprintf(stderr
, _(" [ -dump [1-NR_CONSOLES] ]\n"));
786 fprintf(stderr
, _(" [ -append [1-NR_CONSOLES] ]\n"));
787 fprintf(stderr
, _(" [ -file dumpfilename ]\n"));
788 fprintf(stderr
, _(" [ -msg [on|off] ]\n"));
789 fprintf(stderr
, _(" [ -msglevel [0-8] ]\n"));
790 fprintf(stderr
, _(" [ -powersave [on|vsync|hsync|powerdown|off] ]\n"));
791 fprintf(stderr
, _(" [ -powerdown [0-60] ]\n"));
792 fprintf(stderr
, _(" [ -blength [0-2000] ]\n"));
793 fprintf(stderr
, _(" [ -bfreq freqnumber ]\n"));
796 static char *ti_entry(const char *name
) {
797 /* name: Terminfo capability string to lookup. */
799 /* Return the specified terminfo string, or an empty string if no such terminfo
805 if ((buf_ptr
= tigetstr(name
)) == (char *)-1) buf_ptr
= NULL
;
810 perform_sequence(int vcterm
) {
811 /* vcterm: Set if terminal is a virtual console. */
814 /* Perform the selected options. */
818 putp(ti_entry("rs1"));
822 if (opt_initialize
) {
823 putp(ti_entry("is2"));
826 /* -cursor [on|off]. */
829 putp(ti_entry("cnorm"));
831 putp(ti_entry("civis"));
834 /* -linewrap [on|off]. Vc only (vt102) */
835 if (opt_linewrap
&& vcterm
) {
842 /* -repeat [on|off]. Vc only (vt102) */
843 if (opt_repeat
&& vcterm
) {
850 /* -appcursorkeys [on|off]. Vc only (vt102) */
851 if (opt_appcursorkeys
&& vcterm
) {
859 /* -snow [on|off]. Vc only. */
860 if (opt_snow
&& vcterm
) {
862 printf("%s%s%s", DCS
, "snow.on", ST
);
864 printf("%s%s%s", DCS
, "snow.off", ST
);
867 /* -softscroll [on|off]. Vc only. */
868 if (opt_softscroll
&& vcterm
) {
870 printf("%s%s%s", DCS
, "softscroll.on", ST
);
872 printf("%s%s%s", DCS
, "softscroll.off", ST
);
876 /* -default. Vc sets default rendition, otherwise clears all
883 putp(ti_entry("sgr0"));
886 /* -foreground black|red|green|yellow|blue|magenta|cyan|white|default.
889 if (opt_foreground
&& vcterm
) {
890 printf("%s%s%c%s", ESC
, "[3", '0' + opt_fo_color
, "m");
893 /* -background black|red|green|yellow|blue|magenta|cyan|white|default.
896 if (opt_background
&& vcterm
) {
897 printf("%s%s%c%s", ESC
, "[4", '0' + opt_ba_color
, "m");
900 /* -ulcolor black|red|green|yellow|blue|magenta|cyan|white|default.
903 if (opt_ulcolor
&& vcterm
) {
904 printf("\033[1;%d]", opt_ul_color
);
907 /* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default.
910 if (opt_hbcolor
&& vcterm
) {
911 printf("\033[2;%d]", opt_hb_color
);
914 /* -inversescreen [on|off]. Vc only (vt102).
916 if (opt_inversescreen
) {
925 /* -bold [on|off]. Vc behaves as expected, otherwise off turns off
930 putp(ti_entry("bold"));
933 printf("%s%s", ESC
, "[22m");
935 putp(ti_entry("sgr0"));
939 /* -half-bright [on|off]. Vc behaves as expected, otherwise off turns off
942 if (opt_halfbright
) {
944 putp(ti_entry("dim"));
947 printf("%s%s", ESC
, "[22m");
949 putp(ti_entry("sgr0"));
953 /* -blink [on|off]. Vc behaves as expected, otherwise off turns off
958 putp(ti_entry("blink"));
961 printf("%s%s", ESC
, "[25m");
963 putp(ti_entry("sgr0"));
967 /* -reverse [on|off]. Vc behaves as expected, otherwise off turns
968 * off all attributes.
972 putp(ti_entry("rev"));
975 printf("%s%s", ESC
, "[27m");
977 putp(ti_entry("sgr0"));
981 /* -underline [on|off]. */
984 putp(ti_entry("smul"));
986 putp(ti_entry("rmul"));
989 /* -store. Vc only. */
990 if (opt_store
&& vcterm
) {
994 /* -clear [all|rest]. */
997 putp(ti_entry("clear"));
999 putp(ti_entry("ed"));
1002 /* -tabs Vc only. */
1003 if (opt_tabs
&& vcterm
) {
1006 if (opt_tb_array
[0] == -1)
1009 for(i
=0; opt_tb_array
[i
] > 0; i
++)
1010 printf("\033[%dG\033H", opt_tb_array
[i
]);
1015 /* -clrtabs Vc only. */
1016 if (opt_clrtabs
&& vcterm
) {
1019 if (opt_tb_array
[0] == -1)
1022 for(i
=0; opt_tb_array
[i
] > 0; i
++)
1023 printf("\033[%dG\033[g", opt_tb_array
[i
]);
1027 /* -regtabs Vc only. */
1028 if (opt_regtabs
&& vcterm
) {
1031 printf("\033[3g\r");
1032 for(i
=opt_rt_len
+1; i
<=160; i
+=opt_rt_len
)
1033 printf("\033[%dC\033H",opt_rt_len
);
1037 /* -blank [0-60]. */
1038 if (opt_blank
&& vcterm
)
1039 printf("\033[9;%d]", opt_bl_min
);
1041 /* -powersave [on|vsync|hsync|powerdown|off] (console) */
1042 if (opt_powersave
) {
1044 ioctlarg
[0] = 10; /* powersave */
1045 ioctlarg
[1] = opt_ps_mode
;
1046 if (ioctl(0,TIOCLINUX
,ioctlarg
))
1047 fprintf(stderr
,_("cannot (un)set powersave mode\n"));
1050 /* -powerdown [0-60]. */
1051 if (opt_powerdown
) {
1052 printf("\033[14;%d]", opt_pd_min
);
1056 /* -standout [num]. */
1061 /* -snap [1-NR_CONS]. */
1062 if (opt_snap
|| opt_append
) {
1065 F
= fopen(opt_sn_name
, opt_snap
? "w" : "a");
1067 perror(opt_sn_name
);
1068 fprintf(stderr
,("setterm: can not open dump file %s for output\n"),
1072 screendump(opt_sn_num
, F
);
1076 /* -msg [on|off]. */
1077 if (opt_msg
&& vcterm
) {
1079 /* 7 -- Enable printk's to console */
1080 result
= klogctl(7, NULL
, 0);
1082 /* 6 -- Disable printk's to console */
1083 result
= klogctl(6, NULL
, 0);
1086 printf(_("klogctl error: %s\n"), strerror(result
));
1089 /* -msglevel [0-8] */
1090 if (opt_msglevel
&& vcterm
) {
1091 /* 8 -- Set level of messages printed to console */
1092 result
= klogctl(8, NULL
, opt_msglevel_num
);
1094 printf(_("klogctl error: %s\n"), strerror(result
));
1097 /* -blength [0-2000] */
1098 if (opt_blength
&& vcterm
) {
1099 printf("\033[11;%d]", opt_blength_l
);
1102 /* -bfreq freqnumber */
1103 if (opt_bfreq
&& vcterm
) {
1104 printf("\033[10;%d]", opt_bfreq_f
);
1110 screendump(int vcnum
, FILE *F
) {
1111 #include <sys/param.h>
1112 char infile
[MAXPATHLEN
];
1113 unsigned char header
[4];
1114 unsigned int rows
, cols
;
1116 char *inbuf
, *outbuf
, *p
, *q
;
1118 sprintf(infile
, "/dev/vcsa%d", vcnum
);
1119 fd
= open(infile
, 0);
1120 if (fd
< 0 || read(fd
, header
, 4) != 4)
1124 if (rows
* cols
== 0)
1126 inbuf
= malloc(rows
*cols
*2);
1127 outbuf
= malloc(rows
*(cols
+1));
1128 if(!inbuf
|| !outbuf
) {
1129 fputs(_("Out of memory"), stderr
);
1132 if (read(fd
, inbuf
, rows
*cols
*2) != rows
*cols
*2) {
1133 fprintf(stderr
, _("Error reading %s\n"), infile
);
1138 for(i
=0; i
<rows
; i
++) {
1139 for(j
=0; j
<cols
; j
++) {
1143 while(j
-- > 0 && q
[-1] == ' ')
1147 if (fwrite(outbuf
, 1, q
-outbuf
, F
) != q
-outbuf
) {
1148 fprintf(stderr
, _("Error writing screendump\n"));
1155 #define NUM_COLS 160
1157 char buf
[NUM_COLS
+1];
1158 unsigned char screenbuf
[NUM_ROWS
*NUM_COLS
];
1160 screenbuf
[1] = (unsigned char) vcnum
;
1161 if (ioctl(0,TIOCLINUX
,screenbuf
) < 0) {
1162 fprintf(stderr
,_("couldn't read %s, and cannot ioctl dump\n"),
1166 rows
= screenbuf
[0];
1167 cols
= screenbuf
[1];
1169 for (i
=0; i
<rows
; i
++) {
1170 strncpy(buf
, screenbuf
+2+(cols
*i
), cols
);
1173 while (--j
&& (buf
[j
] == ' '))
1182 main(int argc
, char **argv
) {
1183 int bad_arg
= FALSE
; /* Set if error in arguments. */
1185 char *term
; /* Terminal type. */
1186 int vcterm
; /* Set if terminal is a virtual console. */
1188 setlocale(LC_ALL
, "");
1189 bindtextdomain(PACKAGE
, LOCALEDIR
);
1190 textdomain(PACKAGE
);
1195 /* Parse arguments. */
1197 for (arg
= 1; arg
< argc
;) {
1198 if (*argv
[arg
] == '-') {
1200 /* Parse a single option. */
1202 for (modifier
= arg
+ 1; modifier
< argc
; modifier
++) {
1203 if (*argv
[modifier
] == '-') break;
1205 parse_option(argv
[arg
] + 1, modifier
- arg
- 1,
1206 &argv
[arg
+ 1], &bad_arg
);
1214 /* Display syntax message if error in arguments. */
1221 /* Find out terminal name. */
1224 term
= opt_te_terminal_name
;
1226 term
= getenv("TERM");
1228 fprintf(stderr
, _("%s: $TERM is not defined.\n"),
1234 /* Find terminfo entry. */
1236 setupterm(term
, 1, (int *)0);
1238 /* See if the terminal is a virtual console terminal. */
1240 vcterm
= (!strncmp(term
, "con", 3) || !strncmp(term
, "linux", 5));
1242 /* Perform the selected options. */
1244 perform_sequence(vcterm
);