2 #include "levenshtein.h"
6 struct path_list all_names
= { NULL
, 0, 0, 1 };
7 struct path_list pairs
= { NULL
, 0, 0, 1 };
9 static int compair(const void *a
, const void *b
)
11 const struct path_list_item
*x
= a
, *y
= b
;
13 return (int)x
->util
- (int)y
->util
;
16 int main(int argc
, char **argv
)
19 struct strbuf line
= STRBUF_INIT
;
23 in
= fopen(argv
[1], "r");
25 die ("Could not open %s", argv
[1]);
30 while (strbuf_getline(&line
, in
, '\n') != EOF
)
31 path_list_insert(line
.buf
, &all_names
);
33 for (i
= 0; i
< all_names
.nr
; i
++) {
34 struct strbuf pair
= STRBUF_INIT
;
35 const char *name1
= all_names
.items
[i
].path
;
38 strbuf_addf(&pair
, "%s <-> ", name1
);
41 for (j
= i
+ 1; j
< all_names
.nr
; j
++) {
42 const char *name2
= all_names
.items
[j
].path
;
43 int distance
= levenshtein(name1
, name2
, 1, 9, 1, 1);
45 strbuf_setlen(&pair
, len
);
46 strbuf_addstr(&pair
, name2
);
47 path_list_append(pair
.buf
, &pairs
)->util
=
52 qsort(pairs
.items
, pairs
.nr
, sizeof(*pairs
.items
), compair
);
54 for (i
= 0; i
< pairs
.nr
; i
++)
55 printf("%d\t%s\n", (int)pairs
.items
[i
].util
,