argv ==> stdin (fast)

Lawrence W. McVoy mcvoy at rsch.WISC.EDU
Thu Dec 4 12:22:56 AEST 1986


In article <347 at apple.UUCP> mikes at apple.UUCP (Mike Shannon) writes:
>To people using yacc & lex and trying to read from a file, not stdin,
>you should note that in the code generated by lex for reading a character,
>a call is made to getc(yyin).
>	yyin is simply a variable statically initialized to be stdin, but
>you can *easily* re-assign it via a call to fopen(), as in
>	yyin = fopen(argv[1])
>	or some such.

I've seen one too many of these float by to take it any more.  Please read
what I asked in the first place and answer that.  Your answers imply that 
I'm an idiot.  While that is sometimes true, it's not the case here:

>From the original posting:
    Subject: Re: argv ==> stdin (fast)
    Keywords: make the commandline look like a file?
		       ^^^^^^^^^^^

I am _NOT_ asking how to use fopen.  Jeez.  I'm asking how to make the 
characters typed on the command line look like they are in a file.
>From the point of view of lex/yacc.  For example if I said

% a.out 1+2/3

I want lex to see '1', '+', '2', '/', '3' EOF

By the way, I have a zillion solutions, and thanks go out to all who
replied.  The best one said "get a pipe, stuff argv into it, close 
stdin, dup the read side of the pipe".  Sorry, I can't remember who
sent it, but thanks anyways...

>	Look at the code generated by these tools!  It's easy to change it!
>-- 
>			Michael Shannon {apple!mikes}

Look at the posting generated by these fingers!  It's easy to read!
-- 
Larry McVoy 	        mcvoy at rsch.wisc.edu, 
      		        {seismo, topaz, harvard, ihnp4, etc}!uwvax!mcvoy

"They're coming soon!  Quad-stated guru-gates!"



More information about the Comp.unix.questions mailing list