Example REMVB.PRT
; REMVB
;
; Program for Proteus
;
; (C) 2000-2004 Simone Zanella Productions
;
; Remove remarks from the specified Visual Basic files.
;
; Algorithm:
; - remove all lines starting with ' and remarks at the end of line

#!proteus -z

SourceDir = STRIPQUOTES(ARGV(5))
DestDir = STRIPQUOTES(ARGV(6))

IF OR(ISEMPTY(SourceDir), ISEMPTY(DestDir))
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " [\"filespec\" \"destination\"]"
  CONSOLELN "Purpose: remove remarks from specified VB source files; new files are created"
  CONSOLELN "inside destination, which must be an existing folder."
  ABORT 0
FI

; Determine directory separator according to the operating system
!ifdef UNIX
  DirSep = "/"
!else
  DirSep = "\\"
!endif

; Isolate base directory and file specification
X = STRRSTR(SourceDir, DirSep)
IF X
  BaseDir = LEFT(SourceDir, X)
  Spec = RESTFROM(SourceDir, INC(X))
ELSE
  BaseDir = ""
  Spec = SourceDir
FI

; Build an AVL tree of the files to be processed
H = DIROPEN(SourceDir, 1)
F = IIF(NEQ(H, -1), 1, 0)
A = AVLNEW()
WHILE GT(F, 0)
  AVLSET(A, DIRLAST(H, 1), 0)
  F = DIRNEXT(H)
LOOP
DIRCLOSE(H)

; Transform the tree into an array.
; No sorting is required, keys are already ordered.
VF = AVLKEYS(A)
AVLFREE(A)

IF STRNEQ(RIGHT(DestDir, 1), DirSep)
  DestDir = DestDir DirSep
FI

; Process all files
FOR X = 1 TO VECLEN(VF)
  IF AllowedExt(VECGET(VF, X))
    H = FOPEN(BaseDir IIF(ISNOTEMPTY(BaseDir), DirSep, "") \
              VECGET(VF, X), 1)

    IF EQ(H, -1)
      CONSOLELN "Error: could not open " VECGET(VF, X)
      CONTINUE
    FI

    D = FOPEN(DestDir VECGET(VF, X), 28)

    IF EQ(D, -1)
      CONSOLELN "Error: could not create \"" DestDir VECGET(VF, X) "\""
    ELSE
      CONSOLELN "Converting " VECGET(VF, X)
      WHILE NOT(FEOF(H))
        L = FREADLN(H)
        IF STRNEQ(LEFT(LTRIM(L, " "), 1), "'")
          FWRITELN(D, CheckLine(L))
        FI
      LOOP
      FCLOSE(D)
    FI

    FCLOSE(H)
  ELSE

    CONSOLELN "Copying " VECGET(VF, X)
    FCOPY(BaseDir IIF(ISNOTEMPTY(BaseDir), DirSep, "") \
          VECGET(VF, X), DestDir VECGET(VF, X))
  FI
NEXT

ABORT 0


FUNCTION CheckLine(l)

instr = 0
n = STRLEN(l)
FOR x = 1 TO n
  SWITCH SUBSTR(l, x, 1) STREQ
  ON "\""
    instr = IIF(instr, 0, 1)
  ON "'"
    IF NOT(instr)
      RETURN LEFT(l, DEC(x))
    FI
  OFF
NEXT
RETURN l


FUNCTION AllowedExt(s)

p = STRRSTR(s, ".")
ext = RESTFROM(s, INC(p))
IF OR(STRIEQ(ext, "FRM"), STRIEQ(ext, "BAS"))
  RETURN 1
FI
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