home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- $CRT 14 Jan 1997 : hb
-
- $AUT Holger Burkarth
- $DAT >>FileCmp.c<< 14 Jan 1997 16:43:51 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/c/FileCmp p:pLib/StartCode.o p:/pOS_RKRM/pDos/FileCmp.c p:pLib/StdIO.o -l pOSStub -l pOS
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pExec/Memory.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/Files.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: FileCmp 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* RDA;
- ULONG Ops[4]={0,0,0,0};
- UWORD Err=DOSFAIL_FAIL;
-
- RDA=pOS_ReadDosArgs(
- // 0 1 2 3
- "FILE1/A,FILE2/A,BUF=BUFFERS/K/N,VERBOSE/S",
-
- Ops,sizeof(Ops)/sizeof(ULONG),
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- ARGTAG_VarName, (ULONG)"shell/join",
- TAG_END);
-
- if(RDA) {
- size_t BufSize;
- UBYTE *Buffer;
- struct pOS_FileHandle *AFH,*BFH;
- UBYTE AutoDel=0,Ende=0;
- UBYTE Verbose=Ops[3];
- size_t FileSize=0;
-
- if(Ops[2]) { BufSize=((ULONG*)Ops[2])[0]; }
- else BufSize=8192;
- if(BufSize<2) BufSize=2;
- else if(BufSize>8000000) BufSize=8000000;
-
- if(Buffer=(UBYTE*)pOS_AllocMem(BufSize,MEMF_PUBLIC)) {
- const size_t ReadSize=BufSize/2;
- if(AFH=pOS_OpenFile(NULL,(UBYTE*)Ops[0],FILEHDMOD_Read)) {
- if(BFH=pOS_OpenFile(NULL,(UBYTE*)Ops[1],FILEHDMOD_Read)) {
- dossize_t FilePos,SizeA,SizeB;
-
- Err=DOSFAIL_OK;
-
- for(FilePos=0; ;FilePos+=SizeA) {
- if(pOS_CheckBreakSignal()) break;
-
- if(Verbose) printf("read file <%s> bytes %ld ...",Ops[0],ReadSize);
- SizeA=pOS_ReadFile(AFH,&Buffer[0],ReadSize);
- if(Verbose) printf(" %ld\n",SizeA);
-
- if(Verbose) printf("read file <%s> bytes %ld ...",Ops[1],ReadSize);
- SizeB=pOS_ReadFile(BFH,&Buffer[ReadSize],ReadSize);
- if(Verbose) printf(" %ld\n",SizeB);
-
- if(SizeA!=SizeB) {
- printf("Readsize difference %ld, %ld\n",SizeA,SizeB);
- Err=DOSFAIL_WARN;
- break;
- }
- if(SizeA>0) {
- dossize_t i;
- const UBYTE *P1,*P2;
- P1=&Buffer[0];
- P2=&Buffer[ReadSize];
-
- for(i=0; i<SizeA; ++i,++P1,++P2) {
- if(P1[0]!=P2[0]) {
- printf("Difference by %ld\n",FilePos+i);
- printf("Buf1 %16.lh\n",P1);
- printf("Buf2 %16.lh\n",P2);
- Err=DOSFAIL_WARN;
- break;
- }
- }
- }
- else {
- printf("Compare - Ok\n");
- break;
- }
- }
- pOS_CloseFile(BFH);
- }
- else printf("Cannot open file <%s> DosErr=%ld\n",Ops[1],pOS_GetIoErr());
- pOS_CloseFile(AFH);
- }
- else printf("Cannot open file <%s> DosErr=%ld\n",Ops[0],pOS_GetIoErr());
-
- pOS_FreeMem(Buffer,BufSize);
- }
- else printf("Cannot allocate memory, bytes=%ld\n",BufSize);
- pOS_DeleteDosArgs(RDA);
- }
- pOS_SetShellFail(Err);
- }
-
-
-