1a5ae21e4Smrg#!/usr/bin/env perl 204b94745Smrg# $XTermId: iso2022.pl,v 1.5 2021/02/13 01:24:32 tom Exp $ 3a5ae21e4Smrg# ----------------------------------------------------------------------------- 4a5ae21e4Smrg# Copyright 2021 by Thomas E. Dickey 5a5ae21e4Smrg# 6a5ae21e4Smrg# All Rights Reserved 7a5ae21e4Smrg# 8a5ae21e4Smrg# Permission is hereby granted, free of charge, to any person obtaining a 9a5ae21e4Smrg# copy of this software and associated documentation files (the 10a5ae21e4Smrg# "Software"), to deal in the Software without restriction, including 11a5ae21e4Smrg# without limitation the rights to use, copy, modify, merge, publish, 12a5ae21e4Smrg# distribute, sublicense, and/or sell copies of the Software, and to 13a5ae21e4Smrg# permit persons to whom the Software is furnished to do so, subject to 14a5ae21e4Smrg# the following conditions: 15a5ae21e4Smrg# 16a5ae21e4Smrg# The above copyright notice and this permission notice shall be included 17a5ae21e4Smrg# in all copies or substantial portions of the Software. 18a5ae21e4Smrg# 19a5ae21e4Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20a5ae21e4Smrg# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21a5ae21e4Smrg# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22a5ae21e4Smrg# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 23a5ae21e4Smrg# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24a5ae21e4Smrg# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25a5ae21e4Smrg# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26a5ae21e4Smrg# 27a5ae21e4Smrg# Except as contained in this notice, the name(s) of the above copyright 28a5ae21e4Smrg# holders shall not be used in advertising or otherwise to promote the 29a5ae21e4Smrg# sale, use or other dealings in this Software without prior written 30a5ae21e4Smrg# authorization. 31a5ae21e4Smrg# ----------------------------------------------------------------------------- 32a5ae21e4Smrg# show ISO-2022 characters, by default GL and GR, optionally G1/G2/G3 33a5ae21e4Smrg 34a5ae21e4Smrguse strict; 35a5ae21e4Smrguse warnings; 36a5ae21e4Smrg 37a5ae21e4Smrguse Getopt::Std; 38a5ae21e4Smrg 39a5ae21e4Smrg$| = 1; 40a5ae21e4Smrg 41a5ae21e4Smrgour ( $opt_k, $opt_n, $opt_q, $opt_s ); 42a5ae21e4Smrg 43a5ae21e4Smrgsub doit() { 44a5ae21e4Smrg my $GL = ""; 45a5ae21e4Smrg printf "-- vile: fk=8bit\n"; 46a5ae21e4Smrg my $lo = 0; 47a5ae21e4Smrg if ($opt_q) { 48a5ae21e4Smrg $GL = 49a5ae21e4Smrg "`1234567890-=\n" 50a5ae21e4Smrg . "qwertyuiop[]\\\n" 51a5ae21e4Smrg . "asdfghjkl;'\n" 52a5ae21e4Smrg . "zxcvbnm,./\n" 53a5ae21e4Smrg . "~!@#$%^&*()_+\n" 54a5ae21e4Smrg . "QWERTYUIOP{}|\n" 55a5ae21e4Smrg . "ASDFGHJKL:\"\n" 56a5ae21e4Smrg . "ZXCVBNM<>?"; 57a5ae21e4Smrg } 58a5ae21e4Smrg else { 59a5ae21e4Smrg $lo = $opt_k ? 0 : 32; 60a5ae21e4Smrg for my $n ( $lo .. 127 ) { 61a5ae21e4Smrg $GL .= chr($n); 62a5ae21e4Smrg $GL .= "\n" if ( ( ( $n - 31 ) % 16 ) == 0 ); 63a5ae21e4Smrg } 64a5ae21e4Smrg } 65a5ae21e4Smrg my $GR = ""; 66a5ae21e4Smrg for my $n ( 0 .. ( length($GL) - 1 ) ) { 67a5ae21e4Smrg my $c = substr( $GL, $n, 1 ); 68a5ae21e4Smrg if ( ord($c) == 10 and ( not $opt_k or $n != 10 ) ) { 69a5ae21e4Smrg $GR .= $c; 70a5ae21e4Smrg } 71a5ae21e4Smrg else { 72a5ae21e4Smrg $GR .= chr( ord($c) + 128 ); 73a5ae21e4Smrg } 74a5ae21e4Smrg } 75a5ae21e4Smrg if ($opt_s) { 76a5ae21e4Smrg $GL =~ s/([^\n])/ $1/g; 77a5ae21e4Smrg $GR =~ s/([^\n])/ $1/g; 78a5ae21e4Smrg } 79a5ae21e4Smrg printf "GL:\n%s\n", $GL; 80a5ae21e4Smrg printf "GR:\n%s\n", $GR; 81a5ae21e4Smrg} 82a5ae21e4Smrg 83a5ae21e4Smrgsub main::HELP_MESSAGE() { 84a5ae21e4Smrg printf STDERR <<EOF 85a5ae21e4SmrgUsage: $0 [options] 86a5ae21e4Smrg 87a5ae21e4SmrgOptions: 88a5ae21e4Smrg -k assume 128-159 are printable. 89a5ae21e4Smrg -n print hex value before each character 90a5ae21e4Smrg -q use QWERTY 91a5ae21e4Smrg -s space between characters 92a5ae21e4SmrgEOF 93a5ae21e4Smrg ; 94a5ae21e4Smrg exit 1; 95a5ae21e4Smrg} 96a5ae21e4Smrg$Getopt::Std::STANDARD_HELP_VERSION = 1; 97a5ae21e4Smrg&getopts('knqs') || main::HELP_MESSAGE; 98a5ae21e4Smrg 99a5ae21e4Smrg&doit; 100a5ae21e4Smrg 101a5ae21e4Smrg1; 102