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