/[libconf]/libconf/perl-Libconf/Libconf.pm
ViewVC logotype

Diff of /libconf/perl-Libconf/Libconf.pm

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

revision 1.23 by chl, Tue May 6 20:37:05 2003 UTC revision 1.24 by dams, Sat May 24 17:27:19 2003 UTC
# Line 250  sub writeConf { Line 250  sub writeConf {
250      open F, "> $filename" or die "cannot create config file $filename";      open F, "> $filename" or die "cannot create config file $filename";
251      foreach my $atom (@out_atoms) {      foreach my $atom (@out_atoms) {
252  #       print F "\n" x $$atom{line_feed};  #       print F "\n" x $$atom{line_feed};
253          $$atom{comments} and print F eval($templates{$template_name}{comment_output}) foreach split("\n", $$atom{comments});  #       $$atom{comments} and print F eval($templates{$template_name}{comment_output}) foreach split("\n", $$atom{comments});
254          if (exists $templates{$template_name}->{output}{$atom->{type}}) {          if (exists $templates{$template_name}->{output}{$atom->{type}}) {
255              print F eval($templates{$template_name}->{output}{$atom->{type}});              print F eval($templates{$template_name}->{output}{$atom->{type}});
256          } else {          } else {
# Line 272  sub parse { Line 272  sub parse {
272      my $line_idx = 1;      my $line_idx = 1;
273      foreach my $in (@file) {      foreach my $in (@file) {
274          $out_atoms[$item] ||= {};          $out_atoms[$item] ||= {};
275          $in eq "\n" and $out_atoms[$item]->{comments} .= " \n", next;          $out_atoms[$item]->{comments} ||= [];
276          $in =~ /^(\s*)\n$/ and $out_atoms[$item]->{comments} .= "$1\n", next;          $in =~ /^(\s*)\n$/ and push(@{$out_atoms[$item]->{comments}}, { comment => $1, inline => 0 }), next;
277  #       $in eq "\n" and $out_atoms[$item]->{line_feed}++, next;  #       $in eq "\n" and $out_atoms[$item]->{line_feed}++, next;
278          chomp $in;          chomp $in;
279          #see if we are in a line previously commented          #see if we are in a line previously commented
280          if ($out_atoms[$item]->{current_comment}) {          if ($out_atoms[$item]->{current_comment}) {
281              my $c = $out_atoms[$item]->{current_comment};              my $c = $out_atoms[$item]->{current_comment};
282              if ($in =~ s/^(.*)\Q$c\E//) {              if ($in =~ s/^(.*\Q$c\E)//) {
283                  $out_atoms[$item]->{comments} .= "$1\n";                  push(@{$out_atoms[$item]->{comments}}, { comment => $1, inline => $in =~ /^\s*$/ ? 0 : -1 });
284                  undef $out_atoms[$item]->{current_comment};                  undef $out_atoms[$item]->{current_comment};
285              } else {              } else {
286                  $out_atoms[$item]->{comments} .= "$in\n";                  push(@{$out_atoms[$item]->{comments}}, { comment => $in, inline => 0 });
287                  $in = '';                  $in = '';
288              }              }
289          } else {          } else {
# Line 302  sub parse { Line 302  sub parse {
302                              $level or $end = $i-$start;                              $level or $end = $i-$start;
303                          }                          }
304                      }                      }
305                      $end and $out_atoms[$item]->{comments} .= substr($in, $start + length($open), $end) . "\n";                      $end and push(@{$out_atoms[$item]->{comments}}, { comment => substr($in, $start, $end + length($close)),
306                                                                        inline => $start > 0 ? 1 : 0 });
307                      substr($in, $start, $end + length($close)) = '';                      substr($in, $start, $end + length($close)) = '';
308                      $level and $out_atoms[$item]->{current_comment} = $close, $out_atoms[$item]->{current_level} = $level;                      $level and $out_atoms[$item]->{current_comment} = $close, $out_atoms[$item]->{current_level} = $level;
309                  } elsif (defined $open && defined $close) {                  } elsif (defined $open && defined $close) {
310                      $in =~ s/\Q$open\E(.*)\Q$close\E/$out_atoms[$item]->{comments} .= "$1\n"; undef/eg;                      $in =~ s/(\Q$open\E.*\Q$close\E)/push(@{$out_atoms[$item]->{comments}}, { comment => $1, inline => length($') ? -1 : (length($`) ? 1 : 0) }); undef/eg;
311                      $in =~ s/\Q$open\E(.*)$// and $out_atoms[$item]->{comments} .= "$1\n", $out_atoms[$item]->{current_comment} = $close,last;                      #$in =~ s/(\Q$open\E.*\Q$close\E)/$out_atoms[$item]->{comments} .= "$1\n"; undef/eg;
312                  }                      $in =~ s/(\Q$open\E.*)$// and push(@{$out_atoms[$item]->{comments}}, { comment => $1,
313                  elsif (defined $open) {                                                                                          inline => $in =~ /^\s*$/ ? 0 : 1 }
314                      $in =~ s/\Q$open\E(.*)$// and $out_atoms[$item]->{comments} .= "$1\n";                                                        ), $out_atoms[$item]->{current_comment} = $close, last;
315                    } elsif (defined $open) {
316                        if ($in =~ s/(\Q$open\E.*)$//) {
317                            my $tmp = $1;
318                            push(@{$out_atoms[$item]->{comments}}, { comment => $tmp,
319                                                                     inline => $in =~ /^\s*$/ ? 0 : 1 });
320                        }
321                  }                  }
322              }              }
323          }          }
# Line 341  sub parse { Line 348  sub parse {
348      $out->{atoms} = [@out_atoms];      $out->{atoms} = [@out_atoms];
349  }  }
350    
351    sub handle_comment {
352        my ($string, $comments) = @_;
353        require Data::Dumper;
354        print "-------------\n";
355        print Data::Dumper::Dumper($string) . "\n";
356        print Data::Dumper::Dumper($comments) . "\n";
357        print "-------------\n";
358        my $ret = '';
359        my $flag = 1;
360        foreach my $comment (@$comments) {
361            $comment->{inline} == -1 and $ret .= $comment->{comment} . " $string\n", $flag = 0;
362            $comment->{inline} == 0 and $ret .= $comment->{comment} . "\n";
363            $comment->{inline} == 1 and $ret .= "$string " . $comment->{comment} . "\n", $flag = 0;
364        }
365        $ret . ($flag ? $string . "\n" : '');
366    }
367    
368  sub debug {  sub debug {
369      $ENV{DEBUG} or return;      $ENV{DEBUG} or return;
370      my $i = 0;      my $i = 0;

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26