/[suikacvs]/messaging/manakai/bin/daf.pl
Suika

Contents of /messaging/manakai/bin/daf.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Sat Nov 4 12:25:10 2006 UTC (18 years ago) by wakaba
Branch: MAIN
Changes since 1.17: +1 -2 lines
File MIME type: text/plain
++ manakai/bin/ChangeLog	4 Nov 2006 11:58:05 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* daf.pl: The |--debug| option no longer set
	obsoleted |$Message::DOM::DOMFeature::DEBUG| option.

++ manakai/lib/Message/Markup/ChangeLog	4 Nov 2006 12:14:20 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Atom.dis (AtomImplementation): It no
        longer inherits the |ManakaiDOMImplementation|; it
        is now expected to be implemented by |DOMImplementation|
        objects.
	(AtomDocument, AtomFeedDocument, AtomEntryDocument): It no
        longer inherits the |ManakaiDOMDocument|; it
        is now expected to be implemented by |Document|
        objects.

	* SuikaWikiConfig21.dis (SWCFGImplementation): It no
        longer inherits the |DOMImplementation|; it
        is now expected to be implemented by |DOMImplementation|
        objects.

++ manakai/lib/Message/Util/ChangeLog	4 Nov 2006 12:18:18 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DIS.dis (ManakaiDISImplementation): It no longer
	inherits |ManakaiDISImplementationValue|,
	|ManakaiDISImplementationPerl|, and |ManakaiSWCFGImplementation|
	interfaces.  The class is now expected to be implemented
	by |DOMImplementation| objects.

	* PerlCode.dis (addImplementedFeature, addImplementedElementType):
	New methods.
	(PCHasFeature, PCElementType): New interfaces.
	(PCDocument): It no longer inherits the |ManakaiDOMDocument|; it
        is now expected to be implemented by |Document|
        objects.
	(PCImplementation): It no longer inherits the |ManakaiDOMImplementation|;
	it is now expected to be implemented by |DOMImplementation|
	objects.

++ manakai/lib/Message/Util/DIS/ChangeLog	4 Nov 2006 12:24:32 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DNLite.dis (DISImplementationDNLite): It no
	longer inherits the |ManakaiDISImplementation|; it
        is now expected to be implemented by |DOMImplementation| objects.

	* DPG.dis (DPGDocument): It no longer inherits
	the |ManakaiDOMDocument| class; it is now expected to be
	implemented by all |Document| objects.

	* Perl.dis (DISImplementationPerl): It is now
	expected to be implemented by all |DOMImplementation| objects.
	(plCodeFragment): Support for the |p:require|
	property is added.  It no longer output |ClassInfo|
	for classes for specific element types; instead,
	it invoke |add_implemented_element_type| method.

	* Test.dis (DTImplementation): It no longer
	inherits the |MinimumImplementation| interface;
	instead, it is expected to be implemented
	by all |DOMImplementation| objects.

	* Value.dis (DISImplementationValue): It is now
	expected to be implemented by all |DOMImplementation| objects.

++ manakai/lib/Message/Util/AutoLoad/ChangeLog	4 Nov 2006 12:19:43 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Config.pm (register_all, save): Support for |feature|
	and |element_type| is added.

	* Registry-initial.pm: Updated.

	* .cvsignore: New file.


	* Registry-initial.pm: New module.
++ manakai/lib/Message/DOM/ChangeLog	4 Nov 2006 12:12:45 -0000
	explicitly inherits |urigen:ManakaiURIImplementation| (and
	the |f:ManakaiMinimumImplementation| class inherited
	by it).  The |f:Minimum| feature is ever implemented
	for compatibility (but is expected to be removed).
	Internal methods such as |___report_error| are copied from
	obsolete |f:MinimumImplementation| class.  DOM3
	methods |hasFeature| and |getFeature| are also
	moved from that class, but they now support no
	foreign classes.

	* DOMFeature.dis (ManakaiImplementationSource): It
	now |p:require|s |Message::Util::AutoLoad::Registry|.
	The class no longer support classes
	other than |ManakaiDOMImplementation|.  Note
	that the |ImplementationRegistry| object does continue
	to support foreign classes via foreign classes
	implementing |ImplementationSource|
	or |DOMImplementationSource| interface.
	(MinimumImplementation): Removed.

	* DOMLS.dis (ManakaiDOMImplementationLS): It no
	longer inherit the |ManakaiDOMImplementation|; it
	is now expected to be implemented by |DOMImplementation|
	objects.

	* DOMMain.dis (null): Removed.

	* Document.dis (___create_node_ref): It no
	longer support foreign classes other
	than |Message::DOM::Document::ManakaiDOMDocument|.
	Note that document format specific DOM
	interfaces, if supported, should be
	all instances of the |Document| interface
	in the implementation, as defined
	in the Web Applications 1.0 specification (where
	the |HTMLDocument| interface must be implemented
	by all |Document| objects, even if the |Document|
	contains no HTML element).

	* GenericLS.dis (GLSImplementation): It no
        longer inherit the |MinimumImplementation|; it
        is now expected to be implemented by |DOMImplementation|
        objects.
	(createGLSParser, createGLSSerializer): Load
	module implementing parser or serializer
	if necessary.

	* Traversal.dis (ManakaiDOMDocumentTraversal): It no
	longer inherits the |ManakaiDOMDocument|; it
	is now expected to be implemented by |Document|
	objects.

	* XDP.dis (XDPDocument): It no longer
	inherits the |Document|; it is now expected
	to be implemented by all |Document| objects.

	* XDoctype.dis (ManakaiDOMDocumentXDoctype): It no
        longer inherits the |ManakaiDOMDocument|; it
        is now expected to be implemented by |Document|
        objects.

2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DOMCore.dis (ManakaiDOMImplementation): No longer
++ manakai/lib/Message/URI/ChangeLog	4 Nov 2006 12:14:59 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Generic.dis (URIImplementation): It no
	longer inherits the |MinimumImplementation|; it
	is now expected to be implemented by |DOMImplementation|
	objects.

++ manakai/lib/Message/Charset/ChangeLog	4 Nov 2006 11:56:24 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* Encode.dis (MCEncodeImplementation): It no
	longer inherit the |MinimumImplementation|; it
	is now expected to be implemented by |DOMImplementation|
	objects.

++ manakai/lib/manakai/ChangeLog	4 Nov 2006 12:25:03 -0000
2006-11-04  Wakaba  <wakaba@suika.fam.cx>

	* DISPerl.dis (p:require, p:use): New properties.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24