date and time created 83/07/21 00:14:45 by mckusick
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Thu, 21 Jul 1983 15:14:45 +0000 (07:14 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Thu, 21 Jul 1983 15:14:45 +0000 (07:14 -0800)
SCCS-vsn: usr.bin/locate/bigram/locate.bigram.c 4.1

usr/src/usr.bin/locate/bigram/locate.bigram.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/locate/bigram/locate.bigram.c b/usr/src/usr.bin/locate/bigram/locate.bigram.c
new file mode 100644 (file)
index 0000000..a399112
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef lint
+static char sccsid[] = "@(#)locate.bigram.c    4.1     (Berkeley)      %G%";
+#endif not lint
+
+/*
+ *  bigram < text > bigrams
+ * 
+ * List bigrams for 'find.squeeze' script.
+ * Use 'find.code' to encode a file using this output.
+ */
+
+#include <stdio.h>
+
+#define MAXPATH        1024            /* maximum pathname length */
+
+char path[MAXPATH];
+char oldpath[MAXPATH] = " ";   
+
+main ( )
+{
+       register int count, j;
+
+       while ( gets ( path ) != NULL ) {
+
+               count = prefix_length ( oldpath, path );
+               /*
+                  output post-residue bigrams only
+               */
+               for ( j = count; path[j] != NULL; j += 2 ) {
+                       if ( path[j + 1] == NULL ) 
+                               break;
+                       putchar ( path[j] );
+                       putchar ( path[j + 1] );
+                       putchar ( '\n' );
+               }
+               strcpy ( oldpath, path );
+       }
+}
+
+prefix_length ( s1, s2 )       /* return length of longest common prefix */
+       char *s1, *s2;          /* ... of strings s1 and s2 */
+{
+       register char *start;
+
+       for ( start = s1; *s1 == *s2; s1++, s2++ )      
+               if ( *s1 == NULL )              
+                       break;
+       return ( s1 - start );
+}