Massimo Belgrano wrote:
Wich is best way for list harbour standard function & class?
Basically to way:
read all source prg & clipper
a binary way detect class & function
folowing first way
i have get // get from a public post of [email protected] at
comp.lang.xharbour follow source
at http://groups.google.it/group/comp.lang.xharbour/browse_thread/thread/bf616f29c1ce42a5/d52da4275c05dfed?hl=it&ie=UTF-8&q=cRegExClassTran#d52da4275c05dfed
<http://groups.google.it/group/comp.lang.xharbour/browse_thread/thread/bf616f29c1ce42a5/d52da4275c05dfed?hl=it&ie=UTF-8&q=cRegExClassTran#d52da4275c05dfed>
...
I was curious about the source Massimo posted and I got some basic basic
results.
I do not know much about the xHarbour environment nor the xhb
compatibility library so I had to massage the code to get it to work.
Additionally the contrib folders has changed since the post so I altered
how that folder was handled. The downside is that there are tonnes of
files; maybe one file for std and one file for contrib?
I am unsure about the *cRegExClassTran* in the original xharbour post,
but I suspect it is unnecessary unless the short form CLAS was used in
place of CLASS.
I'm sure I missed some short cuts to my implementation, I am rusty, but
here is my version:
(I'm going to keep playing with this, I'm not sure if it is locating
classes correctly and when that is confirmed I'll try to capture the
vars/methods/etc of a class; maybe the params of a PRG-based func/proc
can be captured, but I'm very unsure about trying to capture the params
of C-based code)
But to try to detect conditional code will push this complexity through
the roof.
April
/*
public post of [email protected] at comp.lang.xharbour
http://groups.google.it/group/comp.lang.xharbour/browse_thread/thread/bf616f29c1ce42a5/d52da4275c05dfed?hl=it&ie=UTF-8&q=cRegExClassTran#d52da4275c05dfed
*/
#include "common.ch"
#include 'Inkey.ch'
#include 'fileio.ch'
#include 'xhb.ch'
//~ #include 'hbeol.ch'
static aFuncsName:={}
static cRegExHbFunc
static cRegExFunc
static cRegExProc
static cRegExClass
static cRegExClassTran
static cRegExFunctionTran
static cRegExFunctionProc
static cRegExFuncTran
static cRegExProcTran
static cRegExHb_FuncTran
#define EOL_WINDOWS chr(13)+chr(10)
#xtranslate a HAS b => b.Has(a)
function Main(cDir)
default cDir to ".\"
GetFromPatch(CDir + '\source\', 'std')
AEval(Directory(CDir + "\contrib\*", "D"), {|x| IIf(x[5] == "D"
.and. x[1] <> "." .and. x[1] <> "..", GetFromPatch(CDir + "\contrib\" +
x[1] + "\", "contrib_" + x[1]), ) })
return 0
init procedure RegexCompiEgb
default cRegExHbFunc to Hb_RegExComp("(?i)^\s*HB_FUNC\s*\(")
default cRegExFunc to Hb_RegExComp("(?i)^\s*(FUNCTION|FUNC)")
default cRegExProc to
Hb_RegExComp("(?i)^\s*(PROCEDURE|PROC)")
default cRegExClass to Hb_RegExComp("(?i)^\s*CLASS\s{1, }")
default cRegExClassTran to Hb_RegExComp("(?i)^CLASS")
default cRegExFunctionTran to Hb_RegExComp("(?i)^FUNCTION")
default cRegExFunctionProc to Hb_RegExComp("(?i)^PROCEDURE")
default cRegExFuncTran to Hb_RegExComp("(?i)^FUNC")
default cRegExProcTran to Hb_RegExComp("(?i)^PROC")
default cRegExHb_FuncTran to Hb_RegExComp("(?i)^HB_FUNC\(")
return
Procedure recurse(arr, dir, n)
default n to 1
//~ qout(ltrim(str(n)) + ".>" + dir)
AEval(;
Directory(dir+"*.*", "D"), ;
<|x, i|
//~ qout("%", x[1], x[2], x[3], x[4], x[5])
If x[5] = "D"
If x[1] <> "." .and. x[1] <> ".." .and. lower(x[1]) <>
"tests"
recurse(arr, dir + x[1] + "\", n + 1)
End
ElseIf right(lower(x[1]), 4) == ".prg" .or.
right(lower(x[1]), 2) == ".c"
x[1] = dir + x[1]
AAdd(arr, x)
End
>;
)
Return
procedure GetFromPatch(cPatch, cFileName, lClearFile)
local aDirs := {}
local i
local FHandleRead
local FHandleWrite
local FHandleWriteF
local nMode
default lClearFile to TRUE
if lClearFile
nMode:= HB_BITOR( HB_BITOR( FO_CREAT, FO_READWRITE ), FO_TRUNC )
else
nMode:= HB_BITOR( FO_CREAT, FO_READWRITE )
endif
aFuncsName:={}
recurse(aDirs, cPatch)
ASort(aDirs, , , {|x, y| x[1] < y[1]})
FHandleWrite:=FOPEN(cFileName+'ws.funcs', nMode)
FSeek(FHandleWrite, 0, FS_END)
for i:=1 to Len(aDirs)
FHandleRead:=FOpen(aDirs[i, 1])
If FHandleRead > 0
GenFuncs(FHandleRead, FHandleWrite, aDirs[i, 1])
FClose(FHandleRead)
Else
qout("Could not open [" + aDirs[i, 1] + "], error " +
ltrim(str(FHandleRead)))
End
next
FClose(FHandleWrite)
stdFuncs(aFuncsName)
ASort(aFuncsName)
FHandleWriteF:=FOPEN(cFileName+'.funcs', nMode)
FSeek(FHandleWriteF, 0, FS_END)
for i:=1 to Len(aFuncsName)
FWrite(FHandleWriteF, aFuncsName[i]+EOL_WINDOWS)
next
FClose(FHandleWriteF)
return
procedure stdFuncs(aFuncsName)
local i
for i:=1 to Len(aFuncsName)
aFuncsName[i]:=StrTran(aFuncsName[i], " ", '')
if (aFuncsName[i] HAS cRegExClassTran)
aFuncsName[i]:="CLASS "+ltrim(SubStr(aFuncsName[i], 6))
elseif (aFuncsName[i] HAS cRegExFunctionTran)
aFuncsName[i]:="FUNCTION "+ltrim(SubStr(aFuncsName[i], 9))
elseif (aFuncsName[i] HAS cRegExFunctionProc)
aFuncsName[i]:="PROCEDURE "+ltrim(SubStr(aFuncsName[i], 10))
elseif (aFuncsName[i] HAS cRegExFuncTran)
aFuncsName[i]:="FUNCTION "+ltrim(SubStr(aFuncsName[i], 5))
elseif (aFuncsName[i] HAS cRegExProcTran)
aFuncsName[i]:="PROCEDURE "+ltrim(SubStr(aFuncsName[i], 5))
elseif (aFuncsName[i] HAS cRegExHb_FuncTran)
aFuncsName[i]:="FUNCTION "+ltrim(SubStr(aFuncsName[i], 9))
endif
next
return
procedure GenFuncs(FHandleRead, FHandleWrite, cFileNameOpened)
local aMaches
local cBuffer
local lAddLine
local lFileSaved:=FALSE
do while HB_FREADLINE( FHandleRead, @cBuffer, { chr(13)+chr(10),
chr(10), chr(13) } )=0
lAddLine:=FALSE
if (cBuffer HAS cRegExHbFunc)
lAddLine:=TRUE
elseif (cBuffer HAS cRegExFunc)
lAddLine:=TRUE
elseif (cBuffer HAS cRegExProc)
lAddLine:=TRUE
elseif (cBuffer HAS cRegExClass)
lAddLine:=TRUE
endif
if lAddLine
AAdd(aFuncsName, cBuffer)
if !lFileSaved
FWrite(FHandleWrite, Space(70)+cFileNameOpened+EOL_WINDOWS)
lFileSaved:=TRUE
endif
FWrite(FHandleWrite, cBuffer+EOL_WINDOWS)
endif
enddo
return
--
Body by Nautilus; Brain by Mattel
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour