argv ==> stdin (fast)

Steven Grady grady at ic.Berkeley.EDU
Thu Nov 20 22:02:13 AEST 1986


I hope someone comes up with a good solution, because I'm not satisfied
with the way I had to handle it:

#include <stdio.h>

/* Make a file pointer point to a string */
FILE *
set_fp_to_str(fp, str)
FILE *fp;
char *str;
{

	/* Check out the src to sscanf, etc, for more fun.. */
	fp->_flag = _IOREAD|_IOSTRG;
	fp->_ptr = fp->_base = str;
	fp->_cnt = 0;
	while (*str++) {
	        fp->_cnt++;
	}
	fp->_bufsiz = fp->_cnt;
    	return(fp);
}

/* Use yyparse() on a string */
foo(str)
char *str;
{
	FILE tmp;

	/* Save old value of stdin */
	tmp = *stdin;
	set_fp_to_str(stdin, str);
	yyresult = yyparse();
	*stdin = tmp;
}



More information about the Comp.unix.wizards mailing list