Dolozylismy obsluge plikow konfiguracyjnych.

Dziala.



git-svn-id: svn://atos.wmid.amu.edu.pl/utt@5 e293616e-ec6a-49c2-aa92-f4a8b91c5d16
This commit is contained in:
obrebski 2008-03-11 13:56:13 +00:00
parent 25ae32e4c2
commit 754d2a3af4

View File

@ -6,9 +6,12 @@
use strict;
use Getopt::Long;
use File::Temp;
my $SHARE_DIR="/usr/share/utt";
my $USER_DIR="$ENV{HOME}/.utt/share";
my $LIB_DIR="/usr/local/lib/utt";
my $systemconfigfile='/usr/local/etc/utt/ser.conf';
my $userconfigfile="$ENV{'HOME'}/.utt/ser.conf";
#use lib "$ENV{HOME}/.utt/lib/perl";
#use attr;
@ -24,12 +27,9 @@ my $flextemplate=0;
my $flex=0;
my $morfield='lem';
my $configfile1="../../conf/ser.conf";
my $configfile2="../conf/ser.conf";
#read configuration files###########################
my $file;
foreach $file ($configfile1, $configfile2){
foreach $file ($systemconfigfile, $userconfigfile){
if(open(CONFIG, $file)){
while (<CONFIG>) {
chomp;
@ -50,7 +50,7 @@ foreach $file ($configfile1, $configfile2){
elsif(($name eq "no-markers")or($name eq "M")){
$no_markers=1;
}
elsif($name eq "define"){
elsif($name eq "macros"){
$macros=$value;
}
elsif($name eq "flex-template"){
@ -73,7 +73,7 @@ GetOptions("pattern|e=s" => \$pattern,
"morph=s" => \$morfield,
"only-matching|m" => \$only_matching,
"no-markers|M" => \$no_markers,
"define=s" => \$macros,
"macros=s" => \$macros,
"flex-template=s" => \$flextemplate,
"flex" => \$flex,
"help|h" => \$help);
@ -87,7 +87,7 @@ Options:
--help -h Help.
--pattern=PATTERN -e PATTERN Search pattern.
--morph=STRING Field containing morphological information (default 'lem').
--define=FILE Read macrodefinitions from FILE.
--macros=FILE Read macrodefinitions from FILE.
--flex-template=FILE Read flex code template from FILE.
--only-matching -m Print only fragments matching PATTERN.
--no-markers -M Do not print BOM and EOM markers [TODO].
@ -101,13 +101,11 @@ die("$0: no pattern given.\n") unless $pattern;
die("$0: flex template file not found") unless
$flextemplate or
-e "$USER_DIR/ser.l.template" and $flextemplate="$USER_DIR/ser.l.template" or
-e "$SHARE_DIR/ser.l.template" and $flextemplate="$SHARE_DIR/ser.l.template";
-e "$LIB_DIR/ser.l.template" and $flextemplate="$LIB_DIR/ser.l.template";
die("$0: macro file not found") unless
$macros or
-e "$USER_DIR/terms.m4" and $macros="$USER_DIR/terms.m4" or
-e "$SHARE_DIR/terms.m4" and $macros="$SHARE_DIR/terms.m4";
-e "$LIB_DIR/terms.m4" and $macros="$LIB_DIR/terms.m4";
#$pattern =~ s/cat\(([^)]+)\)/'cat('.pre($1).')'/ge;
@ -120,6 +118,7 @@ $pattern =~ s/\\/\\\\\\/g;
# discarding spaces
$pattern =~ s/\s+/\\`'/g; #`
my $flexpattern = `echo \"$pattern\" | m4 --define=ENDOFSEGMENT=\\\\n --define=MORFIELD=$morfield $macros - 2>/dev/null`;
die("Incorrect pattern (m4).") if $? >> 8;
@ -152,17 +151,22 @@ my $defaultaction = ($only_matching) ? '' : 'ECHO';
# docelowo posrednie pliki powinny byc w jakims tempie !!!
system "m4 \"--define=PATTERN=$flexpattern\" \"--define=DEFAULTACTION=$defaultaction\" $flextemplate > $USER_DIR/ser.l";
(undef, my $tmpfile_l) = File::Temp::tempfile(SUFFIX=>'.l');
(undef, my $tmpfile_c) = File::Temp::tempfile(SUFFIX=>'.c');
(undef, my $tmpfile_x) = File::Temp::tempfile();
system "m4 \"--define=PATTERN=$flexpattern\" \"--define=DEFAULTACTION=$defaultaction\" $flextemplate > $tmpfile_l";
if($flex)
{
system "cat $USER_DIR/ser.l";
system "cat $tmpfile_l";
exit 0;
}
system "flex -o$USER_DIR/ser.c $USER_DIR/ser.l";
system "cc -O3 -o $USER_DIR/ser.executable $USER_DIR/ser.c -lfl";
system "$USER_DIR/ser.executable";
system "flex -o$tmpfile_c $tmpfile_l";
system "cc -O3 -o $tmpfile_x $tmpfile_c -lfl";
system "$tmpfile_x";
system "rm -f $USER_DIR/ser.{l,c,executable}";
system "rm -f $tmpfile_l $tmpfile_c $tmpfile_x";