-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContext.pm
166 lines (139 loc) · 3.42 KB
/
Context.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
=head1 NAME
Remark::Context - Description
=head1 SYNOPSIS
use Remark::Context;
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: Context.pm,v 1.3 2003/08/09 14:49:54 attila Exp $
Time-stamp: <2011-08-25 23:20:38 [email protected]>
=cut
package Remark::Context;
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 try_file {
my($dir,$fn) = @_;
my $ffn = qq{$dir/$fn};
return $ffn if -f $ffn;
return undef;
}
sub find_map_file {
my $self = shift(@_);
my $name = shift(@_);
my $fname = $name . '.rmap';
my $f = try_file('./.remark', $fname);
$f ||= try_file('.', '.' . $fname);
$f ||= try_file($ENV{'HOME'} . '/.remark', $fname);
$f ||= try_file($ENV{'HOME'}, '.' . $fname);
return $f;
}
sub read_map_file {
my $self = shift(@_);
my($map,$file) = @_;
open(MAP, "< $file") || die qq{could not open map file "$file": $!\n};
$self->printv(1,qq{[Loading map: $file]});
my($nlines,$nents) = (0,0);
while (<MAP>) {
chomp;
++$nlines;
next if /^\#/;
next if /^\s*$/;
next unless /^(\S.*)\s=>\s(.*)$/;
my($key,$val) = ($1,$2);
$key = psychochomp($key);
next unless length $key;
$val = psychochomp($val);
if (!length($val)) {
mapdel($map,$key);
} else {
mapadd($map,$key,$val);
}
++$nents;
}
close(MAP);
$self->printv(1,qq{[Loaded map $file: $nents entries in $nlines lines]});
}
sub get_merged_map {
my $self = shift(@_);
my $mapname = shift(@_);
my $map;
if (defined($self->{MAPS}->{$mapname})) {
$map = $self->{MAPS}->{$mapname};
} else {
$map = mapclone($mapname);
my $mapfile = $self->find_map_file($mapname);
$self->read_map_file($map, $mapfile) if defined $mapfile;
$self->{MAPS}->{$mapname} = $map;
}
return $map;
}
sub get_wigglemap {
my $self = shift(@_);
return $self->get_merged_map('wiggle');
}
sub get_eltmap {
my $self = shift(@_);
return $self->get_merged_map('elt');
}
sub printv {
my $self = shift(@_);
my $level = shift(@_);
return undef unless $self->{VERBOSE} >= $level;
print STDERR "@_\n";
}
sub init_graphy_stuff {
}
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
my $self =
{ VERBOSE => $args{'verbosity'},
Type => $args{'type'},
OutputRevisionLog => $args{'revision_log'},
OutputUn => $args{'unnamed'},
Dots => $args{'dots'},
FormatParas => $args{'format_paras'},
SideMaterial => $args{'side_material'},
NoPreface => $args{'no_preface'},
MAX_BULLET_WORDS => $args{'max_bullet_words'} || $MAX_BULLET_WORDS,
P => $args{'program'} || $main::P,
VERSION => $args{'version'} || $main::VERSION,
MAPS => {},
DTD => "-//OASIS//DTD DocBook V4.2//EN",
DTD_URL => "http://docbook.org/xml/4.2/docbookx.dtd",
ROOT_ELT => "book",
};
bless($self, $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:
##