Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!ames!ucbcad!ic.Berkeley.EDU!grady From: grady@ic.Berkeley.EDU (Steven Grady) Newsgroups: comp.unix.questions,comp.unix.wizards,comp.lang.c Subject: Re: argv ==> stdin (fast) Message-ID: <1137@ucbcad.BERKELEY.EDU> Date: Thu, 20-Nov-86 07:02:13 EST Article-I.D.: ucbcad.1137 Posted: Thu Nov 20 07:02:13 1986 Date-Received: Thu, 20-Nov-86 22:45:33 EST References: <2972@rsch.WISC.EDU> Sender: news@ucbcad.BERKELEY.EDU Reply-To: grady@ic.Berkeley.EDU (Steven Grady) Organization: University of California, Berkeley Lines: 35 Keywords: make the commandline look like a file? Xref: mnetor comp.unix.questions:128 comp.unix.wizards:126 comp.lang.c:112 I hope someone comes up with a good solution, because I'm not satisfied with the way I had to handle it: #include /* 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; }