Example ARC.PRT
; ARC
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program creates an archive file including all files specified, which
; can be later extracted by using DEARC.

#!proteus -z

IF LT(ARGC, 6)
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " <dest> <filespec> [<filespec> ..]"
  ABORT 0
FI

VH = VECNEW(4)
HDest = FOPEN(ARGV(5), 26)
IF EQ(HDest, -1)
  CONSOLELN "Error: could not create/write to " ARGV(5)
  ABORT 1
FI

ErrorNum = 0
FOR X = 6 TO ARGC
  H = DIROPEN(ARGV(X), 1)
  DosSplit(ARGV(X), VH)
  BasePath = VECGET(VH, 1) VECGET(VH, 2)
  F = IIF(NEQ(H, -1), 1, 0)
  IF NOT(F)
    CONSOLELN "Error: no file found matching " ARGV(X)
    INC(@ErrorNum)
  FI
  WHILE GT(F, 0)
    ; File found
    Name = DIRLAST(H, 1)
    Size = DIRLAST(H, 2)
    ; Open for reading
    CONSOLELN "Adding file: " QualifyPath(BasePath, Name)
    FH = FOPEN(QualifyPath(BasePath, Name), 1)
    IF NEQ(FH, -1)
      FWRITE(HDest, CHR(STRLEN(Name)))
      FWRITE(HDest, Name)
      FWRITE(HDest, CHR(STRLEN(Size)))
      FWRITE(HDest, Size)
      ; File opened - copy until the end of file
      WHILE NOT(FEOF(FH))
        L = FREAD(FH, 8192)
        FWRITE(HDest, L)
      LOOP
      FCLOSE(FH)
    ELSE
      CONSOLELN "Error: could not open " Name
      INC(@ErrorNum)
    FI
    F = DIRNEXT(H)
  LOOP
  DIRCLOSE(H)
NEXT
IF GT(ErrorNum, 0)
  CONSOLELN "Warning: a few files could not be copied."
  ABORT 2
ELSE
  CONSOLELN "Archive " ARGV(5) " succesfully created."
FI
ABORT 0


FUNCTION QualifyPath(path, name)

IF ISNOTEMPTY(path)
  RETURN STRTRAN(path "\\" name, "\\\\", "\\")
FI
RETURN name


FUNCTION DosSplit(pathname, vh)

  ; Store into the array vh (pre-allocated, size at least 4)
  ; the various parts of pathname:
  ; 1  drive
  ; 2  path
  ; 3  name
  ; 4  extension

  s = LEFT(pathname, 2)
  ; Isolate drive
  IF REXMATCH(s, "[A-Za-z]:")
    VECSET(vh, 1, s)
    pathname = RESTFROM(pathname, 3)
  ELSE
    VECSET(vh, 1, "")
  FI
  ; Isolate directory
  p = STRRSTR(pathname, "\\")
  IF p
    VECSET(vh, 2, LEFT(pathname, p))
    pathname = RESTFROM(pathname, INC(p))
  ELSE
    VECSET(vh, 2, "")
  FI
  IF ISNOTEMPTY(pathname)
    ; Isolate extension
    p = STRRSTR(pathname, ".")
    IF p
      VECSET(vh, 4, RESTFROM(pathname, p))
      pathname = LEFT(pathname, DEC(p))
    ELSE
      VECSET(vh, 4, "")
    FI
    ; Isolate filename
    VECSET(vh, 3, pathname)
  ELSE
    VECSET(vh, 3, "")
    VECSET(vh, 4, "")
  FI
RETURN
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