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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sat Feb 25 16:49:55 2006 UTC revision 1.21 by wakaba, Sat Dec 2 12:46:18 2006 UTC
# Line 1  Line 1 
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 {
   DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>,  
4    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-->,
5    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/>,
   fe => q<http://suika.fam.cx/www/2006/feature/>,  
6    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#>,
7    swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>,    swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>,
   Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>,  
8  };  };
9    
10    our$VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
11  use Cwd;  use Cwd;
12  use Getopt::Long;  use Getopt::Long;
13  use Pod::Usage;  use Pod::Usage;
14  my %Opt = (create_module => []);  our %Opt = (create_module => []);
15    my @target_modules;
16  GetOptions (  GetOptions (
17      'create-dtd-driver=s' => sub {
18        shift;
19        my $i = [split /\s+/, shift, 3];
20        $i->[3] = 'dtd-driver';
21        push @{$Opt{create_module}}, $i;
22      },
23      'create-dtd-modules=s' => sub {
24        shift;
25        my $i = [split /\s+/, shift, 3];
26        $i->[3] = 'dtd-modules';
27        push @{$Opt{create_module}}, $i;
28      },
29    'create-perl-module=s' => sub {    'create-perl-module=s' => sub {
30      shift;      shift;
31      my $i = [split /\s+/, shift, 3];      my $i = [split /\s+/, shift, 3];
32      $i->[3] = 'pm';      $i->[3] = 'perl-pm';
33        push @{$Opt{create_module}}, $i;
34        push @target_modules, [$i->[0], $i->[2]];
35      },
36      'create-perl-test=s' => sub {
37        shift;
38        my $i = [split /\s+/, shift, 3];
39        $i->[3] = 'perl-t';
40      push @{$Opt{create_module}}, $i;      push @{$Opt{create_module}}, $i;
41        push @target_modules, [$i->[0], $i->[2]];
42    },    },
43    'debug' => \$Opt{debug},    'debug' => \$Opt{debug},
44    'dis-file-suffix=s' => \$Opt{dis_suffix},    'dis-file-suffix=s' => \$Opt{dis_suffix},
45    'daem-file-suffix=s' => \$Opt{daem_suffix},    'daem-file-suffix=s' => \$Opt{daem_suffix},
46      'dafs-file-suffix=s' => \$Opt{dafs_suffix},
47    'dafx-file-suffix=s' => \$Opt{dafx_suffix},    'dafx-file-suffix=s' => \$Opt{dafx_suffix},
48      'dtd-file-suffix=s' => \$Opt{dtd_suffix},
49    'help' => \$Opt{help},    'help' => \$Opt{help},
50      'load-module=s' => sub {
51        shift;
52        my $i = [split /\s+/, shift, 2];
53        push @target_modules, [$i->[0], $i->[1]];
54      },
55      'mod-file-suffix=s' => \$Opt{mod_suffix},
56    'search-path|I=s' => sub {    'search-path|I=s' => sub {
57      shift;      shift;
58      my @value = split /\s+/, shift;      my @value = split /\s+/, shift;
# Line 72  $Opt{no_undef_check} = defined $Opt{no_u Line 99  $Opt{no_undef_check} = defined $Opt{no_u
99  $Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix};  $Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix};
100  $Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix};  $Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix};
101  $Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix};  $Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix};
102  $Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug};  $Opt{dafs_suffix} = '.dafs' unless defined $Opt{dafs_suffix};
103    $Opt{dtd_suffix} = '.dtd' unless defined $Opt{dtd_suffix};
104    $Opt{mod_suffix} = '.mod' unless defined $Opt{mod_suffix};
105  require Error;  require Error;
106  $Error::Debug = 1 if $Opt{debug};  $Error::Debug = 1 if $Opt{debug};
107  $Message::Util::Error::VERBOSE = 1 if $Opt{verbose};  $Message::Util::Error::VERBOSE = 1 if $Opt{verbose};
# Line 99  sub verbose_msg_ ($) { Line 128  sub verbose_msg_ ($) {
128    print STDERR $s if $Opt{verbose};    print STDERR $s if $Opt{verbose};
129  }  }
130    
131    sub daf_open_source_dis_document ($);
132    sub daf_open_current_module_index ($$);
133    sub daf_convert_dis_document_to_dnl_document ();
134    sub daf_get_referring_module_uri_list ($);
135    sub dac_search_file_path_stem ($$$);
136    sub daf_get_module_index_file_name ($);
137    sub daf_check_undefined ();
138    
139    ## ---- The MAIN Program
140    
141  my $start_time;  my $start_time;
142  BEGIN { $start_time = time }  BEGIN { $start_time = time }
143    
144  use Message::Util::DIS::DNLite;  use Message::DOM::DOMCore;
 use Message::Util::PerlCode;  
