Ansified bin/diff
authorNick Downing <downing.nick@gmail.com>
Sun, 29 Jan 2017 15:22:13 +0000 (02:22 +1100)
committerNick Downing <downing.nick@gmail.com>
Sun, 29 Jan 2017 15:22:13 +0000 (02:22 +1100)
bin/diff/diff.c
bin/diff/diff.h
bin/diff/diffdir.c
bin/diff/diffh.c
bin/diff/diffreg.c

index efe7e47..86f1ec8 100644 (file)
@@ -1,6 +1,17 @@
+/*#include <ctype.h> gen.h*/
+#include <gen.h>
+#include <stdio.h>
+/*#include <strings.h> gen.h*/
+/*#include <sys/errno.h> gen.h*/
+#include <sys/file.h>
+/*#include <sys/stat.h> diff.h*/
+#include "diff.h"
+
+#if defined(DOSCCS) && !defined(lint)
 static char sccsid[] = "@(#)diff.c 4.6 4/3/86";
+#endif
 
-#include "diff.h"
+/*#include "diff.h"*/
 /*
  * diff - driver and subroutines
  */
@@ -67,10 +78,7 @@ char diff[] = DIFF;
 char   diffh[] = DIFFH;
 char   pr[] = PR;
 
-main(argc, argv)
-       int argc;
-       char **argv;
-{
+int main(argc, argv) int argc; char **argv; {
        register char *argp;
 
        ifdef1 = "FILE1"; ifdef2 = "FILE2";
@@ -204,10 +212,7 @@ main(argc, argv)
        done();
 }
 
-char *
-savestr(cp)
-       register char *cp;
-{
+char *savestr(cp) register char *cp; {
        register char *dp = malloc(strlen(cp)+1);
 
        if (dp == 0) {
@@ -218,30 +223,23 @@ savestr(cp)
        return (dp);
 }
 
-min(a,b)
-       int a,b;
-{
+int min(a, b) int a; int b; {
 
        return (a < b ? a : b);
 }
 
-max(a,b)
-       int a,b;
-{
+int max(a, b) int a; int b; {
 
        return (a > b ? a : b);
 }
 
-done()
-{
+int done() {
        if (tempfile)
                unlink(tempfile);
        exit(status);
 }
 
-char *
-talloc(n)
-{
+char *talloc(n) int n; {
        register char *p;
 
        if ((p = malloc((unsigned)n)) != NULL)
@@ -249,10 +247,7 @@ talloc(n)
        noroom();
 }
 
-char *
-ralloc(p,n)
-char *p;
-{
+char *ralloc(p, n) char *p; int n; {
        register char *q;
        void *realloc();
 
@@ -261,8 +256,7 @@ char *p;
        return(q);
 }
 
-noroom()
-{
+int noroom() {
        fprintf(stderr, "diff: files too big, try -h\n");
        done();
 }
index bdc5f6b..682d0cc 100644 (file)
@@ -1,15 +1,20 @@
+#ifndef _DIFF_H_
+#define _DIFF_H_
+
+#include <sys/stat.h>
+
 /*     diff.h  4.7     85/08/16        */
 
 /*
  * diff - common declarations
  */
 
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/dir.h>
-#include <signal.h>
+/*#include <stdio.h>*/
+/*#include <ctype.h>*/
+/*#include <sys/param.h>*/
+/*#include <sys/stat.h>*/
+/*#include <sys/dir.h>*/
+/*#include <signal.h>*/
 
 /*
  * Output format options
@@ -77,9 +82,35 @@ extern char  **diffargv;             /* option list to pass to recursive diffs */
 extern char    *file1, *file2, *efile1, *efile2;
 extern struct  stat stb1, stb2;
 
-char   *malloc(), *talloc(), *ralloc();
-char   *savestr(), *splice(), *splicen();
-char   *mktemp(), *copytemp(), *rindex();
-int    done();
+/*char *malloc(), *talloc(), *ralloc();*/
+/*char *savestr(), *splice(), *splicen();*/
+/*char *mktemp(), *copytemp(), *rindex();*/
+/*int  done();*/
 
 extern char diffh[], diff[], pr[];
+
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+/* diff.c */
+int main __P((int argc, char **argv));
+char *savestr __P((register char *cp));
+int min __P((int a, int b));
+int max __P((int a, int b));
+int done __P((void));
+char *talloc __P((int n));
+char *ralloc __P((char *p, int n));
+int noroom __P((void));
+
+/* diffdir.c */
+int diffdir __P((char **argv));
+
+/* diffreg.c */
+int diffreg __P((void));
+
+#endif
index ff86c92..e661074 100644 (file)
@@ -1,6 +1,22 @@
+/*#include <a.out.h> gen.h*/
+#include <gen.h>
+#include <stdio.h>
+/*#include <strings.h> gen.h*/
+/*#include <sys/dir.h> gen.h*/
+/*#include <sys/errno.h> gen.h*/
+/*#include <sys/exec.h> a.out.h*/
+#include <sys/file.h>
+/*#include <sys/proc.h> gen.h*/
+/*#include <sys/stat.h> diff.h*/
+/*#include <sys/types.h> diff.h*/
+#include <sys/wait.h>
+#include "diff.h"
+
+#if defined(DOSCCS) && !defined(lint)
 static char *sccsid = "@(#)diffdir.c   4.9 (Berkeley) 8/28/84";
+#endif
 
-#include "diff.h"
+/*#include "diff.h"*/
 /*
  * diff - directory comparison
  */
@@ -18,13 +34,21 @@ struct dir {
        char    *d_entry;
 };
 
-struct dir *setupdir();
+/*struct       dir *setupdir();*/
 int    header;
 char   title[2*BUFSIZ], *etitle;
 
-diffdir(argv)
-       char **argv;
-{
+static setfile __P((char **fpp, char **epp, char *file));
+static scanpr __P((register struct dir *dp, int test, char *title, char *file1, char *efile1, char *file2, char *efile2));
+static only __P((struct dir *dp, int which));
+static struct dir *setupdir __P((char *cp));
+static entcmp __P((struct dir *d1, struct dir *d2));
+static compare __P((register struct dir *dp));
+static calldiff __P((char *wantpr));
+static ascii __P((int f));
+static useless __P((register char *cp));
+
+int diffdir(argv) char **argv; {
        register struct dir *d1, *d2;
        struct dir *dir1, *dir2;
        register int i;
@@ -110,11 +134,7 @@ diffdir(argv)
        }
 }
 
-static
-setfile(fpp, epp, file)
-       char **fpp, **epp;
-       char *file;
-{
+static setfile(fpp, epp, file) char **fpp; char **epp; char *file; {
        register char *cp;
 
        *fpp = malloc(BUFSIZ);
@@ -129,12 +149,7 @@ setfile(fpp, epp, file)
        *epp = cp;
 }
 
-static
-scanpr(dp, test, title, file1, efile1, file2, efile2)
-       register struct dir *dp;
-       int test;
-       char *title, *file1, *efile1, *file2, *efile2;
-{
+static scanpr(dp, test, title, file1, efile1, file2, efile2) register struct dir *dp; int test; char *title; char *file1; char *efile1; char *file2; char *efile2; {
        int titled = 0;
 
        for (; dp->d_entry; dp++) {
@@ -155,23 +170,16 @@ scanpr(dp, test, title, file1, efile1, file2, efile2)
        }
 }
 
-static
-only(dp, which)
-       struct dir *dp;
-       int which;
-{
+static only(dp, which) struct dir *dp; int which; {
        char *file = which == 1 ? file1 : file2;
        char *efile = which == 1 ? efile1 : efile2;
 
        printf("Only in %.*s: %s\n", efile - file - 1, file, dp->d_entry);
 }
 
-static int     entcmp();
+/*static int   entcmp();*/
 
-static struct dir *
-setupdir(cp)
-       char *cp;
-{
+static struct dir *setupdir(cp) char *cp; {
        register struct dir *dp = 0, *ep;
        register struct direct *rp;
        register int nitems, n;
@@ -216,17 +224,11 @@ setupdir(cp)
        return (dp);
 }
 
-static
-entcmp(d1, d2)
-       struct dir *d1, *d2;
-{
+static entcmp(d1, d2) struct dir *d1; struct dir *d2; {
        return (strcmp(d1->d_entry, d2->d_entry));
 }
 
-static
-compare(dp)
-       register struct dir *dp;
-{
+static compare(dp) register struct dir *dp; {
        register int i, j;
        int f1, f2, fmt1, fmt2;
        struct stat stb1, stb2;
@@ -316,10 +318,7 @@ closem:
 
 static char    *prargs[] = { "pr", "-h", 0, "-f", 0, 0 };
 
-static
-calldiff(wantpr)
-       char *wantpr;
-{
+static calldiff(wantpr) char *wantpr; {
        int pid, status, status2, pv[2];
 
        prargs[2] = wantpr;
@@ -374,12 +373,9 @@ calldiff(wantpr)
 */
 }
 
-#include <a.out.h>
+/*#include <a.out.h>*/
 
-static
-ascii(f)
-       int f;
-{
+static ascii(f) int f; {
        char buf[BUFSIZ];
        register int cnt;
        register char *cp;
@@ -402,10 +398,7 @@ ascii(f)
 /*
  * THIS IS CRUDE.
  */
-static
-useless(cp)
-register char *cp;
-{
+static useless(cp) register char *cp; {
 
        if (cp[0] == '.') {
                if (cp[1] == '\0')
index c0a4798..323d66d 100644 (file)
@@ -1,9 +1,17 @@
+/*#include <ctype.h> gen.h*/
+#include <gen.h>
+#include <stdio.h>
+/*#include <sys/stat.h> diff.h*/
+#include "diff.h"
+
+#if defined(DOSCCS) && !defined(lint)
 static char sccsid[] = "@(#)diffh.c 4.4 11/27/85";
+#endif
 
-#include <stdio.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+/*#include <stdio.h>*/
+/*#include <ctype.h>*/
+/*#include <sys/types.h>*/
+/*#include <sys/stat.h>*/
 
 #define C 3
 #define RANGE 30
@@ -19,9 +27,29 @@ int debug = 0;
 FILE *file[2];
 
        /* return pointer to line n of file f*/
-char *getl(f,n)
-long n;
-{
+#ifndef __P
+#ifdef __STDC__
+#define __P(args) args
+#else
+#define __P(args) ()
+#endif
+#endif
+
+char *getl __P((int f, long n));
+int clrl __P((int f, long n));
+int movstr __P((register char *s, register char *t));
+int main __P((int argc, char **argv));
+int easysynch __P((void));
+int output __P((int a, int b));
+int change __P((long a, int b, long c, int d, char *s));
+int range __P((long a, int b));
+int cmp __P((char *s, char *t));
+FILE *dopen __P((char *f1, char *f2));
+int progerr __P((char *s));
+int error __P((char *s, char *t));
+int hardsynch __P((void));
+
+char *getl(f, n) int f; long n; {
        register char *t;
        void *malloc();
        register delta, nt;
@@ -54,9 +82,7 @@ again:
 }
 
        /*remove thru line n of file f from storage*/
-clrl(f,n)
-long n;
-{
+int clrl(f, n) int f; long n; {
        register i,j;
        j = n-lineno[f]+1;
        for(i=0;i+j<ntext[f];i++)
@@ -65,16 +91,12 @@ long n;
        ntext[f] -= j;
 }
 
-movstr(s,t)
-register char *s, *t;
-{
+int movstr(s, t) register char *s; register char *t; {
        while(*t++= *s++)
                continue;
 }
 
-main(argc,argv)
-char **argv;
-{
+int main(argc, argv) int argc; char **argv; {
        char *s0,*s1;
        FILE *dopen();
        register int status = 0;
@@ -114,8 +136,7 @@ char **argv;
 }
 
        /* synch on C successive matches*/
-easysynch()
-{
+int easysynch() {
        int i,j;
        register k,m;
        char *s0,*s1;
@@ -146,8 +167,7 @@ cont2:                      ;
        return(0);
 }
 
-output(a,b)
-{
+int output(a, b) int a; int b; {
        register i;
        char *s;
        if(a<0)
@@ -177,19 +197,14 @@ output(a,b)
        return(1);
 }
 
-change(a,b,c,d,s)
-long a,c;
-char *s;
-{
+int change(a, b, c, d, s) long a; int b; long c; int d; char *s; {
        range(a,b);
        printf("%s",s);
        range(c,d);
        printf("\n");
 }
 
-range(a,b)
-long a;
-{
+int range(a, b) long a; int b; {
        if(b==INF)
                printf("%ld,$",a);
        else if(b==0)
@@ -198,9 +213,7 @@ long a;
                printf("%ld,%ld",a,a+b);
 }
 
-cmp(s,t)
-char *s,*t;
-{
+int cmp(s, t) char *s; char *t; {
        if(debug)
                printf("%s:%s\n",s,t);
        for(;;){
@@ -216,9 +229,7 @@ char *s,*t;
        return(*s-*t);
 }
 
-FILE *dopen(f1,f2)
-char *f1,*f2;
-{
+FILE *dopen(f1, f2) char *f1; char *f2; {
        FILE *f;
        char b[100],*bptr,*eptr;
        struct stat statbuf;
@@ -244,23 +255,17 @@ char *f1,*f2;
        return(f);
 }
 
-
-progerr(s)
-char *s;
-{
+int progerr(s) char *s; {
        error("program error ",s);
 }
 
-error(s,t)
-char *s,*t;
-{
+int error(s, t) char *s; char *t; {
        fprintf(stderr,"diffh: %s%s\n",s,t);
        exit(2);
 }
 
        /*stub for resychronization beyond limits of text buf*/
-hardsynch()
-{
+int hardsynch() {
        change(n0,INF,n1,INF,"c");
        printf("---change record omitted\n");
        error("can't resynchronize","");
index e45b30f..9df1754 100644 (file)
@@ -1,6 +1,21 @@
+/*#include <a.out.h> gen.h*/
+/*#include <ctype.h> gen.h*/
+#include <gen.h>
+#include <stdio.h>
+/*#include <strings.h> gen.h*/
+/*#include <sys/errno.h> gen.h*/
+/*#include <sys/exec.h> a.out.h*/
+#include <sys/file.h>
+/*#include <sys/signal.h> gen.h*/
+/*#include <sys/stat.h> diff.h*/
+/*#include <time.h> gen.h*/
+#include "diff.h"
+
+#if defined(DOSCCS) && !defined(lint)
 static char sccsid[] = "@(#)diffreg.c 4.16 3/29/86";
+#endif
 
-#include "diff.h"
+/*#include "diff.h"*/
 /*
  * diff - compare two files.
  */
@@ -71,7 +86,7 @@ static        char sccsid[] = "@(#)diffreg.c 4.16 3/29/86";
 #define        prints(s)       fputs(s,stdout)
 
 FILE   *input[2];
-FILE   *fopen();
+/*FILE *fopen();*/
 
 struct cand {
        int     x;
@@ -138,8 +153,28 @@ char       cup2low[256] = {
 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
 };
 
-diffreg()
-{
+static char *copytemp __P((void));
+static char *splice __P((char *dir, char *file));
+static prepare __P((int i, FILE *fd));
+static prune __P((void));
+static equiv __P((struct line *a, int n, struct line *b, int m, int *c));
+static stone __P((int *a, int n, int *b, register int *c));
+static newcand __P((int x, int y, int pred));
+static search __P((int *c, int k, int y));
+static unravel __P((int p));
+static check __P((void));
+static sort __P((struct line *a, int n));
+static unsort __P((struct line *f, int l, int *b));
+static skipline __P((int f));
+static output __P((void));
+static change __P((int a, int b, int c, int d));
+static range __P((int a, int b, char *separator));
+static fetch __P((long *f, int a, int b, FILE *lb, char *s, int oldfile));
+static readhash __P((register FILE *f));
+static asciifile __P((FILE *f));
+static dump_context_vec __P((void));
+
+int diffreg() {
        register int i, j;
        FILE *f1, *f2;
        char buf1[BUFSIZ], buf2[BUFSIZ];
@@ -262,9 +297,7 @@ same:
        done();
 }
 
-static char *
-copytemp()
-{
+static char *copytemp() {
        char buf[BUFSIZ];
        register int i, f;
 
@@ -289,10 +322,7 @@ copytemp()
        return (tempfile);
 }
 
-static char *
-splice(dir, file)
-       char *dir, *file;
-{
+static char *splice(dir, file) char *dir; char *file; {
        char *tail;
        char buf[BUFSIZ];
 
@@ -309,11 +339,7 @@ splice(dir, file)
        return (savestr(buf));
 }
 
-static
-prepare(i, fd)
-       int i;
-       FILE *fd;
-{
+static prepare(i, fd) int i; FILE *fd; {
        register struct line *p;
        register j,h;
 
@@ -327,9 +353,7 @@ prepare(i, fd)
        file[i] = p;
 }
 
-static
-prune()
-{
+static prune() {
        register i,j;
        for(pref=0;pref<len[0]&&pref<len[1]&&
                file[0][pref+1].value==file[1][pref+1].value;
@@ -345,11 +369,7 @@ prune()
        }
 }
 
-static
-equiv(a,n,b,m,c)
-struct line *a, *b;
-int *c;
-{
+static equiv(a, n, b, m, c) struct line *a; int n; struct line *b; int m; int *c; {
        register int i, j;
        i = j = 1;
        while(i<=n && j<=m) {
@@ -374,12 +394,7 @@ int *c;
        c[j] = -1;
 }
 
-static
-stone(a,n,b,c)
-int *a;
-int *b;
-register int *c;
-{
+static stone(a, n, b, c) int *a; int n; int *b; register int *c; {
        register int i, k,y;
        int j, l;
        int oldc, tc;
@@ -416,9 +431,7 @@ register int *c;
        return(k);
 }
 
-static
-newcand(x,y,pred)
-{
+static newcand(x, y, pred) int x; int y; int pred; {
        register struct cand *q;
        clist = (struct cand *)ralloc((char *)clist,++clen*sizeof(cand));
        q = clist + clen -1;
@@ -428,10 +441,7 @@ newcand(x,y,pred)
        return(clen-1);
 }
 
-static
-search(c, k, y)
-int *c;
-{
+static search(c, k, y) int *c; int k; int y; {
        register int i, j, l;
        int t;
        if(clist[c[k]].y<y)     /*quick look for typical case*/
@@ -453,9 +463,7 @@ int *c;
        return(l+1);
 }
 
-static
-unravel(p)
-{
+static unravel(p) int p; {
        register int i;
        register struct cand *q;
        for(i=0; i<=len[0]; i++)
@@ -471,9 +479,7 @@ unravel(p)
 to confounding by hashing (which result in "jackpot")
 2.  collect random access indexes to the two files */
 
-static
-check()
-{
+static check() {
        register int i, j;
        int jackpot;
        long ctold, ctnew;
@@ -571,10 +577,7 @@ check()
 */
 }
 
-static
-sort(a,n)      /*shellsort CACM #201*/
-struct line *a;
-{
+static sort(a, n)      /*shellsort CACM #201*/ struct line *a; int n; {
        struct line w;
        register int j,m;
        struct line *ai;
@@ -607,11 +610,7 @@ struct line *a;
        }
 }
 
-static
-unsort(f, l, b)
-struct line *f;
-int *b;
-{
+static unsort(f, l, b) struct line *f; int l; int *b; {
        register int *a;
        register int i;
        a = (int *)talloc((l+1)*sizeof(int));
@@ -622,9 +621,7 @@ int *b;
        free((char *)a);
 }
 
-static
-skipline(f)
-{
+static skipline(f) int f; {
        register i, c;
 
        for(i=1;(c=getc(input[f]))!='\n';i++)
@@ -633,9 +630,7 @@ skipline(f)
        return(i);
 }
 
-static
-output()
-{
+static output() {
        int m;
        register int i0, i1, j1;
        int j0;
@@ -701,9 +696,7 @@ struct      context_vec     *context_vec_start,
    and this means that there were lines appended (beginning at b).
    If c is greater than d then there are lines missing from the to file.
 */
-static
-change(a,b,c,d)
-{
+static change(a, b, c, d) int a; int b; int c; int d; {
        int ch;
        int lowa,upb,lowc,upd;
        struct stat stbuf;
@@ -792,22 +785,14 @@ change(a,b,c,d)
        }
 }
 
-static
-range(a,b,separator)
-char *separator;
-{
+static range(a, b, separator) int a; int b; char *separator; {
        printf("%d", a>b?b:a);
        if(a<b) {
                printf("%s%d", separator, b);
        }
 }
 
-static
-fetch(f,a,b,lb,s,oldfile)
-long *f;
-FILE *lb;
-char *s;
-{
+static fetch(f, a, b, lb, s, oldfile) long *f; int a; int b; FILE *lb; char *s; int oldfile; {
        register int i, j;
        register int c;
        register int col;
@@ -882,10 +867,7 @@ char *s;
  * arranging line in 7-bit bytes and then
  * summing 1-s complement in 16-bit hunks 
  */
-static
-readhash(f)
-register FILE *f;
-{
+static readhash(f) register FILE *f; {
        register long sum;
        register unsigned shift;
        register t;
@@ -948,12 +930,9 @@ register FILE *f;
        return((short)low(sum) + (short)high(sum));
 }
 
-#include <a.out.h>
+/*#include <a.out.h>*/
 
-static
-asciifile(f)
-       FILE *f;
-{
+static asciifile(f) FILE *f; {
        char buf[BUFSIZ];
        register int cnt;
        register char *cp;
@@ -973,11 +952,8 @@ asciifile(f)
        return (1);
 }
 
-
 /* dump accumulated "context" diff changes */
-static
-dump_context_vec()
-{
+static dump_context_vec() {
        register int    a, b, c, d;
        register char   ch;
        register struct context_vec *cvp = context_vec_start;