[splint-discuss] Syntax of INCLUDE and LARCH_PATH environment variables
Juan Manuel Guerrero
juan.guerrero at gmx.de
Fri Feb 1 04:01:17 PST 2008
A couple of weeks ago while I was porting Splint 3.1.2 to MSDOS and clones using
the DJGPP compiling environment <www.delorie.com> I have observed the following
issue that is OS and compiling environment independent and that I do not
understand. The issue is the different behaviour if splint is started with the
"-I" command line option or used with the INCLUDE environment variable instead.
E.G.: if the INCLUDE environment variable is not set and splint is started with
a command like this:
splint -I /include foo.c
then an entry in the g_cppState struct will be created for the chain of include
dirs to be searched for. If the user decides to set the INCLUDE environment
variable with this value and omit the "-I /include" option from the command
line no entry at all is produced for g_cppState struct and the header files may
not be found. The situation changes if the user terminates the string with the
path separating char for that OS. E.G.: this works as expected:
INCLUDE=/include:
Please note the colon at the end of the environment value. It is the path
separating char for posix OSs. The reason for this behaviour becomes clear
when the following code snippet form function main() in llmain.c is inspected:
[snip]
cstring incval = cstring_copy (osd_getEnvironmentVariable (INCLUDEPATH_VAR));
cstring oincval = incval;
if (cstring_isDefined (incval))
{
/*
** Each directory on the include path is a system include directory.
*/
DPRINTF (("include: %s", incval));
context_setString (FLG_SYSTEMDIRS, cstring_copy (incval));
while (cstring_isDefined (incval))
{
/*@access cstring@*/
char *nextsep = strchr (incval, PATH_SEPARATOR);
if (nextsep != NULL)
{
cstring dir;
*nextsep = '\0';
dir = cstring_copy (incval);
if (cstring_length (dir) == 0
|| !isalpha ((int) cstring_firstChar (dir)))
{
/*
** win32 environment values can have special values,
** ignore them
*/
}
else
{
cppAddIncludeDir (dir);
}
*nextsep = PATH_SEPARATOR;
incval = cstring_fromChars (nextsep + 1);
cstring_free (dir);
}
else
{
break;
}
/*@noaccess cstring@*/
}
}
[snip]
The variable incval contains the value of the INCLUDE environment variable. As
can be seen the code line:
char *nextsep = strchr (incval, PATH_SEPARATOR);
checks for the occurence of the path separating char. If there is no one then
the value of INCLUDE is simply completely ignored. This means that the user
must always remember to add a last colon to the environment variable. This is
realy quite unusual. It is important to notice that if there are multiple
entries in the INCLUDE variable like this:
INCLUDE=/include1:/include2:/include3
the last entry (/include3 in this case) is always ignored because it is has not
been terminated with a path separating char.
It is instructive to notice that the same behaviour happens for the LARCH_PATH
environment variable.
Now the question arises if this is a bug or a feature?
I have inspected the splint documentation and it was not possible to me to find
a clear description of the syntax of the INCLUDE and LARCH_PATH environment
variables.
IMHO or the parsing code for the variables must be a changed or the documentation
must clearly explain what the syntax of the environment variables shall look like.
If I am missing something, please let me know.
Regards,
Juan M. Guerrero
More information about the splint-discuss
mailing list