145    
146  my $limpl = $Message::DOM::ImplementationRegistry->get_implementation  for (@{$Opt{create_module}}) {
147                             ({ExpandedURI q<fe:Min> => '3.0',    my (undef, undef, undef, $out_type) = @$_;
148                               '+' . ExpandedURI q<DIS:DNLite> => '1.0',  
149                               '+' . ExpandedURI q<DIS:Core> => '1.0',    if ($out_type eq 'perl-pm') {
150                               '+' . ExpandedURI q<Util:PerlCode> => '1.0',      require 'manakai/daf-perl-pm.pl';
151                             });    } elsif ($out_type eq 'perl-t') {
152  my $impl = $limpl->get_feature (ExpandedURI q<DIS:Core> => '1.0');      require 'manakai/daf-perl-t.pl';
153  my $parser = $impl->create_dis_parser;    } elsif ($out_type eq 'dtd-modules') {
154  our $DNi = $impl->get_feature (ExpandedURI q<DIS:DNLite> => '1.0');      require 'manakai/daf-dtd-modules.pl';
155      } elsif ($out_type eq 'dtd-driver') {
156        require 'manakai/daf-dtd-modules.pl';
157      }
158    }
159    
160    our $impl = $Message::DOM::ImplementationRegistry->get_dom_implementation;
161    
162    ## --- Loading and Updating the Database
163    
164  my $HasError;  my $HasError;
165  my $db = $impl->create_dis_database;  our $db = $impl->create_dis_database;
166  $db->pl_database_module_resolver (\&daf_db_module_resolver);  $db->pl_database_module_resolver (\&daf_db_module_resolver);
167  $db->dom_config->set_parameter ('error-handler' => \&daf_on_error);  $db->dom_config->set_parameter ('error-handler' => \&daf_on_error);
168    
169    my $parser = $impl->create_dis_parser;
170  my %ModuleSourceDISDocument;  my %ModuleSourceDISDocument;
171  my %ModuleSourceDNLDocument;  my %ModuleSourceDNLDocument;
172  my %ModuleNameNamespaceBinding = (  my %ModuleNameNamespaceBinding = (
# Line 129  my %ModuleNameNamespaceBinding = ( Line 176  my %ModuleNameNamespaceBinding = (
176      ## property.      ## property.
177  );  );
178    
 my @target_modules;  
 for (@{$Opt{create_module}}) {  
   my ($mod_uri, $out_path, $mod_for, $out_type) = @$_;  
   push @target_modules, [$mod_uri, $mod_for];  
 }  
   
