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