home *** CD-ROM | disk | FTP | other *** search
- Index: patchlevel.h
- Prereq: 12
- @@ -1,1 +1,1 @@
- -#define PATCHLEVEL 12
- +#define PATCHLEVEL "12u"
- Index: common.h
- @@ -135,4 +135,5 @@
- =#define ED_DIFF 3
- =#define NEW_CONTEXT_DIFF 4
- +#define UNI_DIFF 5
- =EXT int diff_type INIT(0);
- =
- Index: patch.c
- @@ -1,4 +1,4 @@
- =char rcsid[] =
- - "$Header: patch.c,v 2.0.1.6 88/06/22 20:46:39 lwall Locked $";
- + "$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,4 +10,7 @@
- = *
- = * $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,4 +461,7 @@
- = skip_rest_of_patch = TRUE;
- = break;
- + case 'u':
- + diff_type = UNI_DIFF;
- + break;
- = case 'v':
- = version();
- @@ -530,6 +536,6 @@
- = 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 ? " ----" : " -----");
- + char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
- + char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
- =
- = fprintf(rejfp, "***************\n");
- Index: patch.man
- @@ -81,5 +81,5 @@
- =.SH DESCRIPTION
- =.I Patch
- -will take a patch file containing any of the three forms of difference
- +will take a patch file containing any of the four forms of difference
- =listing produced by the
- =.I diff
- @@ -102,8 +102,10 @@
- =.BR -c ,
- =.BR -e ,
- +.BR -n ,
- =or
- -.B -n
- +.B -u
- =switch.
- -Context diffs and normal diffs are applied by the
- +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,4 +379,9 @@
- =.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
- Index: pch.c
- @@ -2,4 +2,7 @@
- = *
- = * $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,4 +166,5 @@
- = 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,4 +291,13 @@
- = 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,4 +733,146 @@
- = 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 */
- Index: version.c
- @@ -24,5 +24,5 @@
- = rcsid[0] = rcsid[0];
- =#else
- - fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
- + fatal3("%s\nPatch level: %s\n", rcsid, PATCHLEVEL);
- =#endif
- =}
-