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

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

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

revision 1.2 by dams, Fri Jul 11 17:54:51 2003 UTC revision 1.3 by dams, Sat Jul 12 14:11:50 2003 UTC
# Line 32  my @keywords_list = (); Line 32  my @keywords_list = ();
32  sub new {  sub new {
33      my ($pkg, $filename) = @_;      my ($pkg, $filename) = @_;
34      my $libconf = $pkg->Libconf::new($filename, 'samba', '');      my $libconf = $pkg->Libconf::new($filename, 'samba', '');
35  #    print Data::Dumper->Dump([$libconf],['libconf']) . "\n";      $libconf->setUniq();
     #my $ret = Libconf::Glueconf::generateFunctions(@synopsis);  
     #print " plop : $ret\n";  
     #eval Libconf::Glueconf::generateFunctions(@synopsis);  
     #$@ and die $@;  
 #    $self->{content} = {};  
36      tie my %wrapper, 'Libconf::Glueconf::Samba::Wrapper', $libconf;      tie my %wrapper, 'Libconf::Glueconf::Samba::Wrapper', $libconf;
 #    print Data::Dumper->Dump([%wrapper],['wrapper']) . "\n";  
37      \%wrapper;      \%wrapper;
38  }  }
39    
# Line 104  sub NEXTKEY { Line 98  sub NEXTKEY {
98      my $i = 0;      my $i = 0;
99      my $index;      my $index;
100      foreach (@pos) {      foreach (@pos) {
101          if ($obj->{libconf}->getAtom($_)->{section_name} eq $lastkey) {          $obj->{libconf}->getAtom($_)->{section_name} eq $lastkey and $index = $i;
             $index = $i;  
         }  
102          $i++;          $i++;
103      }      }
104      defined $index or return undef;      defined $index or return undef;
# Line 131  sub FETCH { Line 123  sub FETCH {
123      my ($obj, $key) = @_;      my ($obj, $key) = @_;
124      debug "key : $key";      debug "key : $key";
125      $key eq 'libconf' and return $obj->{libconf};      $key eq 'libconf' and return $obj->{libconf};
126      my @section_positions = $obj->{libconf}->findAtomPos( { type => 'SECTION', section_name => $key, sections => [ ] });      my $section_position = $obj->{libconf}->findAtomPos( { type => 'SECTION', section_name => $key, sections => [ ] });
127      my %ret;      my %ret;
128      @section_positions > 1 and die "there are multiple sections named $key, but I don't know how to handle them";      tie %ret, 'Libconf::Glueconf::Samba::SectionWrapper', $obj->{libconf}, $section_position;
     tie %ret, 'Libconf::Glueconf::Samba::SectionWrapper', $obj->{libconf}, $section_positions[0];  
129      \%ret;      \%ret;
130  }  }
131    
# Line 173  sub CLEAR { Line 164  sub CLEAR {
164      debug;      debug;
165      $obj->{lastatom} -= $obj->{libconf}->clearSection($obj->{firstatom});      $obj->{lastatom} -= $obj->{libconf}->clearSection($obj->{firstatom});
166      $obj->{lastatom} == $obj->{firstatom} + 1 or die "removed atoms number is wrong";      $obj->{lastatom} == $obj->{firstatom} + 1 or die "removed atoms number is wrong";
 #    $obj->{lastatom} = $obj->{firstatom} + 1;  
