1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/* $OpenBSD: rcsmerge.c,v 1.50 2007/02/27 07:59:13 xsa Exp $ */
/*
* Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "rcsprog.h"
#include "diff.h"
int
rcsmerge_main(int argc, char **argv)
{
int fd, ch, flags, kflag, status;
char fpath[MAXPATHLEN], r1[16], r2[16], *rev_str1, *rev_str2;
RCSFILE *file;
RCSNUM *rev1, *rev2;
BUF *bp;
flags = 0;
kflag = RCS_KWEXP_ERR;
status = D_ERROR;
rev1 = rev2 = NULL;
rev_str1 = rev_str2 = NULL;
while ((ch = rcs_getopt(argc, argv, "AEek:p::q::r::TVx::z:")) != -1) {
switch (ch) {
case 'A':
/*
* kept for compatibility
*/
break;
case 'E':
flags |= MERGE_EFLAG;
flags |= MERGE_OFLAG;
break;
case 'e':
flags |= MERGE_EFLAG;
break;
case 'k':
kflag = rcs_kflag_get(rcs_optarg);
if (RCS_KWEXP_INVAL(kflag)) {
warnx("invalid RCS keyword substitution mode");
(usage)();
exit(D_ERROR);
}
break;
case 'p':
rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg);
flags |= PIPEOUT;
break;
case 'q':
rcs_setrevstr2(&rev_str1, &rev_str2, rcs_optarg);
flags |= QUIET;
break;
case 'r':
rcs_setrevstr2(&rev_str1, &rev_str2,
rcs_optarg ? rcs_optarg : "");
break;
case 'T':
/*
* kept for compatibility
*/
break;
case 'V':
printf("%s\n", rcs_version);
exit(0);
case 'x':
/* Use blank extension if none given. */
rcs_suffixes = rcs_optarg ? rcs_optarg : "";
break;
case 'z':
timezone_flag = rcs_optarg;
break;
default:
(usage)();
exit(D_ERROR);
}
}
argc -= rcs_optind;
argv += rcs_optind;
if (rev_str1 == NULL) {
warnx("no base revision number given");
(usage)();
exit(D_ERROR);
}
if (argc < 1) {
warnx("no input file");
(usage)();
exit(D_ERROR);
}
if (argc > 2 || (argc == 2 && argv[1] != NULL))
warnx("warning: excess arguments ignored");
if ((fd = rcs_choosefile(argv[0], fpath, sizeof(fpath))) < 0)
err(status, "%s", fpath);
if (!(flags & QUIET))
(void)fprintf(stderr, "RCS file: %s\n", fpath);
if ((file = rcs_open(fpath, fd, RCS_READ)) == NULL)
return (status);
if (strcmp(rev_str1, "") == 0) {
rev1 = rcsnum_alloc();
rcsnum_cpy(file->rf_head, rev1, 0);
} else if ((rev1 = rcs_getrevnum(rev_str1, file)) == NULL)
errx(D_ERROR, "invalid revision: %s", rev_str1);
if (rev_str2 != NULL && strcmp(rev_str2, "") != 0) {
if ((rev2 = rcs_getrevnum(rev_str2, file)) == NULL)
errx(D_ERROR, "invalid revision: %s", rev_str2);
} else {
rev2 = rcsnum_alloc();
rcsnum_cpy(file->rf_head, rev2, 0);
}
if (rcsnum_cmp(rev1, rev2, 0) == 0)
goto out;
if ((bp = rcs_diff3(file, argv[0], rev1, rev2, flags)) == NULL)
errx(D_ERROR, "failed to merge");
if (!(flags & QUIET)) {
(void)rcsnum_tostr(rev1, r1, sizeof(r1));
(void)rcsnum_tostr(rev2, r2, sizeof(r2));
(void)fprintf(stderr, "Merging differences between %s and "
"%s into %s%s\n", r1, r2, argv[0],
(flags & PIPEOUT) ? "; result to stdout":"");
}
if (diff3_conflicts != 0)
status = D_OVERLAPS;
else
status = 0;
if (flags & PIPEOUT)
rcs_buf_write_fd(bp, STDOUT_FILENO);
else {
/* XXX mode */
if (rcs_buf_write(bp, argv[0], 0644) < 0)
warnx("rcs_buf_write failed");
}
rcs_buf_free(bp);
out:
rcs_close(file);
if (rev1 != NULL)
rcsnum_free(rev1);
if (rev2 != NULL)
rcsnum_free(rev2);
return (status);
}
void
rcsmerge_usage(void)
{
fprintf(stderr,
"usage: rcsmerge [-EV] [-kmode] [-p[rev]] [-q[rev]]\n"
" [-xsuffixes] [-ztz] -rrev file ...\n");
}
|