xref: /titanic_50/usr/src/cmd/refer/refer8.c (revision 6d9a41ff63273acce102bfb2d51423ed920e6dcd)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
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.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 #include "refer..c"
18 
19 static char ahead[1024];
20 static int peeked = 0;
21 static char *noteof = (char *)1;
22 
23 char *
24 input(char *s)
25 {
26 	if (peeked) {
27 		peeked = 0;
28 		if (noteof == 0)
29 			return (0);
30 		strcpy(s, ahead);
31 		return (s);
32 	}
33 	return (fgets(s, 1000, in));
34 }
35 
36 char *
37 lookat(void)
38 {
39 	if (peeked)
40 		return (ahead);
41 	noteof = input(ahead);
42 	peeked = 1;
43 	return (noteof);
44 }
45 
46 void
47 addch(char *s, char c)
48 {
49 	while (*s)
50 		s++;
51 	*s++ = c;
52 	*s = 0;
53 }
54