keyboard/altgr: proper function to convert char maps
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 31 Dec 2023 02:47:15 +0000 (03:47 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 1 Jan 2024 08:32:50 +0000 (09:32 +0100)
Code cleanup.

keyboard/altgr/apl.eng.inc.pl
keyboard/altgr/eurkey.eng.inc.pl
keyboard/altgr/groups.inc.pl
keyboard/altgr/macos-abc.eng.inc.pl
keyboard/altgr/macos.eng.inc.pl
keyboard/altgr/msx.eng.inc.pl
keyboard/altgr/spacecadet.eng.inc.pl
keyboard/altgr/ukext.eng.inc.pl
keyboard/altgr/windows.eng.inc.pl

index a2459967cae39a5d83959b5cbcf762282ae60366..45acbd52a9ac19fff04da3d3d6ebd8469becf7b6 100644 (file)
@@ -1,6 +1,7 @@
 use utf8;
 use strict;
 use warnings;
+do './keyboard/altgr/groups.inc.pl';
 
 my %dyalogx = (
        'Q' => '⍰',
@@ -10,7 +11,7 @@ my %dyalogx = (
        'N' => '⍡',
        'M' => '∥',
 );
-our %rows = (
+my %rows = (
        '~' => '⌺',
        '!' => '⌶',
        '@' => '⍫',
@@ -91,7 +92,7 @@ our %rows = (
        %dyalogx,
 );
 
-my $groups = do 'keyboard/altgr/groups.inc.pl';
+my $groups = kbchars(\%rows);
 $groups->{def}{''}{$_} = 'g4' for split //,'weEriIoOa/*'; # lookalikes
 $groups->{def}{''}{$_} .= ' ext' for keys %dyalogx;
 $groups->{flag}{ext} = ['extended', 'optional operators not available in all variants'];
index cc820e74d2aef1eadbcb9e527cc55c0a584efcbe..b2a98cbc0f422076954109a1891e7a73b4e000a2 100644 (file)
@@ -1,6 +1,7 @@
 use utf8;
 use strict;
 use warnings;
+do './keyboard/altgr/groups.inc.pl';
 
 my $V = v1.3;
 
@@ -26,7 +27,7 @@ my %arrows = (
        '+' => '⇔',
 );
 
-our %rows = (
+my %rows = (
        '1' => '¡',
        '!' => '¹',
        '2' => 'ª',
@@ -265,7 +266,7 @@ our %rows = (
        (map { ($presymbol.$_ => $arrows{$_}) } keys %arrows),
 );
 
-my $groups = do 'keyboard/altgr/groups.inc.pl';
+my $groups = kbchars(\%rows);
 $groups->{mode} = {
        ''  => 'option-shifted ⌥',
        'm' => 'Ω greek prefix ⌥m',
index 363ea035e952d891ead0e6e508760afef0c49584..2968e4bccda7f62b5a41a71f2454e48bda982b21 100644 (file)
@@ -1,19 +1,20 @@
-use strict;
+use 5.020;
 use warnings;
+use experimental 'signatures';
 use Unicode::Normalize qw( NFKD );
 use Text::Unidecode qw( unidecode );
 use Shiar_Sheet::FormatChar;
 
-our %rows;
-
 my $uc = Shiar_Sheet::FormatChar->new;
-my %g; # present group classes
-{
+
+sub kbchars ($rows) {
+       my %g; # present group classes
+       return {
        rows => [1, 0],
        def => {
                '' => {
                        map {
-                               my $v = $rows{$_};
+                               my $v = $rows->{$_};
                                my $class = 'g'.(
                                          !defined $v || $_ eq $v ? 1 # identical
                                        : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
@@ -26,14 +27,14 @@ my %g; # present group classes
                                );
                                $g{$class} = 1;
                                $_ => $class
-                       } keys %rows
+                       } keys %{$rows}
                },
        },
        key => {
                map {
-                       my ($glyph, $title) = $uc->glyph_html($rows{$_});
+                       my ($glyph, $title) = $uc->glyph_html($rows->{$_});
                        $_ => join "\n", $glyph, $title
-               } keys %rows
+               } keys %{$rows}
        },
        flag => {%{{
                g2 => ['accented', "decomposes to the original letter with a combining accent"],
@@ -44,4 +45,7 @@ my %g; # present group classes
                g8 => ['mark', "modifier letter or mark (spacing diacritic)"],
                g9 => ['combining', "diacritical mark to be combined with a following character"],
        }}{keys %g}},
+       };
 }
+
+1;
index 18c7bed1d05369b0a7d60f6a3b3cc4c67d89c2e3..f4a4a0023d6c2192fb5a2c045e58e760594dba06 100644 (file)
@@ -1,7 +1,9 @@
 use utf8;
 use strict;
 use warnings;
-our %rows = (
+do './keyboard/altgr/groups.inc.pl';
+
+my %rows = (
        'A' => "\N{MACRON}",
        'a' => "\N{COMBINING MACRON}",
        'B' => "\N{BREVE}",
@@ -181,7 +183,7 @@ our %rows = (
        '>b' => 'ɓ',
 );
 
-my $groups = do './keyboard/altgr/groups.inc.pl';
+my $groups = kbchars(\%rows);
 $groups->{mode} = {
        ''  => 'option-shifted ⌥',
        ':' => '№ number prefix ⌥:',
index d7bed09ef66a534e2d27fcb84bbd37a843025faf..aa153adafb8f230308da76a2bcb36e3648106030 100644 (file)
@@ -1,7 +1,9 @@
 use utf8;
 use strict;
 use warnings;
-our %rows = (
+do './keyboard/altgr/groups.inc.pl';
+
+my %rows = (
        'A' => 'Å',
        'a' => 'å',
        'B' => 'ı',
@@ -99,7 +101,7 @@ our %rows = (
 );
 
 +{
-       %{ do 'keyboard/altgr/groups.inc.pl' },
+       %{ kbchars(\%rows) },
        version => '1.3',
        title => 'US option',
        intro => join("\n",
index 6ea44e2d8f07d190193f3c8e46c2fc83432491ef..08d961bf81a444ec6b618af7deaec228221b7b4b 100644 (file)
@@ -1,7 +1,9 @@
 use utf8;
 use strict;
 use warnings;
-our %rows = (
+do './keyboard/altgr/groups.inc.pl';
+
+my %rows = (
        '!' => '¡',
        '1' => 'ƒ',
        '@' => '₧',
@@ -80,7 +82,7 @@ our %rows = (
 );
 
 +{
-       %{ do 'keyboard/altgr/groups.inc.pl' },
+       %{ kbchars(\%rows) },
        version => '1.0',
        title => 'msx code',
        intro => join("\n",
index cc6915d185edc299fc73c17e96a32de54af7ce21..d2e1eae5de59019bd174113105c967ce698dc56a 100644 (file)
@@ -1,7 +1,9 @@
 use utf8;
 use strict;
 use warnings;
-our %rows = (
+do './keyboard/altgr/groups.inc.pl';
+
+my %rows = (
        'q' => '∧',
        'w' => '∨',
        'e' => '∩',
@@ -88,7 +90,7 @@ our %rows = (
 );
 
 +{
-       %{ do 'keyboard/altgr/groups.inc.pl' },
+       %{ kbchars(\%rows) },
        version => '1.0',
        title => 'Space Cadet',
        intro => join("\n",
index affecaf288b4403474af6cefa0e7ae7135a4f9fa..bfc995e9cc6ae09f212549fe5fb53d0a97c64b82 100644 (file)
@@ -1,7 +1,9 @@
 use utf8;
 use strict;
 use warnings;
-our %rows = (
+do './keyboard/altgr/groups.inc.pl';
+
+my %rows = (
        '~' => '¦',
        '!' => '¡',
        '1' => '¹',
@@ -100,7 +102,7 @@ $rows{'['} = $rows{'2'};
 $rows{']'} = $rows{'#'};
 
 +{
-       %{ do 'keyboard/altgr/groups.inc.pl' },
+       %{ kbchars(\%rows) },
        title => 'UK-extended',
        version => '1.0',
        intro => join("\n",
index f110c863fe728bd8262819f9337c4ad2a0f24766..d575e81a732fdc3fd2a9a53e5c30a2eb9892fe93 100644 (file)
@@ -1,6 +1,7 @@
 use utf8;
 use strict;
 use warnings;
+do './keyboard/altgr/groups.inc.pl';
 
 my @az = ('A'..'Z', 'a'..'z');
 my @letters = qw(
@@ -21,7 +22,7 @@ my %xkb = (
        '?' => "\N{COMBINING HOOK ABOVE}",
 );
 
-our %rows = (
+my %rows = (
        '~' => "\N{COMBINING TILDE}",
        '`' => "\N{COMBINING GRAVE ACCENT}",
        '!' => '¹',
@@ -60,7 +61,7 @@ our %rows = (
        } 0 .. $#az
 );
 
-my $groups = do './keyboard/altgr/groups.inc.pl';
+my $groups = kbchars(\%rows);
 $groups->{def}{''}{$_} .= ' ext' for keys %xkb;
 $groups->{flag}{ext} = ['xkb', 'unofficial extensions added in Linux (Gnome, KDE)'];