Example DOC.PRT
; DOC
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Extract documentation and (optionally) remarks from specified Proteus files;
; delete directives and initial remark character (; and #).

; Implicit parameters: input and output are NULL
;!proteus -z

Str_BDOC = "!bdoc"
Str_EDOC = "!edoc"

SourceDir = STRIPQUOTES(ARGV(5))

IF ISEMPTY(SourceDir)
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " [\"filespec\" [REM]]"
  CONSOLELN ""
  CONSOLELN "Purpose: extract document blocks and remarks (if REM is specified)"
  CONSOLELN "from filespec"
  ABORT 0
FI

Remarks = STRIEQ(ARGV(6), "REM")

; Determine directory separator according to 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 of 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)

; Convert the AVL into an array.
; No sorting is needed, the keys are already sorted

VF = AVLKEYS(A)
AVLFREE(A)

; Process all files
FOR X = 1 TO VECLEN(VF)
  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
  InDoc = 0
  First = 1
  N = 0

  WHILE NOT(FEOF(H))
    S = FREADLN(H)
    INC(@N)
    CheckLine(S, @First, VECGET(VF, X), N)
  LOOP
  FCLOSE(H)
  CONSOLELN ""
NEXT
ABORT 0


FUNCTION CheckLine(s, first, filename, n)

  ; Check if the line is a remark or is included into a documentation block

  s = ALLTRIM(s, " ")
  IF IN(LEFT(s, 1), ";#")
    IF _Remarks
      IF first
        CONSOLELN "File: " filename
        first = 0
      FI
      CONSOLELN n ": " LTRIM(s, ";# ")
      RETURN
    FI
  ELSE
    IF STRIEQ(LEFT(s, STRLEN(_Str_BDOC)), _Str_BDOC)
      INC(@_InDoc)
    ELSE
      IF STRIEQ(LEFT(s, STRLEN(_Str_EDOC)), _Str_EDOC)
        DEC(@_InDoc)
      ELSE
        IF _InDoc
          CONSOLELN n ": " s
        FI
      FI
    FI
  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