xref: /csrg-svn/old/ssp/ssp.c (revision 1103)
1*1103Sbill static char *sccsid = "@(#)ssp.c	4.1 (Berkeley) 10/01/80";
2*1103Sbill #include <stdio.h>
3*1103Sbill /*
4*1103Sbill  * ssp - single space output
5*1103Sbill  *
6*1103Sbill  * Bill Joy UCB August 25, 1977
7*1103Sbill  *
8*1103Sbill  * Compress multiple empty lines to a single empty line.
9*1103Sbill  * Option - compresses to nothing.
10*1103Sbill  */
11*1103Sbill 
12*1103Sbill char	poof, hadsome;
13*1103Sbill 
14*1103Sbill int	ibuf[256];
15*1103Sbill 
16*1103Sbill 
main(argc,argv)17*1103Sbill main(argc, argv)
18*1103Sbill 	int argc;
19*1103Sbill 	char *argv[];
20*1103Sbill {
21*1103Sbill 	register int c;
22*1103Sbill 	FILE *f;
23*1103Sbill 
24*1103Sbill 	argc--, argv++;
25*1103Sbill 	do {
26*1103Sbill 		while (argc > 0 && argv[0][0] == '-') {
27*1103Sbill 			poof = 1;
28*1103Sbill 			argc--, argv++;
29*1103Sbill 		}
30*1103Sbill 	f = stdin;
31*1103Sbill 		if (argc > 0) {
32*1103Sbill 			if ((f=fopen(argv[0], "r")) == NULL) {
33*1103Sbill 				fflush(f);
34*1103Sbill 				perror(argv[0]);
35*1103Sbill 				exit(1);
36*1103Sbill 			}
37*1103Sbill 			argc--, argv++;
38*1103Sbill 		}
39*1103Sbill 		for (;;) {
40*1103Sbill 			c = getc(f);
41*1103Sbill 			if (c == -1)
42*1103Sbill 				break;
43*1103Sbill 			if (c != '\n') {
44*1103Sbill 				hadsome = 1;
45*1103Sbill 				putchar(c);
46*1103Sbill 				continue;
47*1103Sbill 			}
48*1103Sbill 			/*
49*1103Sbill 			 * Eat em up
50*1103Sbill 			 */
51*1103Sbill 			if (hadsome)
52*1103Sbill 				putchar('\n');
53*1103Sbill 			c = getc(f);
54*1103Sbill 			if (c == -1)
55*1103Sbill 				break;
56*1103Sbill 			if (c != '\n') {
57*1103Sbill 				putchar(c);
58*1103Sbill 				hadsome = 1;
59*1103Sbill 				continue;
60*1103Sbill 			}
61*1103Sbill 			do
62*1103Sbill 				c = getc(f);
63*1103Sbill 			while (c == '\n');
64*1103Sbill 			if (!poof && hadsome)
65*1103Sbill 				putchar('\n');
66*1103Sbill 			if (c == -1)
67*1103Sbill 				break;
68*1103Sbill 			putchar(c);
69*1103Sbill 			hadsome = 1;
70*1103Sbill 		}
71*1103Sbill 	} while (argc > 0);
72*1103Sbill }
73