home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume14 / unidiff / part01 / patch.uni < prev    next >
Encoding:
Text File  |  1990-08-30  |  6.6 KB  |  260 lines

  1. Index: patchlevel.h
  2. Prereq: 12
  3. @@ -1,1 +1,1 @@
  4. -#define PATCHLEVEL 12
  5. +#define PATCHLEVEL "12u"
  6. Index: common.h
  7. @@ -135,4 +135,5 @@
  8. =#define ED_DIFF 3
  9. =#define NEW_CONTEXT_DIFF 4
  10. +#define UNI_DIFF 5
  11. =EXT int diff_type INIT(0);
  12. =
  13. Index: patch.c
  14. @@ -1,4 +1,4 @@
  15. =char rcsid[] =
  16. -    "$Header: patch.c,v 2.0.1.6 88/06/22 20:46:39 lwall Locked $";
  17. +    "$Header: patch.c,v 2.0.2.0 90/05/01 22:17:50 davison Locked $";
  18. =
  19. =/* patch - a program to apply diffs to original files
  20. @@ -10,4 +10,7 @@
  21. = *
  22. = * $Log:    patch.c,v $
  23. + * Revision 2.0.2.0  90/05/01  22:17:50  davison
  24. + * patch12u: unidiff support added
  25. + * 
  26. = * Revision 2.0.1.6  88/06/22  20:46:39  lwall
  27. = * patch12: rindex() wasn't declared
  28. @@ -458,4 +461,7 @@
  29. =        skip_rest_of_patch = TRUE;
  30. =        break;
  31. +        case 'u':
  32. +        diff_type = UNI_DIFF;
  33. +        break;
  34. =        case 'v':
  35. =        version();
  36. @@ -530,6 +536,6 @@
  37. =    LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
  38. =    LINENUM newlast = newfirst + pch_repl_lines() - 1;
  39. -    char *stars = (diff_type == NEW_CONTEXT_DIFF ? " ****" : "");
  40. -    char *minuses = (diff_type == NEW_CONTEXT_DIFF ? " ----" : " -----");
  41. +    char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
  42. +    char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
  43. =
  44. =    fprintf(rejfp, "***************\n");
  45. Index: patch.man
  46. @@ -81,5 +81,5 @@
  47. =.SH DESCRIPTION
  48. =.I Patch
  49. -will take a patch file containing any of the three forms of difference
  50. +will take a patch file containing any of the four forms of difference
  51. =listing produced by the
  52. =.I diff
  53. @@ -102,8 +102,10 @@
  54. =.BR -c ,
  55. =.BR -e ,
  56. +.BR -n ,
  57. =or
  58. -.B -n
  59. +.B -u
  60. =switch.
  61. -Context diffs and normal diffs are applied by the
  62. +Context diffs (old-style, new-style, and unified) and
  63. +normal diffs are applied by the
  64. =.I patch
  65. =program itself, while ed diffs are simply fed to the
  66. @@ -377,4 +379,9 @@
  67. =.sp
  68. =will ignore the first and second of three patches.
  69. +.TP 5
  70. +.B \-u
  71. +forces
  72. +.I patch
  73. +to interpret the patch file as a unified context diff (a unidiff).
  74. =.TP 5
  75. =.B \-v
  76. Index: pch.c
  77. @@ -2,4 +2,7 @@
  78. = *
  79. = * $Log:    pch.c,v $
  80. + * Revision 2.0.2.0  90/05/01  22:17:51  davison
  81. + * patch12u: unidiff support added
  82. + *
  83. = * Revision 2.0.1.7  88/06/03  15:13:28  lwall
  84. = * patch10: Can now find patches in shar scripts.
  85. @@ -163,4 +166,5 @@
  86. =    say3("  %sooks like %s to me...\n",
  87. =        (p_base == 0L ? "L" : "The next patch l"),
  88. +        diff_type == UNI_DIFF ? "a unidiff" :
  89. =        diff_type == CONTEXT_DIFF ? "a context diff" :
  90. =        diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
  91. @@ -287,4 +291,13 @@
  92. =        goto scan_exit;
  93. =    }
  94. +    if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) {
  95. +        if (!atol(s+3))
  96. +        ok_to_create_file = TRUE;
  97. +        p_indent = indent;
  98. +        p_start = this_line;
  99. +        p_sline = p_input_line;
  100. +        retval = UNI_DIFF;
  101. +        goto scan_exit;
  102. +    }
  103. =    stars_this_line = strnEQ(s, "********", 8);
  104. =    if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
  105. @@ -720,4 +733,146 @@
  106. =        assert(filldst==p_end+1 || filldst==repl_beginning);
  107. =    }
  108. +    }
  109. +    else if (diff_type == UNI_DIFF) {
  110. +    long line_beginning = ftell(pfp);
  111. +                    /* file pos of the current line */
  112. +    Reg4 LINENUM fillsrc;        /* index of old lines */
  113. +    Reg5 LINENUM filldst;        /* index of new lines */
  114. +    char ch;
  115. +
  116. +    ret = pgets(buf, sizeof buf, pfp);
  117. +    p_input_line++;
  118. +    if (ret == Nullch || strnNE(buf, "@@ -", 4)) {
  119. +        next_intuit_at(line_beginning,p_input_line);
  120. +        return FALSE;
  121. +    }
  122. +    s = buf+4;
  123. +    if (!*s)
  124. +        goto malformed;
  125. +    p_first = (LINENUM) atol(s);
  126. +    while (isdigit(*s)) s++;
  127. +    if (*s != ',' || !*++s)
  128. +        goto malformed;
  129. +    p_ptrn_lines = (LINENUM) atol(s);
  130. +    while (isdigit(*s)) s++;
  131. +    if (*s == ' ') s++;
  132. +    if (*s != '+' || !*++s)
  133. +        goto malformed;
  134. +    p_newfirst = (LINENUM) atol(s);
  135. +    while (isdigit(*s)) s++;
  136. +    if (*s != ',' || !*++s)
  137. +        goto malformed;
  138. +    p_repl_lines = (LINENUM) atol(s);
  139. +    while (isdigit(*s)) s++;
  140. +    if (*s == ' ') s++;
  141. +    if (*s != '@')
  142. +        goto malformed;
  143. +    if (!p_first && !p_ptrn_lines)
  144. +        p_first = 1;
  145. +    p_max = p_ptrn_lines + p_repl_lines;
  146. +    while (p_max >= hunkmax)
  147. +        grow_hunkmax();
  148. +    p_max = hunkmax;
  149. +    fillsrc = 1;
  150. +    filldst = fillsrc + p_ptrn_lines;
  151. +    p_end = filldst + p_repl_lines;
  152. +    Sprintf(buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1);
  153. +    p_line[0] = savestr(buf);
  154. +    if (out_of_mem) {
  155. +        p_end = -1;
  156. +        return FALSE;
  157. +    }
  158. +    p_char[0] = '*';
  159. +        Sprintf(buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1);
  160. +    p_line[filldst] = savestr(buf);
  161. +    if (out_of_mem) {
  162. +        p_end = 0;
  163. +        return FALSE;
  164. +    }
  165. +    p_char[filldst++] = '=';
  166. +    p_context = 100;
  167. +    context = 0;
  168. +    p_hunk_beg = p_input_line + 1;
  169. +    while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
  170. +        line_beginning = ftell(pfp);
  171. +        ret = pgets(buf, sizeof buf, pfp);
  172. +        p_input_line++;
  173. +        if (ret == Nullch) {
  174. +        if (p_max - filldst < 3)
  175. +            Strcpy(buf, " \n");  /* assume blank lines got chopped */
  176. +        else {
  177. +            fatal1("Unexpected end of file in patch.\n");
  178. +        }
  179. +        }
  180. +        if (*buf == '\t' || *buf == '\n') {
  181. +        ch = ' ';        /* assume the space got eaten */
  182. +        s = savestr(buf);
  183. +        }
  184. +        else {
  185. +        ch = *buf;
  186. +        s = savestr(buf+1);
  187. +        }
  188. +        if (out_of_mem) {
  189. +        while (--filldst > p_ptrn_lines)
  190. +            free(p_line[filldst]);
  191. +        p_end = fillsrc-1;
  192. +        return FALSE;
  193. +        }
  194. +        switch (ch) {
  195. +        case '-':
  196. +        if (fillsrc > p_ptrn_lines) {
  197. +            free(s);
  198. +            p_end = filldst-1;
  199. +            goto malformed;
  200. +        }
  201. +        p_char[fillsrc] = ch;
  202. +        p_line[fillsrc] = s;
  203. +        p_len[fillsrc++] = strlen(s);
  204. +        break;
  205. +        case '=':
  206. +        ch = ' ';
  207. +        /* FALL THROUGH */
  208. +        case ' ':
  209. +        if (fillsrc > p_ptrn_lines) {
  210. +            free(s);
  211. +            while (--filldst > p_ptrn_lines)
  212. +            free(p_line[filldst]);
  213. +            p_end = fillsrc-1;
  214. +            goto malformed;
  215. +        }
  216. +        context++;
  217. +        p_char[fillsrc] = ch;
  218. +        p_line[fillsrc] = s;
  219. +        p_len[fillsrc++] = strlen(s);
  220. +        s = savestr(s);
  221. +        if (out_of_mem) {
  222. +            while (--filldst > p_ptrn_lines)
  223. +            free(p_line[filldst]);
  224. +            p_end = fillsrc-1;
  225. +            return FALSE;
  226. +        }
  227. +        /* FALL THROUGH */
  228. +        case '+':
  229. +        if (filldst > p_end) {
  230. +            free(s);
  231. +            while (--filldst > p_ptrn_lines)
  232. +            free(p_line[filldst]);
  233. +            p_end = fillsrc-1;
  234. +            goto malformed;
  235. +        }
  236. +        p_char[filldst] = ch;
  237. +        p_line[filldst] = s;
  238. +        p_len[filldst++] = strlen(s);
  239. +        break;
  240. +        default:
  241. +        p_end = filldst;
  242. +        goto malformed;
  243. +        }
  244. +        if (ch != ' ' && context > 0) {
  245. +        if (context < p_context)
  246. +            p_context = context;
  247. +        context = -1000;
  248. +        }
  249. +    }/* while */
  250. =    }
  251. =    else {                /* normal diff--fake it up */
  252. Index: version.c
  253. @@ -24,5 +24,5 @@
  254. =    rcsid[0] = rcsid[0];
  255. =#else
  256. -    fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
  257. +    fatal3("%s\nPatch level: %s\n", rcsid, PATCHLEVEL);
  258. =#endif
  259. =}
  260.