Lex and redefining the i/o macros

gregory b. lampshir lampshir at airgun.wg.waii.com
Wed Jul 11 03:45:59 AEST 1990


To someone who knows lex.....,

I need to rewrite the input(), output(), and unput() macros that lex
normally supplies so I can accept a binary file.  I will strip out
the funny control characters found in the binary file so I am not worried
about any recognition problems.  I am, however, having trouble rewriting the
macros into functions.

What I have know is this ....

int filePointerIn;

main()
{
	filePointerIn=open(argv[1],O_RDONLY,0);
	while(1)
		yylex();
} 

char input()
{
	int pos;
	char *ch;  
	
	pos=read(filePointerIn,ch,1);
     	/* Some code to strip the funny characters you get from reading
	   binary files a character at a time.  Yes there are ints	
	   and other misc. chars in the file, but the text is o.k.	
	   somewhere inside there.
	*/	
 	if(pos==0) return(0); /* needed by lex to signal eof */
	else return(*ch);
}

void unput(c)
char c;
{
	lseek(filePointerIn,-1,L_INCR);
}

Can any of you lex wizards help me with this one?  What am I doing wrong?



gregory lampshire    | Searching for the computer which can
western geophysical  | do it all.....



More information about the Comp.unix.questions mailing list