1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
use strict; |
use strict; |
3 |
use Message::Util::QName::Filter { |
use Message::Util::QName::Filter { |
4 |
|
c => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>, |
5 |
DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>, |
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-->, |
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/>, |
dp => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#Perl/>, |
8 |
fe => q<http://suika.fam.cx/www/2006/feature/>, |
fe => q<http://suika.fam.cx/www/2006/feature/>, |
9 |
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
10 |
|
pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>, |
11 |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
12 |
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
13 |
}; |
}; |
14 |
|
|
15 |
|
our$VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
16 |
use Cwd; |
use Cwd; |
17 |
use Getopt::Long; |
use Getopt::Long; |
18 |
use Pod::Usage; |
use Pod::Usage; |
19 |
my %Opt = (create_module => []); |
our %Opt = (create_module => []); |
20 |
|
my @target_modules; |
21 |
GetOptions ( |
GetOptions ( |
22 |
|
'create-dtd-driver=s' => sub { |
23 |
|
shift; |
24 |
|
my $i = [split /\s+/, shift, 3]; |
25 |
|
$i->[3] = 'dtd-driver'; |
26 |
|
push @{$Opt{create_module}}, $i; |
27 |
|
}, |
28 |
|
'create-dtd-modules=s' => sub { |
29 |
|
shift; |
30 |
|
my $i = [split /\s+/, shift, 3]; |
31 |
|
$i->[3] = 'dtd-modules'; |
32 |
|
push @{$Opt{create_module}}, $i; |
33 |
|
}, |
34 |
'create-perl-module=s' => sub { |
'create-perl-module=s' => sub { |
35 |
shift; |
shift; |
36 |
my $i = [split /\s+/, shift, 3]; |
my $i = [split /\s+/, shift, 3]; |
37 |
$i->[3] = 'pm'; |
$i->[3] = 'perl-pm'; |
38 |
push @{$Opt{create_module}}, $i; |
push @{$Opt{create_module}}, $i; |
39 |
|
push @target_modules, [$i->[0], $i->[2]]; |
40 |
|
}, |
41 |
|
'create-perl-test=s' => sub { |
42 |
|
shift; |
43 |
|
my $i = [split /\s+/, shift, 3]; |
44 |
|
$i->[3] = 'perl-t'; |
45 |
|
push @{$Opt{create_module}}, $i; |
46 |
|
push @target_modules, [$i->[0], $i->[2]]; |
47 |
}, |
}, |
48 |
'debug' => \$Opt{debug}, |
'debug' => \$Opt{debug}, |
49 |
'dis-file-suffix=s' => \$Opt{dis_suffix}, |
'dis-file-suffix=s' => \$Opt{dis_suffix}, |
50 |
'daem-file-suffix=s' => \$Opt{daem_suffix}, |
'daem-file-suffix=s' => \$Opt{daem_suffix}, |
51 |
|
'dafs-file-suffix=s' => \$Opt{dafs_suffix}, |
52 |
'dafx-file-suffix=s' => \$Opt{dafx_suffix}, |
'dafx-file-suffix=s' => \$Opt{dafx_suffix}, |
53 |
|
'dtd-file-suffix=s' => \$Opt{dtd_suffix}, |
54 |
'help' => \$Opt{help}, |
'help' => \$Opt{help}, |
55 |
|
'load-module=s' => sub { |
56 |
|
shift; |
57 |
|
my $i = [split /\s+/, shift, 2]; |
58 |
|
push @target_modules, [$i->[0], $i->[1]]; |
59 |
|
}, |
60 |
|
'mod-file-suffix=s' => \$Opt{mod_suffix}, |
61 |
'search-path|I=s' => sub { |
'search-path|I=s' => sub { |
62 |
shift; |
shift; |
63 |
my @value = split /\s+/, shift; |
my @value = split /\s+/, shift; |
104 |
$Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix}; |
$Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix}; |
105 |
$Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix}; |
$Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix}; |
106 |
$Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix}; |
$Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix}; |
107 |
|
$Opt{dafs_suffix} = '.dafs' unless defined $Opt{dafs_suffix}; |
108 |
|
$Opt{dtd_suffix} = '.dtd' unless defined $Opt{dtd_suffix}; |
109 |
|
$Opt{mod_suffix} = '.mod' unless defined $Opt{mod_suffix}; |
110 |
$Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; |
$Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; |
111 |
require Error; |
require Error; |
112 |
$Error::Debug = 1 if $Opt{debug}; |
$Error::Debug = 1 if $Opt{debug}; |
134 |
print STDERR $s if $Opt{verbose}; |
print STDERR $s if $Opt{verbose}; |
135 |
} |
} |
136 |
|
|
137 |
|
## ---- The MAIN Program |
138 |
|
|
139 |
my $start_time; |
my $start_time; |
140 |
BEGIN { $start_time = time } |
BEGIN { $start_time = time } |
141 |
|
|
142 |
use Message::Util::DIS::DNLite; |
use Message::Util::DIS::DNLite; |
|
use Message::Util::PerlCode; |
|
143 |
|
|
144 |
my $limpl = $Message::DOM::ImplementationRegistry->get_implementation |
my %feature; |
145 |
|
|
146 |
|
for (@{$Opt{create_module}}) { |
147 |
|
my (undef, undef, undef, $out_type) = @$_; |
148 |
|
|
149 |
|
if ($out_type eq 'perl-pm') { |
150 |
|
require 'manakai/daf-perl-pm.pl'; |
151 |
|
$feature{'+' . ExpandedURI q<Util:PerlCode>} = '1.0'; |
152 |
|
} elsif ($out_type eq 'perl-t') { |
153 |
|
require 'manakai/daf-perl-t.pl'; |
154 |
|
$feature{ExpandedURI q<fe:GenericLS>} = '3.0'; |
155 |
|
$feature{'+' . ExpandedURI q<DIS:TDT>} = '1.0'; |
156 |
|
$feature{'+' . ExpandedURI q<Util:PerlCode>} = '1.0'; |
157 |
|
} elsif ($out_type eq 'dtd-modules') { |
158 |
|
require 'manakai/daf-dtd-modules.pl'; |
159 |
|
$feature{ExpandedURI q<fe:GenericLS>} = '3.0'; |
160 |
|
$feature{'+' . ExpandedURI q<fe:XDP>} = '3.0'; |
161 |
|
} elsif ($out_type eq 'dtd-driver') { |
162 |
|
require 'manakai/daf-dtd-modules.pl'; |
163 |
|
$feature{ExpandedURI q<fe:GenericLS>} = '3.0'; |
164 |
|
$feature{'+' . ExpandedURI q<fe:XDP>} = '3.0'; |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
our $limpl = $Message::DOM::ImplementationRegistry->get_implementation |
169 |
({ExpandedURI q<fe:Min> => '3.0', |
({ExpandedURI q<fe:Min> => '3.0', |
170 |
'+' . ExpandedURI q<DIS:DNLite> => '1.0', |
'+' . ExpandedURI q<DIS:DNLite> => '1.0', |
171 |
'+' . ExpandedURI q<DIS:Core> => '1.0', |
'+' . ExpandedURI q<DIS:Core> => '1.0', |
172 |
'+' . ExpandedURI q<Util:PerlCode> => '1.0', |
%feature, |
173 |
}); |
}); |
174 |
my $impl = $limpl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
our $impl = $limpl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
175 |
my $parser = $impl->create_dis_parser; |
|
176 |
our $DNi = $impl->get_feature (ExpandedURI q<DIS:DNLite> => '1.0'); |
## --- Loading and Updating the Database |
177 |
|
|
178 |
my $HasError; |
my $HasError; |
179 |
my $db = $impl->create_dis_database; |
our $db = $impl->create_dis_database; |
180 |
$db->pl_database_module_resolver (\&daf_db_module_resolver); |
$db->pl_database_module_resolver (\&daf_db_module_resolver); |
181 |
$db->dom_config->set_parameter ('error-handler' => \&daf_on_error); |
$db->dom_config->set_parameter ('error-handler' => \&daf_on_error); |
182 |
|
|
183 |
|
my $parser = $impl->create_dis_parser; |
184 |
|
my $DNi = $impl->get_feature (ExpandedURI q<DIS:DNLite> => '1.0'); |
185 |
my %ModuleSourceDISDocument; |
my %ModuleSourceDISDocument; |
186 |
my %ModuleSourceDNLDocument; |
my %ModuleSourceDNLDocument; |
187 |
my %ModuleNameNamespaceBinding = ( |
my %ModuleNameNamespaceBinding = ( |
191 |
## property. |
## property. |
192 |
); |
); |
193 |
|
|
|
my @target_modules; |
|
|
for (@{$Opt{create_module}}) { |
|
|
my ($mod_uri, $out_path, $mod_for, $out_type) = @$_; |
|
|
push @target_modules, [$mod_uri, $mod_for]; |
|
|
} |
|
|
|
|
194 |
my $ResourceCount = 0; |
my $ResourceCount = 0; |
195 |
$db->pl_update_module (\@target_modules, |
$db->pl_update_module (\@target_modules, |
196 |
get_module_index_file_name => sub { |
get_module_index_file_name => sub { |
245 |
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
246 |
daf_open_source_dis_document ($module_uri); |
daf_open_source_dis_document ($module_uri); |
247 |
} |
} |
|
daf_convert_dis_document_to_dnl_document (); |
|
248 |
} |
} |
249 |
return daf_get_referring_module_uri_list ($module_uri); |
return daf_get_referring_module_uri_list ($module_uri); |
250 |
}, |
}, |
274 |
status_msg_ " " if ($ResourceCount % (10 * 10)) == 0; |
status_msg_ " " if ($ResourceCount % (10 * 10)) == 0; |
275 |
status_msg '' if ($ResourceCount % (10 * 50)) == 0; |
status_msg '' if ($ResourceCount % (10 * 50)) == 0; |
276 |
} |
} |
277 |
}); |
}, implementation => $impl); |
278 |
status_msg ''; |
status_msg ''; |
279 |
status_msg "done"; |
status_msg "done"; |
280 |
|
|
308 |
|
|
309 |
daf_check_undefined (); |
daf_check_undefined (); |
310 |
|
|
311 |
|
undef $DNi; |
312 |
|
undef %ModuleSourceDNLDocument; |
313 |
|
exit $HasError if $HasError; |
314 |
|
|
315 |
|
## --- Creating Files |
316 |
|
|
317 |
for (@{$Opt{create_module}}) { |
for (@{$Opt{create_module}}) { |
318 |
my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_; |
my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_; |
319 |
unless (defined $mod_for) { |
|
320 |
$mod_for = $db->get_module ($mod_uri) |
if ($out_type eq 'perl-pm') { |
321 |
->get_property_text (ExpandedURI q<dis:DefaultFor>, |
daf_perl_pm ($mod_uri, $out_file_path, $mod_for); |
322 |
ExpandedURI q<ManakaiDOM:all>); |
} elsif ($out_type eq 'perl-t') { |
323 |
} |
daf_perl_t ($mod_uri, $out_file_path, $mod_for); |
324 |
my $mod = $db->get_module ($mod_uri, for_arg => $mod_for); |
} elsif ($out_type eq 'dtd-modules') { |
325 |
|
daf_dtd_modules ($mod_uri, $out_file_path, $mod_for); |
326 |
if ($out_type eq 'pm') { |
} elsif ($out_type eq 'dtd-driver') { |
327 |
status_msg_ qq<Generating Perl module from <$mod_uri> for <$mod_for>...>; |
daf_dtd_driver ($mod_uri, $out_file_path, $mod_for); |
|
my $pl = $mod->pl_generate_perl_module_file; |
|
|
status_msg qq<done>; |
|
|
|
|
|
my $output; |
|
|
defined $out_file_path |
|
|
? (open $output, '>', $out_file_path or die "$0: $out_file_path: $!") |
|
|
: ($output = \*STDOUT); |
|
|
|
|
|
status_msg_ sprintf qq<Writing Perl module %s...>, |
|
|
defined $out_file_path |
|
|
? q<">.$out_file_path.q<"> |
|
|
: 'to stdout'; |
|
|
print $output $pl->stringify; |
|
|
close $output; |
|
|
status_msg q<done>; |
|
328 |
} |
} |
329 |
} |
} |
330 |
|
|
331 |
daf_check_undefined (); |
daf_check_undefined (); |
332 |
|
|
333 |
|
## --- The END |
334 |
|
|
335 |
status_msg_ "Closing the database..."; |
status_msg_ "Closing the database..."; |
336 |
$db->free; |
$db->free; |
337 |
undef $db; |
undef $db; |
|
undef %ModuleSourceDNLDocument; |
|
338 |
status_msg "done"; |
status_msg "done"; |
339 |
|
|
340 |
undef $DNi; |
undef $limpl; |
341 |
|
undef $impl; |
342 |
|
|
343 |
{ |
{ |
344 |
use integer; |
use integer; |
351 |
$db->free if $db; |
$db->free if $db; |
352 |
} |
} |
353 |
|
|
354 |
|
## ---- Subroutines |
355 |
|
|
356 |
sub daf_open_source_dis_document ($) { |
sub daf_open_source_dis_document ($) { |
357 |
my ($module_uri) = @_; |
my ($module_uri) = @_; |
358 |
|
|
478 |
sub dac_search_file_path_stem ($$$) { |
sub dac_search_file_path_stem ($$$) { |
479 |
my ($ns, $ln, $suffix) = @_; |
my ($ns, $ln, $suffix) = @_; |
480 |
require File::Spec; |
require File::Spec; |
481 |
for my $dir ('.', @{$Opt{input_search_path}->{$ns}||[]}) { |
for my $dir (@{$Opt{input_search_path}->{$ns}||[]}) { |
482 |
my $name = Cwd::abs_path |
my $name = Cwd::abs_path |
483 |
(File::Spec->canonpath |
(File::Spec->canonpath |
484 |
(File::Spec->catfile ($dir, $ln))); |
(File::Spec->catfile ($dir, $ln))); |
537 |
my ($db, $mod, $type) = @_; |
my ($db, $mod, $type) = @_; |
538 |
my $ns = $mod->namespace_uri; |
my $ns = $mod->namespace_uri; |
539 |
my $ln = $mod->local_name; |
my $ln = $mod->local_name; |
540 |
my $suffix = $type eq ExpandedURI q<dp:ModuleIndexFile> |
my $suffix = { |
541 |
? $Opt{dafx_suffix} : $Opt{daem_suffix}; |
ExpandedURI q<dp:ModuleIndexFile> => $Opt{dafx_suffix}, |
542 |
|
ExpandedURI q<dp:ModuleResourceFile> => $Opt{daem_suffix}, |
543 |
|
ExpandedURI q<dp:ModuleNodeStorageFile> => $Opt{dafs_suffix}, |
544 |
|
}->{$type} or die "Unsupported type: <$type>"; |
545 |
verbose_msg qq<Database module <$ns$ln> is requested>; |
verbose_msg qq<Database module <$ns$ln> is requested>; |
546 |
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
547 |
if (defined $name) { |
if (defined $name) { |
624 |
and then I<input.dis> file is loaded in the context of it. |
and then I<input.dis> file is loaded in the context of it. |
625 |
Otherwise, a new database is created. |
Otherwise, a new database is created. |
626 |
|
|
|
=item C<--output-file-name=I<file-name>> (Required) |
|
|
|
|
|
The |
|
|
|
|
627 |
=back |
=back |
628 |
|
|
629 |
=head1 SEE ALSO |
=head1 SEE ALSO |
630 |
|
|
|
L<bin/dac2pm.pl> - Generating Perl module from "dac" file. |
|
|
|
|
631 |
L<lib/Message/Util/DIS.dis> - The actual implementation |
L<lib/Message/Util/DIS.dis> - The actual implementation |
632 |
of the "dis" interpretation. |
of the "dis" interpretation. |
633 |
|
|
634 |
=head1 LICENSE |
=head1 LICENSE |
635 |
|
|
636 |
Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved. |
Copyright 2004-2006 Wakaba <w@suika.fam.cx>. All rights reserved. |
637 |
|
|
638 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
639 |
modify it under the same terms as Perl itself. |
modify it under the same terms as Perl itself. |