Received: by FINTUVM (Mailer X1.25) id 3414; Wed, 18 May 88 11:13:50 EET
Received: from HNYKUN11(MAILER) by FINTUVM (Mailer X1.25) id 2967;
          Wed, 18 May 88 10:46:46 EET
Received: by HNYKUN11 (Mailer X1.25) id 6907; Tue, 17 May 88 18:45:08 MET
Date:         Tue, 17 May 88 18:38:23 MET
From:         "Olaf {Rhialto{ Seibert" <U211344@HNYKUN11>
Subject:      For the source/binary group: fix.c
To:           Matti <FYS-MA@FINTUVM>
 
Hi,
 
This comes straight from a large shar file of updates from Minix 1.1 to
1.2, so it has no proper header, but who cares.
 
I have not tried it, I just looked at it, and I would say that it should
work on the Amiga without problems.
 
 
[[ Mods words:  Yes it works, but is far short from Larry Wall's
                PATCH utility (which is PD, but HUGE set of files
                -- Just checked from my UNIX subsystem: 5555 lines
                of shar for that System V.0 UNIX.)
                  /Matti Aarnio  12-Jul-88                         ]]
 
#!/bin/sh
echo extracting - fix.c
sed 's/^X//' > fix.c << '!EOR!'
X/* fix - combine file and diff listing Author: Erik Baalbergen */
X
X/* Notes:
X   * files old and old.fix are equal after the following commands
X          diff old new > difflist
X          fix old difflist > old.fix
X   * the diff output is assumed to be produced by my diff program.
X   * the difflist has the following form:
X          difflist ::= chunk*
X          chunk ::= append | delete | change ;
X          append ::= n1 'a' n2 [',' n3]? '\n' ['> ' line '\n'](n3 - n2 + 1)
X          delete ::= n1 [',' n2]? 'd' n3 '\n' ['< ' line '\n'](n2 - n1 + 1)
X          change ::= n1 [',' n2]? 'c' n3 [',' n4]? '\n'
X                     ['< ' line '\n'](n2 - n1 + 1)
X                     '---\n'
X                     ['> ' line '\n'](n4 - n3 + 1)
X          where
X          - n[1234] is an unsigned integer
X          - "[pat](expr)" means "(expr) occurences of pat"
X          - "[pat]?" means "either pat or nothing"
X   * the information in the diff listing is checked against the file to which
X     it is applied; an error is printed if there is a conflict
X*/
X
X#include <stdio.h>
X
Xextern char *fgets();
Xextern FILE *fopen();
X#define LINELEN        1024
X
Xchar *prog = 0;
X
Xchar *
Xgetline(fp, b)
X       FILE *fp;
X       char *b;
X{
X       if (fgets(b, LINELEN, fp) == NULL)
X               fatal("unexpected eof");
X       return b;
X}
X
X#define copy(str) printf("%s", str)
X
Xmain(argc, argv)
X       char **argv;
X{
X       char cmd, *fl, *fd, obuf[LINELEN], nbuf[LINELEN];
X       int o1, o2, n1, n2, here;
X       FILE *fpf, *fpd;
X
X       prog = argv[0];
X       if (argc != 3)
X               fatal("use: %s original-file diff-list-file", prog);
X       if ((fpf = fopen(argv[1], "r")) == NULL)
X               fatal("can't read %s", argv[1]);
X       if ((fpd = fopen(argv[2], "r")) == NULL)
X               fatal("can't read %s", argv[2]);
X       here = 0;
X       while (getcommand(fpd, &o1, &o2, &cmd, &n1, &n2)) {
X               while (here < o1 - 1) {
X                       here++;
X                       copy(getline(fpf, obuf));
X               }
X               switch (cmd) {
X               case 'c':
X               case 'd':
X                       if (cmd == 'd' && n1 != n2)
X                               fatal("delete count conflict");
X                       while (o1 <= o2) {
X                               fl = getline(fpf, obuf);
X                               here++;
X                               fd = getline(fpd, nbuf);
X                               if (strncmp(fd, "< ", 2))
X                                       fatal("illegal delete line");
X                               if (strcmp(fl, fd + 2))
X                                       fatal("delete line conflict");
X                               o1++;
X                       }
X                       if (cmd == 'd')
X                               break;
X                       if (strcmp(getline(fpd, nbuf), "---\n"))
X                               fatal("illegal separator in chunk");
X                       /*FALLTHROUGH*/
X               case 'a':
X                       if (cmd == 'a') {
X                               if (o1 != o2)
X                                       fatal("append count conflict");
X                               copy(getline(fpf, obuf));
X                               here++;
X                       }
X                       while (n1 <= n2) {
X                               if (strncmp(getline(fpd, nbuf), "> ", 2))
X                                       fatal("illegal append line");
X                               copy(nbuf + 2);
X                               n1++;
X                       }
X                       break;
X               }
X       }
X       while (fgets(obuf, LINELEN, fpf) != NULL)
X               copy(obuf);
X       exit(0);
X}
X
Xisdigit(c)
X       char c;
X{
X       return c >= '0' && c <= '9';
X}
X
Xchar *
Xrange(s, p1, p2)
X       char *s;
X       int *p1, *p2;
X{
X       register int v1 = 0, v2;
X
X       while (isdigit(*s))
X               v1 = 10 * v1 + *s++ - '0';
X       v2 = v1;
X       if (*s == ',') {
X               s++;
X               v2 = 0;
X               while (isdigit(*s))
X                       v2 = 10 * v2 + *s++ - '0';
X       }
X       if (v1 == 0 || v2 == 0 || v1 > v2)
X               fatal("illegal range");
X       *p1 = v1;
X       *p2 = v2;
X       return s;
X}
X
Xgetcommand(fp, o1, o2, pcmd, n1, n2)
X       FILE *fp;
X       int *o1, *o2, *n1, *n2;
X       char *pcmd;
X{
X       char buf[LINELEN];
X       register char *s;
X       char cmd;
X
X       if ((s = fgets(buf, LINELEN, fp)) == NULL)
X               return 0;
X       s = range(s, o1, o2);
X       if ((cmd = *s++) != 'a' && cmd != 'c' && cmd != 'd')
X               fatal("illegal command");
X       s = range(s, n1, n2);
X       if (*s != '\n' && s[1] != '\0')
X               fatal("extra characters at end of command: %s", s);
X       *pcmd = cmd;
X       return 1;
X}
X
Xfatal(s, a)
X       char *s, *a;
X{
X       fprintf(stderr, "%s: fatal: ", prog);
X       fprintf(stderr, s, a);
X       fprintf(stderr, "\n");
X       exit(1);
X}
X
X
X
X
!EOR!
#edit 0
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    +++ Let me tell you that I disclaim anything you care to name +++
 --- Olaf Rhialto Seibert the Marvellous --- U211344@hnykun11.bitnet ---
                         7167 BYTES FREE
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
