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;
}
static unsigned char Start_html_string;
int Line_number;
static char *InputFile;
-static gets_f Lexer_gets;
static void
storeFileName (char* fname, int len)
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))))
* 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)
}
/* 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;