Index: app/src/mar/mar
===================================================================
--- app/src/mar/mar	(revision 20b4e44e7537762f6aceb72b039f6e8f8a50e201)
+++ app/src/mar/mar	(revision 756213194ab50cc6e0ef6edfb9065ff3219f5372)
@@ -13,6 +13,12 @@
 use strict;
 use Getopt::Long;
+use File::HomeDir;
 
 use attr;
+
+
+my $LIB_DIR="/usr/local/lib/utt";
+my $systemconfigfile='/usr/local/etc/utt/mar.conf';
+my $userconfigfile=home()."/.utt/mar.conf";
 
 Getopt::Long::Configure('no_ignore_case_always');
@@ -26,61 +32,51 @@
 my $eos="seg(EOS)";
 my $explicit_space=0;
-
-#this is our help function to  cut the re to get another tag
-#it takes only one argument which is our patern (after m4 processing)
-#returns: the first root-level brace with content
-sub cutRe
-{
- my $i = 0;
- my $level = 0;
- my $text = $_[0];
- my $temp;
- for( $i =0; $i < (length $text);$i++)
- {
-	 $temp = substr($text, $i,1);
-	 if( $temp eq "(")
-	 {#we have an opening
-		 $level++;
-	 }
-	 elsif ( $temp eq ")")
-	 {#we close
-		 $level--;
-	 }
-	 if ( $level == 0)
-	 { 
-		$temp  = substr($text,0,$i+1);
-		last;
-	 }
- }
- $temp;
-}
-
-#the same function as above althought it returns everything after the
-#first root level brace
-sub restRe
-{
- my $i = 0;
- my $level = 0;
- my $text = $_[0];
- my $temp;
- for( $i =0; $i < (length $text);$i++)
- {
-	 $temp = substr($text, $i,1);
-	 if( $temp eq "(")
-	 {#we have an opening
-		 $level++;
-	 }
-	 elsif ( $temp eq ")")
-	 {#we close
-		 $level--;
-	 }
-	 if ( $level == 0)
-	 { #we cut everything in the begining
-		$temp  = substr($text,$i+1);
-		last;
-	 }
- }
- $temp;
-}
+my $morfield='lem';
+my $tags=0;
+
+#read configuration files###########################
+my $file;
+foreach $file ($systemconfigfile, $userconfigfile){
+  if(open(CONFIG, $file)){
+  	while (<CONFIG>) {
+  		chomp;                  
+      		s/#.*//;                
+	      	s/^\s+//;               
+      		s/\s+$//;               
+    		next unless length;     
+    		my ($name, $value) = split(/\s*=\s*/, $_, 2);
+    		if(($name eq "pattern")or($name eq "e")){
+			$pattern=$value;
+    		}
+    		elsif($name eq "eos"){
+			$eos=$value;
+    		}
+    		elsif($name eq "macros"){
+			$macrofile=$value;
+    		}
+    		elsif($name eq "tags"){
+    			$tags=$value;
+    		}
+    		elsif($name eq "morph"){
+			$morfield=$value;
+    		}
+    		elsif($name eq "command"){
+			$command=1;
+    		}
+    		elsif($name eq "action"){
+			$action=$value;
+    		}
+    		elsif($name eq "space"){
+			$explicit_space=1;
+    		}
+    		elsif(($name eq "help")or($name eq "h")){
+			$help=1;
+    		}
+    	
+	} 
+  	close CONFIG;
+  }
+}
+#########################################################
 
 GetOptions("pattern|e=s" => \$pattern,
@@ -93,4 +89,7 @@
 	   "space|s" => \$explicit_space
    );
+
+
+
 
 if($help)
@@ -141,9 +140,70 @@
 die("$0: no pattern given. Run with -h to get help.\n") unless $pattern || $action !~ /g/;
 
-die("$0: macro file not found") unless -e "terms.m4" and $macrofile="terms.m4";
+die("$0: macro file not found") unless
+    $macrofile or
+    -e "$LIB_DIR/terms.m4" and $macrofile="$LIB_DIR/terms.m4";
 
 my $preproc    = ($action =~ /p/) ? ' fla  | '  : '';
 
 my $postproc   = ($action =~ /P/) ? ' | unfla '  : '';
+
+
+#this is our help function to  cut the re to get another tag
+#it takes only one argument which is our patern (after m4 processing)
+#returns: the first root-level brace with content
+sub cutRe
+{
+ my $i = 0;
+ my $level = 0;
+ my $text = $_[0];
+ my $temp;
+ for( $i =0; $i < (length $text);$i++)
+ {
+	 $temp = substr($text, $i,1);
+	 if( $temp eq "(")
+	 {#we have an opening
+		 $level++;
+	 }
+	 elsif ( $temp eq ")")
+	 {#we close
+		 $level--;
+	 }
+	 if ( $level == 0)
+	 { 
+		$temp  = substr($text,0,$i+1);
+		last;
+	 }
+ }
+ $temp;
+}
+
+#the same function as above althought it returns everything after the
+#first root level brace
+sub restRe
+{
+ my $i = 0;
+ my $level = 0;
+ my $text = $_[0];
+ my $temp;
+ for( $i =0; $i < (length $text);$i++)
+ {
+	 $temp = substr($text, $i,1);
+	 if( $temp eq "(")
+	 {#we have an opening
+		 $level++;
+	 }
+	 elsif ( $temp eq ")")
+	 {#we close
+		 $level--;
+	 }
+	 if ( $level == 0)
+	 { #we cut everything in the begining
+		$temp  = substr($text,$i+1);
+		last;
+	 }
+ }
+ $temp;
+}
+
 
 #here we are preparing re for extended matching
@@ -186,5 +246,6 @@
 $patternmod =~ s/(\{\d*),(\d*\})/\1\\`\\`,''\2/g;
 #print "After m4:".$re."\n";
-my $re = `echo \"$patternmod\" | m4 --define=ENDOFSEGMENT='[[:cntrl:]]' $macrofile - 2>/dev/null`;
+
+my $re = `echo \"$patternmod\" | m4 --define=ENDOFSEGMENT='[[:cntrl:]]' --define=MORFIELD=$morfield $macrofile - 2>/dev/null`;
 
 die("Incorrect pattern (m4).") if $? >> 8;
@@ -195,5 +256,5 @@
 # <> expansion
 
-$re =~ s/<([^>]+)>/`echo $1 | .\/terms\.tag2re`/ge;
+$re =~ s/<([^>]+)>/`echo $1 | $tags.tag2re`/ge;
 
 # Perl-like special sequences
