xref: /titanic_51/usr/src/cmd/refer/hunt3.c (revision 4bc0a2ef2b7ba50a7a717e7ddbf31472ad28e358)
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 <locale.h>
18 #include "refer..c"
19 #define	BSIZ 250
20 
21 int
22 getq(char *v[])
23 {
24 	static char buff[BSIZ];
25 	static int eof = 0;
26 	extern char *sinput;
27 	char *p;
28 	int c, n = 0, las = 0;
29 	if (eof)
30 		return (-1);
31 	p = buff;
32 	while ((c = (sinput ? *sinput++ : getchar())) > 0) {
33 		if (c == '\n')
34 			break;
35 		if (isalpha(c) || isdigit(c)) {
36 			if (las == 0) {
37 				v[n++] = p;
38 				las = 1;
39 			}
40 			if (las++ <= 6)
41 				*p++ = c;
42 		} else {
43 			if (las > 0)
44 				*p++ = 0;
45 			las = 0;
46 		}
47 	}
48 	*p = 0;
49 	if (p > buff + BSIZ)
50 		fprintf(stderr, gettext("query long than %d characters\n"),
51 		    BSIZ);
52 	assert(p < buff + BSIZ);
53 	if (sinput == 0 && c <= 0) eof = 1;
54 #if D1
55 	fprintf(stderr, "no. keys %d\n", n);
56 	for (c = 0; c < n; c++)
57 		fprintf(stderr, "keys X%sX\n", v[c]);
58 #endif
59 	return (n);
60 }
61