xref: /illumos-gate/usr/src/cmd/refer/hunt3.c (revision 2a8bcb4e)
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 #include <locale.h>
167c478bd9Sstevel@tonic-gate #include "refer..c"
17*11a8fa6cSceastha #define	BSIZ 250
187c478bd9Sstevel@tonic-gate 
19*11a8fa6cSceastha int
getq(char * v[])20*11a8fa6cSceastha getq(char *v[])
217c478bd9Sstevel@tonic-gate {
227c478bd9Sstevel@tonic-gate 	static char buff[BSIZ];
237c478bd9Sstevel@tonic-gate 	static int eof = 0;
247c478bd9Sstevel@tonic-gate 	extern char *sinput;
257c478bd9Sstevel@tonic-gate 	char *p;
267c478bd9Sstevel@tonic-gate 	int c, n = 0, las = 0;
27*11a8fa6cSceastha 	if (eof)
28*11a8fa6cSceastha 		return (-1);
297c478bd9Sstevel@tonic-gate 	p = buff;
30*11a8fa6cSceastha 	while ((c = (sinput ? *sinput++ : getchar())) > 0) {
31*11a8fa6cSceastha 		if (c == '\n')
327c478bd9Sstevel@tonic-gate 			break;
33*11a8fa6cSceastha 		if (isalpha(c) || isdigit(c)) {
34*11a8fa6cSceastha 			if (las == 0) {
357c478bd9Sstevel@tonic-gate 				v[n++] = p;
36*11a8fa6cSceastha 				las = 1;
377c478bd9Sstevel@tonic-gate 			}
387c478bd9Sstevel@tonic-gate 			if (las++ <= 6)
397c478bd9Sstevel@tonic-gate 				*p++ = c;
40*11a8fa6cSceastha 		} else {
41*11a8fa6cSceastha 			if (las > 0)
427c478bd9Sstevel@tonic-gate 				*p++ = 0;
43*11a8fa6cSceastha 			las = 0;
447c478bd9Sstevel@tonic-gate 		}
457c478bd9Sstevel@tonic-gate 	}
46*11a8fa6cSceastha 	*p = 0;
477c478bd9Sstevel@tonic-gate 	if (p > buff + BSIZ)
48*11a8fa6cSceastha 		fprintf(stderr, gettext("query long than %d characters\n"),
49*11a8fa6cSceastha 		    BSIZ);
507c478bd9Sstevel@tonic-gate 	assert(p < buff + BSIZ);
51*11a8fa6cSceastha 	if (sinput == 0 && c <= 0) eof = 1;
52*11a8fa6cSceastha #if D1
53*11a8fa6cSceastha 	fprintf(stderr, "no. keys %d\n", n);
54*11a8fa6cSceastha 	for (c = 0; c < n; c++)
557c478bd9Sstevel@tonic-gate 		fprintf(stderr, "keys X%sX\n", v[c]);
56*11a8fa6cSceastha #endif
57*11a8fa6cSceastha 	return (n);
587c478bd9Sstevel@tonic-gate }
59