| 57 | | chomp; |
| 58 | | s/\s*#.*$//o; /^$/ and next; |
| 59 | | if ($_ eq "CHARMAP"){ |
| 60 | | $in_charmap = 1; |
| 61 | | for my $must (qw/code_set_name mb_cur_min mb_cur_max/){ |
| 62 | | exists $Hdr{$must} or nit "<$must> nonexistent"; |
| | 57 | chomp; |
| | 58 | s/\s*#.*$//o; /^$/ and next; |
| | 59 | if ($_ eq "CHARMAP"){ |
| | 60 | $in_charmap = 1; |
| | 61 | for my $must (qw/code_set_name mb_cur_min mb_cur_max/){ |
| | 62 | exists $Hdr{$must} or nit "<$must> nonexistent"; |
| | 63 | } |
| | 64 | $Hdr{mb_cur_min} > $Hdr{mb_cur_max} |
| | 65 | and nit sprintf("mb_cur_min(%d) > mb_cur_max(%d)", |
| | 66 | $Hdr{mb_cur_min},$Hdr{mb_cur_max}); |
| | 67 | $in_charmap = 1; |
| | 68 | next; |
| 64 | | $Hdr{mb_cur_min} > $Hdr{mb_cur_max} |
| 65 | | and nit sprintf("mb_cur_min(%d) > mb_cur_max(%d)", |
| 66 | | $Hdr{mb_cur_min},$Hdr{mb_cur_max}); |
| 67 | | $in_charmap = 1; |
| 68 | | next; |
| 69 | | } |
| 70 | | unless ($in_charmap){ |
| 71 | | my($hkey, $hvalue) = /^<(\S+)>\s+[\"\']?([^\"\']+)/o or next; |
| 72 | | $Opt{D} and warn "$hkey => $hvalue"; |
| 73 | | if ($hkey eq "code_set_name"){ # name check |
| 74 | | exists $Hdr{code_set_name} |
| 75 | | and nit "Duplicate <code_set_name>: $hkey"; |
| | 70 | unless ($in_charmap){ |
| | 71 | my($hkey, $hvalue) = /^<(\S+)>\s+[\"\']?([^\"\']+)/o or next; |
| | 72 | $Opt{D} and warn "$hkey => $hvalue"; |
| | 73 | if ($hkey eq "code_set_name"){ # name check |
| | 74 | exists $Hdr{code_set_name} |
| | 75 | and nit "Duplicate <code_set_name>: $hkey"; |
| | 76 | } |
| | 77 | if ($hkey eq "code_set_alias"){ # alias check |
| | 78 | $hvalue eq $Hdr{code_set_name} |
| | 79 | and nit qq(alias "$hvalue" is already in <code_set_name>); |
| | 80 | } |
| | 81 | $Hdr{$hkey} = $hvalue; |
| | 82 | }else{ |
| | 83 | my $name = $Hdr{code_set_name}; |
| | 84 | my($unistr, $encstr, $fb) = /^(\S+)\s+(\S+)\s(\S+)/o or next; |
| | 85 | $Opt{v} and nit $_, 2; |
| | 86 | my $uni = uniparse($unistr); |
| | 87 | my $enc = encparse($encstr); |
| | 88 | $fb =~ /^\|([0123])$/ or nit "malformed fallback: $fb"; |
| | 89 | $fb = $1; |
| | 90 | $Opt{f} and $fb = 0; |
| | 91 | unless ($fb == 1){ # check uni -> enc |
| | 92 | if (exists $U2E{$uni}){ |
| | 93 | nit "dupe encode map: U$uni => $U2E{$uni} and $enc", 1; |
| | 94 | }else{ |
| | 95 | $U2E{$uni} = $enc; |
| | 96 | if ($Opt{e} and $fb != 3) { |
| | 97 | my $e = hex2enc($enc); |
| | 98 | my $u = hex2uni($uni); |
| | 99 | my $eu = Encode::encode($name, $u); |
| | 100 | $e eq $eu |
| | 101 | or nit qq(encode('$name', $uni) != $enc); |
| | 102 | } |
| | 103 | } |
| | 104 | } |
| | 105 | unless ($fb == 3){ # check enc -> uni |
| | 106 | if (exists $E2U{$enc}){ |
| | 107 | nit "dupe decode map: $enc => U$E2U{$enc} and U$uni", 1; |
| | 108 | }else{ |
| | 109 | $E2U{$enc} = $uni; |
| | 110 | if ($Opt{e} and $fb != 1) { |
| | 111 | my $e = hex2enc($enc); |
| | 112 | my $u = hex2uni($uni); |
| | 113 | $Opt{D} and warn "$uni, $enc"; |
| | 114 | my $de = Encode::decode($name, $e); |
| | 115 | $de eq $u |
| | 116 | or nit qq(decode('$name', $enc) != $uni); |
| | 117 | } |
| | 118 | } |
| | 119 | } |
| | 120 | # warn "$uni, $enc, $fb"; |
| 77 | | if ($hkey eq "code_set_alias"){ # alias check |
| 78 | | $hvalue eq $Hdr{code_set_name} |
| 79 | | and nit qq(alias "$hvalue" is already in <code_set_name>); |
| 80 | | } |
| 81 | | $Hdr{$hkey} = $hvalue; |
| 82 | | }else{ |
| 83 | | my $name = $Hdr{code_set_name}; |
| 84 | | my($unistr, $encstr, $fb) = /^(\S+)\s+(\S+)\s(\S+)/o or next; |
| 85 | | $Opt{v} and nit $_, 2; |
| 86 | | my $uni = uniparse($unistr); |
| 87 | | my $enc = encparse($encstr); |
| 88 | | $fb =~ /^\|([0123])$/ or nit "malformed fallback: $fb"; |
| 89 | | $fb = $1; |
| 90 | | $Opt{f} and $fb = 0; |
| 91 | | unless ($fb == 1){ # check uni -> enc |
| 92 | | if (exists $U2E{$uni}){ |
| 93 | | nit "dupe encode map: U$uni => $U2E{$uni} and $enc", 1; |
| 94 | | }else{ |
| 95 | | $U2E{$uni} = $enc; |
| 96 | | if ($Opt{e} and $fb != 3) { |
| 97 | | my $e = hex2enc($enc); |
| 98 | | my $u = hex2uni($uni); |
| 99 | | my $eu = Encode::encode($name, $u); |
| 100 | | $e eq $eu |
| 101 | | or nit qq(encode('$name', $uni) != $enc); |
| 102 | | } |
| 103 | | } |
| 104 | | } |
| 105 | | unless ($fb == 3){ # check enc -> uni |
| 106 | | if (exists $E2U{$enc}){ |
| 107 | | nit "dupe decode map: $enc => U$E2U{$enc} and U$uni", 1; |
| 108 | | }else{ |
| 109 | | $E2U{$enc} = $uni; |
| 110 | | if ($Opt{e} and $fb != 1) { |
| 111 | | my $e = hex2enc($enc); |
| 112 | | my $u = hex2uni($uni); |
| 113 | | $Opt{D} and warn "$uni, $enc"; |
| 114 | | my $de = Encode::decode($name, $e); |
| 115 | | $de eq $u |
| 116 | | or nit qq(decode('$name', $enc) != $uni); |
| 117 | | } |
| 118 | | } |
| 119 | | } |
| 120 | | # warn "$uni, $enc, $fb"; |
| 121 | | } |