Scrunch blank lines

Stephen Peckham peckham at svax.cs.cornell.edu
Sat Mar 25 03:03:21 AEST 1989


In article <620 at gonzo.UUCP> daveb at 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.  [f]lex, Yacc, [na]awk, sed,
>perl, c, c++ are all acceptable.  This will be an amusing excercise in
>typical text massaging that can be enlightening for many people.
>
Here's an awk program that will do the trick.  Single blank lines are left as
is.  Multiple blank lines are removed, and a new line directive is added.

{if (NF == 0) blanks++
 else if ($1=="#") {l_no = $2-1; f = $3; blanks = 2;}
 else {
	if (blanks > 1) print "#", l_no, f;
	else if (blanks == 1) print "";
	blanks = 0;
	print $0;
      }
 l_no++;
}	

Steve Peckham



More information about the Comp.lang.c mailing list