confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Confuse-devel] Deleting a section...


From: Nathan Phillip Brink
Subject: Re: [Confuse-devel] Deleting a section...
Date: Tue, 31 Aug 2010 23:56:43 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

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!

Attachment: pgpJ3CEHyVOMk.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]