-/* $NetBSD: mkdict.c,v 1.2 1995/03/21 12:14:49 cgd Exp $ */
+/* $NetBSD: mkdict.c,v 1.8 2001/08/29 18:22:56 jsm Exp $ */
/*-
* Copyright (c) 1993
*/
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1993\n\
+static const char copyright[] =
+ "@(#) Copyright (c) 1993\n\
The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
#if 0
static char sccsid[] = "@(#)mkdict.c 8.1 (Berkeley) 6/11/93";
#else
-static char rcsid[] = "$NetBSD: mkdict.c,v 1.2 1995/03/21 12:14:49 cgd Exp $";
+static const char rcsid[] =
+ "$NetBSD: mkdict.c,v 1.8 2001/08/29 18:22:56 jsm Exp $";
#endif
#endif /* not lint */
#include "bog.h"
+int main(int, char *[]);
+
int
main(argc, argv)
int argc;
char *argv[];
{
- register char *p, *q;
- register int ch, common, n, nwords;
+ char *p, *q;
+ int ch, common, nwords;
int current, len, prev, qcount;
char buf[2][MAXWORDLEN + 1];
prev = 0;
current = 1;
buf[prev][0] = '\0';
- if (argc == 2)
- n = atoi(argv[1]);
for (nwords = 1;
fgets(buf[current], MAXWORDLEN + 1, stdin) != NULL; ++nwords) {
- if ((p = index(buf[current], '\n')) == NULL) {
- fprintf(stderr,
- "mkdict: word too long: %s\n", buf[current]);
+ if ((p = strchr(buf[current], '\n')) == NULL) {
+ fprintf(stderr, "word too long: %s\n", buf[current]);
while ((ch = getc(stdin)) != EOF && ch != '\n')
;
if (ch == EOF)
if (*q != 'u')
break;
else {
- while (*q = *(q + 1))
+ while ((*q = *(q + 1)))
q++;
}
len++;
}
if (*p != '\n' || len < 3 || len > MAXWORDLEN)
continue;
- if (argc == 2 && nwords % n)
+ if (argc == 2 && nwords % atoi(argv[1]))
continue;
*p = '\0';
current = !current;
}
fprintf(stderr, "%d words\n", nwords);
+ fflush(stdout);
+ if (ferror(stdout)) {
+ perror("error writing standard output");
+ exit(1);
+ }
exit(0);
}