179  my $ResourceCount = 0;  my $ResourceCount = 0;
180  $db->pl_update_module (\@target_modules,  $db->pl_update_module (\@target_modules,
181  get_module_index_file_name => sub {  get_module_index_file_name => sub {
182    shift; # $db    shift; # $db
183    daf_get_module_index_file_name (@_);    daf_get_module_index_file_name (shift);
184  },  },
185  get_module_source_document_from_uri => sub {  get_module_source_document_from_uri => sub {
186    my ($db, $module_uri, $module_for) = @_;    my ($db, $module_uri, $module_for) = @_;
# Line 189  get_referring_module_uri_list => sub { Line 230  get_referring_module_uri_list => sub {
230      unless (defined $ModuleSourceDISDocument{$module_uri}) {      unless (defined $ModuleSourceDISDocument{$module_uri}) {
231        daf_open_source_dis_document ($module_uri);        daf_open_source_dis_document ($module_uri);
232      }      }
     daf_convert_dis_document_to_dnl_document ();  
233    }    }
234    return daf_get_referring_module_uri_list ($module_uri);    return daf_get_referring_module_uri_list ($module_uri);
235  },  },
# Line 219  $db->read_properties (on_resource_read = Line 259  $db->read_properties (on_resource_read =
259      status_msg_ " " if ($ResourceCount % (10 * 10)) == 0;      status_msg_ " " if ($ResourceCount % (10 * 10)) == 0;
260      status_msg '' if ($ResourceCount % (10 * 50)) == 0;      status_msg '' if ($ResourceCount % (10 * 50)) == 0;
261    }    }
262  });  }, implementation => $impl);
263  status_msg '';  status_msg '';
264  status_msg "done";  status_msg "done";
265    
# Line 253  status_msg "done"; Line 293  status_msg "done";
293    
294  daf_check_undefined ();  daf_check_undefined ();
295    
296    undef %ModuleSourceDNLDocument;
297    exit $HasError if $HasError;
298    
299    ## --- Creating Files
300    
301  for (@{$Opt{create_module}}) {  for (@{$Opt{create_module}}) {
302    my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_;    my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_;
303    unless (defined $mod_for) {  
304      $mod_for = $db->get_module ($mod_uri)    if ($out_type eq 'perl-pm') {
305                    ->get_property_text (ExpandedURI q<dis:DefaultFor>,      daf_perl_pm ($mod_uri, $out_file_path, $mod_for);
306                                         ExpandedURI q<ManakaiDOM:all>);    } elsif ($out_type eq 'perl-t') {
307    }      daf_perl_t ($mod_uri, $out_file_path, $mod_for);
308    my $mod = $db->get_module ($mod_uri, for_arg => $mod_for);    } elsif ($out_type eq 'dtd-modules') {
309        daf_dtd_modules ($mod_uri, $out_file_path, $mod_for);
310    if ($out_type eq 'pm') {    } elsif ($out_type eq 'dtd-driver') {
311      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>;  
312    }    }
313  }  }
314    
315  daf_check_undefined ();  daf_check_undefined ();
316    
317    ## --- The END
318    
319  status_msg_ "Closing the database...";  status_msg_ "Closing the database...";
320  $db->free;  $db->free;
321  undef $db;  undef $db;
 undef %ModuleSourceDNLDocument;  
