source: app/src/tok/tok @ 246900a

help
Last change on this file since 246900a was 246900a, checked in by pawelk <pawelk@…>, 19 years ago

Przejrzałem kody programów pod kątem korzystania z plików konfiguracyjnych.

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

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#!/usr/bin/perl
2
3use locale;
4use Getopt::Long;
5
6my $interactive=0;
7my $help;
8
9my $systemconfigfile='/usr/local/etc/utt/tok.conf';
10my $userconfigfile="$ENV{'HOME'}/.utt/tok.conf";
11
12#read configuration files###########################
13my $file;
14foreach $file ($systemconfigfile, $userconfigfile){
15        if(open(CONFIG, $configfile1)){
16                while (<CONFIG>) {
17                        chomp;
18                        s/#.*//;
19                        s/^\s+//;
20                        s/\s+$//;
21                        next unless length;
22                        my ($name, $value) = split(/\s*=\s*/, $_, 2);
23                        if(($name eq "interactive")or($name eq "i")){
24                                $interactive=1;
25                        }
26                        elsif(($name eq "help")or($name eq "h")){
27                                $help=1;
28                        }
29                }
30                close CONFIG;
31        }
32}
33#########################################################s
34
35GetOptions("interactive|i" => \$interactive,
36           "help|h" => \$help);
37
38if($help)
39{
40    print <<'END'
41Usage: tok [OPTIONS]
42
43Options:
44   --interactive                Interactive (no output buffering).
45   --help -h                    Help.
46END
47;
48    exit 0;
49}
50
51
52$| = $interactive;
53
54my $offset = 0;
55
56while(<>)
57{
58    1 while
59        / [[:alpha:]]+   (?{seg('W',$&)})
60        | \d+            (?{seg('N',$&)})
61        | \s+            (?{seg('S',$&)})
62        | [[:punct:]]    (?{seg('P',$&)})
63        | .              (?{seg('B',$&)})
64        /gxo;
65}
66
67#       | [^[:print:]]   (?{seg("B",$&)})
68
69
70sub seg
71{
72    my ($tag,$match) = @_;
73    my $len=length $match;
74    printf "%04d %02d %s ", $offset, $len, $tag;
75    if($tag eq 'S')
76    {
77        for(my $i=0; $i<$len; ++$i)
78        {
79            my $c = substr $match, $i, 1;
80            print '_' if $c eq ' ';
81            print '\n' if $c eq "\n";
82            print '\t' if $c eq "\t";
83            print '\r' if $c eq "\r";
84            print '\f' if $c eq "\f";
85        }
86    }
87    elsif($tag eq 'B')
88    {
89        printf "\\x%02X", ord($match);
90    }
91    else
92    {
93        print $match;
94    }
95    print "\n";
96    $offset += $len;
97}
Note: See TracBrowser for help on using the repository browser.