From 6d6bb88a0215b87a4a47ed86a84ae3c75d399962 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Sun, 24 Apr 2016 18:05:02 -0400 Subject: Initial import of 5.0 source code with minor changes to use termios on Linux. --- merg.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 merg.c (limited to 'merg.c') diff --git a/merg.c b/merg.c new file mode 100644 index 0000000..d917867 --- /dev/null +++ b/merg.c @@ -0,0 +1,150 @@ +#include +#if defined(DOS) | defined(NT) +#include +#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} {}"); + puts(""); + puts("Merg: Create a new file from an old file and a differences file"); + puts("Merg {}"); + puts(""); + puts("Clist: Create a file containing unchanged, deleted and inserted lines"); + puts("Clist {-} {}"); + 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 -- cgit v1.2.3