Move scrshot(1) functionality into vidcontrol(1).
Suggested by: many Not objected to by: nik (scrshot co-author)
This commit is contained in:
parent
aa3a855755
commit
d02ca551d3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=76845
@ -224,7 +224,6 @@ SUBDIR+=ar \
|
||||
nm \
|
||||
ranlib \
|
||||
sasc \
|
||||
scrshot \
|
||||
size \
|
||||
strings \
|
||||
strip
|
||||
|
@ -1,5 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= scrshot
|
||||
|
||||
.include <bsd.prog.mk>
|
@ -1,162 +0,0 @@
|
||||
.\" Copyright (c) 2001 Nik Clayton
|
||||
.\" All rights reserved
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd May 17, 2001
|
||||
.Dt SCRSHOT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm scrshot
|
||||
.Nd capture the contents of a syscons terminal
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ar device
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility uses the
|
||||
.Xr syscons 4
|
||||
.Dv CONS_SCRSHOT
|
||||
.Xr ioctl 2
|
||||
to capture the current contents of the video buffer corresponding to the
|
||||
terminal device given as the first argument.
|
||||
.Nm
|
||||
writes version and additional information to the standard output, followed by
|
||||
the contents of the terminal device.
|
||||
.Sh IMPLEMENTATION NOTES
|
||||
PC video memory is typically arranged in two byte tuples, one per character
|
||||
position.
|
||||
In each tuple, the first byte will be the character code, and the
|
||||
second byte is the character's color attribute.
|
||||
.Pp
|
||||
The color attribute byte is further broken down in to the low nibble, which
|
||||
specifies which of 16 different foreground colors is active, and the high
|
||||
nibble, which specifies which of 16 different background colors is active.
|
||||
.Pp
|
||||
.Bl -hang -offset indent -compact
|
||||
.It 0
|
||||
Black
|
||||
.It 1
|
||||
Blue
|
||||
.It 2
|
||||
Green
|
||||
.It 3
|
||||
Cyan
|
||||
.It 4
|
||||
Red
|
||||
.It 5
|
||||
Magenta
|
||||
.It 6
|
||||
Brown
|
||||
.It 7
|
||||
White
|
||||
.It 8
|
||||
Grey
|
||||
.It 9
|
||||
Light Blue
|
||||
.It 10
|
||||
Light Green
|
||||
.It 11
|
||||
Light Cyan
|
||||
.It 12
|
||||
Light Red
|
||||
.It 13
|
||||
Light Magenta
|
||||
.It 14
|
||||
Yellow
|
||||
.It 15
|
||||
White
|
||||
.El
|
||||
.Pp
|
||||
It can be seen that the last 8 colors are brighter versions of the first 8.
|
||||
.Pp
|
||||
For example, the two bytes
|
||||
.Pp
|
||||
.Dl "65 158"
|
||||
.Pp
|
||||
specify an uppercase A (character code 65), in yellow (low nibble 15) on a
|
||||
light blue background (high nibble 9).
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
output contains a small header which includes additional information which may
|
||||
be useful to utilities processing the output.
|
||||
.Pp
|
||||
The first 10 bytes are always arranged as follows:
|
||||
.Bl -column "Byte range" "Contents" -offset indent
|
||||
.It Sy "Byte Range Contents"
|
||||
.It "1 thru 8 Literal text" Dq Li SCRSHOT_
|
||||
.It "9 File format version number"
|
||||
.It "10 Remaining number of bytes in the header"
|
||||
.El
|
||||
.Pp
|
||||
Subsequent bytes depend on the version number.
|
||||
.Bl -column "Version" "13 and up" -offset indent
|
||||
.It Sy "Version Byte Meaning"
|
||||
.It "1 11 Terminal width, in characters"
|
||||
.It " 12 Terminal depth, in characters"
|
||||
.It " 13 and up The snapshot data"
|
||||
.El
|
||||
.Pp
|
||||
So a dump of an 80x25 screen would start (in hex)
|
||||
.Bd -literal -offset indent
|
||||
53 43 52 53 48 4f 54 5f 01 02 50 19
|
||||
----------------------- -- -- -- --
|
||||
| | | | ` 25 decimal
|
||||
| | | `--- 80 decimal
|
||||
| | `------ 2 remaining bytes of header data
|
||||
| `--------- File format version 1
|
||||
`------------------------ Literal "SCRSHOT_"
|
||||
.Ed
|
||||
.Sh EXAMPLES
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "scrshot /dev/ttyv0 > shot.scr"
|
||||
.Pp
|
||||
will capture the contents of the first virtual terminal, and redirect the
|
||||
output to the
|
||||
.Pa shot.scr
|
||||
file.
|
||||
.Sh DIAGNOSTICS
|
||||
The
|
||||
.Nm
|
||||
utility exits 0 on success or >0 if an error occurred.
|
||||
.Sh SEE ALSO
|
||||
.Xr syscons 4 ,
|
||||
.Xr ascii 7 ,
|
||||
.Xr watch 8
|
||||
.Pp
|
||||
The various
|
||||
.Li shot2*
|
||||
utilities in the
|
||||
.Li textproc
|
||||
category of the ports collection.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
utility first appeared in
|
||||
.Fx 4.4 .
|
||||
.Sh AUTHORS
|
||||
.An Joel Holveck Aq joelh@gnu.org
|
||||
.An Nik Clayton Aq nik@FreeBSD.org
|
@ -1,81 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2001 Joel Holveck and Nik Clayton
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer,
|
||||
* without modification, immediately at the beginning of the file.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/consio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define VERSION 1 /* File format version */
|
||||
|
||||
/*
|
||||
* Given the path to a syscons terminal (e.g., "/dev/ttyv0"), tries to
|
||||
* snapshot the video memory of that terminal, using the CONS_SCRSHOT
|
||||
* ioctl, and writes the results to stdout.
|
||||
*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
scrshot_t shot;
|
||||
vid_info_t info;
|
||||
|
||||
if (argc != 2)
|
||||
errx(1, "improper # of args");
|
||||
|
||||
fd = open(argv[1], O_RDWR);
|
||||
if (fd < 0)
|
||||
err(1, "%s", argv[1]);
|
||||
|
||||
info.size = sizeof(info);
|
||||
if (ioctl(fd, CONS_GETINFO, &info) == -1)
|
||||
err(1, "ioctl(CONS_GETINFO)");
|
||||
|
||||
shot.buf = malloc(info.mv_csz * info.mv_rsz * sizeof(u_int16_t));
|
||||
if (shot.buf == NULL)
|
||||
err(1, "couldn't allocate shot space");
|
||||
|
||||
shot.xsize = info.mv_csz;
|
||||
shot.ysize = info.mv_rsz;
|
||||
if (ioctl(fd, CONS_SCRSHOT, &shot) == -1)
|
||||
err(1, "ioctl(CONS_SCRSHOT)");
|
||||
|
||||
printf("SCRSHOT_%c%c%c%c", VERSION, 2, shot.xsize, shot.ysize);
|
||||
fflush(stdout);
|
||||
|
||||
(void)write(STDOUT_FILENO, shot.buf,
|
||||
shot.xsize * shot.ysize * sizeof(u_int16_t));
|
||||
|
||||
exit(0);
|
||||
}
|
@ -36,6 +36,8 @@
|
||||
.Op Fl M Ar char
|
||||
.Op Fl m Cm on | off
|
||||
.Op Fl r Ar foreground Ar background
|
||||
.Op Fl p
|
||||
.Op Fl P
|
||||
.Op Fl s Ar number
|
||||
.Op Fl t Ar N | Cm off
|
||||
.Op Fl x
|
||||
@ -185,6 +187,21 @@ or
|
||||
Used together with the
|
||||
.Xr moused 8
|
||||
daemon for text mode cut & paste functionality.
|
||||
.It Fl p
|
||||
Capture the current contents of the video buffer corresponding
|
||||
to the terminal device referred to by standard input.
|
||||
.Nm
|
||||
writes contents of the video buffer to the standard
|
||||
output in a raw binary format. For details about that
|
||||
format see
|
||||
.Sx Format of Video Buffer Dump
|
||||
below.
|
||||
.It Fl P
|
||||
Same as
|
||||
.Fl p ,
|
||||
but dump contents of the video buffer in a plain text format
|
||||
ignoring nonprintable characters and information about text
|
||||
attributes.
|
||||
.It Fl r Ar foreground background
|
||||
Change reverse mode colors to
|
||||
.Ar foreground
|
||||
@ -253,6 +270,106 @@ you need to recompile your kernel with the
|
||||
option. See
|
||||
.Xr syscons 4
|
||||
for more details on this kernel option.
|
||||
.Ss Format of Video Buffer Dump
|
||||
The
|
||||
.Nm
|
||||
utility uses the
|
||||
.Xr syscons 4
|
||||
.Dv CONS_SCRSHOT
|
||||
.Xr ioctl 2
|
||||
to capture the current contents of the video buffer.
|
||||
.Nm
|
||||
writes version and additional information to the standard
|
||||
output, followed by the contents of the terminal device.
|
||||
.Pp
|
||||
PC video memory is typically arranged in two byte tuples,
|
||||
one per character position. In each tuple, the first byte
|
||||
will be the character code, and the second byte is the
|
||||
character's color attribute.
|
||||
.Pp
|
||||
The color attribute byte is further broken down in to the
|
||||
low nibble, which specifies which of 16 different foreground
|
||||
colors is active, and the high nibble, which specifies which
|
||||
of 16 different background colors is active.
|
||||
.Pp
|
||||
.Bl -hang -offset indent -compact
|
||||
.It 0
|
||||
Black
|
||||
.It 1
|
||||
Blue
|
||||
.It 2
|
||||
Green
|
||||
.It 3
|
||||
Cyan
|
||||
.It 4
|
||||
Red
|
||||
.It 5
|
||||
Magenta
|
||||
.It 6
|
||||
Brown
|
||||
.It 7
|
||||
White
|
||||
.It 8
|
||||
Grey
|
||||
.It 9
|
||||
Light Blue
|
||||
.It 10
|
||||
Light Green
|
||||
.It 11
|
||||
Light Cyan
|
||||
.It 12
|
||||
Light Red
|
||||
.It 13
|
||||
Light Magenta
|
||||
.It 14
|
||||
Yellow
|
||||
.It 15
|
||||
White
|
||||
.El
|
||||
.Pp
|
||||
It can be seen that the last 8 colors are brighter
|
||||
versions of the first 8.
|
||||
.Pp
|
||||
For example, the two bytes
|
||||
.Pp
|
||||
.Dl "65 158"
|
||||
.Pp
|
||||
specify an uppercase A (character code 65), in
|
||||
yellow (low nibble 15) on a light blue background
|
||||
(high nibble 9).
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
output contains a small header which includes additional
|
||||
information which may be useful to utilities processing
|
||||
the output.
|
||||
.Pp
|
||||
The first 10 bytes are always arranged as follows:
|
||||
.Bl -column "Byte range" "Contents" -offset indent
|
||||
.It Sy "Byte Range Contents"
|
||||
.It "1 thru 8 Literal text" Dq Li SCRSHOT_
|
||||
.It "9 File format version number"
|
||||
.It "10 Remaining number of bytes in the header"
|
||||
.El
|
||||
.Pp
|
||||
Subsequent bytes depend on the version number.
|
||||
.Bl -column "Version" "13 and up" -offset indent
|
||||
.It Sy "Version Byte Meaning"
|
||||
.It "1 11 Terminal width, in characters"
|
||||
.It " 12 Terminal depth, in characters"
|
||||
.It " 13 and up The snapshot data"
|
||||
.El
|
||||
.Pp
|
||||
So a dump of an 80x25 screen would start (in hex)
|
||||
.Bd -literal -offset indent
|
||||
53 43 52 53 48 4f 54 5f 01 02 50 19
|
||||
----------------------- -- -- -- --
|
||||
| | | | ` 25 decimal
|
||||
| | | `--- 80 decimal
|
||||
| | `------ 2 remaining bytes of header data
|
||||
| `--------- File format version 1
|
||||
`------------------------ Literal "SCRSHOT_"
|
||||
.Ed
|
||||
.Sh VIDEO OUTPUT CONFIGURATION
|
||||
.Ss Boot Time Configuration
|
||||
You may set the following variables in
|
||||
@ -329,6 +446,18 @@ The following command will set-up a 100x37 raster text mode (useful for
|
||||
some LCD models):
|
||||
.Pp
|
||||
.Dl vidcontrol -g 100x37 VESA_800x600
|
||||
.Pp
|
||||
The following command will capture the contents of the first virtual
|
||||
terminal, and redirect the output to the
|
||||
.Pa shot.scr
|
||||
file:
|
||||
.Pp
|
||||
.Dl vidcontrol -p < /dev/ttyv0 > shot.scr
|
||||
.Pp
|
||||
The following command will dump contents of the forth virtual terminal
|
||||
to the standard output in the human readable format:
|
||||
.Pp
|
||||
.Dl vidcontrol -P < /dev/ttyv3
|
||||
.Sh SEE ALSO
|
||||
.Xr kbdcontrol 1 ,
|
||||
.Xr vidfont 1 ,
|
||||
@ -339,5 +468,13 @@ some LCD models):
|
||||
.Xr rc.conf 5 ,
|
||||
.Xr kldload 8 ,
|
||||
.Xr moused 8
|
||||
.Xr watch 8
|
||||
.Pp
|
||||
The various
|
||||
.Li shot2*
|
||||
utilities in the
|
||||
.Li textproc
|
||||
category of the
|
||||
.Em "Ports Collection" .
|
||||
.Sh AUTHORS
|
||||
.An S\(/oren Schmidt Aq sos@FreeBSD.org
|
||||
|
@ -50,6 +50,11 @@ static const char rcsid[] =
|
||||
#define _VESA_800x600_DFL_ROWS 25
|
||||
#define _VESA_800x600_DFL_FNSZ 16
|
||||
|
||||
#define DUMP_RAW 0
|
||||
#define DUMP_TXT 1
|
||||
|
||||
#define DUMP_FMT_REV 1
|
||||
|
||||
char legal_colors[16][16] = {
|
||||
"black", "blue", "green", "cyan",
|
||||
"red", "magenta", "brown", "white",
|
||||
@ -70,8 +75,8 @@ usage()
|
||||
fprintf(stderr, "%s\n%s\n%s\n%s\n",
|
||||
"usage: vidcontrol [-r fg bg] [-b color] [-c appearance] [-d] [-l scrmap]",
|
||||
" [-i adapter | mode] [-L] [-M char] [-m on|off]",
|
||||
" [-f size file] [-s number] [-t N|off] [-x] [-g geometry]",
|
||||
" [mode] [fgcol [bgcol]] [show]");
|
||||
" [-f size file] [-s number] [-t N|off] [-x] [-g geometry]",
|
||||
" [-p] [-P] [mode] [fgcol [bgcol]] [show]");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -638,6 +643,77 @@ test_frame()
|
||||
info.mv_rev.fore, info.mv_rev.back);
|
||||
}
|
||||
|
||||
/*
|
||||
* Snapshot the video memory of that terminal, using the CONS_SCRSHOT
|
||||
* ioctl, and writes the results to stdout either in the special
|
||||
* binary format (see manual page for details), or in the plain
|
||||
* text format.
|
||||
*/
|
||||
void
|
||||
dump_screen(int mode)
|
||||
{
|
||||
scrshot_t shot;
|
||||
vid_info_t info;
|
||||
|
||||
info.size = sizeof(info);
|
||||
if (ioctl(0, CONS_GETINFO, &info) == -1) {
|
||||
warn("failed to obtain current video mode parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
shot.buf = alloca(info.mv_csz * info.mv_rsz * sizeof(u_int16_t));
|
||||
if (shot.buf == NULL) {
|
||||
warn("failed to allocate memory for dump");
|
||||
return;
|
||||
}
|
||||
|
||||
shot.xsize = info.mv_csz;
|
||||
shot.ysize = info.mv_rsz;
|
||||
if (ioctl(0, CONS_SCRSHOT, &shot) == -1) {
|
||||
warn("failed to get dump of the screen");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == DUMP_RAW) {
|
||||
printf("SCRSHOT_%c%c%c%c", DUMP_FMT_REV, 2,
|
||||
shot.xsize, shot.ysize);
|
||||
fflush(stdout);
|
||||
|
||||
(void)write(STDOUT_FILENO, shot.buf,
|
||||
shot.xsize * shot.ysize * sizeof(u_int16_t));
|
||||
} else {
|
||||
char *line;
|
||||
int x, y;
|
||||
u_int16_t ch;
|
||||
|
||||
line = alloca(shot.xsize + 1);
|
||||
if (line == NULL) {
|
||||
warn("failed to allocate memory for line buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < shot.ysize; y++) {
|
||||
for (x = 0; x < shot.xsize; x++) {
|
||||
ch = shot.buf[x + (y * shot.xsize)];
|
||||
ch &= 0xff;
|
||||
if (isprint(ch) == 0)
|
||||
ch = ' ';
|
||||
line[x] = (char)ch;
|
||||
}
|
||||
|
||||
/* Trim trailing spaces */
|
||||
do {
|
||||
line[x--] = '\0';
|
||||
} while (line[x] == ' ' && x != 0);
|
||||
|
||||
puts(line);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -648,7 +724,7 @@ main(int argc, char **argv)
|
||||
info.size = sizeof(info);
|
||||
if (ioctl(0, CONS_GETINFO, &info) < 0)
|
||||
err(1, "must be on a virtual console");
|
||||
while((opt = getopt(argc, argv, "b:c:df:g:i:l:LM:m:r:s:t:x")) != -1)
|
||||
while((opt = getopt(argc, argv, "b:c:df:g:i:l:LM:m:pPr:s:t:x")) != -1)
|
||||
switch(opt) {
|
||||
case 'b':
|
||||
set_border_color(optarg);
|
||||
@ -690,6 +766,12 @@ main(int argc, char **argv)
|
||||
case 'm':
|
||||
set_mouse(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
dump_screen(DUMP_RAW);
|
||||
break;
|
||||
case 'P':
|
||||
dump_screen(DUMP_TXT);
|
||||
break;
|
||||
case 'r':
|
||||
set_reverse_colors(argc, argv, &optind);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user