home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / misc / hwgrcs / src / rcs.rcsfiles / merger.c,v < prev    next >
Encoding:
Text File  |  1995-06-25  |  6.8 KB  |  319 lines

  1. head    1.3;
  2. branch    1.3.1;
  3. access;
  4. symbols
  5.     HWGRCSP12F:1.3.1.2
  6.     HWGRCSP11F:1.3.1.2
  7.     HWGRCSP10F:1.3.1.2
  8.     HWGRCSP9:1.3.1.2
  9.     HWGRCSP8F:1.3.1.2
  10.     HWGRCSP7F:1.3.1.2
  11.     HWGRCSP6F:1.3.1.2
  12.     HWGRCSP5F:1.3.1.1
  13.     HWGRCSp4:1.3.1.1
  14.     HWGRCSp3:1.3.1
  15.     HWGRCS_Fish:1.3.1
  16.     HWGRCS:1.3.1;
  17. locks; strict;
  18. comment    @ * @;
  19.  
  20.  
  21. 1.3
  22. date    91.08.20.23.05.00;    author eggert;    state Exp;
  23. branches
  24.     1.3.1.1;
  25. next    ;
  26.  
  27. 1.3.1.1
  28. date    93.01.18.14.37.40;    author heinz;    state Exp;
  29. branches;
  30. next    1.3.1.2;
  31.  
  32. 1.3.1.2
  33. date    93.12.04.11.02.32;    author heinz;    state Exp;
  34. branches;
  35. next    ;
  36.  
  37.  
  38. desc
  39. @Checked in with -k 16.jan.93 HWG
  40. @
  41.  
  42.  
  43. 1.3
  44. log
  45. @checked in with -k by heinz at 1993/01/17 01:53:17
  46. @
  47. text
  48. @/* merger - three-way file merge internals */
  49.  
  50. /* Copyright 1991 by Paul Eggert
  51.    Distributed under license by the Free Software Foundation, Inc.
  52.  
  53. This file is part of RCS.
  54.  
  55. RCS is free software; you can redistribute it and/or modify
  56. it under the terms of the GNU General Public License as published by
  57. the Free Software Foundation; either version 2, or (at your option)
  58. any later version.
  59.  
  60. RCS is distributed in the hope that it will be useful,
  61. but WITHOUT ANY WARRANTY; without even the implied warranty of
  62. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  63. GNU General Public License for more details.
  64.  
  65. You should have received a copy of the GNU General Public License
  66. along with RCS; see the file COPYING.  If not, write to
  67. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  68.  
  69. Report problems and direct all questions to:
  70.  
  71.     rcs-bugs@@cs.purdue.edu
  72.  
  73. */
  74.  
  75. #include "rcsbase.h"
  76.  
  77. libId(mergerId, "$Id: merger.c,v 1.3 1991/08/20 23:05:00 eggert Exp $")
  78.  
  79.     static char const *
  80. normalize_arg(s, b)
  81.     char const *s;
  82.     char **b;
  83. /*
  84.  * If S looks like an option, prepend ./ to it.  Yield the result.
  85.  * Set *B to the address of any storage that was allocated..
  86.  */
  87. {
  88.     char *t;
  89.     switch (*s) {
  90.         case '-': case '+':
  91.             *b = t = testalloc(strlen(s) + 3);
  92.             VOID sprintf(t, ".%c%s", SLASH, s);
  93.             return t;
  94.         default:
  95.             *b = 0;
  96.             return s;
  97.     }
  98. }
  99.  
  100.     int
  101. merge(tostdout, label, argv)
  102.     int tostdout;
  103.     char const *const label[2];
  104.     char const *const argv[3];
  105. /*
  106.  * Do `merge [-p] -L l0 -L l1 a0 a1 a2',
  107.  * where TOSTDOUT specifies whether -p is present,
  108.  * LABEL gives l0 and l1, and ARGV gives a0, a1, and a2.
  109.  * Yield DIFF_SUCCESS or DIFF_FAILURE.
  110.  */
  111. {
  112.     register int i;
  113.     FILE *f;
  114.     RILE *rt;
  115.     char const *a[3], *t;
  116.     char *b[3];
  117.     int s;
  118. #if !DIFF3_BIN
  119.     char const *d[2];
  120. #endif
  121.  
  122.     for (i=3; 0<=--i; )
  123.         a[i] = normalize_arg(argv[i], &b[i]);
  124.  
  125. #if DIFF3_BIN
  126.     t = 0;
  127.     if (!tostdout)
  128.         t = maketemp(0);
  129.     s = run(
  130.         (char*)0, t,
  131.         DIFF3, "-am", "-L", label[0], "-L", label[1],
  132.         a[0], a[1], a[2], (char*)0
  133.     );
  134.     switch (s) {
  135.         case DIFF_SUCCESS:
  136.             break;
  137.         case DIFF_FAILURE:
  138.             if (!quietflag)
  139.                 warn("overlaps during merge");
  140.             break;
  141.         default:
  142.             exiterr();
  143.     }
  144.     if (t) {
  145.         if (!(f = fopen(argv[0], FOPEN_W)))
  146.             efaterror(argv[0]);
  147.         if (!(rt = Iopen(t, FOPEN_R, (struct stat*)0)))
  148.             efaterror(t);
  149.         fastcopy(rt, f);
  150.         Ifclose(rt);
  151.         Ofclose(f);
  152.     }
  153. #else
  154.     for (i=0; i<2; i++)
  155.         switch (run(
  156.             (char*)0, d[i]=maketemp(i),
  157.             DIFF, a[i], a[2], (char*)0
  158.         )) {
  159.             case DIFF_FAILURE: case DIFF_SUCCESS: break;
  160.             default: exiterr();
  161.         }
  162.     t = maketemp(2);
  163.     s = run(
  164.         (char*)0, t,
  165.         DIFF3, "-E", d[0], d[1], a[0], a[1], a[2],
  166.         label[0], label[1], (char*)0
  167.     );
  168.     if (s != DIFF_SUCCESS) {
  169.         s = DIFF_FAILURE;
  170.         if (!quietflag)
  171.             warn("overlaps or other problems during merge");
  172.     }
  173.     if (!(f = fopen(t, "a")))
  174.         efaterror(t);
  175.     aputs(tostdout ? "1,$p\n" : "w\n",  f);
  176.     Ofclose(f);
  177.     if (run(t, (char*)0, ED, "-", a[0], (char*)0))
  178.         exiterr();
  179. #endif
  180.  
  181.     tempunlink();
  182.     for (i=3; 0<=--i; )
  183.         if (b[i])
  184.             tfree(b[i]);
  185.     return s;
  186. }
  187. @
  188.  
  189.  
  190. 1.3.1.1
  191. log
  192. @Start of the AMIGA port of RCS 5.6. I call it HWGRCS now ;^)
  193. @
  194. text
  195. @@
  196.  
  197.  
  198. 1.3.1.2
  199. log
  200. @Put in RCS-5.6.0.1 changes for DIFF3_A
  201. @
  202. text
  203. @d30 1
  204. a30 1
  205. libId(mergerId, "$Id: merger.c,v 1.3.1.1 1993/01/18 14:37:40 heinz Exp heinz $")
  206. d32 1
  207. a32 1
  208.         static char const *
  209. d34 2
  210. a35 2
  211.         char const *s;
  212.         char **b;
  213. d41 10
  214. a50 10
  215.         char *t;
  216.         switch (*s) {
  217.                 case '-': case '+':
  218.                         *b = t = testalloc(strlen(s) + 3);
  219.                         VOID sprintf(t, ".%c%s", SLASH, s);
  220.                         return t;
  221.                 default:
  222.                         *b = 0;
  223.                         return s;
  224.         }
  225. d53 1
  226. a53 1
  227.         int
  228. d55 3
  229. a57 3
  230.         int tostdout;
  231.         char const *const label[2];
  232.         char const *const argv[3];
  233. d65 6
  234. a70 6
  235.         register int i;
  236.         FILE *f;
  237.         RILE *rt;
  238.         char const *a[3], *t;
  239.         char *b[3];
  240.         int s;
  241. d72 1
  242. a72 1
  243.         char const *d[2];
  244. d75 2
  245. a76 2
  246.         for (i=3; 0<=--i; )
  247.                 a[i] = normalize_arg(argv[i], &b[i]);
  248. d79 27
  249. a105 8
  250.         t = 0;
  251.         if (!tostdout)
  252.                 t = maketemp(0);
  253.         s = run(
  254.                 (char*)0, t,
  255. #if DIFF3_A
  256.                       /* GNU diff 2.1 or later.  We turn off -A for now.  */
  257.                 DIFF3, "-amE", "-L", label[0], "-L", "", "-L", label[1],
  258. d107 25
  259. a131 2
  260.                       /* GNU diff 2.0 or earlier */
  261.                 DIFF3, "-am", "-L", label[0], "-L", label[1],
  262. a132 48
  263.                 a[0], a[1], a[2], (char*)0
  264.         );
  265.         switch (s) {
  266.                 case DIFF_SUCCESS:
  267.                         break;
  268.                 case DIFF_FAILURE:
  269.                         if (!quietflag)
  270.                                 warn("overlaps during merge");
  271.                         break;
  272.                 default:
  273.                         exiterr();
  274.         }
  275.         if (t) {
  276.                 if (!(f = fopen(argv[0], FOPEN_W)))
  277.                         efaterror(argv[0]);
  278.                 if (!(rt = Iopen(t, FOPEN_R, (struct stat*)0)))
  279.                         efaterror(t);
  280.                 fastcopy(rt, f);
  281.                 Ifclose(rt);
  282.                 Ofclose(f);
  283.         }
  284. #else
  285.         for (i=0; i<2; i++)
  286.                 switch (run(
  287.                         (char*)0, d[i]=maketemp(i),
  288.                         DIFF, a[i], a[2], (char*)0
  289.                 )) {
  290.                         case DIFF_FAILURE: case DIFF_SUCCESS: break;
  291.                         default: exiterr();
  292.                 }
  293.         t = maketemp(2);
  294.         s = run(
  295.                 (char*)0, t,
  296.                 DIFF3, "-E", d[0], d[1], a[0], a[1], a[2],
  297.                 label[0], label[1], (char*)0
  298.         );
  299.         if (s != DIFF_SUCCESS) {
  300.                 s = DIFF_FAILURE;
  301.                 if (!quietflag)
  302.                         warn("overlaps or other problems during merge");
  303.         }
  304.         if (!(f = fopen(t, "a")))
  305.                 efaterror(t);
  306.         aputs(tostdout ? "1,$p\n" : "w\n",  f);
  307.         Ofclose(f);
  308.         if (run(t, (char*)0, ED, "-", a[0], (char*)0))
  309.                 exiterr();
  310. #endif
  311. d134 5
  312. a138 5
  313.         tempunlink();
  314.         for (i=3; 0<=--i; )
  315.                 if (b[i])
  316.                         tfree(b[i]);
  317.         return s;
  318. @
  319.