New scrshot utility, using the CONS_SCRSHOT ioctl. Usage is

scrshot /dev/ttyv0 > shot.scr

See the shot2{txt,png} utilities (soon to be) in the ports collection.

Reviewed by:	-arch
This commit is contained in:
nik 2001-05-18 09:00:51 +00:00
parent 288113e7a8
commit 1136460dcc
3 changed files with 253 additions and 0 deletions

8
usr.bin/scrshot/Makefile Normal file
View File

@ -0,0 +1,8 @@
#
# $FreeBSD$
#
PROG= scrshot
CFLAGS+=-Wall
.include <bsd.prog.mk>

165
usr.bin/scrshot/scrshot.1 Normal file
View File

@ -0,0 +1,165 @@
.\" 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
.Li CONS_SCRSHOT
ioctl 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 colour attribute.
.Pp
The colour attribute byte is further broken down in to the low nybble, which
specifies which of 16 different foreground colours is active, and the high
nybble, which specifies which of 16 different background colours 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 colours are brighter versions of the first 8.
.Pp
For example, the two bytes
.Bd -literal -offset indent
65 158
.Ed
.Pp
specify an uppercase A (character code 65), in yellow (low nybble 15) on a
light blue background (high nybble 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 Ta Sy Contents
.It 1 thru 8 Ta Literal text Dq SCRSHOT_
.It 9 Ta File format version number
.It 10 Ta Remaining number of bytes in the header
.El
.Pp
Subsequent bytes depend on the version number.
.Bl -column "Version " "4 and up" -offset indent
.It Sy Version Ta Sy Byte Ta Sy Meaning
.It 1 Ta 11 Ta Terminal width, in characters
.It Ta 12 Ta Terminal depth, in characters
.It Ta 13 and up Ta 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 RETURN VALUES
The
.Nm
utility exits 0 on success or >0 if an error occurred.
.Sh EXAMPLES
The command:
.Bd -literal -offset indent
.Ic scrshot /dev/ttyv0 > shot.scr
.Ed
.Pp
will capture the contents of the first virtual terminal, and redirect the
output to the
.Li shot.scr
file.
.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 appeared in
.Fx 5.0
and was backported to
.Fx 4.4 .
.Sh AUTHORS
.An Joel Holveck Aq joelh@gnu.org
and
.An Nik Clayton Aq nik@FreeBSD.org

80
usr.bin/scrshot/scrshot.c Normal file
View File

@ -0,0 +1,80 @@
/*-
* 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);
(void)write(STDOUT_FILENO, shot.buf,
shot.xsize * shot.ysize * sizeof(u_int16_t));
exit(0);
}