mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-24 11:15:51 +01:00
wmmenugen: Add executable detection, make Wmconfig use it
Add fileInPath, which determines whether or not a given file exists in $PATH (some heuristics apply). Make the Wconfig parser use it. Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
committed by
Carlos R. Mafra
parent
0451160f7d
commit
5377ec8fba
@@ -124,3 +124,48 @@ out:
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/* determine whether (first token of) given file is in $PATH
|
||||
*/
|
||||
Bool fileInPath(const char *file)
|
||||
{
|
||||
char *p, *t;
|
||||
static char *path = NULL;
|
||||
|
||||
if (!file || !*file)
|
||||
return False;
|
||||
|
||||
/* if it's an absolute path spec, don't override the user.
|
||||
* s/he might just know better.
|
||||
*/
|
||||
if (*file == '/')
|
||||
return True;
|
||||
|
||||
/* if it has a directory separator at random places,
|
||||
* we might know better.
|
||||
*/
|
||||
p = strchr(file, '/');
|
||||
if (p)
|
||||
return False;
|
||||
|
||||
if (!path) {
|
||||
path = getenv("PATH");
|
||||
if (!path)
|
||||
return False;
|
||||
}
|
||||
|
||||
p = wstrdup(file);
|
||||
t = strpbrk(p, " \t");
|
||||
if (t)
|
||||
*t = '\0';
|
||||
|
||||
t = wfindfile(path, p);
|
||||
wfree(p);
|
||||
|
||||
if (t) {
|
||||
wfree(t);
|
||||
return True;
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user