ecf7b6b9045da2542e26a486edbe2bf9aa476c19
[debian/elilo] / debian / sys2ansi.pl
1 #!/usr/bin/perl
2 # $Id: sys2ansi.pl,v 1.1 2002/10/29 22:35:52 bdale Exp $
3 #
4 # Perl script to convert a Syslinux-format screen to PC-ANSI
5 # to display in a color xterm or on the Linux console
6 #
7 @ansicol = (0,4,2,6,1,5,3,7);
8
9 $getting_file = 0;
10 $enable = 1;
11
12 while ( read(STDIN, $ch, 1) > 0 ) {
13     if ( $ch eq "\x1A" ) {      # <SUB> <Ctrl-Z> EOF
14         last;
15     } elsif ( $ch eq "\x0C" ) { # <FF>  <Ctrl-L> Clear screen
16         print "\x1b[2J" if ( $enable && !$getting_file );
17     } elsif ( $ch eq "\x0F" ) { # <SI>  <Ctrl-O> Attribute change
18         if ( !$getting_file ) {
19             if ( read(STDIN, $attr, 2) == 2 ) {
20                 $attr = hex $attr;
21                 if ( $enable ) {
22                     print "\x1b[0;";
23                     if ( $attr & 0x80 ) {
24                         print "5;";
25                         $attr &= ~0x80;
26                     }
27                     if ( $attr & 0x08 ) {
28                         print "1;";
29                         $attr &= ~0x08;
30                     }
31                     printf "%d;%dm",
32                     $ansicol[$attr >> 4] + 40, $ansicol[$attr & 7] + 30;
33                 }
34             }
35         }
36     } elsif ( $ch eq "\x18" ) { # <CAN> <Ctrl-X> Display image
37         # We can't display an image; pretend to be a text screen
38         # Ignore all input until end of line
39         $getting_file = 1;
40     } elsif ( (ord($ch) & ~07) == 0x10 ) { # Mode controls
41         $enable = (ord($ch) & 0x01); # Emulate the text screen
42     } elsif ( $ch eq "\x0D" ) { # <CR>  <Ctrl-M> Carriage return
43         # Ignore
44     } elsif ( $ch eq "\x0A" ) { # <LF>  <Ctrl-J> Line feed
45         if ( $getting_file ) {
46             $getting_file = 0;
47         } else {
48             print $ch if ( $enable );
49         }
50     } elsif ( $ch eq "\x01" ) { # <SOH>  <Ctrl-A> Prompt delimiter
51         # Ignore
52     } elsif ( $ch eq "\x02" ) { # <STX>  <Ctrl-B> Menu delimiter
53         # Ignore
54     } else {
55         print $ch if ( $enable && !$getting_file );
56     }
57 }