From: John Ellson Date: Thu, 16 Aug 2012 12:04:35 +0000 (-0400) Subject: provide replacement for missing strtok_r() X-Git-Tag: LAST_LIBGRAPH~32^2~348 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a1f262ee4b06d6ac2193d8a292322584513bbc8;p=graphviz provide replacement for missing strtok_r() --- diff --git a/configure.ac b/configure.ac index 3c8a916a8..0888a323f 100644 --- a/configure.ac +++ b/configure.ac @@ -475,7 +475,7 @@ AC_FUNC_ALLOCA AC_CHECK_FUNCS([lrand48 drand48 srand48 setmode setenv getenv \ __freadable _sysconf getrusage strerror cbrt lsqrt vsnprintf \ strtoul strtoll strtoull uname memset nl_langinfo pow sqrt \ - strchr strdup strerror strstr _NSGetEnviron]) + strchr strdup strerror strstr strtok_r _NSGetEnviron]) AC_REPLACE_FUNCS([strcasecmp strncasecmp strcasestr]) diff --git a/lib/common/emit.c b/lib/common/emit.c index 11e2de9f8..0f84d0182 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -28,14 +28,41 @@ #include "gvc.h" #include "xdot.h" -#ifdef WIN32 -#define strtok_r strtok_s -#endif - #define P2RECT(p, pr, sx, sy) (pr[0].x = p.x - sx, pr[0].y = p.y - sy, pr[1].x = p.x + sx, pr[1].y = p.y + sy) #define FUZZ 3 #define EPSILON .0001 +// #ifdef WIN32 +// #define strtok_r strtok_s +// #endif + +#ifndef HAVE_STRTOK_R +/* + * From: http://sourceforge.net/tracker/?func=detail&aid=2673480&group_id=2435&atid=352435 + * + * NB this implementation uses strok(), so will corrupt any existing strok() state. + */ +char *strtok_r(char *str, const char *delim, char **save) +{ + char *res, *last; + + if( !save ) + return strtok(str, delim); + if( !str && !(str = *save) ) + return NULL; + last = str + strlen(str); + if( (*save = res = strtok(str, delim)) ) + { + *save += strlen(res); + if( *save < last ) + (*save)++; + else + *save = NULL; + } + return res; +} +#endif + typedef struct { xdot_op op; boxf bb;