Module Name: othersrc Committed By: agc Date: Mon Jan 14 01:54:23 UTC 2013
Modified Files: othersrc/external/bsd/netdiff/dist: diffreg.c netwdiff.1 Log Message: Get rid of the pseudo 8-bit "ASCII 4 EVAH!" character translation tables to perform case-insensitive comparisons. For now, we just use the ctype.h tolower(3) macro to obtain lower case. Definitely an area for future development. No functional changes, all test s run to completion and pass, so there are no regressions. Sync the wdiff(1) man page with reality in the RETURN VALUES section. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/netdiff/dist/diffreg.c cvs rdiff -u -r1.1 -r1.2 othersrc/external/bsd/netdiff/dist/netwdiff.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: othersrc/external/bsd/netdiff/dist/diffreg.c diff -u othersrc/external/bsd/netdiff/dist/diffreg.c:1.4 othersrc/external/bsd/netdiff/dist/diffreg.c:1.5 --- othersrc/external/bsd/netdiff/dist/diffreg.c:1.4 Sun Jan 13 22:17:22 2013 +++ othersrc/external/bsd/netdiff/dist/diffreg.c Mon Jan 14 01:54:23 2013 @@ -247,9 +247,8 @@ typedef struct stone_t { int suff; /* length of prefix and suffix */ int changec; /* # of changes */ size_t candc; - candidate_t *candlist; /* merely a free storage pot for candidates */ + candidate_t *candlist; /* merely a free storage pot for candidates */ size_t candlistlen; /* the length of candlist */ - uint8_t *chrtran; /* translation table for case-folding */ diffrange_t *context_vec_start; diffrange_t *context_vec_end; diffrange_t *context_vec_ptr; @@ -259,72 +258,15 @@ typedef struct stone_t { size_t max_context; } stone_t; -/* - * chrtran points to one of 2 translation tables: cup2low if folding upper to - * lower case clow2low if not folding case - */ -static uint8_t clow2low[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, - 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, - 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, - 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, - 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, - 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, - 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, - 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, - 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, - 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, - 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, - 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, - 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, - 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, - 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, - 0xfd, 0xfe, 0xff -}; - -static uint8_t cup2low[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, - 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, - 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, - 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x60, 0x61, - 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, - 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x60, 0x61, 0x62, - 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, - 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, - 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, - 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, - 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, - 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, - 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, - 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, - 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, - 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, - 0xfd, 0xfe, 0xff -}; - static FILE * opentemp(const char *filename) { - char buf[BUFSIZ]; const char *tempdir; - char tempfile[MAXPATHLEN]; - ssize_t nread; - int ifd, ofd; + ssize_t nread; + char tempfile[MAXPATHLEN]; + char buf[BUFSIZ]; + int ifd; + int ofd; if (strcmp(filename, "-") == 0) { ifd = STDIN_FILENO; @@ -433,16 +375,19 @@ diff_ferror(file_t *f) } static int -diff_getc(file_t *f) +diff_getc(diff_t *diff, file_t *f) { + int ch; + if (f->mapped) { if (f->curpos == (off_t)f->size) { return -1; } - return f->mapped[f->curpos++]; + ch = f->mapped[f->curpos++]; } else { - return getc(f->fp); + ch = getc(f->fp); } + return DIFF_GET_FLAG(diff, 'i') ? tolower(ch) : ch; } static int @@ -505,7 +450,7 @@ files_differ(diff_t *diff, file_t *f, in * Hash function taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578. */ static int -readhash(diff_t *diff, stone_t *s, file_t *f) +readhash(diff_t *diff, file_t *f) { int i, t, space; int sum; @@ -513,30 +458,19 @@ readhash(diff_t *diff, stone_t *s, file_ sum = 1; space = 0; if (!DIFF_GET_FLAG(diff, 'b') && !DIFF_GET_FLAG(diff, 'w')) { - if (DIFF_GET_FLAG(diff, 'i')) { - for (i = 0; (t = diff_getc(f)) != '\n'; i++) { - if (t == EOF) { - if (i == 0) { - return 0; - } - break; - } - sum = sum * 127 + s->chrtran[t]; - } - } else { - for (i = 0; (t = diff_getc(f)) != '\n'; i++) { - if (t == EOF) { - if (i == 0) { - return 0; - } - break; + for (i = 0; (t = diff_getc(diff, f)) != '\n'; i++) { + if (t == EOF) { + if (i == 0) { + return 0; } - sum = sum * 127 + t; + break; } + sum = sum * 255 + t; } } else { - for (i = 0;;) { - switch (t = diff_getc(f)) { + i = 0; + for (;;) { + switch (t = diff_getc(diff, f)) { case '\t': case '\r': case '\v': @@ -549,7 +483,7 @@ readhash(diff_t *diff, stone_t *s, file_ i++; space = 0; } - sum = sum * 127 + s->chrtran[t]; + sum = sum * 255 + t; i++; continue; case EOF: @@ -587,7 +521,7 @@ stretch(void **p, size_t *size, size_t e } static int -prepare(diff_t *diff, stone_t *s, file_t *f, off_t filesize) +prepare(diff_t *diff, file_t *f, off_t filesize) { diffline_t *p; size_t j; @@ -603,7 +537,7 @@ prepare(diff_t *diff, stone_t *s, file_t if ((p = calloc(sizeof(*p), sz + 3)) == NULL) { return 0; } - for (j = 0; (h = readhash(diff, s, f)) != 0 ; ) { + for (j = 0; (h = readhash(diff, f)) != 0 ; ) { if (j == sz) { if (!stretch((void **)&p, &sz, sizeof(*p), sz / 2)) { return 0; @@ -796,11 +730,11 @@ unravel(stone_t *s, file_t *f, int p) } static int -skipline(file_t *f) +skipline(diff_t *diff, file_t *f) { int i, c; - for (i = 1; (c = diff_getc(f)) != '\n' && c != EOF; i++) { + for (i = 1; (c = diff_getc(diff, f)) != '\n' && c != EOF; i++) { } return i; } @@ -838,19 +772,19 @@ check(diff_t *diff, stone_t *s, file_t * ct[0] = ct[1] = 0; for (i = 1; i <= f[0].len; i++) { if (s->J[i] == 0) { - f[0].offsets[i] = ct[0] += skipline(&f[0]); + f[0].offsets[i] = ct[0] += skipline(diff, &f[0]); continue; } while (j < s->J[i]) { - f[1].offsets[j] = ct[1] += skipline(&f[1]); + f[1].offsets[j] = ct[1] += skipline(diff, &f[1]); j++; } if (IGNORE_WHITESPACE_DIFFS(diff) || IGNORE_CASE(diff) || IGNORE_TAB_EXPANSION(diff)) { for (;;) { - c = diff_getc(&f[0]); - d = diff_getc(&f[1]); + c = diff_getc(diff, &f[0]); + d = diff_getc(diff, &f[1]); /* * GNU diff ignores a missing newline * in one file if -b || -w. @@ -868,20 +802,20 @@ check(diff_t *diff, stone_t *s, file_t * break; } ct[0]++; - } while (isspace(c = diff_getc(&f[0]))); + } while (isspace(c = diff_getc(diff, &f[0]))); do { if (d == '\n') { break; } ct[1]++; - } while (isspace(d = diff_getc(&f[1]))); + } while (isspace(d = diff_getc(diff, &f[1]))); } else if (IGNORE_ALL_SPACE(diff)) { while (isspace(c) && c != '\n') { - c = diff_getc(&f[0]); + c = diff_getc(diff, &f[0]); ct[0]++; } while (isspace(d) && d != '\n') { - d = diff_getc(&f[1]); + d = diff_getc(diff, &f[1]); ct[1]++; } } else if (IGNORE_BLANK_LINES(diff)) { @@ -890,14 +824,14 @@ check(diff_t *diff, stone_t *s, file_t * if (c == '\n') { ct[0]++; } - } while ((c = diff_getc(&f[0])) == '\n'); + } while ((c = diff_getc(diff, &f[0])) == '\n'); } if (d == '\n' && c != '\n') { do { if (d == '\n') { ct[1]++; } - } while ((d = diff_getc(&f[1])) == '\n'); + } while ((d = diff_getc(diff, &f[1])) == '\n'); } break; } else if (IGNORE_TAB_EXPANSION(diff)) { @@ -909,14 +843,14 @@ check(diff_t *diff, stone_t *s, file_t * */ diff_fgetpos(&f[0], &position); for (spacecount = 1; spacecount <= 8; spacecount++) { - c = diff_getc(&f[0]); + c = diff_getc(diff, &f[0]); if (c != ' ') { break; } } diff_fsetpos(&f[0], &position); while (c == ' ' && spacecount == 9) { - c = diff_getc(&f[0]); + c = diff_getc(diff, &f[0]); ct[0]++; } } @@ -927,27 +861,27 @@ check(diff_t *diff, stone_t *s, file_t * */ diff_fgetpos(&f[1], &position); for (spacecount = 1; spacecount <= 8; spacecount++) { - d = diff_getc(&f[1]); + d = diff_getc(diff, &f[1]); if (d != ' ') { break; } } diff_fsetpos(&f[1], &position); while (d == ' ' && spacecount == 9) { - d = diff_getc(&f[1]); + d = diff_getc(diff, &f[1]); ct[1]++; } } } } - if (s->chrtran[c] != s->chrtran[d]) { + if (c != d) { jackpot++; s->J[i] = 0; if (c != '\n' && c != EOF) { - ct[0] += skipline(&f[0]); + ct[0] += skipline(diff, &f[0]); } if (d != '\n' && c != EOF) { - ct[1] += skipline(&f[1]); + ct[1] += skipline(diff, &f[1]); } break; } @@ -959,14 +893,14 @@ check(diff_t *diff, stone_t *s, file_t * for (;;) { ct[0]++; ct[1]++; - if ((c = diff_getc(&f[0])) != (d = diff_getc(&f[1]))) { + if ((c = diff_getc(diff, &f[0])) != (d = diff_getc(diff, &f[1]))) { /* jackpot++; */ s->J[i] = 0; if (c != '\n' && c != EOF) { - ct[0] += skipline(&f[0]); + ct[0] += skipline(diff, &f[0]); } if (d != '\n' && c != EOF) { - ct[1] += skipline(&f[1]); + ct[1] += skipline(diff, &f[1]); } break; } @@ -980,7 +914,7 @@ check(diff_t *diff, stone_t *s, file_t * j++; } for (; j <= f[1].len; j++) { - f[1].offsets[j] = ct[1] += skipline(&f[1]); + f[1].offsets[j] = ct[1] += skipline(diff, &f[1]); } /* * if (jackpot) @@ -1227,7 +1161,7 @@ fetch(diff_t *diff, stone_t *s, file_t * /* print through if append (a>b), else to (nb: 0 vs 1 orig) */ nc = f->offsets[(a > b) ? b : a - 1] - curpos; for (i = 0; i < nc; i++) { - diff_printf(diff, "%c", diff_getc(f)); + diff_printf(diff, "%c", diff_getc(diff, f)); } } if (a > b) { @@ -1250,7 +1184,7 @@ fetch(diff_t *diff, stone_t *s, file_t * } col = 0; for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { - if ((c = diff_getc(f)) == EOF) { + if ((c = diff_getc(diff, f)) == EOF) { if (WARN_NO_NEWLINE(diff)) { warnx("No newline at end of file"); } else { @@ -1579,7 +1513,7 @@ bdiff_catchup(diff_t *diff, long *indice /* get text in a malloc'ed buffer */ static char * -get_add_text(file_t *f, int32_t cc) +get_add_text(diff_t *diff, file_t *f, int32_t cc) { int32_t i; char *p; @@ -1589,7 +1523,7 @@ get_add_text(file_t *f, int32_t cc) return NULL; } for (i = 0 ; i < cc ; i++) { - if ((ch = diff_getc(f)) >= 0) { + if ((ch = diff_getc(diff, f)) >= 0) { p[i] = ch; } } @@ -1606,7 +1540,7 @@ bdiff_add_text(diff_t *diff, long *indic diff_fseek(f, curpos = indices[from2 - 1], SEEK_SET); nc = (int32_t)(indices[to2] - curpos); if (nc > 0) { - if ((p = get_add_text(f, nc)) == NULL) { + if ((p = get_add_text(diff, f, nc)) == NULL) { return 0; } bdiff_encode_add(diff, p, nc); @@ -1793,7 +1727,7 @@ output(diff_t *diff, stone_t *s, file_t for (;;) { int c; - if ((c = diff_getc(&f[0])) == EOF) { + if ((c = diff_getc(diff, &f[0])) == EOF) { return; } diff_printf(diff, "%c", c); @@ -1826,7 +1760,7 @@ istextfile(diff_t *diff, file_t *f) } diff_fseek(f, 0, SEEK_SET); for (i = 0; i <= MAX_CHECK ; i++) { - ch = diff_getc(f); + ch = diff_getc(diff, f); if (ch == '\0') { diff_fseek(f, 0, SEEK_SET); return 0; @@ -1907,8 +1841,8 @@ diffit(diff_t *diff, file_t *f, stone_t free(header); } } - prepare(diff, s, &f[0], diff->st[0].st_size); - prepare(diff, s, &f[1], diff->st[1].st_size); + prepare(diff, &f[0], diff->st[0].st_size); + prepare(diff, &f[1], diff->st[1].st_size); prune(s, f); sort(f[0].sfile, f[0].slen); sort(f[1].sfile, f[1].slen); @@ -2226,7 +2160,6 @@ diff_file(diff_t *diff, const char *ofil s.lastmatchline = 0; s.max_context = 64; s.context_vec_ptr = s.context_vec_start - 1; - s.chrtran = (DIFF_GET_FLAG(diff, 'i')) ? cup2low : clow2low; d[0] = S_ISDIR(diff->st[0].st_mode); d[1] = S_ISDIR(diff->st[1].st_mode); if (d[0] != d[1]) { @@ -2278,7 +2211,6 @@ diff_mem(diff_t *diff, const char *m1, s s.lastmatchline = 0; s.max_context = 64; s.context_vec_ptr = s.context_vec_start - 1; - s.chrtran = (DIFF_GET_FLAG(diff, 'i')) ? cup2low : clow2low; setupmem(&f[0], &diff->st[0], m1, size1); setupmem(&f[1], &diff->st[1], m2, size2); return diffit(diff, f, &s, flags, 0); Index: othersrc/external/bsd/netdiff/dist/netwdiff.1 diff -u othersrc/external/bsd/netdiff/dist/netwdiff.1:1.1 othersrc/external/bsd/netdiff/dist/netwdiff.1:1.2 --- othersrc/external/bsd/netdiff/dist/netwdiff.1:1.1 Sun Jan 13 22:17:22 2013 +++ othersrc/external/bsd/netdiff/dist/netwdiff.1 Mon Jan 14 01:54:23 2013 @@ -1,4 +1,4 @@ -.\" $NetBSD: netwdiff.1,v 1.1 2013/01/13 22:17:22 agc Exp $ +.\" $NetBSD: netwdiff.1,v 1.2 2013/01/14 01:54:23 agc Exp $ .\" .\" Copyright (c) 2013 Alistair Crooks <a...@netbsd.org> .\" All rights reserved. @@ -73,8 +73,17 @@ Perform comparisons in a case-insensitiv .Sh RETURN VALUES The .Nm -utility will return 0 for success, -and 1 for failure. +utility exits with one of the following values: +.Bl -tag -width 4n +.It 0 +The files are identical. +.It 1 +The files are different; this includes the case +where one file is identical to the first part of +the other. +.It 2 +An error occurred. +.El .Sh EXAMPLES .Bd -literal % netwdiff f1 f2