Programma di esempio XCOMP.PRT
; XCOMP
;
; Programma per Proteus
;
; (C) 1998-2003 Simone Zanella Productions
;
; Confronta ricorsivamente un gruppo di file tra due alberi di directory.

; Parametri impliciti: input e output predefiniti nulli
;!proteus -z

IF OR(ISEMPTY(ARGV(5)), ISEMPTY(ARGV(6)))
  CONSOLELN "Sintassi: " ARGV(1) " " ARGV(2) \
            " \"specifica\" \"radicedest\""
  CONSOLELN ""
  CONSOLELN "Scopo: confronta ricorsivamente (includendo le sottodirectory)"
  CONSOLELN "tutti i file che corrispondono a \"specifica\" partendo " \
            "da \"radicedest\"."
  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 "Riassunto risultati"
CONSOLELN "-------------------"
CONSOLELN "Files trovati: " TotFound
IF NotComp
  CONSOLELN "Files che non hanno potuto essere aperti: " NotComp
FI
IF DifSize
  CONSOLELN "Files di dimensioni differenti: " DifSize
FI
IF Different
  CONSOLELN "Files con differenze: " Different
FI
CONSOLELN IIF(NEQ(TotFound, Success), \
          "Errore: non tutti i file corrispondono.", \
          "Confronto completato con successo.")
ABORT 0


FUNCTION CompareFiles(source, dest)

  hs = FOPEN(source, 1)
  IF EQ(hs, -1)
    CONSOLELN "Impossibile aprire " source
    RETURN -1
  FI
  hd = FOPEN(dest, 1)
  IF EQ(hd, -1)
    FCLOSE(hs)
    CONSOLELN "Impossibile aprire " dest
    RETURN -1
  FI
  IF NEQ(FSIZE(hs), FSIZE(hd))
    FCLOSE(hs)
    FCLOSE(hd)
    CONSOLELN "Le dimensioni dei file non corrispondono (" \
              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 "Riscontrate " diff " differenze tra " source " e " 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 trovato
    IF NAND(DIRLAST(h, 5), 16)
      ; Directory - entro...
      CONSOLELN "Entro directory " DIRLAST(h, 1) "..."
      RecursiveCompare(extdir DIRLAST(h, 1) _DirSep)
    ELSE
      ; File - confronto...
      CONSOLELN "Confronto 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
Indice esempi Prossimo esempio Esempio precedente Indice per argomenti Indice analitico
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