-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPar.pm
186 lines (168 loc) · 4.16 KB
/
Par.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
=head1 NAME
Remark::Par - Description
=head1 SYNOPSIS
use Remark::Par;
blah;
=head1 DESCRIPTION
Describe the module.
=head1 AUTHOR
attila <[email protected]>
=head1 COPYRIGHT AND LICENSE
(C) 2002-2003 by attila <[email protected]>. all rights reserved.
=head1 VERSION
$Id: Par.pm,v 1.5 2003/08/09 14:49:58 attila Exp $
Time-stamp: <2003-08-09 10:38:00 EDT>
=cut
package Remark::Par;
use strict;
use Carp;
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUGGING $TESTING);
$VERSION = q{0.1.0};
@ISA = qw(Exporter);
@EXPORT_OK = qw();
@EXPORT = @EXPORT_OK;
$DEBUGGING = 0;
$TESTING = 0;
use Remark::Utils;
=head1 DETAILED DOCUMENTATION
This class exports the following interface:
=head2 new [args=>vals]
=cut
sub count_words {
return scalar((split(/[\s\.\,]+/, shift(@_))));
}
##
sub add_line {
my $self = shift(@_);
my $line = shift(@_);
return unless $line;
my $nw = count_words($line);
push(@{$self->{lines}}, $line);
$self->{nwords} += $nw;
print STDERR "[P<",$self->{name},"> added $nw words (",
scalar(@{$self->{lines}}),")]\n"
if ($self->{context}->{VERBOSE} > 2);
return $self;
}
##
sub append_line {
my $self = shift(@_);
my $text = shift(@_);
return unless $text;
if (!scalar(@{$self->{lines}})) {
print STDERR "[P- append_line to empty para]\n" if ($self->{context}->{VERBOSE} > 2);
push @{$self->{lines}}, "";
}
my $last_line = pop @{$self->{lines}};
$text =~ s/^\s+//;
my $nw = count_words($text);
$last_line .= " $text";
push @{$self->{lines}}, $last_line;
$self->{nwords} += $nw;
print STDERR "[P+<",$self->{name},"> added $nw words to last line (",
scalar(@{$self->{lines}}),")]\n" if ($self->{context}->{VERBOSE} > 2);
return $self;
}
##
sub get_wigglemap {
my $self = shift(@_);
return $self->{context}->get_wigglemap();
}
##
sub get_eltmap {
my $self = shift(@_);
return $self->{context}->get_eltmap();
}
##
sub output_docbook {
my $self = shift(@_);
my $level = shift(@_);
my $ostream = shift(@_);
my $i = indent($level);
my $wigmap = $self->get_wigglemap();
my $eltmap = $self->get_eltmap();
my $n;
if (!$self->marked("revision_log")) {
print $ostream "$i<para>\n";
my $fmtme = $self->{context}->{FormatParas} && !$self->marked("nofmt");
if ($fmtme) {
my($p,$tmpfile) = ($self->{context}->{P},$self->{context}->{TEMPFILE});
open(TMP,"|fmt >$tmpfile") || die "$p: fmt: $!\n";
}
print STDERR "." if $self->{context}->{Dots};
my $paratext = "$i ".join("\n$i ",@{$self->{lines}})."\n";
$paratext =~ s/^\s+//;
$paratext =~ s/\s+$//;
$paratext = wiggle($paratext,$wigmap);
$paratext = eltify($paratext,$eltmap);
$paratext =~ s/\[\[([^\]]+)\]\]/<comment>$1<\/comment>/gs;
$paratext =~ s/\{\{([^\}]+)\}\}/<!-- $1 -->/gs; # comments
print STDERR ">>$i $paratext\n" if ($self->{context}->{VERBOSE} > 3);
if (!$fmtme) {
print $ostream "$i $paratext\n";
} else {
print TMP "$i $paratext\n";
}
if ($fmtme) {
close(TMP);
my($p,$tmpfile) = ($self->{context}->{P},$self->{context}->{TEMPFILE});
open(TMP,"< $tmpfile") || die "$p: reopening $tmpfile: $!\n";
while (<TMP>) {
print $ostream $_;
}
close(TMP);
unlink($tmpfile);
}
print $ostream "$i</para>\n";
$n = 1;
} elsif ($self->{context}->{OutputRevisionLog}) {
print $ostream join("\n",map{"$i<!-- $_ -->"} @{$self->{lines}}),"\n";
$n = 1;
} else {
$n = 0;
}
return $n;
}
##
sub mark {
my $self = shift(@_);
foreach my $m (@_) {
$self->{marks}->{$m}++;
}
}
##
sub marked {
my $self = shift(@_);
my $what = shift(@_);
return 0 unless $what;
return defined($self->{marks}->{$what})? 1: 0;
}
##
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
my $name = $args{name} || "noname Par";
my $self =
bless
{ name => psychochomp($name),
lines => [],
nwords => 0,
marks => {},
context => $args{context},
}, $class;
return $self;
}
##
1;
__END__
##
# Local variables:
# tab-width: 2
# perl-indent-level: 2
# indent-tabs-mode: nil
# comment-column: 40
# time-stamp-line-limit: 40
# End:
##