1 /* vi: set tabstop=4 : */ 2 3 #include <stdio.h> 4 5 #include "bog.h" 6 7 main(argc, argv) 8 int argc; 9 char **argv; 10 { 11 int clen, rlen, prev; 12 long off, start; 13 char buf[MAXWORDLEN + 1], *p, *nextword(); 14 15 prev = '\0'; 16 off = start = 0L; 17 while (nextword(stdin, buf, &clen, &rlen) != (char *) NULL) { 18 if (*buf != prev) { 19 if (prev != '\0') 20 printf("%c %6ld %6ld\n", prev, start, off - 1); 21 prev = *buf; 22 start = off; 23 } 24 off += clen + 1; 25 } 26 printf("%c %6ld %6ld\n", prev, start, off - 1); 27 exit(0); 28 } 29 30 /* 31 * Return the next word in the compressed dictionary in 'buffer' or 32 * NULL on end-of-file 33 * Also set clen to the length of the compressed word (for mkindex) and 34 * rlen to the strlen() of the real word 35 */ 36 char * 37 nextword(fp, buffer, clen, rlen) 38 FILE *fp; 39 char *buffer; 40 int *clen, *rlen; 41 { 42 register int ch, pcount; 43 register char *p, *q; 44 static char buf[MAXWORDLEN + 1]; 45 static int first = 1; 46 static int lastch = 0; 47 48 if (first) { 49 if ((pcount = getc(fp)) == EOF) 50 return((char *) NULL); 51 first = 0; 52 } 53 else if ((pcount = lastch) == EOF) 54 return((char *) NULL); 55 56 p = buf + (*clen = pcount); 57 58 while ((ch = getc(fp)) != EOF && ch >= 'a') 59 *p++ = ch; 60 lastch = ch; 61 *p = '\0'; 62 63 *rlen = (int) (p - buf); 64 *clen = *rlen - *clen; 65 66 p = buf; 67 q = buffer; 68 while ((*q++ = *p) != '\0') { 69 if (*p++ == 'q') 70 *q++ = 'u'; 71 } 72 return(buffer); 73 } 74 75