LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File chconfig.jyj of Package chdrv (Project home:zhonghuaren)

#!/usr/bin/perl
# -*- perl -*-

$chsys = $ARGV[0];
open(FD,"/etc/chinese/chinese.conf");
system("rm ${chsys}/config");

open(DAT,">>${chsys}/config");
while(<FD>)
{
    if (/^\s*#/) {loop;}
    if ( /^\s*BEGIN[ \t]*([a-zA-Z0-9]*)/)
    {
	print "Parse $1 block\n";
	if ($1 eq "WINDOW")	{&translate_window($ARGV[0]);}
	elsif ($1 eq "INPUT")	{&translate_input($ARGV[0]);}
	elsif ($1 eq "FONT")	{&translate_font($ARGV[0]);}
	elsif ($1 eq "ENV")	{&translate_env($ARGV[0]);}
	elsif ($1 eq "OTHER")	{&translate_other($ARGV[0]);}
	else
	{
	    print STDERR "Error block $1 encounter\n";
	    while(<FD>) {if (/END/) {last;}}
	}
    }
}


sub translate_window 
{
    local($path) = @_;
    $sizex = 80;
    $sizey = 29;
    $fc	= 1;
    $bc = 0;
    $sc = 7;
    while(<FD>)
    {
	if ( /^#/) {loop;}
	if ( /SIZE\s*([0-9]*)\s*([0-9]*)/)
	{
	    print DAT "SIZE=$1,$2\n";
	}
	elsif ( /FORECOLOR\s*([0-9]*)/)
	{
	    print DAT "FORECOLOR=$1\n";
	}
	elsif ( /BACKCOLOR\s*([0-9]*)/)
	{
	    print DAT "BACKCOLOR=$1\n";
	}
	elsif ( /SYSTEMCOLOR\s*([0-9]*)/)
	{
	    print DAT "SYSTEMCOLOR=$1\n";
	}
	elsif ( /SYSTEMBACK\s*([0-9]*)/)
	{
	    print DAT "SYSTEMBACK=$1\n";
	}
        elsif (/COLORTABLE\s*([0-9 ]*)/)
        {
	    print DAT "COLORTABLE=$1\n";
	}
	elsif ( /END/)
	{
	    last;
	}
    }
}

sub translate_input
{
    local($path) = @_;
    open(MULTITAB,">/etc/chinese/multitab");
    $i = 1;
    while(<FD>)
    {
	if ( /^#/) {loop;}
	if ( /PHONETIC[ \t]*([^ \t\n]*)/)
	{
	    $ENV{'PHONETIC_TABLE'} = $1;
	}	
	elsif ( /MULTI[ \t]*([^ \t\n]*)/)
	{
	    printf MULTITAB "$i $1\n";
	    $i++;
	}
	elsif ( /END/)
	{ last;}
	else
	{
	    print STDERR "error line $_";
	}
    }
    close(MULTITAB);
}
	
sub translate_font
{
    local($path) = @_;
    while(<FD>)
    {
	if ( /^#/) 
	    {loop;}  
	if ( /STYLE[ \t]*([^ \t\n]*)/)
	{
	    if ($1 eq "HBF")
	    { $ishbf = 1;}
	    else
	    { $ishbf = 0;}
	    last;
	}
        else		
	{
	    print STDERR "The first line of font block must be STYLE\n";
	}
    }
    open(FONT,">${path}kcfont");
    $has_ascii = 0;
    if ($ishbf)
	{print FONT "!!!HBF\n";}
    while(<FD>)
    {
	if ( /^\#/) {loop;}
	if ( /ASCII[ \t]*([^ \t]*)[ \t]*([0-9]*)[ \t]*([0-9]*)/)
	{
	    if ($has_ascii)
	    { print STDERR "Duplicte ASCII\n";}
	    else
	    {
		print FONT "$1 $2 $3\n";
	    }
	    $has_ascii = 1;
	}
	elsif( /CFONT[ \t]*([^ \t]*)[ \t]*([0-9]*)[ \t]*([0-9]*)/)
	{
	    if ($ishbf)
	    {loop;}
	    if ($has_ascii == 0)
	    { print STDERR "Must has ASCII before FONT\n";}
	    print FONT "$1 $2 $3\n";
	    $_ = <FD>;	
	    print FONT $_;	
	}
	elsif ( /HBF[ \t]*([^ \t\n]*)/)
	{
	    if ($ishbf) {print FONT "$1\n";}
	}			
	elsif ( /HBFPATH[ \t]*([^ \t\n]*)/)
	{
	    print EXEC "export CFONTDIR=$1\n";
	}
	elsif ( /PFONT([DKLM])[ \t]*([^ \t\n]*)/)
	{
	    if ($1 eq "L")
	    {system "ln -sf $2 cn24l.hbf";}
	    elsif ($1 eq "K")
	    {system "ln -sf $2 cn24k.hbf";}
	    elsif ($1 eq "M")
	    {system "ln -sf $2 cn24m.hbf";}
	    elsif ($1 eq "D")
	    {system "ln -sf $2 cn24j.hbf";}
	}
	elsif ( /END/)
	    {last;}
    }
    close(FONT);
}
	
sub translate_env
{
    local($path) = @_;
    open(PRO,">${path}ch_profile");
    while(<FD>)
    {
	if (/END/)
	{last;}
	print PRO $_;
    }
    close(PRO);
    chmod(755,"${path}ch_profile");
}

sub translate_other
{
    while(<FD>)
    {
	if (/^\s*#/) { next;}
	if (/ETMODE\s*(\w*)/)
	{
	    if ($1 == "on") { print DAT "ETMODE = on";}
	    elsif ($1 == "off") { print DAT "ETMODE = off";}
	    else { print stderr "ETMODE invalid\n";}
	}
	elsif (/GRDR\s*(\w*)/)
	{
	    print DAT "GRDR=$1\n";
	}
	elsif (/VT\s*(\w*)/)
	{
	    print DAT "VT=$1\n";
	}
	elsif (/BLANK_TIME\s*([0-9]*)/)
	{
	    print stderr "feature not implement now\n";
	    print DAT "BLANK_TIME=$1\n";
	}
	elsif (/LOGINPROGRAM\s*([^\n]*)/)
	{
	    print DAT "LOGINPROGRAM=$1\n";
	}
	elsif (/END/)
	{
	    last;
	}
	else
	{
	    print stderr "error command : $_\n";
	}
    }
}