1 /* $NetBSD: mkindex.c,v 1.10 2005/07/01 16:38:24 jmc Exp $ */
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char copyright
[] = "@(#) Copyright (c) 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
40 static char sccsid
[] = "@(#)mkindex.c 8.1 (Berkeley) 6/11/93";
43 "$NetBSD: mkindex.c,v 1.10 2005/07/01 16:38:24 jmc Exp $";
52 static char *nextword(FILE *, char *, int *, int *);
57 int clen
, rlen
, prev
, i
;
59 char buf
[MAXWORDLEN
+ 1];
63 while (nextword(stdin
, buf
, &clen
, &rlen
) != NULL
) {
66 * Boggle expects a full index even if the dictionary
67 * had no words beginning with some letters.
68 * So we write out entries for every letter from prev
72 printf("%c %6ld %6ld\n", prev
, start
, off
- 1);
73 for (i
= (prev
? prev
+ 1 : 'a'); i
< *buf
; i
++)
74 printf("%c %6ld %6ld\n", i
, off
, off
- 1);
80 printf("%c %6ld %6ld\n", prev
, start
, off
- 1);
81 for (i
= prev
+ 1; i
<= 'z'; i
++)
82 printf("%c %6ld %6ld\n", i
, off
, off
- 1);
85 perror("error writing standard output");
92 * Return the next word in the compressed dictionary in 'buffer' or
94 * Also set clen to the length of the compressed word (for mkindex) and
95 * rlen to the strlen() of the real word
98 nextword(FILE *fp
, char *buffer
, int *clen
, int *rlen
)
102 static char buf
[MAXWORDLEN
+ 1];
103 static int first
= 1;
104 static int lastch
= 0;
107 if ((pcount
= getc(fp
)) == EOF
)
111 else if ((pcount
= lastch
) == EOF
)
114 p
= buf
+ (*clen
= pcount
);
116 while ((ch
= getc(fp
)) != EOF
&& ch
>= 'a')
121 *rlen
= (int) (p
- buf
);
122 *clen
= *rlen
- *clen
;
126 while ((*q
++ = *p
) != '\0') {