322  status_msg "done";  status_msg "done";
323    
324  undef $DNi;  undef $impl;
325    
326  {  {
327    use integer;    use integer;
# Line 303  END { Line 334  END {
334    $db->free if $db;    $db->free if $db;
335  }  }
336    
337    ## ---- Subroutines
338    
339  sub daf_open_source_dis_document ($) {  sub daf_open_source_dis_document ($) {
340    my ($module_uri) = @_;    my ($module_uri) = @_;
341    
# Line 380  sub daf_convert_dis_document_to_dnl_docu Line 413  sub daf_convert_dis_document_to_dnl_docu
413      my $dis_doc = $ModuleSourceDISDocument{$module_uri};      my $dis_doc = $ModuleSourceDISDocument{$module_uri};
414      next M unless $dis_doc;      next M unless $dis_doc;
415      verbose_msg_ qq<Converting <$module_uri>...>;      verbose_msg_ qq<Converting <$module_uri>...>;
416      my $dnl_doc = $DNi->convert_dis_document_to_dnl_document      my $dnl_doc = $impl->convert_dis_document_to_dnl_document
417                            ($dis_doc, database_arg => $db,                            ($dis_doc, database_arg => $db,
418                             base_namespace_binding =>                             base_namespace_binding =>
419                               {(map {$_->local_name => $_->target_namespace_uri}                               {(map {$_->local_name => $_->target_namespace_uri}
# Line 428  sub daf_get_referring_module_uri_list ($ Line 461  sub daf_get_referring_module_uri_list ($
461  sub dac_search_file_path_stem ($$$) {  sub dac_search_file_path_stem ($$$) {
462    my ($ns, $ln, $suffix) = @_;    my ($ns, $ln, $suffix) = @_;
463    require File::Spec;    require File::Spec;
464    for my $dir ('.', @{$Opt{input_search_path}->{$ns}||[]}) {    for my $dir (@{$Opt{input_search_path}->{$ns}||[]}) {
465      my $name = Cwd::abs_path      my $name = Cwd::abs_path
466          (File::Spec->canonpath          (File::Spec->canonpath
467           (File::Spec->catfile ($dir, $ln)));           (File::Spec->catfile ($dir, $ln)));
# Line 439  sub dac_search_file_path_stem ($$$) { Line 472  sub dac_search_file_path_stem ($$$) {
472    return undef;    return undef;
473  } # dac_search_file_path_stem;  } # dac_search_file_path_stem;
474    
475  sub daf_get_module_index_file_name ($$) {  sub daf_get_module_index_file_name ($) {
476    my ($module_uri) = @_;    my ($module_uri) = @_;
477    my $ns = $module_uri;    my $ns = $module_uri;
478    $ns =~ s/(\w+)\z//;    $ns =~ s/(\w+)\z//;
# Line 487  sub daf_db_module_resolver ($$$) { Line 520  sub daf_db_module_resolver ($$$) {
520    my ($db, $mod, $type) = @_;    my ($db, $mod, $type) = @_;
521    my $ns = $mod->namespace_uri;    my $ns = $mod->namespace_uri;
522    my $ln = $mod->local_name;    my $ln = $mod->local_name;
523    my $suffix = $type eq ExpandedURI q<dp:ModuleIndexFile>    my $suffix = {
524                   ? $Opt{dafx_suffix} : $Opt{daem_suffix};      ExpandedURI q<dp:ModuleIndexFile> => $Opt{dafx_suffix},
525        ExpandedURI q<dp:ModuleResourceFile> => $Opt{daem_suffix},
526        ExpandedURI q<dp:ModuleNodeStorageFile> => $Opt{dafs_suffix},
527      }->{$type} or die "Unsupported type: <$type>";
528    verbose_msg qq<Database module <$ns$ln> is requested>;    verbose_msg qq<Database module <$ns$ln> is requested>;
529    my $name = dac_search_file_path_stem ($ns, $ln, $suffix);    my $name = dac_search_file_path_stem ($ns, $ln, $suffix);
530    if (defined $name) {    if (defined $name) {
# Line 571  option is specified, the database file i Line 607  option is specified, the database file i
607  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.
608  Otherwise, a new database is created.  Otherwise, a new database is created.
609    
 =item C<--output-file-name=I<file-name>> (Required)  
   
 The  
   
610  =back  =back
611    
612  =head1 SEE ALSO  =head1 SEE ALSO
613    
 L<bin/dac2pm.pl> - Generating Perl module from "dac" file.  
   
614  L<lib/Message/Util/DIS.dis> - The actual implementation  L<lib/Message/Util/DIS.dis> - The actual implementation
615  of the "dis" interpretation.  of the "dis" interpretation.
616    
617  =head1 LICENSE  =head1 LICENSE
618    
619  Copyright 2004-2005 Wakaba <w@suika.fam.cx>.  All rights reserved.  Copyright 2004-2006 Wakaba <w@suika.fam.cx>.  All rights reserved.
620    
621  This program is free software; you can redistribute it and/or  This program is free software; you can redistribute it and/or
622  modify it under the same terms as Perl itself.  modify it under the same terms as Perl itself.

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.21

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24