Here is a C++ program I wrote to do this. It compiles in Visual Studio 2008 Express, and probably any other compiler.
This input output is via redirect, which is perhaps not so convenient, but you can write a cmd file to call it, such as
@echo off
copy /y %1 \temp\t
resolve %2 %3 < \temp\t > %1
del \temp\t
The code is
// resolve.cpp
#include "stdafx.h"
#include "string.h"
int main(int argc, char* argv[])
{
const int MAXWIDTH = 10000;
char line[MAXWIDTH];
enum { ECHO, OLD, NEW, ERROR };
int state = ECHO;
int num = 0;
int quiet = 0;
int pick = OLD;
for (int i = 1; i < argc; ++i)
{
if (!strcmp(argv[i],"-h") || !strcmp(argv[i],"--help") || !strcmp(argv[i],"?"))
{
printf("Automatically fix CVS merge conflicts.\n"
"Options:\n"
" -n use the bottom code, the new code (default uses top, old code).\n"
" -q quiet\n"
" -h help\n"
"use stdin and stdout for input/output and stderr for status.");
return 0;
}
else if (!strcmp(argv[i],"-n"))
{
pick = NEW;
}
else if (!strcmp(argv[i],"-q"))
{
quiet = 1;
}
else
fprintf(stderr,"unknown option %s\n",argv[i]);
}
while (fgets(line, MAXWIDTH, stdin))
{
// trim trailing whitespace
for (int i = strlen(line); i >= 0 && line[i] < ' '; --i)
line[i] = 0;
++num;
if (!strncmp(line,"<<<<<<< ",8))
{
state = (state==ECHO) ? OLD : ERROR;
if (!quiet)
fprintf(stderr,"At line: %d\n", num);
}
else if (!strcmp(line,"======="))
{
state = (state==OLD) ? NEW : ERROR;
}
else if (!strncmp(line,">>>>>>> ",8))
{
state = (state==NEW) ? ECHO : ERROR;
}
else
{
if (state == ECHO || state == pick)
printf("%s\n",line);
if (!quiet && state != ECHO)
fprintf(stderr,"%c%s\n", (state==pick) ? '+' : '-', line);
continue;
}
if (!quiet)
fprintf(stderr,"%s\n",line);
}
return 0;
}
Disclaimer: You might want to verify your output.