diff -C2 -N patch-2.0.12/common.h patch-2.0.12u/common.h *** patch-2.0.12/common.h Fri Jun 5 01:08:02 1992 --- patch-2.0.12u/common.h Sat Jul 4 00:21:53 1992 *************** *** 136,139 **** --- 136,140 ---- #define ED_DIFF 3 #define NEW_CONTEXT_DIFF 4 + #define UNI_DIFF 5 EXT int diff_type INIT(0); diff -C2 -N patch-2.0.12/patch.c patch-2.0.12u/patch.c *** patch-2.0.12/patch.c Fri Jun 5 01:07:59 1992 --- patch-2.0.12u/patch.c Sat Jul 4 00:21:54 1992 *************** *** 1,4 **** char rcsid[] = ! "$Header: patch.c,v 2.0.1.6 88/06/22 20:46:39 lwall Locked $"; /* patch - a program to apply diffs to original files --- 1,4 ---- char rcsid[] = ! "$Header: patch.c,v 2.0.2.0 90/05/01 22:17:50 davison Locked $"; /* patch - a program to apply diffs to original files *************** *** 10,13 **** --- 10,16 ---- * * $Log: patch.c,v $ + * Revision 2.0.2.0 90/05/01 22:17:50 davison + * patch12u: unidiff support added + * * Revision 2.0.1.6 88/06/22 20:46:39 lwall * patch12: rindex() wasn't declared *************** *** 458,461 **** --- 461,467 ---- skip_rest_of_patch = TRUE; break; + case 'u': + diff_type = UNI_DIFF; + break; case 'v': version(); *************** *** 530,535 **** LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1; LINENUM newlast = newfirst + pch_repl_lines() - 1; ! char *stars = (diff_type == NEW_CONTEXT_DIFF ? " ****" : ""); ! char *minuses = (diff_type == NEW_CONTEXT_DIFF ? " ----" : " -----"); fprintf(rejfp, "***************\n"); --- 536,541 ---- LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1; LINENUM newlast = newfirst + pch_repl_lines() - 1; ! char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : ""); ! char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----"); fprintf(rejfp, "***************\n"); diff -C2 -N patch-2.0.12/patch.man patch-2.0.12u/patch.man *** patch-2.0.12/patch.man Fri Jun 5 01:07:54 1992 --- patch-2.0.12u/patch.man Sat Jul 4 00:21:54 1992 *************** *** 81,85 **** .SH DESCRIPTION .I Patch ! will take a patch file containing any of the three forms of difference listing produced by the .I diff --- 81,85 ---- .SH DESCRIPTION .I Patch ! will take a patch file containing any of the four forms of difference listing produced by the .I diff *************** *** 102,109 **** .BR -c , .BR -e , or ! .B -n switch. ! Context diffs and normal diffs are applied by the .I patch program itself, while ed diffs are simply fed to the --- 102,111 ---- .BR -c , .BR -e , + .BR -n , or ! .B -u switch. ! Context diffs (old-style, new-style, and unified) and ! normal diffs are applied by the .I patch program itself, while ed diffs are simply fed to the *************** *** 377,380 **** --- 379,387 ---- .sp will ignore the first and second of three patches. + .TP 5 + .B \-u + forces + .I patch + to interpret the patch file as a unified context diff (a unidiff). .TP 5 .B \-v diff -C2 -N patch-2.0.12/patchlevel.h patch-2.0.12u/patchlevel.h *** patch-2.0.12/patchlevel.h Fri Jun 5 01:08:09 1992 --- patch-2.0.12u/patchlevel.h Sat Jul 4 00:21:52 1992 *************** *** 1 **** ! #define PATCHLEVEL 12 --- 1 ---- ! #define PATCHLEVEL "12u" diff -C2 -N patch-2.0.12/pch.c patch-2.0.12u/pch.c *** patch-2.0.12/pch.c Fri Jun 5 01:07:53 1992 --- patch-2.0.12u/pch.c Sat Jul 4 00:21:55 1992 *************** *** 2,5 **** --- 2,8 ---- * * $Log: pch.c,v $ + * Revision 2.0.2.0 90/05/01 22:17:51 davison + * patch12u: unidiff support added + * * Revision 2.0.1.7 88/06/03 15:13:28 lwall * patch10: Can now find patches in shar scripts. *************** *** 163,166 **** --- 166,170 ---- say3(" %sooks like %s to me...\n", (p_base == 0L ? "L" : "The next patch l"), + diff_type == UNI_DIFF ? "a unidiff" : diff_type == CONTEXT_DIFF ? "a context diff" : diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" : *************** *** 287,290 **** --- 291,303 ---- goto scan_exit; } + if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) { + if (!atol(s+3)) + ok_to_create_file = TRUE; + p_indent = indent; + p_start = this_line; + p_sline = p_input_line; + retval = UNI_DIFF; + goto scan_exit; + } stars_this_line = strnEQ(s, "********", 8); if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line && *************** *** 720,723 **** --- 733,878 ---- assert(filldst==p_end+1 || filldst==repl_beginning); } + } + else if (diff_type == UNI_DIFF) { + long line_beginning = ftell(pfp); + /* file pos of the current line */ + Reg4 LINENUM fillsrc; /* index of old lines */ + Reg5 LINENUM filldst; /* index of new lines */ + char ch; + + ret = pgets(buf, sizeof buf, pfp); + p_input_line++; + if (ret == Nullch || strnNE(buf, "@@ -", 4)) { + next_intuit_at(line_beginning,p_input_line); + return FALSE; + } + s = buf+4; + if (!*s) + goto malformed; + p_first = (LINENUM) atol(s); + while (isdigit(*s)) s++; + if (*s != ',' || !*++s) + goto malformed; + p_ptrn_lines = (LINENUM) atol(s); + while (isdigit(*s)) s++; + if (*s == ' ') s++; + if (*s != '+' || !*++s) + goto malformed; + p_newfirst = (LINENUM) atol(s); + while (isdigit(*s)) s++; + if (*s != ',' || !*++s) + goto malformed; + p_repl_lines = (LINENUM) atol(s); + while (isdigit(*s)) s++; + if (*s == ' ') s++; + if (*s != '@') + goto malformed; + if (!p_first && !p_ptrn_lines) + p_first = 1; + p_max = p_ptrn_lines + p_repl_lines; + while (p_max >= hunkmax) + grow_hunkmax(); + p_max = hunkmax; + fillsrc = 1; + filldst = fillsrc + p_ptrn_lines; + p_end = filldst + p_repl_lines; + Sprintf(buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1); + p_line[0] = savestr(buf); + if (out_of_mem) { + p_end = -1; + return FALSE; + } + p_char[0] = '*'; + Sprintf(buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1); + p_line[filldst] = savestr(buf); + if (out_of_mem) { + p_end = 0; + return FALSE; + } + p_char[filldst++] = '='; + p_context = 100; + context = 0; + p_hunk_beg = p_input_line + 1; + while (fillsrc <= p_ptrn_lines || filldst <= p_end) { + line_beginning = ftell(pfp); + ret = pgets(buf, sizeof buf, pfp); + p_input_line++; + if (ret == Nullch) { + if (p_max - filldst < 3) + Strcpy(buf, " \n"); /* assume blank lines got chopped */ + else { + fatal1("Unexpected end of file in patch.\n"); + } + } + if (*buf == '\t' || *buf == '\n') { + ch = ' '; /* assume the space got eaten */ + s = savestr(buf); + } + else { + ch = *buf; + s = savestr(buf+1); + } + if (out_of_mem) { + while (--filldst > p_ptrn_lines) + free(p_line[filldst]); + p_end = fillsrc-1; + return FALSE; + } + switch (ch) { + case '-': + if (fillsrc > p_ptrn_lines) { + free(s); + p_end = filldst-1; + goto malformed; + } + p_char[fillsrc] = ch; + p_line[fillsrc] = s; + p_len[fillsrc++] = strlen(s); + break; + case '=': + ch = ' '; + /* FALL THROUGH */ + case ' ': + if (fillsrc > p_ptrn_lines) { + free(s); + while (--filldst > p_ptrn_lines) + free(p_line[filldst]); + p_end = fillsrc-1; + goto malformed; + } + context++; + p_char[fillsrc] = ch; + p_line[fillsrc] = s; + p_len[fillsrc++] = strlen(s); + s = savestr(s); + if (out_of_mem) { + while (--filldst > p_ptrn_lines) + free(p_line[filldst]); + p_end = fillsrc-1; + return FALSE; + } + /* FALL THROUGH */ + case '+': + if (filldst > p_end) { + free(s); + while (--filldst > p_ptrn_lines) + free(p_line[filldst]); + p_end = fillsrc-1; + goto malformed; + } + p_char[filldst] = ch; + p_line[filldst] = s; + p_len[filldst++] = strlen(s); + break; + default: + p_end = filldst; + goto malformed; + } + if (ch != ' ' && context > 0) { + if (context < p_context) + p_context = context; + context = -1000; + } + }/* while */ } else { /* normal diff--fake it up */ diff -C2 -N patch-2.0.12/version.c patch-2.0.12u/version.c *** patch-2.0.12/version.c Fri Jun 5 01:07:49 1992 --- patch-2.0.12u/version.c Sat Jul 4 00:21:55 1992 *************** *** 24,28 **** rcsid[0] = rcsid[0]; #else ! fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL); #endif } --- 24,28 ---- rcsid[0] = rcsid[0]; #else ! fatal3("%s\nPatch level: %s\n", rcsid, PATCHLEVEL); #endif }