167  }  }
168    
169  sub DELETE {  sub DELETE {
170      my ($obj, $key) = @_;      my ($obj, $key) = @_;
171      debug "key : $key";      debug "key : $key";
172  #    my @pos = $obj->{libconf}->findAtomPos( { type => 'SECTION', section_name => $key, sections => [ ] },      my @pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key },
173  #                                            $obj->{firstatom}+1,                                              $obj->{firstatom}+1, $obj->{lastatom}-1
174  #                                            $obj->{lastatom}-1);                                            );
175      foreach ($obj->{firstatom}+1..$obj->{lastatom}-1) {      foreach (@pos) {
176          my $atom = $obj->{libconf}->getAtom($_);          $obj->{libconf}->deleteAtom($_);
177          if ($atom->{type} eq 'SECTION' &&          $obj->{lastatom}--;
             $atom->{section_name} eq $key) {  
             my $removed = $obj->{libconf}->deleteSection($_, 1);  
             $obj->{lastatom} -= $removed;  
             last;  
         } elsif ($atom->{type} eq 'KEY_VALUE' &&  
                  $atom->{key} eq $key) {  
             $obj->{libconf}->deleteAtom($_);  
             $obj->{lastatom}--;  
         } elsif ($atom->{type} eq 'VALUE' &&  
                  $atom->{value} eq $key) {  
             $obj->{libconf}->deleteAtom($_);  
             $obj->{lastatom}--;  
         }  
178      }      }
179  }  }
180    
# Line 206  sub FIRSTKEY { Line 183  sub FIRSTKEY {
183      debug;      debug;
184      $obj->{firstatom} + 1 == $obj->{lastatom} and return undef;      $obj->{firstatom} + 1 == $obj->{lastatom} and return undef;
185      my $atom = $obj->{libconf}->getAtom($obj->{firstatom}+1);      my $atom = $obj->{libconf}->getAtom($obj->{firstatom}+1);
     $atom->{type} eq 'SECTION' and return $atom->{section_name};  
186      $atom->{type} eq 'KEY_VALUE' and return $atom->{key};      $atom->{type} eq 'KEY_VALUE' and return $atom->{key};
     $atom->{type} eq 'VALUE' and return $atom->{value};  
187      die "houston, we have a problem";      die "houston, we have a problem";
188  }  }
189    
190  sub EXISTS {  sub EXISTS {
191      my ($obj, $key) = @_;      my ($obj, $key) = @_;
192      debug "key : $key";      debug "key : $key";
193      foreach ($obj->{firstatom}+1..$obj->{lastatom}-1) {      my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key },
194          my $atom = $obj->{libconf}->getAtom($_);                                              $obj->{firstatom}+1, $obj->{lastatom}-1
195          ($atom->{type} eq 'SECTION' && $atom->{section_name} eq $key) ||                                            );
196          ($atom->{type} eq 'KEY_VALUE' && $atom->{key} eq $key) and return 1;      defined $pos ? 1 : 0;
         ($atom->{type} eq 'VALUE' && $atom->{value} eq $key) and return 1;  
     }  
197  }  }
198    
199  sub NEXTKEY {  sub NEXTKEY {
200      my ($obj, $lastkey) = @_;      my ($obj, $lastkey) = @_;
201      debug "SectionWrapper - NEXTKEY - lastkey : $lastkey";      debug "SectionWrapper - NEXTKEY - lastkey : $lastkey";
202      foreach ($obj->{firstatom}+1..$obj->{lastatom}-1) {      my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $lastkey },
203          my $atom = $obj->{libconf}->getAtom($_);                                              $obj->{firstatom}+1, $obj->{lastatom}-1
204          if ($atom->{type} eq 'SECTION' && $atom->{section_name} eq $lastkey) {                                            );
205              $_+1 == $obj->{lastatom} and return undef;      !defined $pos || $pos+1 == $obj->{lastatom} and return undef;
206              return $obj->{libconf}->getAtom($_+1)->{section_name};      return $obj->{libconf}->getAtom($pos+1)->{key};
         }  
         if ($atom->{type} eq 'KEY_VALUE' && ! $atom->{type2} && $atom->{key} eq $lastkey) {  
             $_+1 == $obj->{lastatom} and return undef;  
             return $obj->{libconf}->getAtom($_+1)->{key};  
         }  
         if ($atom->{type} eq 'VALUE' && ! $atom->{type2} && $atom->{value} eq $lastkey) {  
             $_+1 == $obj->{lastatom} and return undef;  
             return $obj->{libconf}->getAtom($_+1)->{value};  
         }  
     }  
     undef;  
