Debian Codegraph @

sadmin/vcsaview

raw
1 #!/usr/bin/perl
2 # SPDX-License-Identifier: MIT
3 # SPDX-FileCopyrightText: 2004-2007 Jan Engelhardt
4 #
5 # vcsaview - show Linux vt contents
6
7 use strict;
8
9 undef $/;
10 my $data = join("", <>);
11 my $height = ord(substr($data, 0, 1));
12 my $width = ord(substr($data, 1, 1));
13
14 for (my $y = 0; $y < $height; ++$y) {
15 for (my $x = 0; $x < $width; ++$x) {
16 my $p = 4 + 2 * ($y * $width + $x);
17 print &attr2color(substr($data, $p+1, 1)),
18 substr($data, $p, 1);
19 }
20 print "\n";
21 }
22
23 sub asc2ans ()
24 {
25 my $i = shift @_;
26 return ($i &~ 5) | (($i & 1) ? 4 : 0) | (($i & 4) ? 1 : 0);
27 }
28
29 sub attr2color ()
30 {
31 my $char = ord shift @_;
32
33 print "\e[0;";
34 if ($char & 0x08) {
35 print "1;";
36 }
37 print "4", &asc2ans(($char & 0x70) >> 4), ";";
38 print "3", &asc2ans(($char & 0x07)), "m";
39 return;
40 }