1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * James A. Woods. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 static char copyright[] = 13 "@(#) Copyright (c) 1989, 1993\n\ 14 The Regents of the University of California. All rights reserved.\n"; 15 #endif /* not lint */ 16 17 #ifndef lint 18 static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berkeley) 06/06/93"; 19 #endif /* not lint */ 20 21 /* 22 * bigram < text > bigrams 23 * 24 * List bigrams for 'updatedb' script. 25 * Use 'code' to encode a file using this output. 26 */ 27 28 #include <stdio.h> 29 #include <sys/param.h> /* for MAXPATHLEN */ 30 31 char buf1[MAXPATHLEN] = " "; 32 char buf2[MAXPATHLEN]; 33 34 main ( ) 35 { 36 register char *cp; 37 register char *oldpath = buf1, *path = buf2; 38 39 while ( fgets ( path, sizeof(buf2), stdin ) != NULL ) { 40 41 /* skip longest common prefix */ 42 for ( cp = path; *cp == *oldpath; cp++, oldpath++ ) 43 if ( *oldpath == NULL ) 44 break; 45 /* 46 * output post-residue bigrams only 47 */ 48 while ( *cp != NULL && *(cp + 1) != NULL ) { 49 putchar ( *cp++ ); 50 putchar ( *cp++ ); 51 putchar ( '\n' ); 52 } 53 if ( path == buf1 ) /* swap pointers */ 54 path = buf2, oldpath = buf1; 55 else 56 path = buf1, oldpath = buf2; 57 } 58 } 59