home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pDos / FileCmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  5.0 KB  |  175 lines

  1. /*******************************************************************
  2.  $CRT 14 Jan 1997 : hb
  3.  
  4.  $AUT Holger Burkarth
  5.  $DAT >>FileCmp.c<<   14 Jan 1997    16:43:51 - (C) ProDAD
  6. *******************************************************************/
  7.  
  8. //##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
  9.  
  10. /***********************************************************
  11.   pOS programing example - Copyright (C) 1995-97 proDAD
  12.  
  13.   This code was written as an easy to understand example,
  14.   how to program pOS features. It is provided 'as-is',
  15.   without any express or implied warranty.
  16.  
  17.   Permission is hereby granted to use, copy and modify
  18.   this source code for any purpose, without fee, subject
  19.   to the following conditions:
  20.  
  21.     (1) This notice may not be removed or altered from any
  22.         source distribution.
  23.  
  24.     (2) Altered source versions must be plainly marked as
  25.         such, and must not be misrepresented as being
  26.         the original source code.
  27.  
  28.     (3) If only executable code is distributed, then the
  29.         accompanying documentation have to state that
  30.         "this software is based in part on examples of
  31.         the pOS developer packet".
  32.  
  33.     (4) Permission for use of this code is granted only
  34.         if the user accepts full responsibility for any
  35.         undesirable consequences. proDAD accept NO LIABILITY
  36.         for damages of any kind.
  37.  
  38.   ©proDAD
  39. ***********************************************************/
  40.  
  41. #define __COMPUTER_AMIGA 1
  42. #define NOMYDEBUG
  43.  
  44. #include "p:pExec/Types.h"
  45. #include "p:pExec/Memory.h"
  46. #include "p:pDOS/ArgTags.h"
  47. #include "p:pDOS/DosSig.h"
  48. #include "p:pDOS/Files.h"
  49. #include "p:pDOS/DosErrors.h"
  50. #include "p:proto/pLibExt.h"
  51. #include "p:proto/pExec2.h"
  52. #include "p:proto/pDOS2.h"
  53.  
  54. #ifdef _____ME_____
  55.   #include "grund/inc_string.h"
  56.   #include "grund/inc_stdio.h"
  57. #else
  58.  #ifdef __cplusplus
  59.  extern "C" {
  60.  #endif
  61.   #include <string.h>
  62.   #include <stdio.h>
  63.  #ifdef __cplusplus
  64.  }
  65.  #endif
  66. #endif
  67.  
  68.  
  69. const CHAR *HelpText=
  70. ""
  71. ;
  72.  
  73. const CHAR *PrgHeader=
  74. "";
  75.  
  76. const CHAR *PrgVerText=
  77. "$VER: FileCmp 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
  78. /*----------------------------------
  79. -----------------------------------*/
  80. #ifdef __cplusplus
  81. extern "C"
  82. #endif
  83.  
  84. VOID main()
  85. {
  86.   struct pOS_DosArgs* RDA;
  87.   ULONG  Ops[4]={0,0,0,0};
  88.   UWORD Err=DOSFAIL_FAIL;
  89.  
  90.   RDA=pOS_ReadDosArgs(
  91. //  0      1      2                3
  92. "FILE1/A,FILE2/A,BUF=BUFFERS/K/N,VERBOSE/S",
  93.  
  94.     Ops,sizeof(Ops)/sizeof(ULONG),
  95.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  96.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  97.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  98.     ARGTAG_VarName,       (ULONG)"shell/join",
  99.     TAG_END);
  100.  
  101.   if(RDA) {
  102.     size_t BufSize;
  103.     UBYTE *Buffer;
  104.     struct pOS_FileHandle *AFH,*BFH;
  105.     UBYTE AutoDel=0,Ende=0;
  106.     UBYTE Verbose=Ops[3];
  107.     size_t FileSize=0;
  108.  
  109.     if(Ops[2]) {  BufSize=((ULONG*)Ops[2])[0]; }
  110.     else          BufSize=8192;
  111.     if(BufSize<2) BufSize=2;
  112.     else if(BufSize>8000000) BufSize=8000000;
  113.  
  114.     if(Buffer=(UBYTE*)pOS_AllocMem(BufSize,MEMF_PUBLIC)) {
  115.       const size_t ReadSize=BufSize/2;
  116.       if(AFH=pOS_OpenFile(NULL,(UBYTE*)Ops[0],FILEHDMOD_Read)) {
  117.         if(BFH=pOS_OpenFile(NULL,(UBYTE*)Ops[1],FILEHDMOD_Read)) {
  118.           dossize_t FilePos,SizeA,SizeB;
  119.  
  120.           Err=DOSFAIL_OK;
  121.  
  122.           for(FilePos=0; ;FilePos+=SizeA) {
  123.             if(pOS_CheckBreakSignal()) break;
  124.  
  125.             if(Verbose) printf("read file <%s> bytes %ld ...",Ops[0],ReadSize);
  126.             SizeA=pOS_ReadFile(AFH,&Buffer[0],ReadSize);
  127.             if(Verbose) printf(" %ld\n",SizeA);
  128.  
  129.             if(Verbose) printf("read file <%s> bytes %ld ...",Ops[1],ReadSize);
  130.             SizeB=pOS_ReadFile(BFH,&Buffer[ReadSize],ReadSize);
  131.             if(Verbose) printf(" %ld\n",SizeB);
  132.  
  133.             if(SizeA!=SizeB) {
  134.               printf("Readsize difference %ld, %ld\n",SizeA,SizeB);
  135.               Err=DOSFAIL_WARN;
  136.               break;
  137.             }
  138.             if(SizeA>0) {
  139.               dossize_t i;
  140.               const UBYTE *P1,*P2;
  141.               P1=&Buffer[0];
  142.               P2=&Buffer[ReadSize];
  143.  
  144.               for(i=0; i<SizeA; ++i,++P1,++P2) {
  145.                 if(P1[0]!=P2[0]) {
  146.                   printf("Difference by %ld\n",FilePos+i);
  147.                   printf("Buf1 %16.lh\n",P1);
  148.                   printf("Buf2 %16.lh\n",P2);
  149.                   Err=DOSFAIL_WARN;
  150.                   break;
  151.                 }
  152.               }
  153.             }
  154.             else {
  155.               printf("Compare - Ok\n");
  156.               break;
  157.             }
  158.           }
  159.           pOS_CloseFile(BFH);
  160.         }
  161.         else printf("Cannot open file <%s> DosErr=%ld\n",Ops[1],pOS_GetIoErr());
  162.         pOS_CloseFile(AFH);
  163.       }
  164.       else printf("Cannot open file <%s> DosErr=%ld\n",Ops[0],pOS_GetIoErr());
  165.  
  166.       pOS_FreeMem(Buffer,BufSize);
  167.     }
  168.     else printf("Cannot allocate memory, bytes=%ld\n",BufSize);
  169.     pOS_DeleteDosArgs(RDA);
  170.   }
  171.   pOS_SetShellFail(Err);
  172. }
  173.  
  174.  
  175.