enable to choose coding system also in other environment than UniMulti.
authorimiyazaki <imiyazaki>
Mon, 3 Nov 2003 16:26:17 +0000 (16:26 +0000)
committerimiyazaki <imiyazaki>
Mon, 3 Nov 2003 16:26:17 +0000 (16:26 +0000)
inCHISE

diff --git a/inCHISE b/inCHISE
index 3ca903f..73ad012 100755 (executable)
--- a/inCHISE
+++ b/inCHISE
@@ -4,11 +4,11 @@
 
 use strict;
 use vars qw($omegadb_path
-           $opt_protrude $opt_order
+           $opt_protrude %opt_order
            $opt_in_cs $opt_out_cs
            $opt_help $usage
            $in_cs $out_cs $i @chars
-           @order %order
+           %order %order_map
            $char $char_id $out_char
            $ids $ids_argc %ids $idsdb
            $idsdata_file $ids_start $font_start
@@ -24,11 +24,17 @@ my $omegadb_path="/usr/local/lib/chise/omega";
 
 ### Options ###
 
-#$opt_order='jcgk';
-$opt_order='jGcgkHC';
+#$opt_order{'UniMulti'}='jcgk';
+$opt_order{'UniMulti'}='jGcgkHC';
+$opt_order{'UniGB'}='g';
+$opt_order{'UniCNS'}='c';
+$opt_order{'UniJIS'}='j';
+$opt_order{'UniKS'}='k';
+
 $opt_protrude=0;# 1=true, 0=false.
 
-###
+### End ###
+
 my $strictly_forbidden_after = '「【『[(〈“‘‘(〔{《{\[\(\x{3016}{「';
 #       \x{3016} | # white 【
 
@@ -112,28 +118,34 @@ $ids_argc=0;
 $ids="";
 
 @GT=(#"=gt","=gt-k",
-     "=gt-pj-1","=gt-pj-2","=gt-pj-3","=gt-pj-4","=gt-pj-5","=gt-pj-6","=gt-pj-7","=gt-pj-8","=gt-pj-9","=gt-pj-10","=gt-pj-11"
+     "=gt-pj-1","=gt-pj-2","=gt-pj-3","=gt-pj-4","=gt-pj-5",
+     "=gt-pj-6","=gt-pj-7","=gt-pj-8","=gt-pj-9","=gt-pj-10",
+     "=gt-pj-11"
      #,"=gt-pj-k1","=gt-pj-k2"
      );
-@HZK=("=hanziku-1","=hanziku-2","=hanziku-3","=hanziku-4","=hanziku-5","=hanziku-6","=hanziku-7","=hanziku-8","=hanziku-9","=hanziku-10","=hanziku-11","=hanziku-12");
+@HZK=("=hanziku-1","=hanziku-2","=hanziku-3","=hanziku-4",
+      "=hanziku-5","=hanziku-6","=hanziku-7","=hanziku-8",
+      "=hanziku-9","=hanziku-10","=hanziku-11","=hanziku-12");
 @CDP=("=big5-cdp");
 
-%order=('c'=>'UniCNS',
-       'g'=>'UniGB',
-       'j'=>'UniJIS',
-       'k'=>'UniKS',
-       'G'=>'GT',
-       'H'=>'HZK',
-       'C'=>'CDP',
-       );
-
-if(defined($opt_order)){
-    if($opt_order=~/^[cgjkGHC]*$/){
-       @order=split(//,$opt_order);
-       @order=map {$order{$_}} @order;
-    }else{
-       print STDERR "Invalid order!\n";
-       exit 1;
+%order_map=('c'=>'UniCNS',
+           'g'=>'UniGB',
+           'j'=>'UniJIS',
+           'k'=>'UniKS',
+           'G'=>'GT',
+           'H'=>'HZK',
+           'C'=>'CDP',
+           );
+
+foreach $out_cs ('UniGB','UniCNS','UniJIS','UniKS','UniMulti'){
+    if(defined($opt_order{$out_cs})){
+       if($opt_order{$out_cs}=~/^[cgjkGHC]*$/){
+           @{$order{$out_cs}}=map {$order_map{$_}}
+           (split(//,$opt_order{$out_cs}));
+       }else{
+           print STDERR "Invalid order for $out_cs!\n";
+           exit 1;
+       }
     }
 }
 
@@ -388,95 +400,56 @@ sub normalize_ids{
 
 sub get_output_char{
     # argument: <char-id>
-    # return: character in output coding system or TeX macro.
+    # return: character in output coding system or TeX macro or undef.
     my($char_id,$out_cs)=@_;
     my($char,$out_char_id,$suffix);
     my($gt,$hzk,$cdp);
 
     $char=pack('U',$char_id);
 
-    if($out_cs eq 'UniJIS'
-       and &get_char_attribute($char,"vnd-adobe-cid-unijis-utf16-h")){
-       if($out_char_id=&get_char_attribute($char,'=ucs@jis')
-          or $out_char_id=&get_char_attribute($char,'=ucs')
-          or $out_char_id=&get_char_attribute($char,'=>ucs@jis')
-          or $out_char_id=&get_char_attribute($char,'=>ucs')
-          ){
-           return pack("U",$out_char_id);
-       }
-    }elsif($out_cs eq 'UniGB'
-          and &get_char_attribute($char,"vnd-adobe-cid-unigb-ucs2-h")){
-       if($out_char_id=&get_char_attribute($char,'=ucs@gb')
-          or $out_char_id=&get_char_attribute($char,'=ucs')
-          or $out_char_id=&get_char_attribute($char,'=>ucs@gb')
-          or $out_char_id=&get_char_attribute($char,'=>ucs')
-          ){
-           return pack("U",$out_char_id);
-       }
-    }elsif($out_cs eq 'UniCNS'
-          and &get_char_attribute($char,"vnd-adobe-cid-unicns-ucs2-h")){
-       if($out_char_id=&get_char_attribute($char,'=ucs@cns')
-          or $out_char_id=&get_char_attribute($char,'=ucs')
-          or $out_char_id=&get_char_attribute($char,'=>ucs@cns')
-          or $out_char_id=&get_char_attribute($char,'=>ucs')
-          ){
-           return pack("U",$out_char_id);
-       }
-    }elsif($out_cs eq 'UniKS'
-          and &get_char_attribute($char,"vnd-adobe-cid-uniks-ucs2-h")){
-       if($out_char_id=&get_char_attribute($char,'=ucs@ks')
-          or $out_char_id=&get_char_attribute($char,'=ucs')
-          or $out_char_id=&get_char_attribute($char,'=>ucs@ks')
-          or $out_char_id=&get_char_attribute($char,'=>ucs')
-          ){
-           return pack("U",$out_char_id);
-       }
-    }elsif($out_cs eq 'UniMulti'){
-       foreach $out_cs (@order){
-    
-           if($out_cs eq 'UniJIS'
-              and &get_char_attribute($char,"vnd-adobe-cid-unijis-utf16-h")){
-               if($out_char_id=&get_char_attribute($char,'=ucs@jis')
-                  or $out_char_id=&get_char_attribute($char,'=ucs')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs@jis')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs')
-                  ){
-                   return '{\selectjisfont\char'.$out_char_id.'}';
-               }
-           }elsif($out_cs eq 'UniGB'
-                  and &get_char_attribute($char,"vnd-adobe-cid-unigb-ucs2-h")){
-               if($out_char_id=&get_char_attribute($char,'=ucs@gb')
-                  or $out_char_id=&get_char_attribute($char,'=ucs')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs@gb')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs')
-                  ){
-                   return '{\selectgbsfont\char'.$out_char_id.'}';
-               }
-           }elsif($out_cs eq 'UniCNS'
-                  and &get_char_attribute($char,"vnd-adobe-cid-unicns-ucs2-h")){
-               if($out_char_id=&get_char_attribute($char,'=ucs@cns')
-                  or $out_char_id=&get_char_attribute($char,'=ucs')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs@cns')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs')
-                  ){
-                   return '{\selectcnsfont\char'.$out_char_id.'}';
-               }
-           }elsif($out_cs eq 'UniKS'
-                  and &get_char_attribute($char,"vnd-adobe-cid-uniks-ucs2-h")){
-               if($out_char_id=&get_char_attribute($char,'=ucs@ks')
-                  or $out_char_id=&get_char_attribute($char,'=ucs')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs@ks')
-                  or $out_char_id=&get_char_attribute($char,'=>ucs')
-                  ){
-                   return '{\selectksxfont\char'.$out_char_id.'}';
-               }
-           }elsif($out_cs eq 'GT'){
-               return $gt if($gt=&get_macro_for_GT($char_id));
-           }elsif($out_cs eq 'HZK'){
-               return $hzk if($hzk=&get_macro_for_HZK($char_id));
-           }elsif($out_cs eq 'CDP'){
-               return $cdp if($cdp=&get_macro_for_CDP($char_id));
+    foreach $out_cs (@{$order{$out_cs}}){
+       if($out_cs eq 'UniJIS'
+          and &get_char_attribute($char,"vnd-adobe-cid-unijis-utf16-h")){
+           if($out_char_id=&get_char_attribute($char,'=ucs@jis')
+              or $out_char_id=&get_char_attribute($char,'=ucs')
+              or $out_char_id=&get_char_attribute($char,'=>ucs@jis')
+              or $out_char_id=&get_char_attribute($char,'=>ucs')
+              ){
+               return '{\selectjisfont\char'.$out_char_id.'}';
            }
+       }elsif($out_cs eq 'UniGB'
+              and &get_char_attribute($char,"vnd-adobe-cid-unigb-ucs2-h")){
+           if($out_char_id=&get_char_attribute($char,'=ucs@gb')
+              or $out_char_id=&get_char_attribute($char,'=ucs')
+              or $out_char_id=&get_char_attribute($char,'=>ucs@gb')
+              or $out_char_id=&get_char_attribute($char,'=>ucs')
+              ){
+               return '{\selectgbsfont\char'.$out_char_id.'}';
+           }
+       }elsif($out_cs eq 'UniCNS'
+              and &get_char_attribute($char,"vnd-adobe-cid-unicns-ucs2-h")){
+           if($out_char_id=&get_char_attribute($char,'=ucs@cns')
+              or $out_char_id=&get_char_attribute($char,'=ucs')
+              or $out_char_id=&get_char_attribute($char,'=>ucs@cns')
+              or $out_char_id=&get_char_attribute($char,'=>ucs')
+              ){
+               return '{\selectcnsfont\char'.$out_char_id.'}';
+           }
+       }elsif($out_cs eq 'UniKS'
+              and &get_char_attribute($char,"vnd-adobe-cid-uniks-ucs2-h")){
+           if($out_char_id=&get_char_attribute($char,'=ucs@ks')
+              or $out_char_id=&get_char_attribute($char,'=ucs')
+              or $out_char_id=&get_char_attribute($char,'=>ucs@ks')
+              or $out_char_id=&get_char_attribute($char,'=>ucs')
+              ){
+               return '{\selectksxfont\char'.$out_char_id.'}';
+           }
+       }elsif($out_cs eq 'GT'){
+           return $gt if($gt=&get_macro_for_GT($char_id));
+       }elsif($out_cs eq 'HZK'){
+           return $hzk if($hzk=&get_macro_for_HZK($char_id));
+       }elsif($out_cs eq 'CDP'){
+           return $cdp if($cdp=&get_macro_for_CDP($char_id));
        }
     }
     return undef;
@@ -497,7 +470,7 @@ sub get_ids{
 
 sub get_char_id_for_ids{
     # argument: <ideographic description sequence>
-    # return: char-id
+    # return: char-id or undef.
     my($ids)=@_;
     my($output_char);
 
@@ -527,7 +500,7 @@ sub get_char_id{
 
 sub get_macro_for_GT{
     # argument: <char-id>
-    # return: TeX macro for GT fonts.
+    # return: TeX macro for GT fonts or undef.
     my($char_id)=@_;
     my($char,$gt,$GT);
     $char=pack("U",$char_id);
@@ -547,6 +520,8 @@ sub get_macro_for_GT{
 }
 
 sub get_macro_for_HZK{
+    # argument: <char-id>
+    # return: TeX macro for Hanziku fonts or undef.
     my($char_id)=@_;
     my($char,$hzk,$HZK);
     $char=pack("U",$char_id);
@@ -564,6 +539,8 @@ sub get_macro_for_HZK{
 }
 
 sub get_macro_for_CDP{
+    # argument: <char-id>
+    # return: TeX macro for CDP fonts or undef.
     my($char_id)=@_;
     my($char,$cdp,$ucs);
     $char=pack("U",$char_id);