207  }  }
208    
209  sub STORE {  sub STORE {
210      my ($obj, $key, $value) = @_;      my ($obj, $key, $value) = @_;
211      debug "key : $key - value : $value";      debug "key : $key - value : $value";
212      #ref $value eq 'HASH' or die 'trying to store anything else than hash ref';      #ref $value eq 'HASH' or die 'trying to store anything else than hash ref';
213      my $index;      ref $value eq '' or die "try to store a hash in a kery_value atom";
214      if (ref $value eq 'HASH') {      my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key },
215          foreach ($obj->{firstatom}+1..$obj->{lastatom}-1) {                                              $obj->{firstatom}+1, $obj->{lastatom}-1
216              my $atom = $obj->{libconf}->getAtom($_);                                            );
217              ($atom->{type} eq 'SECTION' && $atom->{section_name} eq $key) and $index = $_, last;      if (!defined $pos) {
218          }          $pos = $obj->{libconf}->insertAtom($obj->{lastatom}, { type => 'KEY_VALUE', key => $key,
219          if (!defined $index) {                                                                 sections => [ @{$obj->{sections}} ],
220              $index = $obj->{libconf}->insertAtom($obj->{lastatom}, { section_name => $key,                                                               }
221                                                                      type => 'SECTION',                                            );
222                                                                      sections => [ @{$obj->{sections}} ],          $obj->{lastatom}++;
                                                                   } );  
             $obj->{libconf}->insertAtom($obj->{lastatom}, { type => 'ENDSECTION',  
                                                                     sections => [ @{$obj->{sections}} ],  
                                                                   });  
             $obj->{lastatom} += 2;  
         }  
         my %hash;  
         tie %hash, 'Libconf::Glueconf::Samba::SectionWrapper', $obj->{libconf}, $index;  
         %hash = %$value;  
     } elsif (ref $value eq '') {  
         foreach ($obj->{firstatom}+1..$obj->{lastatom}-1) {  
             my $atom = $obj->{libconf}->getAtom($_);  
             ($atom->{type} eq 'KEY_VALUE' && $atom->{key} eq $key) and $index = $_, last;  
         }  
         if (!defined $index) {  
             $index = $obj->{libconf}->insertAtom($obj->{lastatom}, { key => $key,  
                                                                     type => 'KEY_VALUE',  
                                                                     sections => [ @{$obj->{sections}} ],  
                                                                   } );  
             $obj->{lastatom}++;  
         }  
         $obj->{libconf}->editAtom($index, { value => $value });  
     } else {  
         die "not implemented yet";  
223      }      }
224        $obj->{libconf}->editAtom($pos, { value => $value });
225  }  }
226    
227  sub FETCH {  sub FETCH {
228      my ($obj, $key) = @_;      my ($obj, $key) = @_;
229      debug "key : $key\n";      debug "key : $key\n";
230      my $index;      my $pos = $obj->{libconf}->findAtomPos( {type => 'KEY_VALUE', key => $key },
231      foreach ($obj->{firstatom}+1..$obj->{lastatom}-1) { #CHANGE THIS, don't go into subsections, use better find_atom                                              $obj->{firstatom}+1, $obj->{lastatom}-1
232          my $atom = $obj->{libconf}->getAtom($_);                                            );
233          ($atom->{type} eq 'SECTION' && $atom->{section_name} eq $key) ||      defined $pos or return undef;
234          ($atom->{type} eq 'KEY_VALUE' && $atom->{key} eq $key) and $index = $_, last;      return $obj->{libconf}->getAtom($pos)->{value};
         ($atom->{type} eq 'VALUE' && $atom->{value} eq $key) and $index = $_, last;  
     }  
     defined $index or return undef;  
     my $atom = $obj->{libconf}->getAtom($index);  
     if ($atom->{type} eq 'SECTION') {  
         my %ret;  
         tie %ret, 'Libconf::Glueconf::Samba::SectionWrapper', $obj->{libconf}, $index;  
         return \%ret;  
     }  
     if ($atom->{type} eq 'KEY_VALUE') {  
         return $atom->{value};  
     }  
     if ($atom->{type} eq 'VALUE') {  
         return $atom->{value};  
     }  
235  }  }
236    
237  1;  1;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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