Merge commit '6e270ca825f06ec0e2d77db462b83074ec585f2f'
[unleashed.git] / usr / src / cmd / refer / refer4.c
blob20cd77b7b5a10e902dd0be0236e66b0b852d5c54
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
9 /*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #include "refer..c"
16 #include <locale.h>
18 #define punctuat(c) (c == '.' || c == '?' || c == '!' || \
19 c == ',' || c == ';' || c == ':')
21 static int gate = 0;
22 static char buff[BUFSIZ];
24 extern void err();
26 char *trimnl(char *);
28 void
29 output(char *s)
31 if (gate)
32 fputs(buff, ftemp);
33 else
34 gate = 1;
35 strcpy(buff, s);
36 if (strlen(buff) > BUFSIZ)
37 err(gettext("one buff too big (%d)!"), BUFSIZ);
40 void
41 append(char *s)
43 char *p;
44 int lch;
46 trimnl(buff);
47 for (p = buff; *p; p++)
49 lch = *--p;
50 if (postpunct && punctuat(lch))
51 *p = '\0';
52 else /* pre-punctuation */
53 switch (lch) {
54 case '.':
55 case '?':
56 case '!':
57 case ',':
58 case ';':
59 case ':':
60 *p++ = lch;
61 *p = '\0';
63 strcat(buff, s);
64 if (postpunct)
65 switch (lch) {
66 case '.':
67 case '?':
68 case '!':
69 case ',':
70 case ';':
71 case ':':
72 for (p = buff; *p; p++)
74 if (*--p == '\n')
75 *p = '\0';
76 *p++ = lch;
77 *p++ = '\n';
78 *p = '\0';
80 if (strlen(buff) > BUFSIZ)
81 err(gettext("output buff too long (%d)"), BUFSIZ);
84 void
85 flout(void)
87 if (gate)
88 fputs(buff, ftemp);
89 gate = 0;
92 char *
93 trimnl(char *ln)
95 char *p = ln;
97 while (*p)
98 p++;
99 p--;
100 if (*p == '\n')
101 *p = 0;
102 return (ln);