1 |
wakaba |
1.1 |
#!/usr/bin/perl -w |
2 |
|
|
use strict; |
3 |
|
|
use Message::Util::QName::Filter { |
4 |
wakaba |
1.2 |
c => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>, |
5 |
wakaba |
1.1 |
DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>, |
6 |
|
|
dis => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-->, |
7 |
|
|
dp => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#Perl/>, |
8 |
|
|
fe => q<http://suika.fam.cx/www/2006/feature/>, |
9 |
|
|
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
10 |
wakaba |
1.2 |
pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>, |
11 |
wakaba |
1.1 |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
12 |
|
|
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
13 |
|
|
}; |
14 |
|
|
|
15 |
wakaba |
1.15 |
our$VERSION=do{my @r=(q$Revision: 1.40 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
16 |
wakaba |
1.1 |
use Cwd; |
17 |
|
|
use Getopt::Long; |
18 |
|
|
use Pod::Usage; |
19 |
wakaba |
1.15 |
our %Opt = (create_module => []); |
20 |
wakaba |
1.14 |
my @target_modules; |
21 |
wakaba |
1.1 |
GetOptions ( |
22 |
wakaba |
1.14 |
'create-dtd-modules=s' => sub { |
23 |
|
|
shift; |
24 |
|
|
my $i = [split /\s+/, shift, 3]; |
25 |
|
|
$i->[3] = 'dtd-modules'; |
26 |
|
|
push @{$Opt{create_module}}, $i; |
27 |
|
|
}, |
28 |
wakaba |
1.1 |
'create-perl-module=s' => sub { |
29 |
|
|
shift; |
30 |
|
|
my $i = [split /\s+/, shift, 3]; |
31 |
wakaba |
1.2 |
$i->[3] = 'perl-pm'; |
32 |
|
|
push @{$Opt{create_module}}, $i; |
33 |
wakaba |
1.14 |
push @target_modules, [$i->[0], $i->[2]]; |
34 |
wakaba |
1.2 |
}, |
35 |
|
|
'create-perl-test=s' => sub { |
36 |
|
|
shift; |
37 |
|
|
my $i = [split /\s+/, shift, 3]; |
38 |
|
|
$i->[3] = 'perl-t'; |
39 |
wakaba |
1.1 |
push @{$Opt{create_module}}, $i; |
40 |
wakaba |
1.14 |
push @target_modules, [$i->[0], $i->[2]]; |
41 |
wakaba |
1.1 |
}, |
42 |
|
|
'debug' => \$Opt{debug}, |
43 |
|
|
'dis-file-suffix=s' => \$Opt{dis_suffix}, |
44 |
|
|
'daem-file-suffix=s' => \$Opt{daem_suffix}, |
45 |
wakaba |
1.11 |
'dafs-file-suffix=s' => \$Opt{dafs_suffix}, |
46 |
wakaba |
1.1 |
'dafx-file-suffix=s' => \$Opt{dafx_suffix}, |
47 |
|
|
'help' => \$Opt{help}, |
48 |
wakaba |
1.14 |
'load-module=s' => sub { |
49 |
|
|
shift; |
50 |
|
|
my $i = [split /\s+/, shift, 2]; |
51 |
|
|
push @target_modules, [$i->[0], $i->[1]]; |
52 |
|
|
}, |
53 |
wakaba |
1.15 |
'mod-file-suffix=s' => \$Opt{mod_suffix}, |
54 |
wakaba |
1.1 |
'search-path|I=s' => sub { |
55 |
|
|
shift; |
56 |
|
|
my @value = split /\s+/, shift; |
57 |
|
|
while (my ($ns, $path) = splice @value, 0, 2, ()) { |
58 |
|
|
unless (defined $path) { |
59 |
|
|
die qq[$0: Search-path parameter without path: "$ns"]; |
60 |
|
|
} |
61 |
|
|
push @{$Opt{input_search_path}->{$ns} ||= []}, $path; |
62 |
|
|
} |
63 |
|
|
}, |
64 |
|
|
'search-path-catalog-file-name=s' => sub { |
65 |
|
|
shift; |
66 |
|
|
require File::Spec; |
67 |
|
|
my $path = my $path_base = shift; |
68 |
|
|
$path_base =~ s#[^/]+$##; |
69 |
|
|
$Opt{search_path_base} = $path_base; |
70 |
|
|
open my $file, '<', $path or die "$0: $path: $!"; |
71 |
|
|
while (<$file>) { |
72 |
|
|
if (s/^\s*\@//) { ## Processing instruction |
73 |
|
|
my ($target, $data) = split /\s+/; |
74 |
|
|
if ($target eq 'base') { |
75 |
|
|
$Opt{search_path_base} = File::Spec->rel2abs ($data, $path_base); |
76 |
|
|
} else { |
77 |
|
|
die "$0: $target: Unknown target"; |
78 |
|
|
} |
79 |
|
|
} elsif (/^\s*\#/) { ## Comment |
80 |
|
|
# |
81 |
|
|
} elsif (/\S/) { ## Catalog entry |
82 |
|
|
s/^\s+//; |
83 |
|
|
my ($ns, $path) = split /\s+/; |
84 |
|
|
push @{$Opt{input_search_path}->{$ns} ||= []}, |
85 |
|
|
File::Spec->rel2abs ($path, $Opt{search_path_base}); |
86 |
|
|
} |
87 |
|
|
} |
88 |
|
|
## NOTE: File paths with SPACEs are not supported |
89 |
|
|
## NOTE: Future version might use file: URI instead of file path. |
90 |
|
|
}, |
91 |
|
|
'undef-check!' => \$Opt{no_undef_check}, |
92 |
|
|
'verbose!' => \$Opt{verbose}, |
93 |
|
|
) or pod2usage (2); |
94 |
|
|
pod2usage ({-exitval => 0, -verbose => 1}) if $Opt{help}; |
95 |
|
|
$Opt{no_undef_check} = defined $Opt{no_undef_check} |
96 |
|
|
? $Opt{no_undef_check} ? 0 : 1 : 0; |
97 |
|
|
$Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix}; |
98 |
|
|
$Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix}; |
99 |
|
|
$Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix}; |
100 |
wakaba |
1.11 |
$Opt{dafs_suffix} = '.dafs' unless defined $Opt{dafs_suffix}; |
101 |
wakaba |
1.15 |
$Opt{mod_suffix} = '.mod' unless defined $Opt{mod_suffix}; |
102 |
wakaba |
1.1 |
$Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; |
103 |
|
|
require Error; |
104 |
|
|
$Error::Debug = 1 if $Opt{debug}; |
105 |
|
|
$Message::Util::Error::VERBOSE = 1 if $Opt{verbose}; |
106 |
|
|
|
107 |
|
|
sub status_msg ($) { |
108 |
|
|
my $s = shift; |
109 |
|
|
$s .= "\n" unless $s =~ /\n$/; |
110 |
|
|
print STDERR $s; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
sub status_msg_ ($) { |
114 |
|
|
my $s = shift; |
115 |
|
|
print STDERR $s; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
sub verbose_msg ($) { |
119 |
|
|
my $s = shift; |
120 |
|
|
$s .= "\n" unless $s =~ /\n$/; |
121 |
|
|
print STDERR $s if $Opt{verbose}; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
sub verbose_msg_ ($) { |
125 |
|
|
my $s = shift; |
126 |
|
|
print STDERR $s if $Opt{verbose}; |
127 |
|
|
} |
128 |
|
|
|
129 |
wakaba |
1.2 |
## ---- The MAIN Program |
130 |
|
|
|
131 |
wakaba |
1.1 |
my $start_time; |
132 |
|
|
BEGIN { $start_time = time } |
133 |
|
|
|
134 |
|
|
use Message::Util::DIS::DNLite; |
135 |
wakaba |
1.5 |
|
136 |
|
|
my %feature; |
137 |
wakaba |
1.1 |
|
138 |
wakaba |
1.13 |
for (@{$Opt{create_module}}) { |
139 |
|
|
my (undef, undef, undef, $out_type) = @$_; |
140 |
|
|
|
141 |
|
|
if ($out_type eq 'perl-pm') { |
142 |
|
|
require 'manakai/daf-perl-pm.pl'; |
143 |
|
|
$feature{'+' . ExpandedURI q<Util:PerlCode>} = '1.0'; |
144 |
|
|
} elsif ($out_type eq 'perl-t') { |
145 |
|
|
require 'manakai/daf-perl-t.pl'; |
146 |
|
|
$feature{ExpandedURI q<fe:GenericLS>} = '3.0'; |
147 |
|
|
$feature{'+' . ExpandedURI q<DIS:TDT>} = '1.0'; |
148 |
|
|
$feature{'+' . ExpandedURI q<Util:PerlCode>} = '1.0'; |
149 |
wakaba |
1.14 |
} elsif ($out_type eq 'dtd-modules') { |
150 |
|
|
require 'manakai/daf-dtd-modules.pl'; |
151 |
|
|
$feature{ExpandedURI q<fe:GenericLS>} = '3.0'; |
152 |
|
|
$feature{'+' . ExpandedURI q<fe:XDP>} = '3.0'; |
153 |
wakaba |
1.13 |
} |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
our $limpl = $Message::DOM::ImplementationRegistry->get_implementation |
157 |
wakaba |
1.1 |
({ExpandedURI q<fe:Min> => '3.0', |
158 |
|
|
'+' . ExpandedURI q<DIS:DNLite> => '1.0', |
159 |
|
|
'+' . ExpandedURI q<DIS:Core> => '1.0', |
160 |
wakaba |
1.5 |
%feature, |
161 |
wakaba |
1.1 |
}); |
162 |
wakaba |
1.13 |
our $impl = $limpl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
163 |
wakaba |
1.2 |
|
164 |
|
|
## --- Loading and Updating the Database |
165 |
wakaba |
1.1 |
|
166 |
|
|
my $HasError; |
167 |
wakaba |
1.13 |
our $db = $impl->create_dis_database; |
168 |
wakaba |
1.1 |
$db->pl_database_module_resolver (\&daf_db_module_resolver); |
169 |
|
|
$db->dom_config->set_parameter ('error-handler' => \&daf_on_error); |
170 |
|
|
|
171 |
wakaba |
1.2 |
my $parser = $impl->create_dis_parser; |
172 |
|
|
my $DNi = $impl->get_feature (ExpandedURI q<DIS:DNLite> => '1.0'); |
173 |
wakaba |
1.1 |
my %ModuleSourceDISDocument; |
174 |
|
|
my %ModuleSourceDNLDocument; |
175 |
|
|
my %ModuleNameNamespaceBinding = ( |
176 |
|
|
DISCore => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Core#>, |
177 |
|
|
## This builtin binding is required since |
178 |
|
|
## some module has |DISCore:author| property before |dis:Require| |
179 |
|
|
## property. |
180 |
|
|
); |
181 |
|
|
|
182 |
|
|
my $ResourceCount = 0; |
183 |
|
|
$db->pl_update_module (\@target_modules, |
184 |
|
|
get_module_index_file_name => sub { |
185 |
|
|
shift; # $db |
186 |
|
|
daf_get_module_index_file_name (@_); |
187 |
|
|
}, |
188 |
|
|
get_module_source_document_from_uri => sub { |
189 |
|
|
my ($db, $module_uri, $module_for) = @_; |
190 |
|
|
status_msg ''; |
191 |
|
|
status_msg qq<Loading module <$module_uri> for <$module_for>...>; |
192 |
|
|
$ResourceCount = 0; |
193 |
|
|
|
194 |
|
|
unless (defined $ModuleSourceDNLDocument{$module_uri}) { |
195 |
|
|
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
196 |
|
|
daf_open_source_dis_document ($module_uri); |
197 |
|
|
} |
198 |
|
|
daf_convert_dis_document_to_dnl_document (); |
199 |
|
|
} |
200 |
|
|
return $ModuleSourceDNLDocument{$module_uri}; |
201 |
|
|
}, |
202 |
|
|
get_module_source_document_from_resource => sub ($$$$$$) { |
203 |
|
|
my ($self, $db, $uri, $ns, $ln, $for) = @_; |
204 |
|
|
status_msg ''; |
205 |
|
|
status_msg qq<Loading module "$ln" for <$for>...>; |
206 |
|
|
$ResourceCount = 0; |
207 |
|
|
|
208 |
|
|
my $module_uri = $ns.$ln; |
209 |
|
|
unless (defined $ModuleSourceDNLDocument{$module_uri}) { |
210 |
|
|
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
211 |
|
|
daf_open_source_dis_document ($module_uri); |
212 |
|
|
} |
213 |
|
|
daf_convert_dis_document_to_dnl_document (); |
214 |
|
|
} |
215 |
|
|
return $ModuleSourceDNLDocument{$module_uri}; |
216 |
|
|
}, |
217 |
|
|
get_module_source_revision => sub { |
218 |
|
|
my ($db, $module_uri) = @_; |
219 |
|
|
my $ns = $module_uri; |
220 |
|
|
$ns =~ s/(\w+)\z//; |
221 |
|
|
my $ln = $1; |
222 |
|
|
|
223 |
|
|
my $name = dac_search_file_path_stem ($ns, $ln, $Opt{dis_suffix}); |
224 |
|
|
if (defined $name) { |
225 |
|
|
return [stat $name.$Opt{dis_suffix}]->[9]; |
226 |
|
|
} else { |
227 |
|
|
return 0; |
228 |
|
|
} |
229 |
|
|
}, |
230 |
|
|
get_referring_module_uri_list => sub { |
231 |
|
|
my ($db, $module_uri) = @_; |
232 |
|
|
unless (defined $ModuleSourceDNLDocument{$module_uri}) { |
233 |
|
|
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
234 |
|
|
daf_open_source_dis_document ($module_uri); |
235 |
|
|
} |
236 |
|
|
} |
237 |
|
|
return daf_get_referring_module_uri_list ($module_uri); |
238 |
|
|
}, |
239 |
|
|
on_resource_read => sub ($$) { |
240 |
|
|
if ((++$ResourceCount % 10) == 0) { |
241 |
|
|
status_msg_ "*"; |
242 |
|
|
status_msg_ " " if ($ResourceCount % (10 * 10)) == 0; |
243 |
|
|
status_msg '' if ($ResourceCount % (10 * 50)) == 0; |
244 |
|
|
} |
245 |
|
|
}); |
246 |
|
|
|
247 |
|
|
|
248 |
|
|
## Removes reference from document to database |
249 |
|
|
our @Document; |
250 |
|
|
for my $dis (@Document) { |
251 |
|
|
$dis->unlink_from_document; |
252 |
|
|
$dis->dis_database (undef); |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
status_msg ''; |
256 |
|
|
|
257 |
|
|
status_msg qq<Reading properties...>; |
258 |
|
|
$ResourceCount = 0; |
259 |
|
|
$db->read_properties (on_resource_read => sub ($$) { |
260 |
|
|
if ((++$ResourceCount % 10) == 0) { |
261 |
|
|
status_msg_ "*"; |
262 |
|
|
status_msg_ " " if ($ResourceCount % (10 * 10)) == 0; |
263 |
|
|
status_msg '' if ($ResourceCount % (10 * 50)) == 0; |
264 |
|
|
} |
265 |
|
|
}); |
266 |
|
|
status_msg ''; |
267 |
|
|
status_msg "done"; |
268 |
|
|
|
269 |
|
|
status_msg_ qq<Writing database files...>; |
270 |
|
|
$db->pl_store ('dummy', sub ($$) { |
271 |
|
|
my ($db, $mod, $type) = @_; |
272 |
|
|
my $ns = $mod->namespace_uri; |
273 |
|
|
my $ln = $mod->local_name; |
274 |
|
|
my $suffix = $type eq ExpandedURI q<dp:ModuleIndexFile> |
275 |
|
|
? $Opt{dafx_suffix} : $Opt{daem_suffix}; |
276 |
|
|
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
277 |
|
|
if (defined $name) { |
278 |
|
|
$name .= $suffix; |
279 |
|
|
} elsif (defined ($name = dac_search_file_path_stem |
280 |
|
|
($ns, $ln, $Opt{dis_suffix}))) { |
281 |
|
|
$name .= $suffix; |
282 |
|
|
} else { |
283 |
|
|
$name = Cwd::abs_path |
284 |
|
|
(File::Spec->canonpath |
285 |
|
|
(File::Spec->catfile |
286 |
|
|
(defined $Opt{input_search_path}->{$ns}->[0] |
287 |
|
|
? $Opt{input_search_path}->{$ns}->[0] : '.', |
288 |
|
|
$ln.$suffix))); |
289 |
|
|
} |
290 |
|
|
verbose_msg qq<Database >. |
291 |
|
|
($type eq <Q::dp|ModuleIndexFile> ? 'index' : 'module'). |
292 |
|
|
qq< <$ns$ln> is written to "$name">; |
293 |
|
|
return $name; |
294 |
|
|
}, no_main_database => 1); |
295 |
|
|
status_msg "done"; |
296 |
|
|
|
297 |
|
|
daf_check_undefined (); |
298 |
|
|
|
299 |
wakaba |
1.2 |
undef $DNi; |
300 |
|
|
undef %ModuleSourceDNLDocument; |
301 |
|
|
exit $HasError if $HasError; |
302 |
|
|
|
303 |
|
|
## --- Creating Files |
304 |
|
|
|
305 |
wakaba |
1.1 |
for (@{$Opt{create_module}}) { |
306 |
|
|
my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_; |
307 |
|
|
|
308 |
wakaba |
1.2 |
if ($out_type eq 'perl-pm') { |
309 |
wakaba |
1.13 |
daf_perl_pm ($mod_uri, $out_file_path, $mod_for); |
310 |
wakaba |
1.2 |
} elsif ($out_type eq 'perl-t') { |
311 |
wakaba |
1.13 |
daf_perl_t ($mod_uri, $out_file_path, $mod_for); |
312 |
wakaba |
1.14 |
} elsif ($out_type eq 'dtd-modules') { |
313 |
|
|
daf_dtd_modules ($mod_uri, $out_file_path, $mod_for); |
314 |
wakaba |
1.1 |
} |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
daf_check_undefined (); |
318 |
|
|
|
319 |
wakaba |
1.2 |
## --- The END |
320 |
|
|
|
321 |
wakaba |
1.1 |
status_msg_ "Closing the database..."; |
322 |
|
|
$db->free; |
323 |
|
|
undef $db; |
324 |
|
|
status_msg "done"; |
325 |
|
|
|
326 |
wakaba |
1.7 |
undef $limpl; |
327 |
|
|
undef $impl; |
328 |
|
|
|
329 |
wakaba |
1.1 |
{ |
330 |
|
|
use integer; |
331 |
|
|
my $time = time - $start_time; |
332 |
|
|
status_msg sprintf qq<%d'%02d''>, $time / 60, $time % 60; |
333 |
|
|
} |
334 |
|
|
exit $HasError; |
335 |
|
|
|
336 |
|
|
END { |
337 |
|
|
$db->free if $db; |
338 |
|
|
} |
339 |
|
|
|
340 |
wakaba |
1.2 |
## ---- Subroutines |
341 |
|
|
|
342 |
wakaba |
1.1 |
sub daf_open_source_dis_document ($) { |
343 |
|
|
my ($module_uri) = @_; |
344 |
|
|
|
345 |
|
|
## -- Finds |dis| source file |
346 |
|
|
my $ns = $module_uri; |
347 |
|
|
$ns =~ s/(\w+)\z//; |
348 |
|
|
my $ln = $1; |
349 |
|
|
my $file_name = dac_search_file_path_stem ($ns, $ln, $Opt{dis_suffix}); |
350 |
|
|
unless (defined $file_name) { |
351 |
|
|
die "$0: Source file for <$ns$ln> is not found"; |
352 |
|
|
} |
353 |
|
|
$file_name .= $Opt{dis_suffix}; |
354 |
|
|
|
355 |
|
|
status_msg_ qq<Opening dis source file "$file_name"...>; |
356 |
|
|
|
357 |
|
|
## -- Opens |dis| file and construct |DISDocument| tree |
358 |
|
|
open my $file, '<', $file_name or die "$0: $file_name: $!"; |
359 |
|
|
my $dis = $parser->parse ({character_stream => $file}); |
360 |
|
|
require File::Spec; |
361 |
|
|
$dis->flag (ExpandedURI q<swcfg21:fileName> => |
362 |
|
|
File::Spec->abs2rel ($file_name)); |
363 |
|
|
$dis->dis_namespace_resolver (\&daf_module_name_namespace_resolver); |
364 |
|
|
close $file; |
365 |
|
|
|
366 |
|
|
## -- Registers namespace URI |
367 |
|
|
my $mod = $dis->module_element; |
368 |
|
|
if ($mod) { |
369 |
|
|
my $qn = $mod->get_attribute_ns (ExpandedURI q<dis:>, 'QName'); |
370 |
|
|
if ($qn) { |
371 |
|
|
my $prefix = $qn->value; |
372 |
|
|
$prefix =~ s/^[^:|]*[:|]\s*//; |
373 |
|
|
$prefix =~ s/\s+$//; |
374 |
|
|
unless (defined $ModuleNameNamespaceBinding{$prefix}) { |
375 |
|
|
$ModuleNameNamespaceBinding{$prefix} = $mod->defining_namespace_uri; |
376 |
|
|
} |
377 |
|
|
} |
378 |
|
|
} |
379 |
|
|
|
380 |
|
|
$ModuleSourceDISDocument{$module_uri} = $dis; |
381 |
|
|
status_msg q<done>; |
382 |
|
|
|
383 |
|
|
R: for (@{daf_get_referring_module_uri_list ($module_uri)}) { |
384 |
|
|
next R if defined $db->{modDef}->{$_}; |
385 |
|
|
next R if defined $ModuleSourceDNLDocument{$_}; |
386 |
|
|
next R if defined $ModuleSourceDISDocument{$_}; |
387 |
|
|
my $idx_file_name = daf_get_module_index_file_name ($_); |
388 |
|
|
if (-f $idx_file_name) { |
389 |
|
|
daf_open_current_module_index ($_, $idx_file_name); |
390 |
|
|
} else { |
391 |
|
|
daf_open_source_dis_document ($_); |
392 |
|
|
} |
393 |
|
|
} |
394 |
|
|
} # daf_open_source_dis_document |
395 |
|
|
|
396 |
|
|
sub daf_open_current_module_index ($$) { |
397 |
|
|
my ($module_uri, $file_name) = @_; |
398 |
|
|
$db->pl_load_dis_database_index ($file_name); |
399 |
|
|
|
400 |
|
|
R: for (@{$db->get_module ($module_uri) |
401 |
|
|
->get_referring_module_uri_list}) { |
402 |
|
|
next R if defined $db->{modDef}->{$_}; |
403 |
|
|
next R if defined $ModuleSourceDNLDocument{$_}; |
404 |
|
|
next R if defined $ModuleSourceDISDocument{$_}; |
405 |
|
|
my $idx_file_name = daf_get_module_index_file_name ($_); |
406 |
|
|
if (-f $idx_file_name) { |
407 |
|
|
daf_open_current_module_index ($_, $idx_file_name); |
408 |
|
|
} else { |
409 |
|
|
daf_open_source_dis_document ($_); |
410 |
|
|
} |
411 |
|
|
} |
412 |
|
|
} # daf_open_current_module_index |
413 |
|
|
|
414 |
|
|
sub daf_convert_dis_document_to_dnl_document () { |
415 |
|
|
M: for my $module_uri (keys %ModuleSourceDISDocument) { |
416 |
|
|
my $dis_doc = $ModuleSourceDISDocument{$module_uri}; |
417 |
|
|
next M unless $dis_doc; |
418 |
|
|
verbose_msg_ qq<Converting <$module_uri>...>; |
419 |
|
|
my $dnl_doc = $DNi->convert_dis_document_to_dnl_document |
420 |
|
|
($dis_doc, database_arg => $db, |
421 |
|
|
base_namespace_binding => |
422 |
|
|
{(map {$_->local_name => $_->target_namespace_uri} |
423 |
|
|
grep {$_} values %{$db->{modDef}}), |
424 |
|
|
%ModuleNameNamespaceBinding}); |
425 |
|
|
push @Document, $dnl_doc; |
426 |
|
|
$ModuleSourceDNLDocument{$module_uri} = $dnl_doc; |
427 |
|
|
$dis_doc->free; |
428 |
|
|
delete $ModuleSourceDISDocument{$module_uri}; |
429 |
|
|
verbose_msg q<done>; |
430 |
|
|
} |
431 |
|
|
} # daf_convert_dis_document_to_dnl_document |
432 |
|
|
|
433 |
|
|
sub daf_get_referring_module_uri_list ($) { |
434 |
|
|
my $module_uri = shift; |
435 |
|
|
my $ns = $module_uri; |
436 |
|
|
$ns =~ s/\w+\z//; |
437 |
|
|
my $src = $ModuleSourceDNLDocument{$module_uri}; |
438 |
|
|
$src = $ModuleSourceDISDocument{$module_uri} unless defined $src; |
439 |
|
|
my $mod_el = $src->module_element; |
440 |
|
|
my $r = []; |
441 |
|
|
if ($mod_el) { |
442 |
|
|
my $req_el = $mod_el->require_element; |
443 |
|
|
if ($req_el) { |
444 |
|
|
M: for my $m_el (@{$req_el->child_nodes}) { |
445 |
|
|
next M unless $m_el->node_type eq '#element'; |
446 |
|
|
next M unless $m_el->expanded_uri eq ExpandedURI q<dis:Module>; |
447 |
|
|
my $qn_el = $m_el->get_attribute_ns (ExpandedURI q<dis:>, 'QName'); |
448 |
|
|
if ($qn_el) { |
449 |
|
|
push @$r, $qn_el->qname_value_uri; |
450 |
|
|
} else { |
451 |
|
|
my $n_el = $m_el->get_attribute_ns (ExpandedURI q<dis:>, 'Name'); |
452 |
|
|
if ($n_el) { |
453 |
|
|
push @$r, $ns.$n_el->value; |
454 |
|
|
} else { |
455 |
|
|
# The module itself |
456 |
|
|
} |
457 |
|
|
} |
458 |
|
|
} |
459 |
|
|
} |
460 |
|
|
} |
461 |
|
|
return $r; |
462 |
|
|
} # daf_get_referring_module_uri_list |
463 |
|
|
|
464 |
|
|
sub dac_search_file_path_stem ($$$) { |
465 |
|
|
my ($ns, $ln, $suffix) = @_; |
466 |
|
|
require File::Spec; |
467 |
wakaba |
1.8 |
for my $dir (@{$Opt{input_search_path}->{$ns}||[]}) { |
468 |
wakaba |
1.1 |
my $name = Cwd::abs_path |
469 |
|
|
(File::Spec->canonpath |
470 |
|
|
(File::Spec->catfile ($dir, $ln))); |
471 |
|
|
if (-f $name.$suffix) { |
472 |
|
|
return $name; |
473 |
|
|
} |
474 |
|
|
} |
475 |
|
|
return undef; |
476 |
|
|
} # dac_search_file_path_stem; |
477 |
|
|
|
478 |
|
|
sub daf_get_module_index_file_name ($$) { |
479 |
|
|
my ($module_uri) = @_; |
480 |
|
|
my $ns = $module_uri; |
481 |
|
|
$ns =~ s/(\w+)\z//; |
482 |
|
|
my $ln = $1; |
483 |
|
|
|
484 |
|
|
verbose_msg qq<Database module index <$module_uri> is requested>; |
485 |
|
|
my $suffix = $Opt{dafx_suffix}; |
486 |
|
|
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
487 |
|
|
if (defined $name) { |
488 |
|
|
$name .= $suffix; |
489 |
|
|
} elsif (defined ($name = dac_search_file_path_stem |
490 |
|
|
($ns, $ln, $Opt{dis_suffix}))) { |
491 |
|
|
$name .= $suffix; |
492 |
|
|
} else { |
493 |
|
|
$name = Cwd::abs_path |
494 |
|
|
(File::Spec->canonpath |
495 |
|
|
(File::Spec->catfile |
496 |
|
|
(defined $Opt{input_search_path}->{$ns}->[0] |
497 |
|
|
? $Opt{input_search_path}->{$ns}->[0] : '.', |
498 |
|
|
$ln.$suffix))); |
499 |
|
|
} |
500 |
|
|
return $name; |
501 |
|
|
} # daf_get_module_index_file_name |
502 |
|
|
|
503 |
|
|
sub daf_module_name_namespace_resolver ($) { |
504 |
|
|
my $prefix = shift; |
505 |
|
|
|
506 |
|
|
## -- From modules in database |
507 |
|
|
M: for (values %{$db->{modDef}}) { |
508 |
|
|
my $mod = $_; |
509 |
|
|
next M unless defined $mod; |
510 |
|
|
if ($mod->local_name eq $prefix) { |
511 |
|
|
return $mod->target_namespace_uri; |
512 |
|
|
} |
513 |
|
|
} |
514 |
|
|
|
515 |
|
|
## -- From not-in-database-yet module list |
516 |
|
|
if (defined $ModuleNameNamespaceBinding{$prefix}) { |
517 |
|
|
return $ModuleNameNamespaceBinding{$prefix}; |
518 |
|
|
} |
519 |
|
|
return undef; |
520 |
|
|
} # daf_module_name_namespace_resolver |
521 |
|
|
|
522 |
|
|
sub daf_db_module_resolver ($$$) { |
523 |
|
|
my ($db, $mod, $type) = @_; |
524 |
|
|
my $ns = $mod->namespace_uri; |
525 |
|
|
my $ln = $mod->local_name; |
526 |
wakaba |
1.11 |
my $suffix = { |
527 |
|
|
ExpandedURI q<dp:ModuleIndexFile> => $Opt{dafx_suffix}, |
528 |
|
|
ExpandedURI q<dp:ModuleResourceFile> => $Opt{daem_suffix}, |
529 |
|
|
ExpandedURI q<dp:ModuleNodeStorageFile> => $Opt{dafs_suffix}, |
530 |
|
|
}->{$type} or die "Unsupported type: <$type>"; |
531 |
wakaba |
1.1 |
verbose_msg qq<Database module <$ns$ln> is requested>; |
532 |
|
|
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
533 |
|
|
if (defined $name) { |
534 |
|
|
return $name.$suffix; |
535 |
|
|
} else { |
536 |
|
|
return undef; |
537 |
|
|
} |
538 |
|
|
} # daf_db_module_resolver |
539 |
|
|
|
540 |
|
|
sub daf_on_error ($$) { |
541 |
|
|
my ($self, $err) = @_; |
542 |
|
|
if ($err->severity == $err->SEVERITY_WARNING) { |
543 |
|
|
my $info = ExpandedURI q<dp:info>; |
544 |
|
|
if ($err->type =~ /\Q$info\E/) { |
545 |
|
|
my $msg = $err->text; |
546 |
|
|
if ($msg =~ /\.\.\.\z/) { |
547 |
|
|
verbose_msg_ $msg; |
548 |
|
|
} else { |
549 |
|
|
verbose_msg $msg; |
550 |
|
|
} |
551 |
|
|
} else { |
552 |
|
|
my $msg = $err->text; |
553 |
|
|
if ($msg =~ /\.\.\.\z/) { |
554 |
|
|
status_msg_ $msg; |
555 |
|
|
} else { |
556 |
|
|
status_msg $msg; |
557 |
|
|
} |
558 |
|
|
} |
559 |
|
|
} else { |
560 |
|
|
warn $err; |
561 |
|
|
$HasError = 1; |
562 |
|
|
} |
563 |
|
|
} # daf_on_error |
564 |
|
|
|
565 |
|
|
sub daf_check_undefined () { |
566 |
|
|
unless ($Opt{no_undef_check}) { |
567 |
|
|
status_msg_ "Checking undefined resources..."; |
568 |
|
|
$db->check_undefined_resource; |
569 |
|
|
print STDERR "done\n"; |
570 |
|
|
} |
571 |
|
|
} # daf_check_undefined |
572 |
wakaba |
1.2 |
|
573 |
wakaba |
1.1 |
__END__ |
574 |
|
|
|
575 |
|
|
=head1 NAME |
576 |
|
|
|
577 |
|
|
dac.pl - Creating "dac" Database File from "dis" Source Files |
578 |
|
|
|
579 |
|
|
=head1 SYNOPSIS |
580 |
|
|
|
581 |
|
|
perl path/to/dac.pl [--input-db-file-name=input.dac] \ |
582 |
|
|
--output-file-name=out.dac [options...] \ |
583 |
|
|
input.dis |
584 |
|
|
perl path/to/dac.pl --help |
585 |
|
|
|
586 |
|
|
=head1 DESCRIPTION |
587 |
|
|
|
588 |
|
|
This script, C<dac.pl>, compiles "dis" source files into "dac" |
589 |
|
|
database file. The generated database file can be used |
590 |
|
|
in turn to generate Perl module file, for example, by another |
591 |
|
|
script C<dac2pm.pl> or can be used to create larger database |
592 |
|
|
by specifying its file name as the C<--input-db-file-name> |
593 |
|
|
argument of another C<dac.pl> execution. |
594 |
|
|
|
595 |
|
|
This script is part of manakai. |
596 |
|
|
|
597 |
|
|
=head1 OPTIONS |
598 |
|
|
|
599 |
|
|
=over 4 |
600 |
|
|
|
601 |
|
|
=item I<input.dis> (Required) |
602 |
|
|
|
603 |
|
|
The unnamed option specifies a file name path of the source "dis" file |
604 |
|
|
from which a database is created. This option is required. |
605 |
|
|
|
606 |
|
|
=item C<--input-db-file-name=I<file-name>> (Default: none) |
607 |
|
|
|
608 |
|
|
A file path of the base database. This option is optional; if this |
609 |
|
|
option is specified, the database file is loaded first |
610 |
|
|
and then I<input.dis> file is loaded in the context of it. |
611 |
|
|
Otherwise, a new database is created. |
612 |
|
|
|
613 |
|
|
=back |
614 |
|
|
|
615 |
|
|
=head1 SEE ALSO |
616 |
|
|
|
617 |
|
|
L<lib/Message/Util/DIS.dis> - The actual implementation |
618 |
|
|
of the "dis" interpretation. |
619 |
|
|
|
620 |
|
|
=head1 LICENSE |
621 |
|
|
|
622 |
wakaba |
1.13 |
Copyright 2004-2006 Wakaba <w@suika.fam.cx>. All rights reserved. |
623 |
wakaba |
1.1 |
|
624 |
|
|
This program is free software; you can redistribute it and/or |
625 |
|
|
modify it under the same terms as Perl itself. |
626 |
|
|
|
627 |
|
|
=cut |