#include "render.h"
#include "htmltable.h"
#include <limits.h>
-#ifdef WIN32
-#include "libltdl/lt_system.h"
-#endif
-#ifndef WIN32
-#include <unistd.h>
-#endif
#define RBCONST 12
#define RBCURVE .5
boolean pfilled; /* true if fill not handled by user shape */
char *color, *name;
int doMap = (obj->url || obj->explicit_tooltip);
- static char* ipfilename = NULL;
- static char* imagepath = NULL;
- static boolean firsttime = TRUE;
- char *p;
if (doMap && !(job->flags & EMIT_CLUSTERS_LAST))
gvrender_begin_anchor(job,
name = agget(n, "shapefile");
usershape_p = TRUE;
} else if ((name = agget(n, "image"))) {
-
- if (firsttime) {
- imagepath = agget(agraphof(n),"imagepath");
- firsttime = FALSE;
- }
- if ((access (safefile(name), R_OK) != 0) && imagepath != NULL){
- if (p = strrchr(name, '/'))
- name = ++p;
- ipfilename = realloc(ipfilename,(strlen(imagepath) + strlen(name) + 2));
- sprintf (ipfilename, "%s%s%s", imagepath, DIRSEP, name);
- name = ipfilename;
- }
usershape_p = TRUE;
}
if (usershape_p) {
/* safefile:
* Check to make sure it is okay to read in files.
- * For normal uses, it is a no-op, and returns the input.
* It returns NULL if the filename is trivial.
*
* If the application has set the SERVER_NAME environment variable,
* If filename contains multiple components, the user is
* warned, once, that everything to the left is ignored.
*
+ * For non-server applications, we use the path list in Gvimagepath to
+ * resolve relative pathnames.
+ *
* N.B. safefile uses a fixed buffer, so functions using it should use the
* value immediately or make a copy.
*/
#ifdef WIN32
-#define DIRSEP "\\"
#define PATHSEP ";"
#else
-#define DIRSEP "/"
#define PATHSEP ":"
#endif
+static char** mkDirlist (const char* list, int* maxdirlen)
+{
+ int cnt = 0;
+ char* s = strdup (list);
+ char* dir;
+ char** dirs = NULL;
+ int maxlen = 0;
+
+ for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) {
+ dirs = ALLOC (cnt+2,dirs,char*);
+ dirs[cnt++] = dir;
+ maxlen = MAX(maxlen, strlen (dir));
+ }
+ dirs[cnt] = NULL;
+ *maxdirlen = maxlen;
+ return dirs;
+}
+
+static char* findPath (char** dirs, int maxdirlen, const char* str)
+{
+ static char *safefilename = NULL;
+ char** dp;
+
+ /* allocate a buffer that we are sure is big enough
+ * +1 for null character.
+ * +1 for directory separator character.
+ */
+ safefilename = realloc(safefilename, (maxdirlen + strlen(str) + 2));
+
+ for (dp = dirs; *dp; dp++) {
+ sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str);
+ if (access (safefilename, R_OK) == 0)
+ return safefilename;
+ }
+ return NULL;
+}
+
const char *safefile(const char *filename)
{
static boolean onetime = TRUE;
- static boolean firsttime = TRUE;
- static char *safefilename = NULL;
+ static char *pathlist = NULL;
static int maxdirlen;
static char** dirs;
- char** dp;
const char *str, *p;
if (!filename || !filename[0])
return NULL;
- if (HTTPServerEnVar) {
+
+ if (HTTPServerEnVar) { /* If used as a server */
/*
* If we are running in an http server we allow
* files only from the directory specified in
}
return NULL;
}
- if (firsttime) {
- int cnt = 0;
- char* s = strdup (Gvfilepath);
- char* dir;
- for (dir = strtok (s, PATHSEP); dir; dir = strtok (NULL, PATHSEP)) {
- dirs = ALLOC (cnt+2,dirs,char*);
- dirs[cnt++] = dir;
- maxdirlen = MAX(maxdirlen, strlen (dir));
- }
- dirs[cnt] = NULL;
- firsttime = FALSE;
+ if (!pathlist) {
+ dirs = mkDirlist (Gvfilepath, &maxdirlen);
+ pathlist = Gvfilepath;
}
str = filename;
onetime = FALSE;
}
- /* allocate a buffer that we are sure is big enough
- * +1 for null character.
- * +1 for directory separator character.
- */
- safefilename = realloc(safefilename,
- (maxdirlen + strlen(str) + 2));
+ return findPath (dirs, maxdirlen, str);
+ }
- for (dp = dirs; *dp; dp++) {
- sprintf (safefilename, "%s%s%s", *dp, DIRSEP, str);
- if (access (safefilename, R_OK) == 0)
- return safefilename;
+ if (pathlist != Gvimagepath) {
+ if (dirs) {
+ free (dirs[0]);
+ free (dirs);
+ dirs = NULL;
}
- return NULL;
+ pathlist = Gvimagepath;
+ if (pathlist && *pathlist)
+ dirs = mkDirlist (pathlist, &maxdirlen);
}
- /* else, not in server, use original filename without modification. */
- else
+
+ if ((*filename == DIRSEP[0]) || !dirs)
return filename;
+
+ return findPath (dirs, maxdirlen, filename);
}
int maptoken(char *p, char **name, int *val)
#include <string.h>
#include <errno.h>
-#ifdef WIN32
-#include "libltdl/lt_system.h"
-#endif
-#ifndef WIN32
-#include <unistd.h>
-#endif
-
#include "types.h"
#include "logic.h"
#include "memory.h"
#define XML_MAGIC "<?xml"
#define SVG_MAGIC "<svg"
-#ifdef WIN32
-#define DIRSEP "\\"
-#else
-#define DIRSEP "/"
-#endif
-
static knowntype_t knowntypes[] = {
{ PNG_MAGIC, sizeof(PNG_MAGIC)-1, FT_PNG, "png", },
{ PS_MAGIC, sizeof(PS_MAGIC)-1, FT_PS, "ps", },
*/
point gvusershape_size(graph_t * g, char *name)
{
- static char *ipfilename = NULL;
- static char* imagepath;
- static boolean firsttime = TRUE;
- const char *str;
- char *p;
point rv;
pointf dpi;
-
+
/* no shape file, no shape size */
if (!name || (*name == '\0')) {
rv.x = rv.y = -1;
dpi.x = dpi.y;
else
dpi.x = dpi.y = (double)DEFAULT_DPI;
-
- //imagepath is typically set as a graph attribute on macos platforms
- //It points to the directory where node images are located
- if (firsttime) {
- imagepath = agget(g,"imagepath");
- firsttime = FALSE;
- }
- if ((access (safefile(name), R_OK) != 0) && imagepath != NULL){
- if (p = strrchr(name, '/'))
- name = ++p;
- ipfilename = realloc(ipfilename,(strlen(imagepath) + strlen(name) + 2));
- sprintf (ipfilename, "%s%s%s", imagepath, DIRSEP, name);
- name = ipfilename;
- }
return gvusershape_size_dpi (gvusershape_open (name), dpi);
-
}