Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 May 2001 02:42:28 +0300 (EEST)
From:      Maxim Sobolev <sobomax@mail-in.net>
To:        nik@FreeBSD.org, ru@FreeBSD.org, audit@FreeBSD.org, arch@FreeBSD.org
Subject:   Integrating new scrshot(1) utility into vidcontrol(1) [patch for review]
Message-ID:  <200105182342.f4INgJx36064@mail.uic-in.net>

next in thread | raw e-mail | index | archive | help
Ok, as it was agreed I've integrated scrshot(1) into
vidcontrol(1) and also added ability to dump contents
of display buffer in plain text format, so you don't
even need a special utility to see what's going on
on a console of display-less machine. :-)

Please somebody review attached patches (esp. manpage).
Thank you!

-Maxim

Index: vidcontrol.1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.sbin/vidcontrol/vidcontrol.1,v
retrieving revision 1.34
diff -d -u -r1.34 vidcontrol.1
--- vidcontrol.1=092001/04/18 15:51:56=091.34
+++ vidcontrol.1=092001/05/18 23:32:37
@@ -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 @@
 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 @@
 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=09Contents"
+.It "1 thru 8=09Literal text" Dq Li SCRSHOT_
+.It "9=09File format version number"
+.It "10=09Remaining 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=09Byte=09Meaning"
+.It "1=0911=09Terminal width, in characters"
+.It "=0912=09Terminal depth, in characters"
+.It "=0913 and up=09The 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 @@
 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 @@
 .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
Index: vidcontrol.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.sbin/vidcontrol/vidcontrol.c,v
retrieving revision 1.36
diff -d -u -r1.36 vidcontrol.c
--- vidcontrol.c=092001/04/21 13:50:32=091.36
+++ vidcontrol.c=092001/05/18 23:32:37
@@ -50,6 +50,11 @@
 #define _VESA_800x600_DFL_ROWS 25
 #define _VESA_800x600_DFL_FNSZ 16
 =

+#define DUMP_RAW=090
+#define DUMP_TXT=091
+
+#define DUMP_FMT_REV=091
+
 char =09legal_colors[16][16] =3D {
 =09"black", "blue", "green", "cyan",
 =09"red", "magenta", "brown", "white",
@@ -70,8 +75,8 @@
 =09fprintf(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]");
 =09exit(1);
 }
 =

@@ -638,6 +643,77 @@
 =09=09info.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)
+{
+=09scrshot_t shot;
+=09vid_info_t info;
+
+=09info.size =3D sizeof(info);
+=09if (ioctl(0, CONS_GETINFO, &info) =3D=3D -1) {
+=09=09warn("failed to obtain current video mode parameters");
+=09=09return;
+=09}
+
+=09shot.buf =3D alloca(info.mv_csz * info.mv_rsz * sizeof(u_int16_t));
+=09if (shot.buf =3D=3D NULL) {
+=09=09warn("failed to allocate memory for dump");
+=09=09return;
+=09}
+
+=09shot.xsize =3D info.mv_csz;
+=09shot.ysize =3D info.mv_rsz;
+=09if (ioctl(0, CONS_SCRSHOT, &shot) =3D=3D -1) {
+=09=09warn("failed to get dump of the screen");
+=09=09return;
+=09}
+
+=09if (mode =3D=3D DUMP_RAW) {
+=09=09printf("SCRSHOT_%c%c%c%c", DUMP_FMT_REV, 2,
+=09=09       shot.xsize, shot.ysize);
+=09=09fflush(stdout);
+
+=09=09(void)write(STDOUT_FILENO, shot.buf,
+=09=09=09    shot.xsize * shot.ysize * sizeof(u_int16_t));
+=09} else {
+=09=09char *line;
+=09=09int x, y;
+=09=09u_int16_t ch;
+
+=09=09line =3D alloca(shot.xsize + 1);
+=09=09if (line =3D=3D NULL) {
+=09=09=09warn("failed to allocate memory for line buffer");
+=09=09=09return;
+=09=09}
+
+=09=09for (y =3D 0; y < shot.ysize; y++) {
+=09=09=09for (x =3D 0; x < shot.xsize; x++) {
+=09=09=09=09ch =3D shot.buf[x + (y * shot.xsize)];
+=09=09=09=09ch &=3D 0xff;
+=09=09=09=09if (isprint(ch) =3D=3D 0)
+=09=09=09=09=09ch =3D ' ';
+=09=09=09=09line[x] =3D (char)ch;
+=09=09=09}
+
+=09=09=09/* Trim trailing spaces */
+=09=09=09do {
+=09=09=09=09line[x--] =3D '\0';
+=09=09=09} while (line[x] =3D=3D ' ' && x !=3D 0);
+
+=09=09=09puts(line);
+=09=09}
+=09=09fflush(stdout);
+=09}
+
+=09return;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -648,7 +724,7 @@
 =09info.size =3D sizeof(info);
 =09if (ioctl(0, CONS_GETINFO, &info) < 0)
 =09=09err(1, "must be on a virtual console");
-=09while((opt =3D getopt(argc, argv, "b:c:df:g:i:l:LM:m:r:s:t:x")) !=3D -1=
)
+=09while((opt =3D getopt(argc, argv, "b:c:df:g:i:l:LM:m:pPr:s:t:x")) !=3D =
-1)
 =09=09switch(opt) {
 =09=09=09case 'b':
 =09=09=09=09set_border_color(optarg);
@@ -689,6 +765,12 @@
 =09=09=09=09break;
 =09=09=09case 'm':
 =09=09=09=09set_mouse(optarg);
+=09=09=09=09break;
+=09=09=09case 'p':
+=09=09=09=09dump_screen(DUMP_RAW);
+=09=09=09=09break;
+=09=09=09case 'P':
+=09=09=09=09dump_screen(DUMP_TXT);
 =09=09=09=09break;
 =09=09=09case 'r':
 =09=09=09=09set_reverse_colors(argc, argv, &optind);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105182342.f4INgJx36064>