[comp.emacs] applying diffs to GNU emacs

romain@pyrnj.uucp (Romain Kang) (11/11/87)

The updates to GNU emacs aren't completely completely handled by patch
because of the new files that come out from time to time.  To avoid the
tedium of breaking the new files out with an editor (I was three
versions behind) I hacked this up thing out.  It's a crock but it
works.

I suspect someone already has something like this, but I didn't see
such a beast in the directories on prep.

/*
 * gnumod.c
 *  apply diffs from GNU project.
 *  awful 5-minute hack.  check diff file for special instructions. then
 *   cd ~emacs; zcat diff-xx.xx-yy.yy.Z | gnumod
 */
#include <stdio.h>
#define	PATCH	"/usr/new/patch"

/* current state of program */
#define PREAMBLE	0
#define INFILE		1
#define SKIPPING	2
#define DIFFING		3

#define NEWMARK	\
"======================================== New file "
#define	NEWSIZE	((sizeof NEWMARK)-1)

#define DIFMARK	\
"======================================================================"

main()
{
	char fname[128], lbuf[BUFSIZ];
	int state = PREAMBLE;
	FILE *newf;

	while (gets(lbuf)) {
		/* new file marker */
		if (strncmp(lbuf, NEWMARK, NEWSIZE) == 0)
		{
			if (state == INFILE) fclose(newf);
			strcpy(fname, &lbuf[NEWSIZE]);
			printf("New file %s\n", fname);
			if ((newf = fopen(fname, "w")) == 0)
			{
				state = SKIPPING;
				perror(fname);
				puts("skipping...");
			} else
				state = INFILE;
			continue;
		}
		/* diff marker -- get out and call patch */
		if (strcmp(DIFMARK, lbuf) == 0)
		{
			if (state == INFILE) fclose(newf);
			state = DIFFING;
			break;
		}
		/* pass through to file */
		if (state == INFILE)
		{
			fprintf(newf, "%s\n", lbuf);
			continue;
		}
		if (state == SKIPPING)
			continue;
	}

	if (state == DIFFING)
	{
		execl(PATCH, "patch", "-p1", 0);
		perror(PATCH);
		exit(1);
	}
	exit(0);
}

david@elroy.Jpl.Nasa.Gov (David Robinson) (11/12/87)

Instead of distributing a program to everyone to run their
GNU diffs through just to create a new file, a better
solution is to have the diff makers in FSF to add files
in a way that patch can handle.  The way I create a new
file for a diff is to:

	% diff -c /dev/null newfile.c

The most current version of patch can handle this and
creates a file.


-- 
	David Robinson		elroy!david@csvax.caltech.edu     ARPA
				david@elroy.jpl.nasa.gov
				ames!elroy!david UUCP
Disclaimer: No one listens to me anyway!