1a5ae21e4Smrg#!/usr/bin/env perl
204b94745Smrg# $XTermId: acs.pl,v 1.3 2018/04/22 15:14:45 tom Exp $
3a5ae21e4Smrg# -----------------------------------------------------------------------------
4a5ae21e4Smrg# this file is part of xterm
5a5ae21e4Smrg#
6a5ae21e4Smrg# Copyright 2018 by Thomas E. Dickey
7a5ae21e4Smrg#
8a5ae21e4Smrg#                         All Rights Reserved
9a5ae21e4Smrg#
10a5ae21e4Smrg# Permission is hereby granted, free of charge, to any person obtaining a
11a5ae21e4Smrg# copy of this software and associated documentation files (the
12a5ae21e4Smrg# "Software"), to deal in the Software without restriction, including
13a5ae21e4Smrg# without limitation the rights to use, copy, modify, merge, publish,
14a5ae21e4Smrg# distribute, sublicense, and/or sell copies of the Software, and to
15a5ae21e4Smrg# permit persons to whom the Software is furnished to do so, subject to
16a5ae21e4Smrg# the following conditions:
17a5ae21e4Smrg#
18a5ae21e4Smrg# The above copyright notice and this permission notice shall be included
19a5ae21e4Smrg# in all copies or substantial portions of the Software.
20a5ae21e4Smrg#
21a5ae21e4Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22a5ae21e4Smrg# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23a5ae21e4Smrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24a5ae21e4Smrg# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
25a5ae21e4Smrg# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26a5ae21e4Smrg# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27a5ae21e4Smrg# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28a5ae21e4Smrg#
29a5ae21e4Smrg# Except as contained in this notice, the name(s) of the above copyright
30a5ae21e4Smrg# holders shall not be used in advertising or otherwise to promote the
31a5ae21e4Smrg# sale, use or other dealings in this Software without prior written
32a5ae21e4Smrg# authorization.
33a5ae21e4Smrg# -----------------------------------------------------------------------------
34a5ae21e4Smrg# Assuming at least 24x80, print an array of the printable characters and their
35a5ae21e4Smrg# mapping to alternate character-set.  This also requires cursor-addressing.
36a5ae21e4Smrg
37a5ae21e4Smrguse strict;
38a5ae21e4Smrguse warnings;
39a5ae21e4Smrguse diagnostics;
40a5ae21e4Smrg
41a5ae21e4Smrgsub failed() {
42a5ae21e4Smrg    my $args = shift;
43a5ae21e4Smrg    printf STDERR "? %s\n", $args;
44a5ae21e4Smrg    exit 1;
45a5ae21e4Smrg}
46a5ae21e4Smrg
47a5ae21e4Smrgsub need() {
48a5ae21e4Smrg    my $cap   = shift;
49a5ae21e4Smrg    my $check = `tput $cap 0 0`;
50a5ae21e4Smrg    chomp $check;
51a5ae21e4Smrg    &failed("missing capability: $cap") if ( $check eq "" );
52a5ae21e4Smrg}
53a5ae21e4Smrg
54a5ae21e4Smrg&need("cup");
55a5ae21e4Smrg&need("clear");
56a5ae21e4Smrg&need("smacs");
57a5ae21e4Smrg&need("rmacs");
58a5ae21e4Smrg
59a5ae21e4Smrgsystem("tput clear");
60a5ae21e4Smrgsystem("tput enacs");
61a5ae21e4Smrgmy $smacs = `tput smacs`;
62a5ae21e4Smrgmy $rmacs = `tput rmacs`;
63a5ae21e4Smrg
64a5ae21e4Smrgfor my $row ( 0 .. 15 ) {
65a5ae21e4Smrg    for my $col ( 0 .. 5 ) {
66a5ae21e4Smrg        my $ch = 32 + $row + $col * 16;
67a5ae21e4Smrg        last if ( $ch >= 127 );
68a5ae21e4Smrg        system( sprintf( "tput cup %d %d", $row, 4 + $col * 12 ) );
69a5ae21e4Smrg        my $xx = chr($ch);
70a5ae21e4Smrg        printf '%2x:%s{%s%s%s}', $ch, $xx, $smacs, $xx . $xx . $xx . $xx,
71a5ae21e4Smrg          $rmacs;
72a5ae21e4Smrg    }
73a5ae21e4Smrg}
74a5ae21e4Smrg
75a5ae21e4Smrgprintf "\n";
76a5ae21e4Smrg
77a5ae21e4Smrg1;
78