Index: app/src/dgp/dgc
===================================================================
--- app/src/dgp/dgc	(revision 0214596e4d70b25df913a24f19d50cb0f1b4a69f)
+++ app/src/dgp/dgc	(revision 19dfa5cb763e0eab77888cefb54245f0e847cb94)
@@ -6,11 +6,18 @@
 #author:	Tomasz Obrebski
 
+# wymaga niejawnie programu canonize!!!!
 #use lib "ENV{HOME}/.utt/lib/perl";
-#use strict;
+
+use strict;
 use Getopt::Long;
 use Data::Dumper;
 
 use attr;
-#use File::HomeDir;
+use File::HomeDir;
+
+my $systemconfigfile='/usr/local/etc/utt/dgc.conf';
+my $userconfigfile=home()."/.utt/dgc.conf";
+
+Getopt::Long::Configure('no_ignore_case_always');
 
 my $help=0;
@@ -18,4 +25,62 @@
 my $dicfile=0;
 my $gramfile=0;
+my $outputfile=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 "catfile")or($name eq "c")){
+                        $catfile=$value;
+                }
+                elsif(($name eq "dicfile")or($name eq "d")){
+                        $dicfile=$value;
+                }
+                elsif(($name eq "gramfile")or($name eq "g")){
+                        $gramfile=$value;
+                }
+                elsif(($name eq "outputfile")or($name eq "o")){
+                        $outputfile=$value;
+                }
+                elsif(($name eq "help")or($name eq "h")){
+                        $help=1;
+                }
+
+        }
+        close CONFIG;
+  }
+}
+#########################################################
+
+GetOptions("help|h" => \$help,
+	   "catfile|c=s" => \$catfile,
+	   "dicfile|d=s" => \$dicfile,
+	   "gramfile|g=s" => \$gramfile,
+	   "outputfile|o=s" => \$outputfile);
+
+if($help)
+{
+    print <<'END'
+Usage: dgc [OPTIONS]
+
+Options:
+   --catfile -c filename	List of syntactic categories.
+   --dicfile -d filename        Dictionary.
+   --gramfile -g filename	List of grammar rules.
+   --outputfile -o filename	Output filename.
+   --help -h			Help.
+END
+;
+    exit 0;
+}
+
+die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile;
 
 my $ncat=0;
@@ -27,25 +92,4 @@
 my $nlink=0;
 
-GetOptions("help|h" => \$help,
-	   "catfile|c=s" => \$catfile,
-	   "dicfile|d=s" => \$dicfile,
-	   "gramfile|g=s" => \$gramfile);
-
-if($help)
-{
-    print <<'END'
-Usage: dgpcompile [OPTIONS]
-
-Options:
-   --cats -c filename		List of syntactic categories.
-   --dic  -d filename           Dictionary.
-   --help -h			Help.
-END
-;
-    exit 0;
-}
-
-die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile;
-
 my %cats;
 my %roles;
@@ -53,14 +97,37 @@
 my %gov;
 
+if(!$outputfile) {
+	*OUTPUT = *STDOUT;
+}
+elsif($outputfile eq "-") {
+    *OUTPUT = *STDOUT;
+}
+else {
+	open(OUTPUT, ">$outputfile") or die("Can't open output file: $outputfile!");
+}
+
+
+
 loadcats($catfile) if $catfile;
 extractcats($dicfile) if $dicfile;
 
 
-$cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/;
+my $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/;
 
 # class parse_class:
 # /$attr::cat_re/g;
 
-while(<>)
+
+if(!$gramfile) { 
+	*INPUT = *STDIN;
+}
+elsif($gramfile eq "-"){
+    *INPUT = *STDIN;
+}
+else {
+	open(INPUT, $gramfile) or die("Unable to open: $gramfile!");
+}
+
+while(<INPUT>)
 {
     if(/^\s*AGR\s+(\S+)\s+(\S+)\s*$/)
@@ -75,14 +142,14 @@
     {
 	$roles{$_}=1;
-	print;
+	print OUTPUT;
     }
     elsif(/^\s*SGL\s+\S+\s*$/)
     {
 	++$nsgl;
-	print;
+	print OUTPUT;
     }
     elsif(/^\s*REQ\s+(\S+)\s+(\S+)\s*$/)
     {
-	print "#$_";
+	print OUTPUT "#$_";
 	my $cat = attr::parse $1;
 	for my $atomcat (keys %cats)
@@ -90,5 +157,5 @@
 	    if(attr::match @$cat, @{$cats{$atomcat}})
 	    {
-		print "REQ ".$atomcat." $2\n";
+		print OUTPUT "REQ ".$atomcat." $2\n";
 		++$nreq;
 	    }
@@ -98,17 +165,17 @@
     {
 	++$nleft;
-	print;
+	print OUTPUT;
     }
     elsif(/^\s*RIGHT\s+\S+\s*$/)
     {
 	++$nright;
-	print;
-    }
-    elsif(($hs,$ds,$r) = /^\s*LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s*$/)
-    {
-	print "#$_";
-	for $h ($hs =~ /$attr::cat_re/g)
-	{
-	    for $d ($ds =~ /$attr::cat_re/g)
+	print OUTPUT;
+    }
+    elsif(my ($hs,$ds,$r) = /^\s*LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s*$/)
+    {
+	print OUTPUT "#$_";
+	for my $h ($hs =~ /$attr::cat_re/g)
+	{
+	    for my $d ($ds =~ /$attr::cat_re/g)
 	    {
 		addlinks($h,$d,$r);
@@ -119,5 +186,5 @@
     else
     {
-	print;
+	print OUTPUT;
     }
 }
@@ -126,8 +193,8 @@
 sub addlinks
 {
-    ($h,$d,$r) = @_;
-
-    for my $a (@{$agr{$r}}) { print "#AGR $r $a\n"; }
-    for my $c (@{$gov{$r}}) { print "#GOV $r ".attr::unparse(@$c)."\n"; }
+    my ($h,$d,$r) = @_;
+
+    for my $a (@{$agr{$r}}) { print OUTPUT "#AGR $r $a\n"; }
+    for my $c (@{$gov{$r}}) { print OUTPUT "#GOV $r ".attr::unparse(@$c)."\n"; }
     my $head = attr::parse $h;
     my $dep = attr::parse $d;
@@ -152,7 +219,7 @@
 		}
 		
-		print "LINK ";
-		print $atomhead." ";
-		print $atomdep." $r\n";
+		print OUTPUT "LINK ";
+		print OUTPUT $atomhead." ";
+		print OUTPUT $atomdep." $r\n";
 		++$nlink;
 		
@@ -180,8 +247,8 @@
 	while(/,([^[:space:];]+)/g)
 	{
-	    $cat=$1;
+	    my $cat=$1;
 	    next if !$cat || exists $cats{$cat};
 	    $ncat++;
-	    print "CAT $1\n";
+	    print OUTPUT "CAT $1\n";
 	    $cats{$cat}=attr::parse($cat);
 	}
@@ -199,5 +266,5 @@
 	tr/ \t\n//d;
 	next if !$_ || exists $cats{$_};
-	print "CAT $_\n";
+	print OUTPUT "CAT $_\n";
 	++$ncat;
 	$cats{$_}=attr::parse($_);
@@ -205,2 +272,3 @@
     close CATFILE;
 }
+
