1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-12 17:35:35 +00:00

more default options when trying to localise gnuplot

This commit is contained in:
Antonin Portelli 2020-01-11 16:34:05 +00:00
parent 9f98ed42c3
commit caeb78b143

View File

@ -580,22 +580,23 @@ Plot & Plot::operator<<(PlotModifier &&modifier)
}
// find gnuplot ////////////////////////////////////////////////////////////////
#define SEARCH_DIR(dir) \
sprintf(buf, "%s/%s", dir, gnuplotBin_.c_str());\
if (access(buf, X_OK) == 0)\
{\
sprintf(buf,".");\
gnuplotPath_ = buf;\
\
return gnuplotPath_;\
}
std::string Plot::getProgramPath(void)
{
int i, j, lg;
char *path;
static char buf[MAX_PATH_LENGTH];
// trivial case: try in CWD
sprintf(buf,"./%s", gnuplotBin_.c_str()) ;
if (access(buf, X_OK) == 0)
{
sprintf(buf,".");
gnuplotPath_ = buf;
}
// try out in all paths given in the PATH variable
else
{
buf[0] = 0;
path = getenv("PATH") ;
if (path)
@ -621,16 +622,9 @@ std::string Plot::getProgramPath(void)
if (path[i] == ':') i++ ;
}
}
else
{
LATAN_ERROR(System, "PATH variable not set");
}
// if the buffer is still empty, the command was not found
if (buf[0] == 0)
if (buf[0] != 0)
{
LATAN_ERROR(System, "cannot find gnuplot in $PATH");
}
// otherwise truncate the command name to yield path only
lg = (int)(strlen(buf) - 1);
while (buf[lg]!='/')
{
@ -639,9 +633,19 @@ std::string Plot::getProgramPath(void)
}
buf[lg] = 0;
gnuplotPath_ = buf;
}
return gnuplotPath_;
}
// try in CWD, /usr/bin & /usr/local/bin
SEARCH_DIR(".");
SEARCH_DIR("/usr/bin");
SEARCH_DIR("/usr/local/bin");
// if this code is reached nothing was found
LATAN_ERROR(System, "cannot find gnuplot");
return "";
}
// plot parsing and output /////////////////////////////////////////////////////