[GRASS-dev] etc file finder, take 2

William Kyngesburye woklist at kyngchaos.com
Wed Apr 18 12:46:42 EDT 2007


On Apr 18, 2007, at 11:16 AM, Glynn Clements wrote:

> The main one is that I'd suggest using G_tokenize() to do most of the
> work for you.

(more C details that escape me...)

My little (basic) C book says a program shouldn't alter an env var  
returned by getenv, and G_tokenize() says it changes the token to  
null to terminate token strings (which is what I originally did  
myself before I read that bit about getenv).  Is that what that char  
** or const char * takes care of somehow, do either make a copy of  
the env var?  Or is it part of the tokenize initialization?

> Also, make the argument "const char *" (you don't need
> to modify it) and use GPATH_MAX as the size of the path buffer (I've
> been replacing various random constants with that value as I find
> them; also for GNAME_MAX and GMAPSET_MAX)..
Ah, I used an older find_file as a starting point.  I see you updated  
this yesterday.

> E.g. (untested):
> static char *G__find_etc(const char *name)
> {
> 	const char *pathlist = getenv("GRASS_ADDON_ETC");
> 	char path[GPATH_MAX];
> }
I'll give this a closer look and try it this evening.

> Also:
>> #include <grass/etc.h>
> Not needed; add it to gisdefs.h.
Oops, leftover from the earlier configured-paths version.  Not needed  
now.  But, I do have the prototype for G_find_etc() in gisdefs.h.

>> And a companion g.findetc for use in scripts:
>> 	exit(fpath==NULL);
> 	exit(fpath ? EXIT_SUCCESS : EXIT_FAILURE);
got it.

William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>

[Trillian]  What are you supposed to do WITH a maniacally depressed  

[Marvin]  You think you have problems?  What are you supposed to do  
if you ARE a maniacally depressed robot?  No, don't try and answer,  
I'm 50,000 times more intelligent than you and even I don't know the  

- HitchHiker's Guide to the Galaxy

More information about the grass-dev mailing list