Генератор деклараций функций и процедур
Вроде работает правильно, но все же для тех кто будет использовать, советую подправить в коде имя создаваемого файла. Пусть уж лучше создаст файл рядом, чем перезаписывать существующий.
Автор: cha0s
Code
'Option Explicit
Declare Function Generate_Declares ( file As String ) As Integer
Function Generate_Declares ( file As String ) As Integer
Dim As uByte ch_cr = 13, ch_lf = 10
'' make declare strings
Dim As uByte bm
Dim As Integer f, g, ss, jk
Dim As String x
Redim As String s ( 0 )
f = FreeFile
Open file For Input As #f
Do While Not Eof ( f )
Line Input #f, x
If ucase ( Left( Trim ( x ), 2 )) = "AS" Then
s ( ss - 1 ) += Chr(13) + Chr(10) + " " + x
Else
If UCase$ ( Left ( Trim ( x ), 8 )) = "FUNCTION" Then
Redim Preserve s ( ss )
s ( ss ) = "Declare " + Trim ( x )
If Instr ( s ( ss ), "(" ) <> 0 Then
If Instr ( s ( ss ), ")" ) = 0 Then
Do
Line Input #f, x
s ( ss ) += Chr(13) + Chr(10) + " " + x
Loop Until ( Instr ( s ( ss ), ")" ) <> 0 ) = Not 0
End If
End If
ss += 1
End If
End If
Loop
Close
If ss = 0 Then Return 0
'' read file without declares
f = FreeFile
Open file For Input As #f
g = FreeFile
Open "tmp.tmp" For Output As #g
Do While Not Eof ( f )
Line Input #f, x
If UCase$ ( Left ( Trim ( x ), 7 )) = "DECLARE" Then
Else
Print #g, x
End If
Loop
Close
Close
'' save file with new declares only
f = FreeFile
Open file For Binary As #f
Dim As Integer v, y
For v = 0 To ss - 1
Put #f, , s ( v )
Put #f, , ch_cr
Put #f, , ch_lf
Next
g = FreeFile
Open "tmp.tmp" For Binary As #g
Do While Not Eof ( g )
Get #g, , bm
Put #f, , bm
Loop
Close
Close
kill "tmp.tmp"
Return -1
End Function
Generate_Declares("1.bas")