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
|
#include <stdio.h>
#if defined(DOS) | defined(NT)
#include <malloc.h>
#endif
struct Item {struct Item *Next, *Last; unsigned char *Value;}
*Oldlist=NULL, *Newlist=NULL, *Olditem, *Newitem, *T_Olditem, *T_Newitem;
char *Oldfile, *Newfile, *Listfile, Old_Buffer[513], List_Buffer[513];
int Binary=0, Oldline, Newline, T_Oldline, T_Newline, I, Inserted, Deleted,
Howfar, Done, List_Line;
FILE *Old, *New, *List;
main(Argc,Argv)
int Argc;
char *Argv[];
{char *P, C;
int I;
Oldfile=Newfile=NULL;
Get_Arg(Argc,Argv);
Newline=Oldline=1;
while (fgets(List_Buffer,512,List)!=NULL)
{I=strlen(List_Buffer);
if (I==0||List_Buffer[I-1]!='\n')
{List_Buffer[I]='\n';
List_Buffer[I+1]=0;
}
P=List_Buffer;
if ((C=(*P++))=='d')
{List_Line=(*P++)-'0';
while ((C=(*P++))!=':')
List_Line=List_Line*10+C-'0';
while (Oldline!=List_Line)
{if (fgets(Old_Buffer,512,Old)==NULL)
Fatalerror("Not enough lines in old file");
I=strlen(Old_Buffer);
if (I==0||Old_Buffer[I-1]!='\n')
{Old_Buffer[I]='\n';
Old_Buffer[I+1]=0;
}
Oldline++;
fputs(Old_Buffer,New);
Newline++;
}
if (fgets(Old_Buffer,512,Old)==NULL||strcmp(P,Old_Buffer)!=0)
Fatalerror("Old file does not match differences file");
I=strlen(Old_Buffer);
if (I==0||Old_Buffer[I-1]!='\n')
{Old_Buffer[I]='\n';
Old_Buffer[I+1]=0;
}
Oldline++;
} else
if (C=='i')
{List_Line=(*P++)-'0';
while ((C=(*P++))!=':')
List_Line=List_Line*10+C-'0';
while (Newline!=List_Line)
{if (fgets(Old_Buffer,512,Old)==NULL)
Fatalerror("Not enough records in old file");
I=strlen(Old_Buffer);
if (I==0||Old_Buffer[I-1]!='\n')
{Old_Buffer[I]='\n';
Old_Buffer[I+1]=0;
}
Oldline++;
fputs(Old_Buffer,New);
Newline++;
}
fputs(P,New);
Newline++;
} else
Fatalerror("Illegal record in differences file");
}
while (fgets(Old_Buffer,512,Old)!=NULL)
fputs(Old_Buffer,New);
fclose(Old);
fclose(New);
fclose(List);
}
Get_Arg(Argc,Argv)
int Argc;
char *Argv[];
{char *P;
for (I=1;I<Argc;I++)
{if ((P=Argv[I])[0]=='-')
{if (P[1]=='b'||P[1]=='B'&&P[2]==0)
Binary=1; else
if (P[1]=='a'||P[1]=='A'&&P[2]==0)
Binary=0;
} else
if (Oldfile==NULL)
Oldfile=Argv[I]; else
if (Newfile==NULL)
Newfile=Argv[I]; else
if (Listfile==NULL)
Listfile=Argv[I]; else
Fatalerror("Too many file arguments");
}
if (Oldfile==NULL)
{puts("");
puts("Dif: Create a differences file from an old and a new file");
puts("Dif {-<N>} <Old file> <New file> {<Differences file>}");
puts("");
puts("Merg: Create a new file from an old file and a differences file");
puts("Merg <Old file> <New file> {<Differences file>}");
puts("");
puts("Clist: Create a file containing unchanged, deleted and inserted lines");
puts("Clist {-<N>} <Old File> <New file> {<Listing file>}");
puts("");
puts("N is the number of lines that must be the same for a match (default 2)");
#if defined(VMS)
exit();
#endif
#if defined(DOS) | defined(NT)
_exit(0);
#endif
}
if (Listfile==NULL)
Listfile="CON";
if ((Old=fopen(Oldfile,"r"))==NULL)
Fatalerror("Could not find old file");
#if defined(VMS)
if ((New=fopen(Newfile,"w","fop=tef","rat=cr","rfm=var"))==NULL)
#endif
#if defined(DOS) | defined(NT)
if ((New=fopen(Newfile,"w"))==NULL)
#endif
Fatalerror("Could not create new file");
if ((List=fopen(Listfile,"r"))==NULL)
Fatalerror("Could not find differences file");
}
Fatalerror(S)
char *S;
{printf(S);
_exit(1);
}
#if defined(VMS)
memcpy(D,S,C)
char *D, *S;
int C;
{while (C--)
(*D++)=(*S++);
}
#endif
|