; 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