davison@dri.com (Wayne Davison) (01/01/91)
For those of you who are using the unidiff format context diffs, here's the first (and only?) patch for the unidiff utility set (unify, & unipatch) plus a patch for pch.c in patch and context.c in gnu diff. The only visible change is that the unidiff header was changed from: *** origname Date --- newname Date to a more consistent: --- origname Date +++ newname Date (this way the '-' and '+' characters correspond to the '-' and '+' hunks). The affected pieces in patch and gnu diff were minicule. Unipatch and unify have simple changes to convert the header when needed. Unify was also fixed to make it more portable (I don't know how I let those int<->long assumptions slip by me). For those balking at using unidiffs, a tidbit FYI: last I heard from Richard Stallman gnu diff will officially add unidiff generation. If (when?) this happens it will make them much more "standard." For those that don't know what unidiffs are, mail me. They're smaller than regular context diffs by about 20% and are (IMHO) easier to read. (The patches below are in unidiff format.) Mail to the following address will reach me faster than mail to the reply address. -- \ /| / /|\/ /| /(_) Wayne Davison (_)/ |/ /\|/ / |/ \ 0004475895@mcimail.com (W A Y N e) ...!uunet!mcimail!0004475895 ---8<------8<------8<------8<--- cut here --->8------>8------>8------>8--- Index: unify.c @@ -58,6 +58,7 @@ { char type; char ndiff; /* Equals '*' when we have a new-style context diff */ + char star_dash_plus = ' '; FILE *fp_in = stdin; while (--argc) { @@ -127,7 +128,9 @@ printf("%s", buf); } else if (strnEQ(buf, "Prereq: ", 8)) { printf("%s", buf); - } else if (strnEQ(buf, "*** ", 4) || strnEQ(buf, "--- ", 4)) { + } else if (strnEQ(buf, "*** ", 4) + || strnEQ(buf, "--- ", 4) + || strnEQ(buf, "+++ ", 4)) { if (!found_index) { char *cp; int len; @@ -141,7 +144,19 @@ } } if (!patch_format) { - printf("%s", buf); + if (output_type == 1 && (*buf == '+' + || *buf == '-' && star_dash_plus != '*') + || output_type == 2 && (*buf == '*' + || *buf == '-' && star_dash_plus == '*')) { + printf("%s", buf); + } else if (*buf == '*' || *buf == '+') { + printf("---%s", buf+3); + } else if (*buf == '-' && star_dash_plus == '*') { + printf("+++%s", buf+3); + } else { + printf("***%s", buf+3); + } + star_dash_plus = *buf; } } else if( patch_format && (strnEQ(buf, "Only in ", 8) || strnEQ(buf, "Common subdir", 13) @@ -206,7 +221,7 @@ line_num); exit(1); } - add_line(*buf, 0, buf+1); + add_line(*buf, 0L, buf+1); if (o_line == o_end && n_line == n_end) { generate_output(); state = PARSE_UNIDIFF; @@ -293,7 +308,7 @@ exit(1); } if (o_line > o_last) { - add_line(type, 0, buf+2); + add_line(type, 0L, buf+2); o_last = o_line; n_last = n_line; } else { @@ -374,7 +389,7 @@ add_line(type, o_line, buf+2); n_last++; } else if (type != ' ') { - add_line(type, 0, buf+2); + add_line(type, 0L, buf+2); n_last++; } else { hold = hold->link; @@ -420,7 +435,7 @@ void add_line(type, num, str) char type; -int num; +long num; char *str; { line = (struct liner *)malloc(sizeof (struct liner) + strlen(str)); @@ -443,7 +458,7 @@ return; } if (output_type == 1) { - int i, j; + long i, j; i = o_first ? o_last - o_first + 1 : 0; j = n_first ? n_last - n_first + 1 : 0; Index: unipatch.c @@ -19,7 +19,8 @@ if(!fgets(bf,sizeof bf,stdin)) exit(0); lncnt++; if(!strncmp(bf,"@@ -",4)) break; - fputs(bf,stdout); + if(!strncmp(bf,"+++ ",4)) printf("***%s",bf+3); + else fputs(bf,stdout); } if(sscanf(bf+4,"%ld,%ld +%ld,%ld %c",&os,&ol,&ns,&nl,&ch)!=5||ch!='@') goto bad; The patch for "patch": Index: pch.c @@ -269,6 +269,8 @@ oldtmp = savestr(s+4); else if (strnEQ(s, "--- ", 4)) newtmp = savestr(s+4); + else if (strnEQ(s, "+++ ", 4)) + oldtmp = savestr(s+4); /* pretend it is the old name */ else if (strnEQ(s, "Index:", 6)) indtmp = savestr(s+6); else if (strnEQ(s, "Prereq:", 7)) { The patch for gnu diff: Index: context.c @@ -48,9 +48,9 @@ } else { - fprintf (outfile, "*** %s\t%s", inf[0].name, + fprintf (outfile, "%s %s\t%s", unidiff_flag ? "---" : "***", inf[0].name, ctime (&inf[0].stat.st_mtime)); - fprintf (outfile, "--- %s\t%s", inf[1].name, + fprintf (outfile, "%s %s\t%s", unidiff_flag ? "+++" : "---", inf[1].name, ctime (&inf[1].stat.st_mtime)); } } ---8<------8<------8<------8<--- the end --->8------>8------>8------>8---