2 * Copyright (c) 1994-1996 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software withough specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/usr.sbin/vidcontrol/vidcontrol.c,v 1.32.2.7 2002/09/15 22:31:50 dd Exp $
29 * $DragonFly: src/usr.sbin/vidcontrol/vidcontrol.c,v 1.11 2006/12/29 01:10:35 swildner Exp $
32 #include <machine/console.h>
34 #include <sys/consio.h>
35 #include <sys/errno.h>
36 #include <sys/types.h>
51 #define DATASIZE(x) ((x).w * (x).h * 256 / 8)
56 #define DUMP_FMT_REV 1
59 char legal_colors
[16][16] = {
60 "black", "blue", "green", "cyan",
61 "red", "magenta", "brown", "white",
62 "grey", "lightblue", "lightgreen", "lightcyan",
63 "lightred", "lightmagenta", "yellow", "lightwhite"
68 vid_info_t console_info
;
69 unsigned char screen_map
[256];
70 int video_mode_number
;
71 struct video_info video_mode_info
;
80 int video_mode_changed
;
81 int normal_fore_color
, normal_back_color
;
82 int revers_fore_color
, revers_back_color
;
85 struct video_info new_mode_info
;
89 * Initialize revert data.
91 * NOTE: the following parameters are not yet saved/restored:
93 * screen saver timeout
95 * mouse character and mouse show/hide state
96 * vty switching on/off state
105 if (ioctl(0, VT_GETACTIVE
, &cur_info
.active_vty
) == -1)
106 errc(1, errno
, "getting active vty");
108 cur_info
.console_info
.size
= sizeof(cur_info
.console_info
);
110 if (ioctl(0, CONS_GETINFO
, &cur_info
.console_info
) == -1)
111 errc(1, errno
, "getting console information");
113 if (ioctl(0, GIO_SCRNMAP
, &cur_info
.screen_map
) == -1)
114 errc(1, errno
, "getting screen map");
116 if (ioctl(0, CONS_GET
, &cur_info
.video_mode_number
) == -1)
117 errc(1, errno
, "getting video mode number");
119 cur_info
.video_mode_info
.vi_mode
= cur_info
.video_mode_number
;
121 if (ioctl(0, CONS_MODEINFO
, &cur_info
.video_mode_info
) == -1)
122 errc(1, errno
, "getting video mode parameters");
124 normal_fore_color
= cur_info
.console_info
.mv_norm
.fore
;
125 normal_back_color
= cur_info
.console_info
.mv_norm
.back
;
126 revers_fore_color
= cur_info
.console_info
.mv_rev
.fore
;
127 revers_back_color
= cur_info
.console_info
.mv_rev
.back
;
132 * If something goes wrong along the way we call revert() to go back to the
133 * console state we came from (which is assumed to be working).
135 * NOTE: please also read the comments of init().
143 ioctl(0, VT_ACTIVATE
, (caddr_t
) (long) cur_info
.active_vty
);
145 fprintf(stderr
, "\e[=%dA", cur_info
.console_info
.mv_ovscan
);
146 fprintf(stderr
, "\e[=%dF", cur_info
.console_info
.mv_norm
.fore
);
147 fprintf(stderr
, "\e[=%dG", cur_info
.console_info
.mv_norm
.back
);
148 fprintf(stderr
, "\e[=%dH", cur_info
.console_info
.mv_rev
.fore
);
149 fprintf(stderr
, "\e[=%dI", cur_info
.console_info
.mv_rev
.back
);
151 ioctl(0, PIO_SCRNMAP
, &cur_info
.screen_map
);
153 if (cur_info
.video_mode_number
>= M_VESA_BASE
)
154 ioctl(0, _IO('V', cur_info
.video_mode_number
- M_VESA_BASE
),
157 ioctl(0, _IO('S', cur_info
.video_mode_number
), NULL
);
159 if (cur_info
.video_mode_info
.vi_flags
& V_INFO_GRAPHICS
) {
160 size
[0] = cur_info
.video_mode_info
.vi_width
/ 8;
161 size
[1] = cur_info
.video_mode_info
.vi_height
/
162 cur_info
.console_info
.font_size
;
163 size
[2] = cur_info
.console_info
.font_size
;
165 ioctl(0, KDRASTER
, size
);
171 * Print a short usage string describing all options, then exit.
178 "usage: vidcontrol [-CdLPpx] [-b color] [-c appearance]"
179 " [-f [size] file]\n"
180 " [-g geometry] [-h size] [-i adapter | mode]"
182 " [-M char] [-m on | off] [-r foreground"
184 " [-S on | off] [-s number] [-t N | off]"
186 " [foreground [background]] [show]\n");
193 * Retrieve the next argument from the command line (for options that require
194 * more than one argument).
198 nextarg(int ac
, char **av
, int *indp
, int oc
, int strict
)
201 return(av
[(*indp
)++]);
205 errx(1, "option requires two arguments -- %c", oc
);
213 * Guess which file to open. Try to open each combination of a specified set
214 * of file name components.
218 openguess(const char *a
[], const char *b
[], const char *c
[], const char *d
[], char **name
)
223 for (i
= 0; a
[i
] != NULL
; i
++) {
224 for (j
= 0; b
[j
] != NULL
; j
++) {
225 for (k
= 0; c
[k
] != NULL
; k
++) {
226 for (l
= 0; d
[l
] != NULL
; l
++) {
227 asprintf(name
, "%s%s%s%s",
228 a
[i
], b
[j
], c
[k
], d
[l
]);
230 f
= fopen(*name
, "r");
246 * Load a screenmap from a file and set it.
250 load_scrnmap(char *filename
)
256 const char *a
[] = {"", SCRNMAP_PATH
, NULL
};
257 const char *b
[] = {filename
, NULL
};
258 const char *c
[] = {"", ".scm", NULL
};
259 const char *d
[] = {"", NULL
};
261 fd
= openguess(a
, b
, c
, d
, &name
);
265 errx(1, "screenmap file not found");
268 size
= sizeof(scrnmap
);
270 if (decode(fd
, (char *)&scrnmap
, size
) != size
) {
273 if (fread(&scrnmap
, 1, size
, fd
) != (size_t)size
) {
276 errx(1, "bad screenmap file");
280 if (ioctl(0, PIO_SCRNMAP
, &scrnmap
) == -1) {
282 errc(1, errno
, "loading screenmap");
290 * Set the default screenmap.
294 load_default_scrnmap(void)
299 for (i
= 0; i
< 256; i
++)
300 *((char*)&scrnmap
+ i
) = i
;
302 if (ioctl(0, PIO_SCRNMAP
, &scrnmap
) == -1) {
304 errc(1, errno
, "loading default screenmap");
310 * Print the current screenmap to stdout.
316 unsigned char map
[256];
319 if (ioctl(0, GIO_SCRNMAP
, &map
) == -1) {
321 errc(1, errno
, "getting screenmap");
324 for (i
=0; i
<sizeof(map
); i
++) {
325 if (i
> 0 && i
% 16 == 0)
326 fprintf(stdout
, "\n");
329 fprintf(stdout
, " %02x", map
[i
]);
331 fprintf(stdout
, " %03d", map
[i
]);
334 fprintf(stdout
, "\n");
339 * Determine a file's size.
347 if (fstat(fileno(file
), &sb
) == 0)
355 * Load a font from file and set it.
359 load_font(char *type
, char *filename
)
363 unsigned long io
= 0; /* silence stupid gcc(1) in the Wall mode */
364 char *name
, *fontmap
, size_sufx
[6];
365 const char *a
[] = {"", FONT_PATH
, NULL
};
366 const char *b
[] = {filename
, NULL
};
367 const char *c
[] = {"", size_sufx
, NULL
};
368 const char *d
[] = {"", ".fnt", NULL
};
375 } sizes
[] = {{8, 16, PIO_FONT8x16
},
376 {8, 14, PIO_FONT8x14
},
380 vinfo
.size
= sizeof(vinfo
);
382 if (ioctl(0, CONS_GETINFO
, &vinfo
) == -1) {
384 errc(1, errno
, "obtaining current video mode parameters");
387 snprintf(size_sufx
, sizeof(size_sufx
), "-8x%d", vinfo
.font_size
);
389 fd
= openguess(a
, b
, c
, d
, &name
);
393 errx(1, "%s: can't load font file", filename
);
398 if (sscanf(type
, "%dx%d", &w
, &h
) == 2) {
399 for (i
= 0; sizes
[i
].w
!= 0; i
++) {
400 if (sizes
[i
].w
== w
&& sizes
[i
].h
== h
) {
401 size
= DATASIZE(sizes
[i
]);
403 font_height
= sizes
[i
].h
;
410 errx(1, "%s: bad font size specification", type
);
413 /* Apply heuristics */
418 size
= DATASIZE(sizes
[0]);
419 fontmap
= (char*) malloc(size
);
420 dsize
[0] = decode(fd
, fontmap
, size
);
421 dsize
[1] = fsize(fd
);
425 for (j
= 0; j
< 2; j
++) {
426 for (i
= 0; sizes
[i
].w
!= 0; i
++) {
427 if (DATASIZE(sizes
[i
]) == dsize
[j
]) {
430 font_height
= sizes
[i
].h
;
440 errx(1, "%s: can't guess font size", filename
);
446 fontmap
= (char*) malloc(size
);
448 if (decode(fd
, fontmap
, size
) != size
) {
450 if (fsize(fd
) != size
||
451 fread(fontmap
, 1, size
, fd
) != (size_t)size
) {
455 errx(1, "%s: bad font file", filename
);
459 if (ioctl(0, io
, fontmap
) == -1) {
461 errc(1, errno
, "loading font");
470 * Set the timeout for the screensaver.
474 set_screensaver_timeout(char *arg
)
478 if (!strcmp(arg
, "off")) {
483 if ((*arg
== '\0') || (nsec
< 1)) {
485 errx(1, "argument must be a positive number");
489 if (ioctl(0, CONS_BLANKTIME
, &nsec
) == -1) {
491 errc(1, errno
, "setting screensaver period");
497 * Set the cursor's shape/type.
501 set_cursor_type(char *appearance
)
505 if (!strcmp(appearance
, "normal"))
507 else if (!strcmp(appearance
, "blink"))
509 else if (!strcmp(appearance
, "destructive"))
513 errx(1, "argument to -c must be normal, blink or destructive");
516 if (ioctl(0, CONS_CURSORTYPE
, &type
) == -1) {
518 errc(1, errno
, "setting cursor type");
524 * Set the video mode.
528 video_mode(int argc
, char **argv
, int *mode_index
)
533 unsigned long mode_num
;
534 } modes
[] = {{ "80x25", SW_VGA_C80x25
, M_VGA_C80x25
},
535 { "80x30", SW_VGA_C80x30
, M_VGA_C80x30
},
536 { "80x43", SW_ENH_C80x43
, M_ENH_C80x43
},
537 { "80x50", SW_VGA_C80x50
, M_VGA_C80x50
},
538 { "80x60", SW_VGA_C80x60
, M_VGA_C80x60
},
539 { "132x25", SW_VESA_C132x25
, M_VESA_C132x25
},
540 { "132x43", SW_VESA_C132x43
, M_VESA_C132x43
},
541 { "132x50", SW_VESA_C132x50
, M_VESA_C132x50
},
542 { "132x60", SW_VESA_C132x60
, M_VESA_C132x60
},
543 { "VGA_40x25", SW_VGA_C40x25
, M_VGA_C40x25
},
544 { "VGA_80x25", SW_VGA_C80x25
, M_VGA_C80x25
},
545 { "VGA_80x30", SW_VGA_C80x30
, M_VGA_C80x30
},
546 { "VGA_80x50", SW_VGA_C80x50
, M_VGA_C80x50
},
547 { "VGA_80x60", SW_VGA_C80x60
, M_VGA_C80x60
},
549 { "VGA_90x25", SW_VGA_C90x25
, M_VGA_C90x25
},
550 { "VGA_90x30", SW_VGA_C90x30
, M_VGA_C90x30
},
551 { "VGA_90x43", SW_VGA_C90x43
, M_VGA_C90x43
},
552 { "VGA_90x50", SW_VGA_C90x50
, M_VGA_C90x50
},
553 { "VGA_90x60", SW_VGA_C90x60
, M_VGA_C90x60
},
555 { "VGA_320x200", SW_VGA_CG320
, M_CG320
},
556 { "EGA_80x25", SW_ENH_C80x25
, M_ENH_C80x25
},
557 { "EGA_80x43", SW_ENH_C80x43
, M_ENH_C80x43
},
558 { "VESA_132x25", SW_VESA_C132x25
, M_VESA_C132x25
},
559 { "VESA_132x43", SW_VESA_C132x43
, M_VESA_C132x43
},
560 { "VESA_132x50", SW_VESA_C132x50
, M_VESA_C132x50
},
561 { "VESA_132x60", SW_VESA_C132x60
, M_VESA_C132x60
},
562 { "VESA_800x600", SW_VESA_800x600
, M_VESA_800x600
},
563 { NULL
, NULL
, NULL
},
566 int new_mode_num
= 0;
567 unsigned long mode
= 0;
572 * Parse the video mode argument...
575 if (*mode_index
< argc
) {
576 if (!strncmp(argv
[*mode_index
], "MODE_", 5)) {
577 if (!isdigit(argv
[*mode_index
][5]))
578 errx(1, "invalid video mode number");
580 new_mode_num
= atoi(&argv
[*mode_index
][5]);
582 for (i
= 0; modes
[i
].name
!= NULL
; ++i
) {
583 if (!strcmp(argv
[*mode_index
], modes
[i
].name
)) {
584 mode
= modes
[i
].mode
;
585 new_mode_num
= modes
[i
].mode_num
;
590 if (modes
[i
].name
== NULL
)
591 errx(1, "invalid video mode name");
595 * Collect enough information about the new video mode...
598 new_mode_info
.vi_mode
= new_mode_num
;
600 if (ioctl(0, CONS_MODEINFO
, &new_mode_info
) == -1) {
602 errc(1, errno
, "obtaining new video mode parameters");
606 if (new_mode_num
>= M_VESA_BASE
)
607 mode
= _IO('V', new_mode_num
- M_VESA_BASE
);
609 mode
= _IO('S', new_mode_num
);
613 * Try setting the new mode.
616 if (ioctl(0, mode
, NULL
) == -1) {
618 errc(1, errno
, "setting video mode");
622 * For raster modes it's not enough to just set the mode.
623 * We also need to explicitly set the raster mode.
626 if (new_mode_info
.vi_flags
& V_INFO_GRAPHICS
) {
629 if (font_height
== 0)
630 font_height
= cur_info
.console_info
.font_size
;
632 size
[2] = font_height
;
636 if ((vesa_cols
* 8 > new_mode_info
.vi_width
) ||
638 size
[0] = new_mode_info
.vi_width
/ 8;
645 if ((vesa_rows
* font_height
> new_mode_info
.vi_height
) ||
647 size
[1] = new_mode_info
.vi_height
/
653 /* set raster mode */
655 if (ioctl(0, KDRASTER
, size
)) {
657 errc(1, errno
, "activating raster display");
661 video_mode_changed
= 1;
669 * Return the number for a specified color name.
673 get_color_number(char *color
)
677 for (i
=0; i
<16; i
++) {
678 if (!strcmp(color
, legal_colors
[i
]))
686 * Get normal text and background colors.
690 get_normal_colors(int argc
, char **argv
, int *color_index
)
694 if (*color_index
< argc
&&
695 (color
= get_color_number(argv
[*color_index
])) != -1) {
697 normal_fore_color
= color
;
700 if (*color_index
< argc
&&
701 (color
= get_color_number(argv
[*color_index
])) != -1) {
703 normal_back_color
= color
;
710 * Get reverse text and background colors.
714 get_reverse_colors(int argc
, char **argv
, int *color_index
)
718 if ((color
= get_color_number(argv
[*(color_index
)-1])) != -1) {
719 revers_fore_color
= color
;
722 if (*color_index
< argc
&&
723 (color
= get_color_number(argv
[*color_index
])) != -1) {
725 revers_back_color
= color
;
732 * Set normal and reverse foreground and background colors.
738 fprintf(stderr
, "\e[=%dF", normal_fore_color
);
739 fprintf(stderr
, "\e[=%dG", normal_back_color
);
740 fprintf(stderr
, "\e[=%dH", revers_fore_color
);
741 fprintf(stderr
, "\e[=%dI", revers_back_color
);
746 * Switch to virtual terminal #arg.
750 set_console(char *arg
)
754 if(!arg
|| strspn(arg
,"0123456789") != strlen(arg
)) {
756 errx(1, "bad console number");
761 if (n
< 1 || n
> 16) {
763 errx(1, "console number out of range");
764 } else if (ioctl(0, VT_ACTIVATE
, (caddr_t
) (long) n
) == -1) {
766 errc(1, errno
, "switching vty");
772 * Sets the border color.
776 set_border_color(char *arg
)
780 if ((color
= get_color_number(arg
)) != -1)
781 fprintf(stderr
, "\e[=%dA", color
);
788 set_mouse_char(char *arg
)
790 struct mouse_info mouse
;
793 l
= strtol(arg
, NULL
, 0);
795 if ((l
< 0) || (l
> UCHAR_MAX
)) {
797 errx(1, "argument to -M must be 0 through %d", UCHAR_MAX
);
800 mouse
.operation
= MOUSE_MOUSECHAR
;
801 mouse
.u
.mouse_char
= (int)l
;
803 if (ioctl(0, CONS_MOUSECTL
, &mouse
) == -1) {
805 errc(1, errno
, "setting mouse character");
811 * Show/hide the mouse.
817 struct mouse_info mouse
;
819 if (!strcmp(arg
, "on")) {
820 mouse
.operation
= MOUSE_SHOW
;
821 } else if (!strcmp(arg
, "off")) {
822 mouse
.operation
= MOUSE_HIDE
;
825 errx(1, "argument to -m must be either on or off");
828 if (ioctl(0, CONS_MOUSECTL
, &mouse
) == -1) {
830 errc(1, errno
, "%sing the mouse",
831 mouse
.operation
== MOUSE_SHOW
? "show" : "hid");
837 set_lockswitch(char *arg
)
841 if (!strcmp(arg
, "off")) {
843 } else if (!strcmp(arg
, "on")) {
847 errx(1, "argument to -S must be either on or off");
850 if (ioctl(0, VT_LOCKSWITCH
, &data
) == -1) {
852 errc(1, errno
, "turning %s vty switching",
853 data
== 0x01 ? "off" : "on");
859 * Return the adapter name for a specified type.
863 adapter_name(int type
)
868 } names
[] = {{ KD_MONO
, "MDA" },
869 { KD_HERCULES
, "Hercules" },
879 for (i
= 0; names
[i
].type
!= -1; ++i
) {
880 if (names
[i
].type
== type
)
884 return names
[i
].name
;
889 * Show graphics adapter information.
893 show_adapter_info(void)
895 struct video_adapter_info ad
;
899 if (ioctl(0, CONS_ADPINFO
, &ad
) == -1) {
901 errc(1, errno
, "obtaining adapter information");
904 printf("fb%d:\n", ad
.va_index
);
905 printf(" %.*s%d, type:%s%s (%d), flags:0x%x\n",
906 (int)sizeof(ad
.va_name
), ad
.va_name
, ad
.va_unit
,
907 (ad
.va_flags
& V_ADP_VESA
) ? "VESA " : "",
908 adapter_name(ad
.va_type
), ad
.va_type
, ad
.va_flags
);
909 printf(" initial mode:%d, current mode:%d, BIOS mode:%d\n",
910 ad
.va_initial_mode
, ad
.va_mode
, ad
.va_initial_bios_mode
);
911 printf(" frame buffer window:0x%x, buffer size:0x%x\n",
912 ad
.va_window
, ad
.va_buffer_size
);
913 printf(" window size:0x%x, origin:0x%x\n",
914 ad
.va_window_size
, ad
.va_window_orig
);
915 printf(" display start address (%d, %d), scan line width:%d\n",
916 ad
.va_disp_start
.x
, ad
.va_disp_start
.y
, ad
.va_line_width
);
917 printf(" reserved:0x%x\n", ad
.va_unused0
);
922 * Show video mode information.
928 struct video_info vinfo
;
933 printf(" mode# flags type size "
934 "font window linear buffer\n");
935 printf("---------------------------------------"
936 "---------------------------------------\n");
938 for (mode
= 0; mode
< M_VESA_MODE_MAX
; ++mode
) {
939 vinfo
.vi_mode
= mode
;
941 if (ioctl(0, CONS_MODEINFO
, &vinfo
))
943 if (vinfo
.vi_mode
!= mode
)
946 printf("%3d (0x%03x)", mode
, mode
);
947 printf(" 0x%08x", vinfo
.vi_flags
);
949 if (vinfo
.vi_flags
& V_INFO_GRAPHICS
) {
952 snprintf(buf
, sizeof(buf
), "%dx%dx%d %d",
953 vinfo
.vi_width
, vinfo
.vi_height
,
954 vinfo
.vi_depth
, vinfo
.vi_planes
);
958 snprintf(buf
, sizeof(buf
), "%dx%d",
959 vinfo
.vi_width
, vinfo
.vi_height
);
962 printf(" %c %-15s", c
, buf
);
963 snprintf(buf
, sizeof(buf
), "%dx%d",
964 vinfo
.vi_cwidth
, vinfo
.vi_cheight
);
965 printf(" %-5s", buf
);
966 printf(" 0x%05x %2dk %2dk",
967 vinfo
.vi_window
, (int)vinfo
.vi_window_size
/ 1024,
968 (int)vinfo
.vi_window_gran
/1024);
969 printf(" 0x%08x %dk\n",
970 vinfo
.vi_buffer
, (int)vinfo
.vi_buffer_size
/ 1024);
978 if (!strcmp(arg
, "adapter")) {
980 } else if (!strcmp(arg
, "mode")) {
984 errx(1, "argument to -i must be either adapter or mode");
994 fprintf(stdout
, "\e[=0G\n\n");
996 for (i
= 0; i
< 8; i
++) {
997 fprintf(stdout
, "\e[=15F\e[=0G %2d \e[=%dF%-16s"
998 "\e[=15F\e[=0G %2d \e[=%dF%-16s "
999 "\e[=15F %2d \e[=%dGBACKGROUND\e[=0G\n",
1000 i
, i
, legal_colors
[i
], i
+8, i
+8,
1001 legal_colors
[i
+8], i
, i
);
1004 fprintf(stdout
, "\e[=%dF\e[=%dG\e[=%dH\e[=%dI\n",
1005 info
.mv_norm
.fore
, info
.mv_norm
.back
,
1006 info
.mv_rev
.fore
, info
.mv_rev
.back
);
1011 * Snapshot the video memory of that terminal, using the CONS_SCRSHOT
1012 * ioctl, and writes the results to stdout either in the special
1013 * binary format (see manual page for details), or in the plain
1018 dump_screen(int mode
)
1023 vinfo
.size
= sizeof(vinfo
);
1025 if (ioctl(0, CONS_GETINFO
, &vinfo
) == -1) {
1027 errc(1, errno
, "obtaining current video mode parameters");
1030 shot
.buf
= alloca(vinfo
.mv_csz
* vinfo
.mv_rsz
* sizeof(u_int16_t
));
1032 if (shot
.buf
== NULL
) {
1034 errx(1, "failed to allocate memory for dump");
1037 shot
.xsize
= vinfo
.mv_csz
;
1038 shot
.ysize
= vinfo
.mv_rsz
;
1040 if (ioctl(0, CONS_SCRSHOT
, &shot
) == -1) {
1042 errc(1, errno
, "dumping screen");
1045 if (mode
== DUMP_RAW
) {
1046 printf("SCRSHOT_%c%c%c%c", DUMP_FMT_REV
, 2,
1047 shot
.xsize
, shot
.ysize
);
1051 write(STDOUT_FILENO
, shot
.buf
,
1052 shot
.xsize
* shot
.ysize
* sizeof(u_int16_t
));
1058 line
= alloca(shot
.xsize
+ 1);
1062 errx(1, "failed to allocate memory for line buffer");
1065 for (y
= 0; y
< shot
.ysize
; y
++) {
1066 for (x
= 0; x
< shot
.xsize
; x
++) {
1067 ch
= shot
.buf
[x
+ (y
* shot
.xsize
)];
1070 if (isprint(ch
) == 0)
1076 /* Trim trailing spaces */
1080 } while (line
[x
] == ' ' && x
!= 0);
1091 * Set the console history buffer size.
1095 set_history(char *opt
)
1101 if ((*opt
== '\0') || size
< 0) {
1103 errx(1, "argument must be a positive number");
1106 if (ioctl(0, CONS_HISTORY
, &size
) == -1) {
1108 errc(1, errno
, "setting history buffer size");
1114 * Clear the console history buffer.
1120 if (ioctl(0, CONS_CLRHIST
) == -1) {
1122 errc(1, errno
, "clearing history buffer");
1128 main(int argc
, char **argv
)
1138 info
.size
= sizeof(info
);
1140 if (ioctl(0, CONS_GETINFO
, &info
) == -1)
1141 err(1, "must be on a virtual console");
1143 while((opt
= getopt(argc
, argv
, "b:Cc:df:g:h:i:l:LM:m:pPr:S:s:t:x")) != -1) {
1146 set_border_color(optarg
);
1152 set_cursor_type(optarg
);
1159 font
= nextarg(argc
, argv
, &optind
, 'f', 0);
1166 load_font(type
, font
);
1169 if (sscanf(optarg
, "%dx%d",
1170 &vesa_cols
, &vesa_rows
) != 2) {
1172 warnx("incorrect geometry: %s", optarg
);
1177 set_history(optarg
);
1183 load_scrnmap(optarg
);
1186 load_default_scrnmap();
1189 set_mouse_char(optarg
);
1195 dump_screen(DUMP_RAW
);
1198 dump_screen(DUMP_TXT
);
1201 get_reverse_colors(argc
, argv
, &optind
);
1204 set_lockswitch(optarg
);
1207 set_console(optarg
);
1210 set_screensaver_timeout(optarg
);
1220 if (optind
< argc
&& !strcmp(argv
[optind
], "show")) {
1225 video_mode(argc
, argv
, &optind
);
1227 get_normal_colors(argc
, argv
, &optind
);
1229 if (colors_changed
|| video_mode_changed
) {
1230 if (!(new_mode_info
.vi_flags
& V_INFO_GRAPHICS
)) {
1231 if ((normal_back_color
< 8) && (revers_back_color
< 8)) {
1235 errx(1, "bg color for text modes must be < 8");
1242 if ((optind
!= argc
) || (argc
== 1))