line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# Made by Steven Rubin steven@ssrubin.com (April 2002)
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Text::Shortcuts;
|
5
|
|
|
|
|
|
|
$VERSION = 0.02;
|
6
|
1
|
|
|
1
|
|
194880
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
1294
|
use Text::xSV;
|
|
1
|
|
|
|
|
3734
|
|
|
1
|
|
|
|
|
660
|
|
8
|
|
|
|
|
|
|
sub new {
|
9
|
1
|
|
|
1
|
1
|
89
|
my $invocant = shift;
|
10
|
1
|
|
33
|
|
|
8
|
my $class = ref($invocant) || $invocant;
|
11
|
1
|
|
|
|
|
4
|
my $self = { SF => shift, OF => shift };
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
3
|
bless($self, $class);
|
14
|
1
|
50
|
|
|
|
25
|
unless (-s $self->{SF}) {
|
15
|
0
|
|
|
|
|
0
|
my $file = $self->{SF};
|
16
|
0
|
|
|
|
|
0
|
open(SF, ">>$file");
|
17
|
0
|
|
|
|
|
0
|
print SF "shortcut,output\n";
|
18
|
0
|
|
|
|
|
0
|
close(SF);
|
19
|
|
|
|
|
|
|
}
|
20
|
1
|
|
|
|
|
3
|
return $self;
|
21
|
|
|
|
|
|
|
}
|
22
|
|
|
|
|
|
|
sub set_shortcut {
|
23
|
1
|
|
|
1
|
1
|
36
|
my $self = shift;
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
2
|
my $is_taken=0;
|
26
|
1
|
|
|
|
|
2
|
my $char = shift;
|
27
|
1
|
|
|
|
|
2
|
my $text = shift;
|
28
|
1
|
|
|
|
|
8
|
my $csv = new Text::xSV;
|
29
|
1
|
|
|
|
|
100
|
$csv->open_file($self->{SF});
|
30
|
1
|
|
|
|
|
56
|
$csv->bind_header();
|
31
|
1
|
|
|
|
|
138
|
while ($csv->get_row()) {
|
32
|
2
|
|
|
|
|
555
|
my ($shortcut) = $csv->extract(qw(shortcut));
|
33
|
2
|
100
|
|
|
|
40
|
if ($char eq $shortcut) {
|
34
|
1
|
|
|
|
|
24
|
warn "Shortcut character already used!";
|
35
|
1
|
|
|
|
|
2
|
$is_taken=1;
|
36
|
1
|
|
|
|
|
2
|
last;
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
}
|
39
|
1
|
50
|
|
|
|
5
|
unless ($is_taken) {
|
40
|
0
|
|
|
|
|
0
|
my $file = $self->{SF};
|
41
|
0
|
|
|
|
|
0
|
open(SF, ">>$file");
|
42
|
0
|
|
|
|
|
0
|
print SF "$char,$text\n";
|
43
|
0
|
|
|
|
|
0
|
close(SF);
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
sub get_shortcuts {
|
47
|
0
|
|
|
0
|
1
|
0
|
my $self = shift;
|
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
my $csv = new Text::xSV;
|
50
|
0
|
|
|
|
|
0
|
$csv->open_file($self->{SF});
|
51
|
0
|
|
|
|
|
0
|
$csv->bind_header();
|
52
|
0
|
|
|
|
|
0
|
while ($csv->get_row()) {
|
53
|
0
|
|
|
|
|
0
|
my ($shortcut, $output) = $csv->extract(qw(shortcut output));
|
54
|
0
|
|
|
|
|
0
|
print "\[$shortcut\] produces $output\n";
|
55
|
|
|
|
|
|
|
}
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
sub new_doc {
|
58
|
0
|
|
|
0
|
1
|
0
|
my $self = shift;
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my $file = $self->{OF};
|
61
|
0
|
|
|
|
|
0
|
open(OF, ">>$file");
|
62
|
0
|
|
|
|
|
0
|
while (my $line = ) {
|
63
|
0
|
0
|
|
|
|
0
|
last if $line =~ /^(end)$/;
|
64
|
0
|
|
|
|
|
0
|
my %shortcuts;
|
65
|
0
|
|
|
|
|
0
|
my $csv = new Text::xSV;
|
66
|
0
|
|
|
|
|
0
|
$csv->open_file($self->{SF});
|
67
|
0
|
|
|
|
|
0
|
$csv->bind_header();
|
68
|
0
|
|
|
|
|
0
|
while ($csv->get_row()) {
|
69
|
0
|
|
|
|
|
0
|
my ($shortcut, $output) = $csv->extract(qw(shortcut output));
|
70
|
0
|
|
|
|
|
0
|
$shortcuts{$shortcut} = $output;
|
71
|
|
|
|
|
|
|
}
|
72
|
0
|
|
|
|
|
0
|
$line =~ s/\[(\w)\]+/$shortcuts{$1}/g;
|
73
|
0
|
|
|
|
|
0
|
print OF $line;
|
74
|
|
|
|
|
|
|
}
|
75
|
0
|
|
|
|
|
0
|
close(OF);
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
sub get_doc {
|
78
|
1
|
|
|
1
|
1
|
31
|
my $self = shift;
|
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
3
|
my $file = $self->{OF};
|
81
|
1
|
|
|
|
|
35
|
open(OF, "<$file");
|
82
|
1
|
|
|
|
|
28
|
while () {
|
83
|
1
|
|
|
|
|
24
|
print;
|
84
|
|
|
|
|
|
|
}
|
85
|
1
|
|
|
|
|
10
|
close(OF);
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
1;
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__
|