From: ellson Date: Fri, 27 Feb 2009 19:20:24 +0000 (+0000) Subject: use the fgets() input discipline X-Git-Tag: LAST_LIBGRAPH~32^2~2377 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ba7295eb9ec42a38bc18e356b524d42adda8ac8;p=graphviz use the fgets() input discipline --- diff --git a/lib/graph/graphio.c b/lib/graph/graphio.c index 9f5287914..a81d84392 100644 --- a/lib/graph/graphio.c +++ b/lib/graph/graphio.c @@ -64,23 +64,31 @@ static char *memgets(char *ubuf, int n, FILE * mbuf) Agraph_t *agread(FILE * fp) { - aglexinit(fp, (fgets)); /* use system fgets */ + aglexinit(fp, NULL); /* use fgets from current io discipline */ agparse(); return AG.parsed_g; } Agraph_t *agmemread(char *cp) { - /* cast into a file pointer, but flag that this is in-memory input */ - aglexinit((FILE *) cp, (memgets)); /* memgets defined above */ + gets_f savefgets = AG.fgets; + + AG.fgets = memgets; /* memgets defined above */ + /* cast cp into a file pointer */ + aglexinit((FILE *) cp, NULL); agparse(); + AG.fgets = savefgets; return AG.parsed_g; } Agraph_t *agread_usergets(FILE * fp, gets_f usergets) { - aglexinit(fp, (usergets)); /* usergets provided externally */ + gets_f savefgets = AG.fgets; + + AG.fgets = usergets; /* usergets provided externally */ + aglexinit(fp, NULL); agparse(); + AG.fgets = savefgets; return AG.parsed_g; } diff --git a/lib/graph/lexer.c b/lib/graph/lexer.c index 8659aab41..b1633ab52 100644 --- a/lib/graph/lexer.c +++ b/lib/graph/lexer.c @@ -35,7 +35,6 @@ static unsigned char Comment_start; static unsigned char Start_html_string; int Line_number; static char *InputFile; -static gets_f Lexer_gets; static void storeFileName (char* fname, int len) @@ -76,14 +75,15 @@ void agsetfile(char *f) void aglexinit(FILE * fp, gets_f mygets) { Lexer_fp = fp; - Lexer_gets = mygets; + if (mygets) + AG.fgets = mygets; LexPtr = NULL; if (AG.linebuf == NULL) { LineBufSize = BUFSIZ; AG.linebuf = N_NEW(LineBufSize, char); TokenBuf = N_NEW(LineBufSize, char); } - (Lexer_gets) (AG.linebuf, 0, fp); /* reset mygets */ + AG.fgets (AG.linebuf, 0, fp); /* reset mygets */ } #define ISSPACE(c) ((c != 0) && ((isspace(c) || iscntrl(c)))) @@ -230,9 +230,9 @@ int myaglex(void) * In particular, the buffer will contain a '\n' as the last non-null char. * Ignore lines beginning with '#'; update cpp line number if applicable. * Fold long lines, i.e., ignore escaped newlines. - * Assume the Lexer_gets function reads upto newline or buffer length + * Assume the AG.fgets function reads upto newline or buffer length * like fgets. - * Need to be careful that Lexer_gets might not return full physical line + * Need to be careful that AG.fgets might not return full physical line * because buffer is too small to hold it. */ static char *lex_gets(void) @@ -251,8 +251,7 @@ static char *lex_gets(void) } /* off by one so we can back up in LineBuf */ - clp = - (Lexer_gets) (AG.linebuf + curlen + 1, + clp = AG.fgets (AG.linebuf + curlen + 1, LineBufSize - curlen - 1, Lexer_fp); if (clp == NULL) break;