xref: /titanic_52/usr/src/cmd/refer/refer4.c (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 #include "refer..c"
19 #include <locale.h>
20 
21 #define punctuat(c) (c=='.' || c=='?' || c=='!' || c==',' || c==';' || c==':')
22 
23 static gate = 0;
24 static char buff[BUFSIZ];
25 
26 output(s)
27 char *s;
28 {
29 	if (gate)
30 		fputs(buff,ftemp);
31 	else
32 		gate = 1;
33 	strcpy(buff, s);
34 	if (strlen(buff) > BUFSIZ)
35 		err(gettext("one buff too big (%d)!"), BUFSIZ);
36 }
37 
38 append(s)
39 char *s;
40 {
41 	char *p;
42 	int lch;
43 
44 	trimnl(buff);
45 	for (p = buff; *p; p++)
46 		;
47 	lch = *--p;
48 	if (postpunct && punctuat(lch))
49 		*p = NULL;
50 	else /* pre-punctuation */
51 		switch (lch) {
52 		case '.':
53 		case '?':
54 		case '!':
55 		case ',':
56 		case ';':
57 		case ':':
58 			*p++ = lch;
59 			*p = NULL;
60 		}
61 	strcat(buff, s);
62 	if (postpunct)
63 		switch(lch) {
64 		case '.':
65 		case '?':
66 		case '!':
67 		case ',':
68 		case ';':
69 		case ':':
70 			for(p = buff; *p; p++)
71 				;
72 			if (*--p == '\n')
73 				*p = NULL;
74 			*p++ = lch;
75 			*p++ = '\n';
76 			*p = NULL;
77 		}
78 	if (strlen(buff) > BUFSIZ)
79 		err(gettext("output buff too long (%d)"), BUFSIZ);
80 }
81 
82 flout()
83 {
84 	if (gate)
85 		fputs(buff,ftemp);
86 	gate = 0;
87 }
88 
89 char *
90 trimnl(ln)
91 char *ln;
92 {
93 	register char *p = ln;
94 
95 	while (*p)
96 		p++;
97 	p--;
98 	if (*p == '\n')
99 		*p = 0;
100 	return(ln);
101 }
102