![]() |
![]()
| ![]() |
![]()
NAME
LIBRARYlibrary “libdiff” SYNOPSIS
int
DESCRIPTIONThe
On success,
RETURN VALUESThe EXAMPLESThe following example takes two strings, "asdf" and "fdsa", and displays the edit script to go from the first to the second. int cmp(const void *p1, const void *p2) { return *(const char *)p1 == *(const char *)p2; } void compute(void) { size_t i; int rc; struct diff p; rc = diff(&p, cmp, 1, "asdf", 4, "fdsa", 4); if (rc < 0) err(EXIT_FAILURE, NULL); if (0 == rc) errx(EXIT_FAILURE, "cannot compute distance"); for (i = 0; i < p.sessz; i++) printf("%s%c\n", DIFF_ADD == p.ses[i].type ? "+" : DIFF_DELETE == p.ses[i].type ? "-" : " ", *(const char *)p.ses[i].e); free(p.ses); free(p.lcs); } The second example looks for difference in words. int cmp(const void *p1, const void *p2) { return 0 == strcmp (*(const char **)p1, *(const char **)p2); } void compute(void) { size_t i; int rc; struct diff p; const char *origin[] = { "hello", "there" }; const char *target[] = { "hello", "world" }; rc = diff(&p, cmp, sizeof(char *), origin, 2, target, 2); if (rc < 0) err(EXIT_FAILURE, NULL); if (0 == rc) errx(EXIT_FAILURE, "cannot compute distance"); for (i = 0; i < p.sessz; i++) printf("%s%s\n", DIFF_ADD == p.ses[i].type ? "+" : DIFF_DELETE == p.ses[i].type ? "-" : " ", *(const char **)p.ses[i].e); free(p.ses); free(p.lcs); } SEE ALSOWu Sun, Manber Udi, and Myers Gene, An O(NP) sequence comparison algorithm, Issue 6, Information Processing Letters, Volume 35, 1990.
|