source: src/kot.pl @ 3a2ae91

Last change on this file since 3a2ae91 was 3a2ae91, checked in by Mateusz Hromada <ruanda@…>, 15 years ago

Migration to new build system.

  • kot moved and checked
  • Property mode set to 100644
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2
3#package:       UAM Text Tools
4#component:     kot
5#version:       1.0
6#author:        Tomasz Obrebski
7
8use strict;
9use Getopt::Long;
10use File::HomeDir;
11
12my $help=0;
13my $gap_fill="\n-----\n";
14my $spaces=0;
15
16my $systemconfigfile='/usr/local/etc/utt/kot.conf';
17#my $userconfigfile="$ENV{'HOME'}/.utt/kot.conf";
18my $userconfigfile=home()."/.utt/kot.conf";
19
20#read configuration files###########################
21my $file;
22foreach $file ($systemconfigfile, $userconfigfile){
23  if(open(CONFIG, $file)){
24        while (<CONFIG>) {
25                chomp;
26                s/#.*//;
27                s/^\s+//;
28                s/\s+$//;
29                next unless length;
30                my ($name, $value) = split(/\s*=\s*/, $_, 2);
31                if(($name eq "gap-fill")or($name eq "g")){
32                        $gap_fill=$value;
33                }
34                elsif(($name eq "spaces")or($name eq "s")){
35                        $spaces=1;
36                }
37                elsif(($name eq "help")or($name eq "h")){
38                        $help=1;
39                }
40
41        }
42        close CONFIG;
43  }
44}
45#########################################################
46
47GetOptions("gap-fill|g=s" => \$gap_fill,
48           "spaces|r" => \$spaces,
49           "help|h" => \$help);
50
51if($help)
52{
53    print <<'END'
54Usage: ser [OPTIONS] [file ..]
55
56Options:
57   --gap-fill -g                  Help.
58   --spaces -r
59   --define=FILE                  Read macrodefinitions from FILE.
60   --flex-template=FILE           Read flex code template from FILE.
61   --only-matching -m             Print only fragments matching PATTERN.
62   --flex                         Print only the generated flex code and exit.
63END
64;
65    exit 0;
66}
67
68
69$gap_fill =~ s/\\t/\t/g;
70$gap_fill =~ s/\\n/\n/g;
71$gap_fill =~ s/\\r/\r/g;
72$gap_fill =~ s/\\f/\f/g;
73
74my $prevend=-1;
75my $count=0;
76
77while(<>)
78{
79    my ($start,$len,$type,$form) = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(\S+)/;
80
81    if($start > $prevend)
82    {
83        print $gap_fill unless $count++ == 0;
84    }
85
86    $prevend=$start+$len;
87
88    next if $len==0;# || $form eq "*";
89
90    $form =~ s/\\\*/*/g;
91
92    if($type eq 'S' && ! $spaces)
93    {
94        $form =~ s/_/ /g;
95        $form =~ s/\\t/\t/g;
96        $form =~ s/\\n/\n/g;
97        $form =~ s/\\r/\r/g;
98        $form =~ s/\\f/\f/g;
99    }
100
101    print $form;
102}
Note: See TracBrowser for help on using the repository browser.