File descriptors and streams and copying thereof.

Rich Salz rsalz at bbn.com
Fri Apr 14 08:40:01 AEST 1989


In article <1743 at leah.Albany.Edu> rds95 at leah.Albany.Edu (Robert Seals) writes:
-I want to be able to make "stdin" read from someplace besides, well,
-standard input in the middle of my program, and then go back to where
-it was again.
-
-So what I did was this:
-	FILE *my_file;
-	/* sucessfully open "my_file" */
-	stdin->fd = my_file->fd;
-	if (yyparse()) /* stuff*/ else /* stuff */
-	stdin->fd = 0;	/* presume stdin is/was fd 0 */

I had replied by mail, but all the detailed replies kind of scared
me...  Changing stdin in the middle of a run is a very implementation-
specific task, and should be directed to comp.unix.wizards, comp.sys.vms,
comp.sys.mac, etc., as appropriate.

Robert wants to have yyparse() read from a different file.  We did a
go-round on this a couple of months ago.  The answer is to provide your
own routine named input():
	#undef input
	input()
	{
		int c;

		if (read_from_stdin)
			c = getchar();
		else {
		    open_file_if_necessary();
		    c = getc(file);
		    if (feof(file))
			fclose(file);
		}
		return c == EOF ? '\0' : c;
	}
-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.



More information about the Comp.lang.c mailing list