; DEARC
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program extract files from an archive created with ARC.
; The files are extracted in current directory.
#!proteus -z
IF LT(ARGC, 5)
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " <archive>"
ABORT 0
FI
H = FOPEN(ARGV(5), 1)
IF EQ(H, -1)
CONSOLELN "Error: could not open " ARGV(5)
ABORT 1
FI
ErrorNum = 0
WHILE NOT(FEOF(H))
NameLen = ASC(FREAD(H, 1))
IF FEOF(H)
BREAK
FI
Name = FREAD(H, NameLen)
SizeLen = ASC(FREAD(H, 1))
Size = FREAD(H, SizeLen)
HDest = FOPEN(Name, 26)
CONSOLELN "Extracting file: " Name
IF EQ(HDest, -1)
CONSOLELN "Error: could not create/write to " Name
FSEEK(H, Size, 1)
INC(@ErrorNum)
ELSE
WHILE GT(Size, 0)
L = FREAD(H, MIN(Size, 8192))
FWRITE(HDest, L)
SUB(@Size, STRLEN(L))
LOOP
FCLOSE(HDest)
FI
LOOP
FCLOSE(H)
IF GT(ErrorNum, 0)
CONSOLELN "Warning: not all files could be extracted."
ABORT 2
ELSE
CONSOLELN "File " ARGV(5) " correctly extracted."
FI
ABORT 0