Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: LEX Question Message-ID: <1965@goofy.megatest.UUCP> Date: 15 Feb 89 02:02:25 GMT References: <1989Feb13.190731.24473@utzoo.uucp> Organization: Megatest Corporation, San Jose, Ca Lines: 32 > In article <32240@auc.UUCP> tab@auc.UUCP (0-Terrence Brannon ) writes: >>My question is, is there anyway that I could have the lex program accept >>integers from somewhere other that stdin? ... > The officially sanctioned way is to redefine the macros input(), and unput(). But if you want to do a quick and dirty, probably unportable hack, read on. WARNING!! PURISTS ARE CAUTIONED NOT TO READ BEYOND THIS POINT IN OTHER THAN A THOROUGHLY KICKED BACK AND CHILLED OUT MOOD. If mild flamage results, discontinue reading. In case of violent flamage, or flames that persist beyond one reply posting, make some funny faces in the mirror, while repeating, "Whootie, whootie, whootie," in a high-pitched voice. Now then, the following is probably true for all BSD derived Unixes, and maybe for others, I dunno. I don't know if it's documented, but you can assign another FILE* to the variable [yyin]. Then the standard input() and unput() will work on that stream instead of stdin. If you want the input to come from something other than a file descriptor, as you seemed to imply, you can try being even more devious: Munge around with the struct _iobuf, perhaps using _IOMYBUF and _IOSTRG flags. (If you have the source to sscanf() take a look at that. It uses the same trick.) I have not tried this, so if it doesn't work, well that's life. You will have to be sure that the buffer is never depleted, less _filbuf get called. And remember, if anyone asks, _I_ never told you to do it that way!