Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ig!arizona!rupley From: rupley@arizona.edu (John Rupley) Newsgroups: comp.lang.c Subject: Re: Scrunch blank lines Summary: Lex solution Message-ID: <10029@megaron.arizona.edu> Date: 31 Mar 89 21:13:38 GMT References: <7150@siemens.UUCP> <9900010@bradley> <4896@cbnews.ATT.COM> <26389@cornell.UUCP> Distribution: na Organization: U of Arizona CS Dept, Tucson Lines: 23 From rupley!local Fri Mar 31 13:43:14 1989 In article <620@gonzo.UUCP> daveb@gonzo.UUCP (Dave Brower) writes: >So, I offer this week's challenge: Smallest program that will take >"blank line" style cpp output on stdin and send to stdout a scrunched >version with appropriate #line directives. The following Lex source is somewhat shorter than a previous Lex version. Specifications assumed: single blank lines, as well as runs of blank lines +- <#> line directives, are to be replaced by <# lineno "filename">; only truly blank lines (no space or tab) are to be considered blank. ------------------------------------------------------------------------ char f[80]; %S P %% #.+\n {sscanf(yytext,"#%d%s",&yylineno,f);BEGIN P;}

.+\n {printf("# %d %s\n",yylineno-1,f);ECHO;BEGIN 0;} \n BEGIN P; .+\n ECHO; ------------------------------------------------------------------------ John Rupley rupley!local@megaron.arizona.edu