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 /*	from OpenSolaris "refer4.c	1.4	05/06/02 SMI" 	*/
17 
18 /*
19  * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
20  *
21  * Sccsid @(#)refer4.c	1.3 (gritter) 10/22/05
22  */
23 
24 #include "refer..c"
25 #include <locale.h>
26 #include <string.h>
27 
28 #define punctuat(c) (c=='.' || c=='?' || c=='!' || c==',' || c==';' || c==':')
29 
30 static int gate = 0;
31 static char buff[BUFSIZ];
32 
33 void
output(const char * s)34 output(const char *s)
35 {
36 	if (gate)
37 		fputs(buff,ftemp);
38 	else
39 		gate = 1;
40 	if (strlen(s) > sizeof buff)
41 		err("one buff too big (%d)!", sizeof buff);
42 	n_strcpy(buff, s, sizeof(buff));
43 }
44 
45 void
append(char * s)46 append(char *s)
47 {
48 	char *p;
49 	int lch;
50 
51 	trimnl(buff);
52 	for (p = buff; *p; p++)
53 		;
54 	lch = *--p;
55 	if (postpunct && punctuat(lch))
56 		*p = 0;
57 	else /* pre-punctuation */
58 		switch (lch) {
59 		case '.':
60 		case '?':
61 		case '!':
62 		case ',':
63 		case ';':
64 		case ':':
65 			*p++ = lch;
66 			*p = 0;
67 		}
68 	n_strcat(buff, s, sizeof(buff));
69 	if (postpunct)
70 		switch(lch) {
71 		case '.':
72 		case '?':
73 		case '!':
74 		case ',':
75 		case ';':
76 		case ':':
77 			for(p = buff; *p; p++)
78 				;
79 			if (*--p == '\n')
80 				*p = 0;
81 			*p++ = lch;
82 			*p++ = '\n';
83 			*p = 0;
84 		}
85 	if (strlen(buff) > BUFSIZ)
86 		err("output buff too long (%d)", BUFSIZ);
87 }
88 
89 void
flout(void)90 flout(void)
91 {
92 	if (gate)
93 		fputs(buff,ftemp);
94 	gate = 0;
95 }
96 
97 char *
trimnl(char * ln)98 trimnl(char *ln)
99 {
100 	register char *p = ln;
101 
102 	while (*p)
103 		p++;
104 	p--;
105 	if (*p == '\n')
106 		*p = 0;
107 	return(ln);
108 }
109