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