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[PATH_MAX + 1] = "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)
528
memset(opt_all, 0, PATH_MAX + 1);
530
strncpy((char *)opt_all, argv[0], PATH_MAX);
534
parse_tabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg) {
535
/* argc: Number of arguments for this option. */
536
/* argv: Arguments for this option. */
537
/* option: Clear flag to set. */
538
/* tab_array: Array of tabs */
539
/* bad_arg: Set to true if an error is detected. */
541
if (*option || argc > 160)
544
tab_array[argc] = -1;
546
tab_array[argc] = atoi(argv[argc]);
547
if(tab_array[argc] < 1 || tab_array[argc] > 160) {
555
parse_clrtabs(int argc, char **argv, int *option, int *tab_array, int *bad_arg) {
556
/* argc: Number of arguments for this option. */
557
/* argv: Arguments for this option. */
558
/* option: Clear flag to set. */
559
/* tab_array: Array of tabs */
560
/* bad_arg: Set to true if an error is detected. */
562
if (*option || argc > 160)
569
tab_array[argc] = -1;
571
tab_array[argc] = atoi(argv[argc]);
572
if(tab_array[argc] < 1 || tab_array[argc] > 160) {
580
parse_regtabs(int argc, char **argv, int *option, int *opt_len, int *bad_arg) {
581
/* argc: Number of arguments for this option. */
582
/* argv: Arguments for this option. */
583
/* option: Clear flag to set. */
584
/* opt_len: Regular tab length. */
585
/* bad_arg: Set to true if an error is detected. */
587
if (*option || argc > 1)
594
*opt_len = atoi(argv[0]);
595
if(*opt_len < 1 || *opt_len > 160) {
603
parse_blength(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
604
/* argc: Number of arguments for this option. */
605
/* argv: Arguments for this option. */
606
/* option: Clear flag to set. */
608
/* bad_arg: Set to true if an error is detected. */
610
/* Parse -blength specification. */
612
if (argc > 1 || *option)
616
*opt_all = atoi(argv[0]);
625
parse_bfreq(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {
626
/* argc: Number of arguments for this option. */
627
/* argv: Arguments for this option. */
628
/* option: Clear flag to set. */
630
/* bad_arg: Set to true if an error is detected. */
632
/* Parse -bfreq specification. */
634
if (argc > 1 || *option)
638
*opt_all = atoi(argv[0]);
647
int i, co = tigetnum("cols");
651
for(i = 10; i < co-2; i+=10)
654
for(i = 1; i <= co; i++)
657
for(i = 1; i < co; i++)
664
#define STRCMP(str1,str2) strncmp(str1,str2,strlen(str1))
667
parse_option(char *option, int argc, char **argv, int *bad_arg) {
668
/* option: Option with leading '-' removed. */
669
/* argc: Number of arguments for this option. */
670
/* argv: Arguments for this option. */
671
/* bad_arg: Set to true if an error is detected. */
673
/* Parse a single specification. */
675
if (STRCMP(option, "term") == 0)
676
parse_term(argc, argv, &opt_term, &opt_te_terminal_name, bad_arg);
677
else if (STRCMP(option, "reset") == 0)
678
parse_none(argc, argv, &opt_reset, bad_arg);
679
else if (STRCMP(option, "initialize") == 0)
680
parse_none(argc, argv, &opt_initialize, bad_arg);
681
else if (STRCMP(option, "cursor") == 0)
682
parse_switch(argc, argv, &opt_cursor, &opt_cu_on, bad_arg);
683
else if (STRCMP(option, "repeat") == 0)
684
parse_switch(argc, argv, &opt_repeat, &opt_rep_on, bad_arg);
685
else if (STRCMP(option, "appcursorkeys") == 0)
686
parse_switch(argc, argv, &opt_appcursorkeys, &opt_appck_on, bad_arg);
687
else if (STRCMP(option, "linewrap") == 0)
688
parse_switch(argc, argv, &opt_linewrap, &opt_li_on, bad_arg);
690
else if (STRCMP(option, "snow") == 0)
691
parse_switch(argc, argv, &opt_snow, &opt_sn_on, bad_arg);
692
else if (STRCMP(option, "softscroll") == 0)
693
parse_switch(argc, argv, &opt_softscroll, &opt_so_on, bad_arg);
695
else if (STRCMP(option, "default") == 0)
696
parse_none(argc, argv, &opt_default, bad_arg);
697
else if (STRCMP(option, "foreground") == 0)
698
par_color(argc, argv, &opt_foreground, &opt_fo_color, bad_arg);
699
else if (STRCMP(option, "background") == 0)
700
par_color(argc, argv, &opt_background, &opt_ba_color, bad_arg);
701
else if (STRCMP(option, "ulcolor") == 0)
702
par_color2(argc, argv, &opt_ulcolor, &opt_ul_color, bad_arg);
703
else if (STRCMP(option, "hbcolor") == 0)
704
par_color2(argc, argv, &opt_hbcolor, &opt_hb_color, bad_arg);
705
else if (STRCMP(option, "inversescreen") == 0)
706
parse_switch(argc, argv, &opt_inversescreen, &opt_invsc_on, bad_arg);
707
else if (STRCMP(option, "bold") == 0)
708
parse_switch(argc, argv, &opt_bold, &opt_bo_on, bad_arg);
709
else if (STRCMP(option, "half-bright") == 0)
710
parse_switch(argc, argv, &opt_halfbright, &opt_hb_on, bad_arg);
711
else if (STRCMP(option, "blink") == 0)
712
parse_switch(argc, argv, &opt_blink, &opt_bl_on, bad_arg);
713
else if (STRCMP(option, "reverse") == 0)
714
parse_switch(argc, argv, &opt_reverse, &opt_re_on, bad_arg);
715
else if (STRCMP(option, "underline") == 0)
716
parse_switch(argc, argv, &opt_underline, &opt_un_on, bad_arg);
717
else if (STRCMP(option, "store") == 0)
718
parse_none(argc, argv, &opt_store, bad_arg);
719
else if (STRCMP(option, "clear") == 0)
720
parse_clear(argc, argv, &opt_clear, &opt_cl_all, bad_arg);
721
else if (STRCMP(option, "tabs") == 0)
722
parse_tabs(argc, argv, &opt_tabs, opt_tb_array, bad_arg);
723
else if (STRCMP(option, "clrtabs") == 0)
724
parse_clrtabs(argc, argv, &opt_clrtabs, opt_tb_array, bad_arg);
725
else if (STRCMP(option, "regtabs") == 0)
726
parse_regtabs(argc, argv, &opt_regtabs, &opt_rt_len, bad_arg);
727
else if (STRCMP(option, "blank") == 0)
728
parse_blank(argc, argv, &opt_blank, &opt_bl_min, bad_arg);
729
else if (STRCMP(option, "dump") == 0)
730
parse_snap(argc, argv, &opt_snap, &opt_sn_num, bad_arg);
731
else if (STRCMP(option, "append") == 0)
732
parse_snap(argc, argv, &opt_append, &opt_sn_num, bad_arg);
733
else if (STRCMP(option, "file") == 0)
734
parse_snapfile(argc, argv, &opt_snapfile, (int *)opt_sn_name, bad_arg);
735
else if (STRCMP(option, "msg") == 0)
736
parse_switch(argc, argv, &opt_msg, &opt_msg_on, bad_arg);
737
else if (STRCMP(option, "msglevel") == 0)
738
parse_msglevel(argc, argv, &opt_msglevel, &opt_msglevel_num, bad_arg);
739
else if (STRCMP(option, "powersave") == 0)
740
parse_powersave(argc, argv, &opt_powersave, &opt_ps_mode, bad_arg);
741
else if (STRCMP(option, "powerdown") == 0)
742
parse_blank(argc, argv, &opt_powerdown, &opt_pd_min, bad_arg);
743
else if (STRCMP(option, "blength") == 0)
744
parse_blength(argc, argv, &opt_blength, &opt_blength_l, bad_arg);
745
else if (STRCMP(option, "bfreq") == 0)
746
parse_bfreq(argc, argv, &opt_bfreq, &opt_bfreq_f, bad_arg);
748
else if (STRCMP(option, "standout") == 0)
749
parse_standout(argc, argv, &opt_standout, &opt_st_attr, bad_arg);
755
/* End of command line parsing routines. */
758
usage(char *prog_name) {
759
/* Print error message about arguments, and the command's syntax. */
761
fprintf(stderr, _("%s: Argument error, usage\n"), prog_name);
762
fprintf(stderr, "\n");
763
fprintf(stderr, "%s\n", prog_name);
764
fprintf(stderr, _(" [ -term terminal_name ]\n"));
765
fprintf(stderr, _(" [ -reset ]\n"));
766
fprintf(stderr, _(" [ -initialize ]\n"));
767
fprintf(stderr, _(" [ -cursor [on|off] ]\n"));
769
fprintf(stderr, _(" [ -snow [on|off] ]\n"));
770
fprintf(stderr, _(" [ -softscroll [on|off] ]\n"));
772
fprintf(stderr, _(" [ -repeat [on|off] ]\n"));
773
fprintf(stderr, _(" [ -appcursorkeys [on|off] ]\n"));
774
fprintf(stderr, _(" [ -linewrap [on|off] ]\n"));
775
fprintf(stderr, _(" [ -default ]\n"));
776
fprintf(stderr, _(" [ -foreground black|blue|green|cyan"));
777
fprintf(stderr, _("|red|magenta|yellow|white|default ]\n"));
778
fprintf(stderr, _(" [ -background black|blue|green|cyan"));
779
fprintf(stderr, _("|red|magenta|yellow|white|default ]\n"));
780
fprintf(stderr, _(" [ -ulcolor black|grey|blue|green|cyan"));
781
fprintf(stderr, _("|red|magenta|yellow|white ]\n"));
782
fprintf(stderr, _(" [ -ulcolor bright blue|green|cyan"));
783
fprintf(stderr, _("|red|magenta|yellow|white ]\n"));
784
fprintf(stderr, _(" [ -hbcolor black|grey|blue|green|cyan"));
785
fprintf(stderr, _("|red|magenta|yellow|white ]\n"));
786
fprintf(stderr, _(" [ -hbcolor bright blue|green|cyan"));
787
fprintf(stderr, _("|red|magenta|yellow|white ]\n"));
789
fprintf(stderr, _(" [ -standout [ attr ] ]\n"));
791
fprintf(stderr, _(" [ -inversescreen [on|off] ]\n"));
792
fprintf(stderr, _(" [ -bold [on|off] ]\n"));
793
fprintf(stderr, _(" [ -half-bright [on|off] ]\n"));
794
fprintf(stderr, _(" [ -blink [on|off] ]\n"));
795
fprintf(stderr, _(" [ -reverse [on|off] ]\n"));
796
fprintf(stderr, _(" [ -underline [on|off] ]\n"));
797
fprintf(stderr, _(" [ -store ]\n"));
798
fprintf(stderr, _(" [ -clear [all|rest] ]\n"));
799
fprintf(stderr, _(" [ -tabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"));
800
fprintf(stderr, _(" [ -clrtabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n"));
801
fprintf(stderr, _(" [ -regtabs [1-160] ]\n"));
802
fprintf(stderr, _(" [ -blank [0-60|force|poke] ]\n"));
803
fprintf(stderr, _(" [ -dump [1-NR_CONSOLES] ]\n"));
804
fprintf(stderr, _(" [ -append [1-NR_CONSOLES] ]\n"));
805
fprintf(stderr, _(" [ -file dumpfilename ]\n"));
806
fprintf(stderr, _(" [ -msg [on|off] ]\n"));
807
fprintf(stderr, _(" [ -msglevel [0-8] ]\n"));
808
fprintf(stderr, _(" [ -powersave [on|vsync|hsync|powerdown|off] ]\n"));
809
fprintf(stderr, _(" [ -powerdown [0-60] ]\n"));
810
fprintf(stderr, _(" [ -blength [0-2000] ]\n"));
811
fprintf(stderr, _(" [ -bfreq freqnumber ]\n"));
814
static char *ti_entry(const char *name) {
815
/* name: Terminfo capability string to lookup. */
817
/* Return the specified terminfo string, or an empty string if no such terminfo
823
if ((buf_ptr = tigetstr((char *)name)) == (char *)-1)
829
perform_sequence(int vcterm) {
830
/* vcterm: Set if terminal is a virtual console. */
833
/* Perform the selected options. */
837
putp(ti_entry("rs1"));
841
if (opt_initialize) {
842
putp(ti_entry("is2"));
845
/* -cursor [on|off]. */
848
putp(ti_entry("cnorm"));
850
putp(ti_entry("civis"));
853
/* -linewrap [on|off]. Vc only (vt102) */
854
if (opt_linewrap && vcterm) {
861
/* -repeat [on|off]. Vc only (vt102) */
862
if (opt_repeat && vcterm) {
869
/* -appcursorkeys [on|off]. Vc only (vt102) */
870
if (opt_appcursorkeys && vcterm) {
878
/* -snow [on|off]. Vc only. */
879
if (opt_snow && vcterm) {
881
printf("%s%s%s", DCS, "snow.on", ST);
883
printf("%s%s%s", DCS, "snow.off", ST);
886
/* -softscroll [on|off]. Vc only. */
887
if (opt_softscroll && vcterm) {
889
printf("%s%s%s", DCS, "softscroll.on", ST);
891
printf("%s%s%s", DCS, "softscroll.off", ST);
895
/* -default. Vc sets default rendition, otherwise clears all
902
putp(ti_entry("sgr0"));
905
/* -foreground black|red|green|yellow|blue|magenta|cyan|white|default.
908
if (opt_foreground && vcterm) {
909
printf("%s%s%c%s", ESC, "[3", '0' + opt_fo_color, "m");
912
/* -background black|red|green|yellow|blue|magenta|cyan|white|default.
915
if (opt_background && vcterm) {
916
printf("%s%s%c%s", ESC, "[4", '0' + opt_ba_color, "m");
919
/* -ulcolor black|red|green|yellow|blue|magenta|cyan|white|default.
922
if (opt_ulcolor && vcterm) {
923
printf("\033[1;%d]", opt_ul_color);
926
/* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default.
929
if (opt_hbcolor && vcterm) {
930
printf("\033[2;%d]", opt_hb_color);
933
/* -inversescreen [on|off]. Vc only (vt102).
935
if (opt_inversescreen) {
944
/* -bold [on|off]. Vc behaves as expected, otherwise off turns off
949
putp(ti_entry("bold"));
952
printf("%s%s", ESC, "[22m");
954
putp(ti_entry("sgr0"));
958
/* -half-bright [on|off]. Vc behaves as expected, otherwise off turns off
961
if (opt_halfbright) {
963
putp(ti_entry("dim"));
966
printf("%s%s", ESC, "[22m");
968
putp(ti_entry("sgr0"));
972
/* -blink [on|off]. Vc behaves as expected, otherwise off turns off
977
putp(ti_entry("blink"));
980
printf("%s%s", ESC, "[25m");
982
putp(ti_entry("sgr0"));
986
/* -reverse [on|off]. Vc behaves as expected, otherwise off turns
987
* off all attributes.
991
putp(ti_entry("rev"));
994
printf("%s%s", ESC, "[27m");
996
putp(ti_entry("sgr0"));
1000
/* -underline [on|off]. */
1001
if (opt_underline) {
1003
putp(ti_entry("smul"));
1005
putp(ti_entry("rmul"));
1008
/* -store. Vc only. */
1009
if (opt_store && vcterm) {
1013
/* -clear [all|rest]. */
1016
putp(ti_entry("clear"));
1018
putp(ti_entry("ed"));
1021
/* -tabs Vc only. */
1022
if (opt_tabs && vcterm) {
1025
if (opt_tb_array[0] == -1)
1028
for(i=0; opt_tb_array[i] > 0; i++)
1029
printf("\033[%dG\033H", opt_tb_array[i]);
1034
/* -clrtabs Vc only. */
1035
if (opt_clrtabs && vcterm) {
1038
if (opt_tb_array[0] == -1)
1041
for(i=0; opt_tb_array[i] > 0; i++)
1042
printf("\033[%dG\033[g", opt_tb_array[i]);
1046
/* -regtabs Vc only. */
1047
if (opt_regtabs && vcterm) {
1050
printf("\033[3g\r");
1051
for(i=opt_rt_len+1; i<=160; i+=opt_rt_len)
1052
printf("\033[%dC\033H",opt_rt_len);
1056
/* -blank [0-60]. */
1057
if (opt_blank && vcterm) {
1058
if (opt_bl_min >= 0)
1059
printf("\033[9;%d]", opt_bl_min);
1060
else if (opt_bl_min == BLANKSCREEN) {
1061
char ioctlarg = TIOCL_BLANKSCREEN;
1062
if (ioctl(0,TIOCLINUX,&ioctlarg))
1063
fprintf(stderr,_("cannot force blank\n"));
1064
} else if (opt_bl_min == UNBLANKSCREEN) {
1065
char ioctlarg = TIOCL_UNBLANKSCREEN;
1066
if (ioctl(0,TIOCLINUX,&ioctlarg))
1067
fprintf(stderr,_("cannot force unblank\n"));
1068
} else if (opt_bl_min == BLANKEDSCREEN) {
1069
char ioctlarg = TIOCL_BLANKEDSCREEN;
1071
ret = ioctl(0,TIOCLINUX,&ioctlarg);
1073
fprintf(stderr,_("cannot get blank status\n"));
1079
/* -powersave [on|vsync|hsync|powerdown|off] (console) */
1080
if (opt_powersave) {
1082
ioctlarg[0] = TIOCL_SETVESABLANK;
1083
ioctlarg[1] = opt_ps_mode;
1084
if (ioctl(0,TIOCLINUX,ioctlarg))
1085
fprintf(stderr,_("cannot (un)set powersave mode\n"));
1088
/* -powerdown [0-60]. */
1089
if (opt_powerdown) {
1090
printf("\033[14;%d]", opt_pd_min);
1094
/* -standout [num]. */
1099
/* -snap [1-NR_CONS]. */
1100
if (opt_snap || opt_append) {
1103
F = fopen(opt_sn_name, opt_snap ? "w" : "a");
1105
perror(opt_sn_name);
1106
fprintf(stderr,("setterm: can not open dump file %s for output\n"),
1110
screendump(opt_sn_num, F);
1114
/* -msg [on|off]. */
1115
if (opt_msg && vcterm) {
1117
/* 7 -- Enable printk's to console */
1118
result = klogctl(7, NULL, 0);
1120
/* 6 -- Disable printk's to console */
1121
result = klogctl(6, NULL, 0);
1124
printf(_("klogctl error: %s\n"), strerror(errno));
1127
/* -msglevel [0-8] */
1128
if (opt_msglevel && vcterm) {
1129
/* 8 -- Set level of messages printed to console */
1130
result = klogctl(8, NULL, opt_msglevel_num);
1132
printf(_("klogctl error: %s\n"), strerror(errno));
1135
/* -blength [0-2000] */
1136
if (opt_blength && vcterm) {
1137
printf("\033[11;%d]", opt_blength_l);
1140
/* -bfreq freqnumber */
1141
if (opt_bfreq && vcterm) {
1142
printf("\033[10;%d]", opt_bfreq_f);
1148
screendump(int vcnum, FILE *F) {
1149
char infile[MAXPATHLEN];
1150
unsigned char header[4];
1151
unsigned int rows, cols;
1153
char *inbuf, *outbuf, *p, *q;
1155
sprintf(infile, "/dev/vcsa%d", vcnum);
1156
fd = open(infile, O_RDONLY);
1157
if (fd < 0 && vcnum == 0) {
1158
/* vcsa0 is often called vcsa */
1159
sprintf(infile, "/dev/vcsa");
1160
fd = open(infile, O_RDONLY);
1163
/* try devfs name - for zero vcnum just /dev/vcc/a */
1164
/* some gcc's warn for %.u - add 0 */
1165
sprintf(infile, "/dev/vcc/a%.0u", vcnum);
1166
fd = open(infile, O_RDONLY);
1169
sprintf(infile, "/dev/vcsa%d", vcnum);
1172
if (read(fd, header, 4) != 4)
1176
if (rows * cols == 0)
1178
inbuf = malloc(rows*cols*2);
1179
outbuf = malloc(rows*(cols+1));
1180
if(!inbuf || !outbuf) {
1181
fputs(_("Out of memory"), stderr);
1184
if (read(fd, inbuf, rows*cols*2) != rows*cols*2)
1188
for(i=0; i<rows; i++) {
1189
for(j=0; j<cols; j++) {
1193
while(j-- > 0 && q[-1] == ' ')
1197
if (fwrite(outbuf, 1, q-outbuf, F) != q-outbuf) {
1198
fprintf(stderr, _("Error writing screendump\n"));
1205
fprintf(stderr, _("Couldn't read %s\n"), infile);
1213
main(int argc, char **argv) {
1214
int bad_arg = FALSE; /* Set if error in arguments. */
1216
char *term; /* Terminal type. */
1217
int vcterm; /* Set if terminal is a virtual console. */
1219
setlocale(LC_ALL, "");
1220
bindtextdomain(PACKAGE, LOCALEDIR);
1221
textdomain(PACKAGE);
1226
/* Parse arguments. */
1228
for (arg = 1; arg < argc;) {
1229
if (*argv[arg] == '-') {
1231
/* Parse a single option. */
1233
for (modifier = arg + 1; modifier < argc; modifier++) {
1234
if (*argv[modifier] == '-') break;
1236
parse_option(argv[arg] + 1, modifier - arg - 1,
1237
&argv[arg + 1], &bad_arg);
1245
/* Display syntax message if error in arguments. */
1252
/* Find out terminal name. */
1255
term = opt_te_terminal_name;
1257
term = getenv("TERM");
1259
fprintf(stderr, _("%s: $TERM is not defined.\n"),
1265
/* Find terminfo entry. */
1267
setupterm(term, 1, (int *)0);
1269
/* See if the terminal is a virtual console terminal. */
1271
vcterm = (!strncmp(term, "con", 3) || !strncmp(term, "linux", 5));
1273
/* Perform the selected options. */
1275
perform_sequence(vcterm);