Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!bbn!bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.lang.c Subject: Re: File descriptors and streams and copying thereof. Message-ID: <1672@fig.bbn.com> Date: 13 Apr 89 22:40:01 GMT References: <1743@leah.Albany.Edu> <8450@xanth.cs.odu.edu> Organization: BBN Systems and Technologies Corporation Lines: 37 In article <1743@leah.Albany.Edu> rds95@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@uunet.uu.net.