Adding a section programmatically?

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

Adding a section programmatically?

Kelan Champagne-2
Hi-

I'm just started using libConfuse, and am liking it so far.  However, I have run into 1 issue.

I'd like to be able to read in a config file, add a section (programmatically), and then write the config info back out to the file (with the newly-added section).  But, I don't see a way to do that right now (unless I'm missing something).

Specifically, I was expecting something like cfg_setsec(), but couldn't find anything like that.  I was able to add that function myself (by following the example of the other cfg_set*() functions -- so I actually added cfg_setsec(), cfg_setnsec(), and cfg_opt_setnsec()), but my implementation only works when adding a single section.  If you try to to pass an index aside from 0, it hits the assert at the top of cfg_opt_getval(), because my repeatable section has the CFGF_MULTI flag set (which applies to sections only) and not the CFGF_LIST flag, which that assert is expecting.

I attached my patch (based on the v2.7 downloadable source).

Can anyone provide some insight on how it might be possible to extend this to support multiple sections?

Thanks,
-Kelan



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

libConfuse_addSection.patch (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Adding a section programmatically?

Kelan Champagne-2
On Wed, Nov 9, 2011 at 1:07 PM, Kelan Champagne
<[hidden email]> wrote:
> I was able to add that function myself (by following the example of the other
> cfg_set*() functions -- so I actually added cfg_setsec(), cfg_setnsec(), and
> cfg_opt_setnsec()), but my implementation only works when adding a single
> section.  If you try to to pass an index aside from 0, it hits the assert at
> the top of cfg_opt_getval(), because my repeatable section has the CFGF_MULTI
> flag set (which applies to sections only) and not the CFGF_LIST flag, which
> that assert is expecting.
>
> I attached my patch (based on the v2.7 downloadable source).

I figured out a better approach that adds sections in (what I think is) a more
correct way.  It allows me to add multiple sections programmatically (which was
the basic functionality that I needed, and wasn't working in my previous
patch).  I have attached the updated patch.

I'm still curious to know if there is already a way to do this, or maybe if
this patch would be useful to others.

Thanks,
-Kelan

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

updated_libConfuse_sections.patch (1K) Download Attachment