From: Emden Gansner Date: Fri, 25 Nov 2011 19:33:51 +0000 (-0500) Subject: Move agmemread to io.c. Having it in grammar.y causes some strange error X-Git-Tag: LAST_LIBGRAPH~32^2~585^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f2f9525efc5bb49581376a4855494178522c731;p=graphviz Move agmemread to io.c. Having it in grammar.y causes some strange error during compilation. --- diff --git a/lib/cgraph/grammar.y b/lib/cgraph/grammar.y index 3c01ae49b..9ce100675 100644 --- a/lib/cgraph/grammar.y +++ b/lib/cgraph/grammar.y @@ -541,50 +541,3 @@ Agraph_t *agconcat(Agraph_t *g, void *chan, Agdisc_t *disc) Agraph_t *agread(void *fp, Agdisc_t *disc) {return agconcat(NILgraph,fp,disc); } -typedef struct { - const char *data; - int len; - int cur; -} rdr_t; - -static int -iofread(void *chan, char *buf, int bufsize) -{ - const char *ptr; - char *optr; - char c; - int l; - rdr_t *s; - - if (bufsize == 0) return 0; - s = (rdr_t *) chan; - if (s->cur >= s->len) - return 0; - l = 0; - ptr = s->data + s->cur; - optr = buf; - do { - *optr++ = c = *ptr++; - l++; - } while (c && (c != '\n') && (l < bufsize)); - s->cur += l; - return l; -} - -static Agiodisc_t memIoDisc = { iofread, AgIoDisc.putstr, AgIoDisc.flush }; - -Agraph_t *agmemread(const char *cp) -{ - Agraph_t* g; - rdr_t rdr; - - rdr.data = cp; - rdr.len = strlen(cp); - rdr.cur = 0; - disc.mem = &AgMemDisc; - disc.id = &AgIdDisc; - disc.io = &memIoDisc; - g = agread (&rdr, &disc); - return g; -} - diff --git a/lib/cgraph/io.c b/lib/cgraph/io.c index 51e6bd91d..efaef6b2c 100644 --- a/lib/cgraph/io.c +++ b/lib/cgraph/io.c @@ -85,3 +85,55 @@ static int ioflush(void *chan) /* Agiodisc_t AgIoDisc = { iofreadiconv, ioputstr, ioflush }; */ Agiodisc_t AgIoDisc = { iofread, ioputstr, ioflush }; + +typedef struct { + const char *data; + int len; + int cur; +} rdr_t; + +static int +memiofread(void *chan, char *buf, int bufsize) +{ + const char *ptr; + char *optr; + char c; + int l; + rdr_t *s; + + if (bufsize == 0) return 0; + s = (rdr_t *) chan; + if (s->cur >= s->len) + return 0; + l = 0; + ptr = s->data + s->cur; + optr = buf; + do { + *optr++ = c = *ptr++; + l++; + } while (c && (c != '\n') && (l < bufsize)); + s->cur += l; + return l; +} + +Agraph_t *agmemread(const char *cp) +{ + Agraph_t* g; + rdr_t rdr; + Agdisc_t disc; + Agiodisc_t memIoDisc; + + memIoDisc.afread = memiofread; + memIoDisc.putstr = AgIoDisc.putstr; + memIoDisc.flush = AgIoDisc.flush; + rdr.data = cp; + rdr.len = strlen(cp); + rdr.cur = 0; + + disc.mem = &AgMemDisc; + disc.id = &AgIdDisc; + disc.io = &memIoDisc; + g = agread (&rdr, &disc); + return g; +} +