From: ellson Date: Thu, 25 May 2006 15:02:28 +0000 (+0000) Subject: some input-filter hook code, disabled X-Git-Tag: LAST_LIBGRAPH~32^2~6546 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e8e595e0876fb54140129d5dedaf17413d5d620;p=graphviz some input-filter hook code, disabled --- diff --git a/lib/common/input.c b/lib/common/input.c index 8d35d789c..0ddfe016f 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -359,6 +359,57 @@ void getdouble(graph_t * g, char *name, double *result) } } +#ifdef EXPERIMENTAL_MYFGETS +/* + * Potential input filter - e.g. for iconv + */ + +/* + * myfgets - same api as fgets + * + * gets n chars at a time + * + * returns pointer to user buffer, + * or returns NULL on eof or error. + */ +static char *myfgets(char * ubuf, int n, FILE * fp) +{ + static char *buf; + static int bufsz, pos, len; + int cnt; + + if (!n) { /* a call with n==0 (from aglexinit) resets */ + ubuf[0] = '\0'; + pos = len = 0; + return NULL; + } + + if (!len) { + if (n > bufsz) { + bufsz = n; + buf = realloc(buf, bufsz); + } + if (!(fgets(buf, bufsz, fp))) { + ubuf[0] = '\0'; + return NULL; + } + len = strlen(buf); + pos = 0; + } + + cnt = n - 1; + if (len < cnt) + cnt = len; + + memcpy(ubuf, buf + pos, cnt); + pos += cnt; + len -= cnt; + ubuf[cnt] = '\0'; + + return ubuf; +} +#endif + graph_t *gvNextInputGraph(GVC_t *gvc) { graph_t *g = NULL; @@ -383,7 +434,12 @@ graph_t *gvNextInputGraph(GVC_t *gvc) if (fp == NULL) break; agsetfile(fn ? fn : ""); - if ((g = agread(fp))) { +#ifdef EXPERIMENTAL_MYFGETS + g = agread_usergets(fp, myfgets); +#else + g = agread(fp); +#endif + if (g) { gvg = zmalloc(sizeof(GVG_t)); if (!gvc->gvgs) gvc->gvgs = gvg; @@ -401,6 +457,7 @@ graph_t *gvNextInputGraph(GVC_t *gvc) } return g; } + /* findCharset: * Check if the charset attribute is defined for the graph and, if * so, return the corresponding internal value. If undefined, return