search path

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

search path

J.J. Green
Hi all

I've been using libconfuse for a while, but
have only just tried the "include" facility.  
To my disappointment, I find that included
files are not found if they are not in the
current directory, or a full path is given.  
I think this makes file inclusion barely useful.

A quick look at the code tells me that this would
be fairly easy to implement without disturbing
the API: For a null-terminated array of string

const char* path[] = { "/usr/local/share/myapp",
                       "/usr/share/myapp",
                       NULL };

int cfg_parse_path(cfg_t *cfg,
                   const char *filename,
                   const char** path)

assigns path to global const char** cfg_path
then checks for the existence of the files
at path/filename (with stat() or access())
and if found calls cfg_parse() with the found
file.

cfg_lexer_include() is modified to check the
global cfg_path and if not-null searches in
the same way.

Thoughts?

Would there be any interest in me adding this to
the main code branch rather than just making my
own fork?

Cheers

Jim
--
J.J. Green,  Seaview Sensing Ltd.,
http://seaviewsensing.com/



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

Re: search path

Martin Hedenfalk-4
Hi,

Instead of a global cfg_path, how about setting the include paths as a member of the cfg_t struct?

cfg_t *cfg = cfg_init(opt, flags);
cfg_set_include_paths(cfg, paths);
or
cfg_add_include_path(cfg, path);

then simply call cfg_parse as before, with your modifications to the lexer.

        -martin

21 apr 2010 kl. 12.01 skrev J.J. Green:

> Hi all
>
> I've been using libconfuse for a while, but
> have only just tried the "include" facility.  
> To my disappointment, I find that included
> files are not found if they are not in the
> current directory, or a full path is given.  
> I think this makes file inclusion barely useful.
>
> A quick look at the code tells me that this would
> be fairly easy to implement without disturbing
> the API: For a null-terminated array of string
>
> const char* path[] = { "/usr/local/share/myapp",
>                       "/usr/share/myapp",
>                       NULL };
>
> int cfg_parse_path(cfg_t *cfg,
>                   const char *filename,
>                   const char** path)
>
> assigns path to global const char** cfg_path
> then checks for the existence of the files
> at path/filename (with stat() or access())
> and if found calls cfg_parse() with the found
> file.
>
> cfg_lexer_include() is modified to check the
> global cfg_path and if not-null searches in
> the same way.
>
> Thoughts?
>
> Would there be any interest in me adding this to
> the main code branch rather than just making my
> own fork?
>
> Cheers
>
> Jim
> --
> J.J. Green,  Seaview Sensing Ltd.,
> http://seaviewsensing.com/
>
>
>
> _______________________________________________
> Confuse-devel mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/confuse-devel



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

Re: search path

J.J. Green
Hi Martin

> Instead of a global cfg_path, how about setting the include
> paths as a member of the cfg_t struct?

That's a better idea, I will implement this

Cheers

Jim
--
J.J. Green,  Seaview Sensing Ltd.,
http://seaviewsensing.com/



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