Newsgroups: alt.sources From: dsiler@boi.hp.com (Dan Siler) Subject: ediff - translate diff to English Date: Wed, 10 Nov 1993 16:55:15 GMT Nntp-Posting-Host: hpbs4199.boi.hp.com Organization: Hewlett-Packard / Boise, Idaho X-Newsreader: TIN [version 1.2 PL0.9] --------------------cut here------------------------------------- #!/bin/sh # This is a shell archive (shar 3.27) # made 11/10/1993 02:52 UTC by horwitz@argos # Source directory /u/horwitz/ediff # # existing files WILL be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 539 -rw-r--r-- ediff.1 # 5379 -rw-r--r-- ediff.c # if touch 2>&1 | fgrep 'mmdd' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= ediff.1 ============== echo "x - extracting ediff.1 (Text)" sed 's/^X//' << 'SHAR_EOF' > ediff.1 && X.TH EDIFF 1L "30 December 1988" X.SH NAME Xediff \- translate diff output into plain English X.SH SYNOPSIS X.B ediff X.SH DESCRIPTION X.I Ediff Xis a filter which translates normal X.IR diff (1) Xoutput (not output produced with the X.BR \-c , X.BR \-e , Xor X.B \-f X.I diff Xoptions) into more readable English descriptions. XIt copies non-diff material verbatim. X.SH "SEE ALSO" Xcomm(1), diff(1), uniq(1) X.SH AUTHOR X.nf XDavid MacKenzie (edf@rocky2.rockefeller.edu). XManual page written with the help of R. P. C. Rodgers X(rodgers@maxwell.mmwb.ucsf.edu). SHAR_EOF $TOUCH -am 1109215293 ediff.1 && chmod 0644 ediff.1 || echo "restore of ediff.1 failed" set `wc -c ediff.1`;Wc_c=$1 if test "$Wc_c" != "539"; then echo original size 539, current size $Wc_c fi # ============= ediff.c ============== echo "x - extracting ediff.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ediff.c && X/* X% cc -O ediff.c -o ediff && strip ediff X X ediff - translate diff output into plain English X X Translates only the normal diff output (not -c or -e/-f). X Use as a filter. Copies non-diff lines verbatim. Deletes NULs. X X The Unix variant that runs on our Charles River Data Systems X machines, UNOS, comes with, in addition to the standard diff program, X a program called "difference" that produces more human-readable X output. Ediff provides the advantages of that program to users of other X versions of Unix (soon to include us, as we're hoping to get rid of X the CRDS machines before too long). X X Thanks to Mike Haertel for the following information. X The exact meaning of the normal diff symbols is as follows X (all line numbers are the ORIGINAL line numbers in each file): X X 5,7c8,10 X Change lines 5-7 of file 1 to read as lines 8-10 of file 2 (or, if changing X file 2 into file 1, change lines 8-10 of file 2 to read as lines 5-7 X of file 1). X X 5,7d3 X Delete lines 5-7 of file 1 (alternatively, append lines 5-7 of file 1 X after line 3 of file 2). X X 8a12,15 X Append lines 12-15 of file 2 after line 8 of file 1 (alternatively, X delete lines 12-15 of file 2). X X David MacKenzie X edf@rocky2.rockefeller.edu X X Latest revision: 12/30/88 */ X X#include X X/* Magic value meaning that a line number is missing from the input. */ X#define UNUSED -1L X X#ifdef __STDC__ X#define P(x) x X#else X#define P(x) () X#endif X Xvoid exit P((int)); X Xvoid change P ((long, long, long, long)); Xvoid delete P ((long, long, long)); Xvoid append P ((long, long, long)); Xvoid copylines P ((long, int)); Xint readline P ((char *, int, FILE *)); X Xchar line[BUFSIZ]; /* Input line. */ X Xmain () X{ X long f1n1, f1n2, f2n1, f2n2; /* File 1, line number 1; etc. */ X int result; /* Result of readline. */ X X for (;;) X { X result = readline (line, BUFSIZ, stdin); X f1n2 = f2n2 = UNUSED; X if X (sscanf (line, "%ld,%ldc%ld,%ld\n", &f1n1, &f1n2, &f2n1, &f2n2) == 4 || X sscanf (line, "%ld,%ldc%ld\n", &f1n1, &f1n2, &f2n1) == 3 || X sscanf (line, "%ldc%ld,%ld\n", &f1n1, &f2n1, &f2n2) == 3 || X sscanf (line, "%ldc%ld\n", &f1n1, &f2n1) == 2) X change (f1n1, f1n2, f2n1, f2n2); X else if X (sscanf (line, "%ld,%ldd%ld\n", &f1n1, &f1n2, &f2n1) == 3 || X sscanf (line, "%ldd%ld\n", &f1n1, &f2n1) == 2) X delete (f1n1, f1n2, f2n1); X else if X (sscanf (line, "%lda%ld,%ld\n", &f1n1, &f2n1, &f2n2) == 3 || X sscanf (line, "%lda%ld\n", &f1n1, &f2n1) == 2) X append (f1n1, f2n1, f2n2); X else X { X /* The line wasn't the start of a diff. Copy it verbatim. */ X fputs (line, stdout); X /* If it was a long line, copy the remainder. */ X while (result == -1) X { X result = readline (line, BUFSIZ, stdin); X fputs (line, stdout); X } X } X } X} X Xvoid change (f1n1, f1n2, f2n1, f2n2) X long f1n1, f1n2, f2n1, f2n2; X{ X printf ("\n-------- "); X if (f1n2 == UNUSED && f2n2 == UNUSED) X /* 1c1 */ X printf ("1 line changed at %ld from:\n", X f1n1); X else if (f1n2 == UNUSED) X /* 1c1,2 */ X printf ("1 line changed to %ld lines at %ld from:\n", X f2n2 - f2n1 + 1L, f1n1); X else if (f2n2 == UNUSED) X /* 1,2c1 */ X printf ("%ld lines changed to 1 line at %ld-%ld from:\n", X f1n2 - f1n1 + 1L, f1n1, f1n2); X else if (f1n2 - f1n1 == f2n2 - f2n1) X /* 1,2c1,2 */ X printf ("%ld lines changed at %ld-%ld from:\n", X f1n2 - f1n1 + 1L, f1n1, f1n2); X else X /* 1,2c1,3 */ X printf ("%ld lines changed to %ld lines at %ld-%ld from:\n", X f1n2 - f1n1 + 1L, f2n2 - f2n1 + 1L, f1n1, f1n2); X X if (f1n2 == UNUSED) X copylines (1L, 2); /* Skip the "< ". */ X else X copylines (f1n2 - f1n1 + 1L, 2); X X printf ("-------- to:\n"); X (void) readline (line, BUFSIZ, stdin); /* Eat the "---" line. */ X if (f2n2 == UNUSED) X copylines (1L, 2); /* Skip the "> ". */ X else X copylines (f2n2 - f2n1 + 1L, 2); X} X X/* ARGSUSED */ Xvoid delete (f1n1, f1n2, f2n1) X long f1n1, f1n2, f2n1; X{ X printf ("\n-------- "); X if (f1n2 == UNUSED) X { X /* 1d1 */ X printf ("1 line deleted at %ld:\n", f1n1); X copylines (1L, 2); /* Skip the "< ". */ X } X else X { X /* 1,2d1 */ X printf ("%ld lines deleted at %ld:\n", f1n2 - f1n1 + 1L, f1n1); X copylines (f1n2 - f1n1 + 1L, 2); X } X} X Xvoid append (f1n1, f2n1, f2n2) X long f1n1, f2n1, f2n2; X{ X printf ("\n-------- "); X if (f2n2 == UNUSED) X { X /* 1a1 */ X printf ("1 line added at %ld:\n", f1n1); X copylines (1L, 2); /* Skip the "> ". */ X } X else X { X /* 1a1,2 */ X printf ("%ld lines added at %ld:\n", f2n2 - f2n1 + 1L, f1n1); X copylines (f2n2 - f2n1 + 1L, 2); X } X} X X/* Copy nlines lines from stdin to stdout; start writing at position skip. */ X Xvoid copylines (nlines, skip) X long nlines; X int skip; X{ X int result; X X while (nlines-- > 0L) X { X result = readline (line, BUFSIZ, stdin); X fputs (&line[skip], stdout); X /* If it was a long line, copy the remainder. */ X while (result == -1) X { X result = readline (line, BUFSIZ, stdin); X fputs (line, stdout); X } X } X} X X/* Front end to fgets. X Exit if EOF; return 1 if end of line read, -1 if partial line read. */ X Xint readline (s, length, fp) X char *s; X int length; X FILE *fp; X{ X if (!fgets (s, length, fp)) X exit (0); X if (s[strlen (s) - 1] == '\n') X return 1; X else X return -1; X} SHAR_EOF $TOUCH -am 1109215293 ediff.c && chmod 0644 ediff.c || echo "restore of ediff.c failed" set `wc -c ediff.c`;Wc_c=$1 if test "$Wc_c" != "5379"; then echo original size 5379, current size $Wc_c fi exit 0