From: Emden Gansner Date: Wed, 29 Feb 2012 20:33:07 +0000 (-0500) Subject: Allow the GVPRPATH variable to specify that the default path be prepended or X-Git-Tag: LAST_LIBGRAPH~32^2~466^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d5fd6cb886c2b632c6aab01b9248c4539768fdf;p=graphviz Allow the GVPRPATH variable to specify that the default path be prepended or appended to it. --- diff --git a/cmd/gvpr/gvpr.1 b/cmd/gvpr/gvpr.1 index addd852b5..b9411aca7 100644 --- a/cmd/gvpr/gvpr.1 +++ b/cmd/gvpr/gvpr.1 @@ -1125,7 +1125,12 @@ with the node whose name is \fBARGV[0]\fP, as an indented list. .TP .B GVPRPATH Colon\(hyseparated list of directories to be searched to find -the file specified by the \-f option. +the file specified by the \-f option. \fBgvpr\fP has a default list built in. If \fBGVPRPATH\fP +is not defined, the default list is used. If \fBGVPRPATH\fP starts with colon, the list is formed +by appending \fBGVPRPATH\fP to the default list. If \fBGVPRPATH\fP ends with colon, the list is formed +by appending the default list to \fBGVPRPATH\fP. Otherwise, \fBGVPRPATH\fP is used for the list. +.P +On Windows systems, replace ``colon'' with ``semicolon'' in the previous paragraph. .SH BUGS AND WARNINGS Scripts should be careful deleting nodes during \fBN{}\fP and \fBE{}\fP blocks using BFS and DFS traversals as these rely on stacks and queues of diff --git a/lib/gvpr/gvpr.c b/lib/gvpr/gvpr.c index 3d0c8f441..eb6b32545 100644 --- a/lib/gvpr/gvpr.c +++ b/lib/gvpr/gvpr.c @@ -191,6 +191,19 @@ static int parseArgs(char *s, int argc, char ***argv) #define LISTSEP ':' #endif +static Sfio_t* +concat (char* pfx, char* sfx, char** sp) +{ + Sfio_t *pathp; + if (!(pathp = sfstropen())) { + error(ERROR_ERROR, "Could not open buffer"); + return 0; + } + sfprintf(pathp, "%s%s", pfx, sfx); + *sp = sfstruse(pathp); + return pathp; +} + /* resolve: * Translate -f arg parameter into a pathname. * If arg contains '/', return arg. @@ -204,8 +217,10 @@ static char *resolve(char *arg) char *path; char *s; char *cp; + char c; char *fname = 0; Sfio_t *fp; + Sfio_t *pathp = NULL; size_t sz; #ifdef WIN32_DLL @@ -218,7 +233,15 @@ static char *resolve(char *arg) path = getenv("GVPRPATH"); if (!path) path = getenv("GPRPATH"); // deprecated - if (!path) + if (path && (c = *path)) { + if (c == LISTSEP) { + pathp = concat(DFLT_GVPRPATH, path, &path); + } + else if ((c = path[strlen(path)-1]) == LISTSEP) { + pathp = concat(path, DFLT_GVPRPATH, &path); + } + } + else path = DFLT_GVPRPATH; if (!(fp = sfstropen())) { @@ -253,6 +276,8 @@ static char *resolve(char *arg) error(ERROR_ERROR, "Could not find file \"%s\" in GVPRPATH", arg); sfclose(fp); + if (pathp) + sfclose(pathp); return fname; }