Changeset 754d2a3 for app


Ignore:
Timestamp:
03/11/08 14:56:13 (16 years ago)
Author:
obrebski <obrebski@…>
Branches:
master, help
Children:
52bccea
Parents:
25ae32e
git-author:
obrebski <obrebski@…> (03/11/08 14:56:13)
git-committer:
obrebski <obrebski@…> (03/11/08 14:56:13)
Message:

Dolozylismy obsluge plikow konfiguracyjnych.
Dziala.

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@5 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/src/ser/ser

    r25ae32e r754d2a3  
    77use strict; 
    88use Getopt::Long; 
     9use File::Temp; 
    910 
    10 my $SHARE_DIR="/usr/share/utt"; 
    11 my $USER_DIR="$ENV{HOME}/.utt/share"; 
     11my $LIB_DIR="/usr/local/lib/utt"; 
     12 
     13my $systemconfigfile='/usr/local/etc/utt/ser.conf'; 
     14my $userconfigfile="$ENV{'HOME'}/.utt/ser.conf"; 
    1215 
    1316#use lib "$ENV{HOME}/.utt/lib/perl"; 
     
    2528my $morfield='lem'; 
    2629 
    27 my $configfile1="../../conf/ser.conf"; 
    28 my $configfile2="../conf/ser.conf"; 
    29  
    3030#read configuration files########################### 
    3131my $file; 
    32 foreach $file ($configfile1, $configfile2){ 
     32foreach $file ($systemconfigfile, $userconfigfile){ 
    3333  if(open(CONFIG, $file)){ 
    3434        while (<CONFIG>) { 
     
    5151                        $no_markers=1; 
    5252                } 
    53                 elsif($name eq "define"){ 
     53                elsif($name eq "macros"){ 
    5454                        $macros=$value; 
    5555                } 
     
    7474           "only-matching|m" => \$only_matching, 
    7575           "no-markers|M" => \$no_markers, 
    76            "define=s" => \$macros, 
     76           "macros=s" => \$macros, 
    7777           "flex-template=s" => \$flextemplate, 
    7878           "flex" => \$flex, 
     
    8888   --pattern=PATTERN -e PATTERN   Search pattern. 
    8989   --morph=STRING                 Field containing morphological information (default 'lem'). 
    90    --define=FILE                  Read macrodefinitions from FILE. 
     90   --macros=FILE                  Read macrodefinitions from FILE. 
    9191   --flex-template=FILE           Read flex code template from FILE. 
    9292   --only-matching -m             Print only fragments matching PATTERN. 
     
    102102die("$0: flex template file not found") unless 
    103103    $flextemplate or 
    104     -e "$USER_DIR/ser.l.template" and $flextemplate="$USER_DIR/ser.l.template" or 
    105     -e "$SHARE_DIR/ser.l.template" and $flextemplate="$SHARE_DIR/ser.l.template"; 
     104    -e "$LIB_DIR/ser.l.template" and $flextemplate="$LIB_DIR/ser.l.template"; 
    106105 
    107106die("$0: macro file not found") unless 
    108107    $macros or 
    109     -e "$USER_DIR/terms.m4" and $macros="$USER_DIR/terms.m4" or 
    110     -e "$SHARE_DIR/terms.m4" and $macros="$SHARE_DIR/terms.m4"; 
     108    -e "$LIB_DIR/terms.m4" and $macros="$LIB_DIR/terms.m4"; 
    111109 
    112110 
     
    120118# discarding spaces 
    121119$pattern =~ s/\s+/\\`'/g; #`  
     120 
    122121 
    123122my $flexpattern = `echo \"$pattern\" | m4 --define=ENDOFSEGMENT=\\\\n --define=MORFIELD=$morfield $macros - 2>/dev/null`; 
     
    153152# docelowo posrednie pliki powinny byc w jakims tempie !!! 
    154153 
    155 system "m4 \"--define=PATTERN=$flexpattern\" \"--define=DEFAULTACTION=$defaultaction\" $flextemplate > $USER_DIR/ser.l"; 
     154(undef, my $tmpfile_l) = File::Temp::tempfile(SUFFIX=>'.l'); 
     155(undef, my $tmpfile_c) = File::Temp::tempfile(SUFFIX=>'.c'); 
     156(undef, my $tmpfile_x) = File::Temp::tempfile(); 
     157 
     158 
     159system "m4 \"--define=PATTERN=$flexpattern\" \"--define=DEFAULTACTION=$defaultaction\" $flextemplate > $tmpfile_l"; 
    156160 
    157161if($flex) 
    158162{ 
    159     system "cat $USER_DIR/ser.l"; 
     163    system "cat $tmpfile_l"; 
    160164    exit 0; 
    161165} 
    162166 
    163 system "flex -o$USER_DIR/ser.c $USER_DIR/ser.l"; 
    164 system "cc -O3 -o $USER_DIR/ser.executable $USER_DIR/ser.c -lfl"; 
    165 system "$USER_DIR/ser.executable"; 
     167system "flex -o$tmpfile_c $tmpfile_l"; 
     168system "cc -O3 -o $tmpfile_x $tmpfile_c -lfl"; 
     169system "$tmpfile_x"; 
    166170 
    167 system "rm -f $USER_DIR/ser.{l,c,executable}"; 
     171system "rm -f $tmpfile_l $tmpfile_c $tmpfile_x"; 
    168172 
Note: See TracChangeset for help on using the changeset viewer.