Example XCOMP.PRT
; XCOMP
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Compare a group of file recursively between two directory trees.

; Implicit parameters: input and output NULL

;!proteus -z

IF OR(ISEMPTY(ARGV(5)), ISEMPTY(ARGV(6)))
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) \
            " \"specs\" \"dir_root\""
  CONSOLELN ""
  CONSOLELN "Purpose: compare recursively (including subdirectories)"
  CONSOLELN "all the files corresponding to \"specs\" starting " \
            "from \"dir_root\"."
  ABORT 0
FI

!ifdef UNIX
  DirSep = "/"
!else
  DirSep = "\\"
!endif

SourceDir = STRIPQUOTES(ARGV(5))
DestDir = STRIPQUOTES(ARGV(6))
IF STRNEQ(RIGHT(DestDir, 1), DirSep)
  DestDir = DestDir DirSep
FI

X = STRRSTR(SourceDir, DirSep)
IF X
  BaseDir = LEFT(SourceDir, X)
  Spec = RESTFROM(SourceDir, INC(X))
ELSE
  BaseDir = ""
  Spec = SourceDir
FI
TotFound = 0
NotComp = 0
DifSize = 0
Success = 0
Different = 0

RecursiveCompare("")
CONSOLELN "---------------"
CONSOLELN "Results summary"
CONSOLELN "---------------"
CONSOLELN "Files found: " TotFound
IF NotComp
  CONSOLELN "Files that could not be opened: " NotComp
FI
IF DifSize
  CONSOLELN "Files of different sizes: " DifSize
FI
IF Different
  CONSOLELN "Files with differences: " Different
FI
CONSOLELN IIF(NEQ(TotFound, Success), \
          "Error: not all files were equal.", \
          "Compare succesfull.")
ABORT 0


FUNCTION CompareFiles(source, dest)

  hs = FOPEN(source, 1)
  IF EQ(hs, -1)
    CONSOLELN "Could not open " source
    RETURN -1
  FI
  hd = FOPEN(dest, 1)
  IF EQ(hd, -1)
    FCLOSE(hs)
    CONSOLELN "Could not open " dest
    RETURN -1
  FI
  IF NEQ(FSIZE(hs), FSIZE(hd))
    FCLOSE(hs)
    FCLOSE(hd)
    CONSOLELN "File sizes do not match (" \
              source ", " dest ")"
    RETURN -2
  FI
  diff = 0
  REPEAT
    ss = FREAD(hs, 8192)
    sd = FREAD(hd, 8192)
    dp = POSDIFF(ss, sd)
    WHILE dp
      INC(@diff)
      INC(@dp)
      ss = RESTFROM(ss, dp)
      sd = RESTFROM(sd, dp)
      dp = POSDIFF(ss, sd)
    LOOP
  UNTIL NEQ(STRLEN(ss), 8192)
  IF diff
    CONSOLELN diff " differences found between " source " and " dest
  FI
  FCLOSE(hs)
  FCLOSE(hd)
RETURN diff


FUNCTION RecursiveCompare(extdir)

  h = DIROPEN(_BaseDir extdir _Spec, 3)
  f = IIF(NEQ(h, -1), 1, 0)
  WHILE GT(f, 0)
    ; File found
    IF NAND(DIRLAST(h, 5), 16)
      ; Directory - enter...
      CONSOLELN "Entering directory " DIRLAST(h, 1) "..."
      RecursiveCompare(extdir DIRLAST(h, 1) _DirSep)
    ELSE
      ; File - compare...
      CONSOLELN "Comparing file " DIRLAST(h, 1) "..."
      SWITCH CompareFiles(_BaseDir extdir DIRLAST(h, 1), \
                          _DestDir extdir DIRLAST(h, 1))
        ON -1
          _NotComp = INC(_NotComp)
        ON -2
          _DifSize = INC(_DifSize)
        ON  0
          _Success = INC(_Success)
        OTHER
          _Different = INC(_Different)
      OFF
      _TotFound = INC(_TotFound)
    FI
    f = DIRNEXT(h)
  LOOP
  DIRCLOSE(h)
RETURN 0
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell