

#include <stdio.h>

/* This program takes a file and causes a single newline to disappear
unless it comes at the end of a line that begins with a period
or just before a line that begins with a period.
*/

main(argc, argv)
int argc;
char *argv[];
{
	int charactercount, dotbeginning, doublenewline, verbatim;
	int c, prevchar, beforeprevchar;
	doublenewline = 0;
	prevchar = 0;
	beforeprevchar = 0;
	dotbeginning =0;
	charactercount =0;
	verbatim = 0;
	while ((c = getchar()) != EOF)
	{
		if (verbatim == 1) { 
			putchar(c);
		} else if (prevchar == '\n') {
			if (c == '.') {
				dotbeginning = 1;
				if (doublenewline == 0) {putchar('\n');}
				putchar(c);
				doublenewline = 0;
			}
			else if (c == '\n') { /* double new line*/
				putchar('\n');
				charactercount = 0;
				doublenewline = 1;/* still owe one newline*/
			}
			else if (dotbeginning ==1 ) {
			  /* previous line started with dot */
			  /* c is neither a dot nor a newline*/
				dotbeginning = 0;
				putchar('\n');
				charactercount = 0;
				putchar(c);
				doublenewline = 0;
			}
			else if (doublenewline ==1 ) {
			  /* still owe a newline */
			  /* c is neither a dot nor a newline*/
				dotbeginning = 0;
				putchar('\n');
				charactercount = 0;
				putchar(c);
				doublenewline = 0;
			}
			else  {
			  /* previous line did not start with dot */
			  /* suppress newline */
				dotbeginning = 0;
				putchar(' ');
				putchar(c);
				doublenewline = 0;
			}
		} else if (c != '\n') { /* we may print it */
		    /* if ((c == ' ') && (charactercount > 120)) {
			putchar('\n'); 
			charactercount = 0;
		    } else {
 		   */
			putchar(c); charactercount++;
		    /* } */
		}
		if ((beforeprevchar == '.') && (prevchar == '(')
		   && (c == 'l')) {
			verbatim = 1; /* do what they say */
			dotbeginning = 1;
	     	}
		if ((beforeprevchar == '.') && (prevchar == ')')
		   && (c == 'l')) {
			verbatim = 0; /* back to standard operating proc*/
			dotbeginning = 1;
	     	}
		beforeprevchar = prevchar;
		prevchar = c;
	}
}
