1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * James A. Woods.
7  *
8  * Redistribution and use in source and binary forms are permitted
9  * provided that the above copyright notice and this paragraph are
10  * duplicated in all such forms and that any documentation,
11  * advertising materials, and other materials related to such
12  * distribution and use acknowledge that the software was developed
13  * by the University of California, Berkeley.  The name of the
14  * University may not be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19  */
20 
21 #ifndef lint
22 char copyright[] =
23 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
24  All rights reserved.\n";
25 #endif /* not lint */
26 
27 #ifndef lint
28 static char sccsid[] = "@(#)locate.bigram.c	4.5 (Berkeley) 05/04/89";
29 #endif /* not lint */
30 
31 /*
32  *  bigram < text > bigrams
33  *
34  * List bigrams for 'updatedb' script.
35  * Use 'code' to encode a file using this output.
36  */
37 
38 #include <stdio.h>
39 #include <sys/param.h>			/* for MAXPATHLEN */
40 
41 char buf1[MAXPATHLEN] = " ";
42 char buf2[MAXPATHLEN];
43 
44 main ( )
45 {
46   	register char *cp;
47 	register char *oldpath = buf1, *path = buf2;
48 
49      	while ( gets ( path ) != NULL ) {
50 
51 		/* skip longest common prefix */
52 		for ( cp = path; *cp == *oldpath; cp++, oldpath++ )
53 			if ( *oldpath == NULL )
54 				break;
55 		/*
56 		 * output post-residue bigrams only
57 		 */
58 		while ( *cp != NULL && *(cp + 1) != NULL ) {
59 			putchar ( *cp++ );
60 			putchar ( *cp++ );
61 			putchar ( '\n' );
62 		}
63 		if ( path == buf1 )		/* swap pointers */
64 			path = buf2, oldpath = buf1;
65 		else
66 			path = buf1, oldpath = buf2;
67    	}
68 }
69