"Fossies" - the Fresh Open Source Software Archive 
Member "xterm-379/gen-charsets.pl" (22 Aug 2018, 3504 Bytes) of package /linux/misc/xterm-379.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "gen-charsets.pl" see the
Fossies "Dox" file reference documentation.
1 #! /usr/bin/perl -w
2 # $XTermId: gen-charsets.pl,v 1.2 2018/08/22 22:59:15 tom Exp $
3 # -----------------------------------------------------------------------------
4 # this file is part of xterm
5 #
6 # Copyright 2018 by Thomas E. Dickey
7 #
8 # All Rights Reserved
9 #
10 # Permission is hereby granted, free of charge, to any person obtaining a
11 # copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
17 #
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
20 #
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 # IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
25 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #
29 # Except as contained in this notice, the name(s) of the above copyright
30 # holders shall not be used in advertising or otherwise to promote the
31 # sale, use or other dealings in this Software without prior written
32 # authorization.
33 # -----------------------------------------------------------------------------
34 #
35 # Translate a Unicode mapping, e.g., for one of the ISO-8859-x codepages,
36 # into the form used in charsets.c for converting characters.
37 use strict;
38
39 $| = 1;
40
41 sub do_file($) {
42 my $file = shift;
43 my $undef = hex(0x2426);
44 open( FP, $file ) || do {
45 print STDERR "Can't open $file: $!\n";
46 return;
47 };
48 my @data = <FP>;
49 close(FP);
50 my $name = $file;
51 $name =~ s,^.*/,,;
52 $name =~ s/\..*$//;
53 $name =~ s/^(8859)/ISO-$1/;
54 $name =~ s/-/_/g;
55 printf "#define map_%s(code) \\\n", $name;
56 printf "\tswitch (code) { \\\n";
57 my @target;
58 my @noteof;
59
60 for my $n ( 0 .. $#data ) {
61 chomp $data[$n];
62 $data[$n] =~ s/^\s*//;
63 $data[$n] =~ s/\s*$//;
64 next if ( $data[$n] =~ /^#/ );
65 next if ( $data[$n] eq "" );
66 if ( $data[$n] !~ /^0x[[:xdigit:]]+\s+0x[[:xdigit:]]+\s*#/i ) {
67 printf STDERR "?? %d:%s\n", $n + 1, $data[$n];
68 next;
69 }
70
71 my $source = $data[$n];
72 $source =~ s/\s.*//;
73 $source = hex($source);
74 next if ( $source < 160 or $source > 255 );
75 $source -= 128;
76
77 my $target = $data[$n];
78 $target =~ s/^[^\s]+\s+(0x[[:xdigit:]]+).*$/$1/i;
79 $target = hex($target);
80
81 my $noteof = $data[$n];
82 $noteof =~ s/^[^#]+#\s*//;
83
84 $target[$source] = $target;
85 $noteof[$source] = $noteof;
86 }
87 my $lo = $target[32] ? 32 : 33;
88 my $hi = $target[127] ? 127 : 126;
89 for my $n ( $lo .. $hi ) {
90 if ( defined $target[$n] ) {
91 printf "\t UNI(0x%02x, 0x%04x);\t/* %s */ \\\n", $n,
92 $target[$n], $noteof[$n];
93 }
94 else {
95 printf "\t XXX(0x%02x, UNDEF);\t/* undefined */ \\\n", $n;
96 }
97 }
98 printf "\t}\n";
99 }
100
101 while ( $#ARGV >= 0 ) {
102 &do_file( shift @ARGV );
103 }
104
105 1;