Deleting a section...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting a section...

Sergey Katsev
I'm trying to programmatically delete a section.  Here's some background:

> Hi,
>
> Is there any supported way of deleting a section?
>
> For example, if I have a configuration file that has:
>
> thing name1 {
> parameter1 = "abc"
> parameter2 = "efg"
> }
>
> thing name2 {
> parameter1 = "efc"
> parameter2 = "foo"
> }
>
> I want to be able to:
>
> 1) parse the file
> 2) loop through all of the "things", find the one called "name2"
> 3) delete it so it's completely gone
> 4) write the result back to the file
>
> I don't see any way to do #3.  cfg_free, which seems to be what I would want ends up trashing memory if you try to write this configuration file back out, and cfg_free_value just clears the values rather than deleting the whole thing.
>
> Any ideas on where to look?
>

Martin replied and said this isn't currently supported so I'm looking for a way to implement it.

What I'm trying right now is using cfg_free() on opt->values[i]->section, and then decrement opt->nvalues.  

However, it looks like although it "works", it corrupts memory so the next time I try to use the in-memory parsed data, I get core dumps.  Is there something else that I'm not cleaning up that I should be?

Thanks in advance.

Sergey
_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel
Reply | Threaded
Open this post in threaded view
|

Re: Deleting a section...

ohnobinki
On Tue, Aug 31, 2010 at 04:55:18PM -0400, Sergey Katsev wrote:

> I'm trying to programmatically delete a section.  Here's some background:
>
> > Hi,
> >
> > Is there any supported way of deleting a section?
> >
> > For example, if I have a configuration file that has:
> >
> > thing name1 {
> > parameter1 = "abc"
> > parameter2 = "efg"
> > }
> >
> > thing name2 {
> > parameter1 = "efc"
> > parameter2 = "foo"
> > }
> >
> > I want to be able to:
> >
> > 1) parse the file
> > 2) loop through all of the "things", find the one called "name2"
> > 3) delete it so it's completely gone
> > 4) write the result back to the file
> >
> > I don't see any way to do #3.  cfg_free, which seems to be what I would want ends up trashing memory if you try to write this configuration file back out, and cfg_free_value just clears the values rather than deleting the whole thing.
> >
> > Any ideas on where to look?
> >
>
> Martin replied and said this isn't currently supported so I'm looking for a way to implement it.
>
> What I'm trying right now is using cfg_free() on opt->values[i]->section, and then decrement opt->nvalues.  
>
> However, it looks like although it "works", it corrupts memory so the next time I try to use the in-memory parsed data, I get core dumps.  Is there something else that I'm not cleaning up that I should be?
I think you at least have to shift all of the values after i back one slot in the opt->values array. Possibly with something like:
memmove(&opt->values[i], &opt->values[i + 1], sizeof(cfg_value_t *) * opt->nvalues - 1 - i);

Sorry, I don't have time to test this directly myself or look much further then at just what's in your email.

--
binki

Look out for missing apostrophes!

_______________________________________________
Confuse-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/confuse-devel

attachment0 (205 bytes) Download Attachment