/[webpac]/trunk2/all2xml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk2/all2xml.pl

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

revision 255 by dpavlin, Tue Mar 9 12:17:05 2004 UTC revision 298 by dpavlin, Fri Apr 2 23:31:25 2004 UTC
# Line 17  $|=1; Line 17  $|=1;
17    
18  my $config_file = $0;  my $config_file = $0;
19  $config_file =~ s/\.pl$/.conf/;  $config_file =~ s/\.pl$/.conf/;
20    $config_file = $ARGV[0] if (-f $ARGV[0]);
21  die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);  die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);
22    
23  my $config;  my $config;
# Line 151  sub data2xml { Line 152  sub data2xml {
152          }          }
153    
154    
155            # init variables for different types
156            sub init_visible_type($) {
157                    my $type = shift;
158    
159                    # swish, swish_exact, display, index, index_lookup
160                    # swish and display defaults
161                    my ($s,$se,$d,$i,$il) = (1,0,1,0,0);
162                    if (lc($type) eq "display") {
163                            $s = 0;
164                    } elsif (lc($type) eq "swish") {
165                            $d = 0;
166                    } elsif (lc($type) eq "index") {
167                            ($s,$se,$d,$i) = (0,1,0,1);
168                    } elsif (lc($type) eq "swish_exact") {
169                            ($s,$se,$d,$i) = (0,1,0,0);
170                    } elsif (lc($type) =~ /^lookup/) {
171                            ($s,$se,$d,$i,$il) = (0,1,0,0,1);
172                    }
173                    return ($s,$se,$d,$i,$il);
174            }
175    
176    
177            # convert
178            #
179            # <tag>
180            #  <delimiter>, </delimiter>
181            #  <value>200a</value>
182            # </tag>
183            #
184            # to
185            #
186            # <tag delimiter=", ">200a</tag>
187            #
188            # but without loosing spaces in delimiter (becasue
189            # new XML::Simple strips spaces in attribute values
190            # as defined in XML specification)
191            #
192            sub unroll_x($) {
193                    my $x = shift;
194    
195                    if (defined $x->{value}) {
196                            my ($v,$d) = ($x->{value}->{content}, $x->{delimiter}->{content});
197                            delete $x->{value};
198                            delete $x->{delimiter};
199                            $x->{content} = $v;
200                            $x->{delimiter} = $d;
201                    }
202                    return $x;
203            }
204    
205          # begin real work: go field by field          # begin real work: go field by field
206          foreach my $field (@sorted_tags) {          foreach my $field (@sorted_tags) {
207    
# Line 184  sub data2xml { Line 235  sub data2xml {
235    
236                  foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) {
237    
238                            $x = unroll_x($x);
239    
240                          my $format = x($x->{content});                          my $format = x($x->{content});
241                          my $delimiter = x($x->{delimiter}) || ' ';                          my $delimiter = x($x->{delimiter}) || ' ';
242    
243                          my $repeat_off = 0;     # init repeatable offset                          my $repeat_off = 0;     # init repeatable offset
244    
245                          # swish, swish_exact, display, index, index_lookup                          my ($s,$se,$d,$i,$il) = init_visible_type($x->{type});
                         # swish and display defaults  
                         my ($s,$se,$d,$i,$il) = (1,0,1,0,0);  
                         $s = 0 if (lc($x->{type}) eq "display");  
                         $d = 0 if (lc($x->{type}) eq "swish");  
                         ($s,$se,$d,$i) = (0,1,0,1) if (lc($x->{type}) eq "index");  
                         ($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact");  
                         ($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/);  
246    
247                          # what will separate last line from this one?                          # what will separate last line from this one?
248                          if ($display_data && $x->{append}) {                          if ($display_data && $x->{append}) {
249                                  $line_delimiter = ' ';                                  $line_delimiter = $delimiter;
250                          } elsif ($display_data) {                          } elsif ($display_data) {
251                                  $line_delimiter = '<br/>';                                  $line_delimiter = '<br/>';
252                          }                          }
# Line 210  sub data2xml { Line 256  sub data2xml {
256    
257                          # placeholder for all repeatable entries for index                          # placeholder for all repeatable entries for index
258    
                         sub chk_eval($) {  
                                 my $data = shift;  
                                 return if (! defined($data));  
                                 if ($data && $data =~ s/\s*eval{([^}]+)}\s*//) {  
                                         if (eval "$1") {  
                                                 return $data;  
                                         } else {  
                                                 return undef;  
                                         }  
                                 } else {  
                                         return $data;  
                                 }  
                         }  
   
259                          sub mkformat($$) {                          sub mkformat($$) {
260                                  my $x = shift || die "mkformat needs tag reference";                                  my $x = shift || die "mkformat needs tag reference";
261                                  my $data = shift || return;                                  my $data = shift || return;
262                                  my $format_name = x($x->{format_name}) || return chk_eval($data);                                  my $format_name = x($x->{format_name}) || return $data;
263                                  my $fmt = x($config->{format}->{$format_name}->{content}) || die "<format name=\"$format_name\"> is not defined!";                                  my $fmt = x($config->{format}->{$format_name}->{content}) || die "<format name=\"$format_name\"> is not defined!";
264                                  my $format_delimiter = x($x->{format_delimiter});                                  my $format_delimiter = x($x->{format_delimiter});
265                                  my @data;                                  my @data;
# Line 240  sub data2xml { Line 272  sub data2xml {
272                                  if ($fmt) {                                  if ($fmt) {
273                                          my $nr = scalar $fmt =~ s/%s/%s/g;                                          my $nr = scalar $fmt =~ s/%s/%s/g;
274                                          if (($#data+1) == $nr) {                                          if (($#data+1) == $nr) {
275                                                  return chk_eval(sprintf($fmt,@data));                                                  return sprintf($fmt,@data);
276                                          } else {                                          } else {
277                                                  #print STDERR "mkformat: [$data] can't be split on [$format_delimiter] to $nr fields!\n";                                                  #print STDERR "mkformat: [$data] can't be split on [$format_delimiter] to $nr fields!\n";
278                                                  return chk_eval($data);                                                  return $data;
279                                          }                                          }
280                                  } else {                                  } else {
281                                          print STDERR "usage of link '$format_name' without defined format (<link> tag)\n";                                          print STDERR "usage of link '$format_name' without defined format (<link> tag)\n";
# Line 292  sub data2xml { Line 324  sub data2xml {
324                                  }                                  }
325                                  # type="swish" ; field for swish                                  # type="swish" ; field for swish
326                                  if ($swish) {                                  if ($swish) {
327                                            my $tmp = $swish;
328                                          if ($filter && ($s || $se)) {                                          if ($filter && ($s || $se)) {
329                                                  no strict 'refs';                                                  no strict 'refs';
330                                                  my $tmp = join(" ",&$filter($swish)) if ($s || $se);                                                  $tmp = join(" ",&$filter($tmp)) if ($s || $se);
                                                 $swish_data .= $tmp if ($s);  
                                                 $swish_exact_data .= "xxbxx $tmp xxexx " if ($se && $tmp ne "");  
   
                                         } else {  
                                                 $swish_data .= $swish if ($s);  
                                                 $swish_exact_data .= "xxbxx $swish xxexx " if ($se && $swish ne "");  
331                                          }                                          }
332    
                                         $tmp = chk_eval($tmp);  
333                                          $swish_data .= $tmp if ($s && $tmp);                                          $swish_data .= $tmp if ($s && $tmp);
334                                          $swish_exact_data .= "xxbxx $tmp xxexx " if ($se && $tmp ne "");                                          $swish_exact_data .= "xxbxx $tmp xxexx " if ($tmp && $tmp ne "" && $se);
335                                  }                                  }
336    
337                                  # type="display" ; field for display                                  # type="display" ; field for display
# Line 338  sub data2xml { Line 364  sub data2xml {
364                                                  no strict 'refs';                                                  no strict 'refs';
365                                                  $idisplay = &$filter($idisplay);                                                  $idisplay = &$filter($idisplay);
366                                          }                                          }
                                         $idisplay = chk_eval($idisplay);  
367                                          push @index_data, $idisplay if ($idisplay && !$iterate_by_page);                                          push @index_data, $idisplay if ($idisplay && !$iterate_by_page);
368                                  }                                  }
369    
# Line 438  sub data2xml { Line 463  sub data2xml {
463                  # now try to parse variables from configuration file                  # now try to parse variables from configuration file
464                  foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) {
465    
466                            $x = unroll_x($x);
467    
468                          my $delimiter = x($x->{delimiter}) || ' ';                          my $delimiter = x($x->{delimiter}) || ' ';
469                          my $val = $cfg->val($database, x($x->{content}));                          my $val = $cfg->val($database, x($x->{content}));
470    
471                          my ($s,$d,$i) = (1,1,0);        # swish, display default                          # FIXME index_lookup is not supported!
472                          $s = 0 if (lc($x->{type}) eq "display");                          my ($s,$se,$d,$i,$il) = init_visible_type($x->{type});
                         $d = 0 if (lc($x->{type}) eq "swish");  
                         # no support for swish exact in config.  
                         # IMHO, it's useless  
                         ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");  
473    
474                          if ($val) {                          if ($val) {
475                                  $display_data .= $delimiter.$val if ($d);                                  $display_data .= $delimiter.$val if ($d);
476                                  $swish_data .= $val if ($s);                                  $swish_data .= " ".$val if ($s);
477                                  $index->insert($field, $val, $path) if ($i);                                  $index->insert($field, $val, $path) if ($i);
478                          }                          }
479    
# Line 626  print STDERR "reading ./import_xml/$type Line 649  print STDERR "reading ./import_xml/$type
649          my $type_base = $type;          my $type_base = $type;
650          $type_base =~ s/_.+$//g;          $type_base =~ s/_.+$//g;
651    
652          $config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type_base}, 'config', 'format' ], forcecontent => 1);          $config=XMLin("./import_xml/$type.xml", ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], ForceContent => 1 );
653    
654          # output current progress indicator          # output current progress indicator
655          my $last_p = 0;          my $last_p = 0;
# Line 896  __END__ Line 919  __END__
919    
920  all2xml.pl - read various file formats and dump XML for SWISH-E  all2xml.pl - read various file formats and dump XML for SWISH-E
921    
922    =head1 SYNOPSYS
923    
924     $ all2xml.pl [test.conf]
925    
926  =head1 DESCRIPTION  =head1 DESCRIPTION
927    
928  This command will read ISIS data file using OpenIsis perl module, MARC  This command will read ISIS data file using OpenIsis perl module, MARC
# Line 904  create one XML file for usage with I<SWI Line 931  create one XML file for usage with I<SWI
931  this script B<isn't general xml generator> from isis files (isis allready  this script B<isn't general xml generator> from isis files (isis allready
932  has something like that). Output of this script is tailor-made for SWISH-E.  has something like that). Output of this script is tailor-made for SWISH-E.
933    
934    If no configuration file is specified, it will use default one called
935    C<all2xml.conf>.
936    
937  =head1 BUGS  =head1 BUGS
938    
939  Documentation is really lacking. However, in true Open Source spirit, source  Documentation is really lacking. However, in true Open Source spirit, source

Legend:
Removed from v.255  
changed lines
  Added in v.298

  ViewVC Help
Powered by ViewVC 1.1.26