1 #ifndef lint 2 static char sccsid[] = "@(#)locate.bigram.c 4.2 (Berkeley) 07/21/83"; 3 #endif not lint 4 5 /* 6 * bigram < text > bigrams 7 * 8 * List bigrams for 'updatedb' script. 9 * Use 'code' to encode a file using this output. 10 */ 11 12 #include <stdio.h> 13 14 #define MAXPATH 1024 /* maximum pathname length */ 15 16 char path[MAXPATH]; 17 char oldpath[MAXPATH] = " "; 18 19 main ( ) 20 { 21 register int count, j; 22 23 while ( gets ( path ) != NULL ) { 24 25 count = prefix_length ( oldpath, path ); 26 /* 27 output post-residue bigrams only 28 */ 29 for ( j = count; path[j] != NULL; j += 2 ) { 30 if ( path[j + 1] == NULL ) 31 break; 32 putchar ( path[j] ); 33 putchar ( path[j + 1] ); 34 putchar ( '\n' ); 35 } 36 strcpy ( oldpath, path ); 37 } 38 } 39 40 prefix_length ( s1, s2 ) /* return length of longest common prefix */ 41 char *s1, *s2; /* ... of strings s1 and s2 */ 42 { 43 register char *start; 44 45 for ( start = s1; *s1 == *s2; s1++, s2++ ) 46 if ( *s1 == NULL ) 47 break; 48 return ( s1 - start ); 49 } 50