1*11a8fa6cSceastha /*
2*11a8fa6cSceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*11a8fa6cSceastha * Use is subject to license terms.
4*11a8fa6cSceastha */
5*11a8fa6cSceastha
67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
77c478bd9Sstevel@tonic-gate /* All Rights Reserved */
87c478bd9Sstevel@tonic-gate
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate */
147c478bd9Sstevel@tonic-gate
157c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
167c478bd9Sstevel@tonic-gate
177c478bd9Sstevel@tonic-gate #include "refer..c"
187c478bd9Sstevel@tonic-gate #include <locale.h>
197c478bd9Sstevel@tonic-gate
20*11a8fa6cSceastha #define punctuat(c) (c == '.' || c == '?' || c == '!' || \
21*11a8fa6cSceastha c == ',' || c == ';' || c == ':')
227c478bd9Sstevel@tonic-gate
23*11a8fa6cSceastha static int gate = 0;
247c478bd9Sstevel@tonic-gate static char buff[BUFSIZ];
257c478bd9Sstevel@tonic-gate
26*11a8fa6cSceastha extern void err();
27*11a8fa6cSceastha
28*11a8fa6cSceastha char *trimnl(char *);
29*11a8fa6cSceastha
30*11a8fa6cSceastha void
output(char * s)31*11a8fa6cSceastha output(char *s)
327c478bd9Sstevel@tonic-gate {
337c478bd9Sstevel@tonic-gate if (gate)
347c478bd9Sstevel@tonic-gate fputs(buff, ftemp);
357c478bd9Sstevel@tonic-gate else
367c478bd9Sstevel@tonic-gate gate = 1;
377c478bd9Sstevel@tonic-gate strcpy(buff, s);
387c478bd9Sstevel@tonic-gate if (strlen(buff) > BUFSIZ)
397c478bd9Sstevel@tonic-gate err(gettext("one buff too big (%d)!"), BUFSIZ);
407c478bd9Sstevel@tonic-gate }
417c478bd9Sstevel@tonic-gate
42*11a8fa6cSceastha void
append(char * s)43*11a8fa6cSceastha append(char *s)
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate char *p;
467c478bd9Sstevel@tonic-gate int lch;
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate trimnl(buff);
497c478bd9Sstevel@tonic-gate for (p = buff; *p; p++)
507c478bd9Sstevel@tonic-gate ;
517c478bd9Sstevel@tonic-gate lch = *--p;
527c478bd9Sstevel@tonic-gate if (postpunct && punctuat(lch))
537c478bd9Sstevel@tonic-gate *p = NULL;
547c478bd9Sstevel@tonic-gate else /* pre-punctuation */
557c478bd9Sstevel@tonic-gate switch (lch) {
567c478bd9Sstevel@tonic-gate case '.':
577c478bd9Sstevel@tonic-gate case '?':
587c478bd9Sstevel@tonic-gate case '!':
597c478bd9Sstevel@tonic-gate case ',':
607c478bd9Sstevel@tonic-gate case ';':
617c478bd9Sstevel@tonic-gate case ':':
627c478bd9Sstevel@tonic-gate *p++ = lch;
637c478bd9Sstevel@tonic-gate *p = NULL;
647c478bd9Sstevel@tonic-gate }
657c478bd9Sstevel@tonic-gate strcat(buff, s);
667c478bd9Sstevel@tonic-gate if (postpunct)
677c478bd9Sstevel@tonic-gate switch (lch) {
687c478bd9Sstevel@tonic-gate case '.':
697c478bd9Sstevel@tonic-gate case '?':
707c478bd9Sstevel@tonic-gate case '!':
717c478bd9Sstevel@tonic-gate case ',':
727c478bd9Sstevel@tonic-gate case ';':
737c478bd9Sstevel@tonic-gate case ':':
747c478bd9Sstevel@tonic-gate for (p = buff; *p; p++)
757c478bd9Sstevel@tonic-gate ;
767c478bd9Sstevel@tonic-gate if (*--p == '\n')
777c478bd9Sstevel@tonic-gate *p = NULL;
787c478bd9Sstevel@tonic-gate *p++ = lch;
797c478bd9Sstevel@tonic-gate *p++ = '\n';
807c478bd9Sstevel@tonic-gate *p = NULL;
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate if (strlen(buff) > BUFSIZ)
837c478bd9Sstevel@tonic-gate err(gettext("output buff too long (%d)"), BUFSIZ);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate
86*11a8fa6cSceastha void
flout(void)87*11a8fa6cSceastha flout(void)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate if (gate)
907c478bd9Sstevel@tonic-gate fputs(buff, ftemp);
917c478bd9Sstevel@tonic-gate gate = 0;
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate char *
trimnl(char * ln)95*11a8fa6cSceastha trimnl(char *ln)
967c478bd9Sstevel@tonic-gate {
97*11a8fa6cSceastha char *p = ln;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate while (*p)
1007c478bd9Sstevel@tonic-gate p++;
1017c478bd9Sstevel@tonic-gate p--;
1027c478bd9Sstevel@tonic-gate if (*p == '\n')
1037c478bd9Sstevel@tonic-gate *p = 0;
1047c478bd9Sstevel@tonic-gate return (ln);
1057c478bd9Sstevel@tonic-gate }
106