I wrote this so I could use it for myself, but someone else may find it handy. I'm sure there are a bazillion floating around just like it. Of course, it is better to code everything in a proper order so to not NEED a declarations file, but sometimes that is a hassle.
I know this works in Windows, but I have not tested it in Linux yet. The previous version I had been using that I forked this code from did work fine on linux.
I also definitely welcome (constructive) critcism

Command line arguments are detailed below, and does not open the GUI.
Without arguments, the GUI is opened.
You select your main source file, and this code crawls through all of it looking for all of the files that are included, then creates a declaration file from the procedure definitions.
-PB 4.41 (x86)
-the default output file is "declarations.pbi", in the same directory as the main source file.
-this can also be used in the Tools menu of the PB IDE.
-I used pureFORM to create the initial GUI.
-I've also zipped and loaded the source code onto my website, and will try to keep it up-to-date there, if I forget to update things here.
Hmm...that is all I can think of to mention. Enjoy!
CLI usage notes are in the code.
Code: Select all
;{ OS Specific
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
#Slash = "\"
#NL = #CRLF$
CompilerCase #PB_OS_Linux
#Slash = "/"
#NL = #LF$
CompilerDefault
MessageRequester(#AppTitle,"Sorry, your OS is not supported")
CompilerError
End
CompilerEndSelect
;}
EnableExplicit
Global errbuf.s
;{ AppAbout Info
#AppTitle = "PB Declaration Creator"
Global AppVersion.s = "2.0." + Str(#PB_Editor_BuildCount)
Global AppAbout.s = #AppTitle + #NL
AppAbout = appabout + "; This program is similar to version 1 in that it will read in .pb/.pbi PureBasic source files, " + #NL
AppAbout = appabout + "; and then create an output file of declarations." + #NL
AppAbout = appabout + "; The difference is that you only need to load in your MAIN source file, and it will craw through all of the included files." + #NL + #NL
AppAbout = appabout + "; I find this program useful, and hopefully you do too. Feel free to share (just give me some credit) :-)" + #NL
AppAbout = appabout + ";--Jon Robbins 2010.03.18" + #NL
AppAbout = appabout + "; http://jrob.co.cc" + #NL + #NL
;#####################################################
;PB Declaration Creator v2
; Created by Jon Robbins
; This program will read through selected .pb/.pbi source files and generate a declare file (or multiple).
; My website URL: http://factorq.net/2010/03/05/purebasic-declarations-creator/
; PB Forum URL: http://www.purebasic.fr/english/viewtopic.php?f=12&t=41339
;
; Rev History
; v2.0.5 -- quote required for filenames on CLI (ie. -f "file.pb")
; ;not really a code change, but I ran into an issue with spaces in the file path
; v2.0.4 -- added a line and procedure count (does not include blank lines or comments)
; v2.0.3 -- now ignores outfile (so declarations file is not read, as there is no need), unless forced to read it (--readdec flag)
; -- added option To doublespace declarations output
; v2.0.2 -- small changes, removed unused code, added quiet mode.
; v2.0.1 -- forked from v1 source To make crawling improvements/commandline ready
; so that it can be used As a PB tool IN the IDE
;
;##################################################### /RevHistory
;-{ Usage Info
;{ CLI usage
; ie. Declaration_Creator.exe -f "mainfile.pb" -u -o "new_declarations.pbi"
; ie. Declaration_Creator.exe -f "mainfile.pb"
;
; -f "C:\main_source_file.pb" *REQUIRED for CLI use. needs quotes around it.
; -u unique (don't overwrite existing)
; if file exists, and -u is flagged then a date-time stamp is prefixed to the outfile name
; -o "output file name" -- the default is "declarations.pbi"
; -q quiet (no message boxes, if no errors)
; --dblspc double spaces the declarations in the output file
; --readdec read declarations file (default is to ignore it)
; -c only performs the line and procedure count: does NOT create a declaration file!
;}
;
;{ PureBasic IDE Tools Setup:
; Tools-> Configure Tools
; "New"
; Point To the executable
; Select arguments (see CLI usage above)
; -I use "-f %FILE", which means I have To
; a)be actively on the main source file when the tool is ran
; b)have it saved already
; -"-f %TEMPFILE" would do the same As %FILE, except the file would Not have To be saved
; -no arguments will open the GUI
;
; Give it a name "Declarations Creator"
;
; Event To trigger the tool
; -Menu Or Shortcut
; -will only be triggered manually
; -Before Compile/RUn
; -useful, be sure file is saved, Or use %tempfile above.
; -main file must be selected!
; -Before Create Executable, same As above!
;}
;}
;
; --------------------------------------
;{ Creative Commons
; PuB Declaration Creator by Jon Robbins is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License
; This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ Or send a letter To Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
; URL = http://creativecommons.org/licenses/by-sa/3.0/us/
; Permissions beyond the scope of this license may be available at http://jrob.co.cc
;
; Basically.... share the code if you think it is useful, basically. Just give me some credit :-)
;}
; --------------------------------------
;} /About Info
;Constants
#True = 1
#False = 0
;Global variables
Global MainFile.s
Global outFile.s
Global nProgramLines.i
Global nProgramProcedures.i
;options
Global runQuiet.i
Global DblSpace.i
Global ignoreDecsFile.i
Global OnlyCountStats.i
;################################
;{ Common procedures
Procedure.i FileExists(fname.s)
; -1: File Not found.
; -2: File is a directory.
Define result.q
result = FileSize(fname)
If result >=0
ProcedureReturn result
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure.s TrimComments(s.s, Commenter.s = "!")
Protected pos.i ;, Length.l
s=Trim(s)
pos = FindString(s, Commenter,1)
If pos = 0
;no comments
ProcedureReturn s
ElseIf pos = 1 ;whole line is a comment
ProcedureReturn "" ;return blank line
EndIf
ProcedureReturn Trim(Left(s, pos - 1))
EndProcedure
Procedure ReadFile2Array(Array sarr.s(1), fname.s, RemoveComments.i = #False, Commenter.s = "!")
;trond's take on the readfile2array proc.
;reads in the entire file at once, before using pointers to look at the string in memory, split it at the correct places and put the lines into the array:
;Forum link: http://www.purebasic.fr/english/viewtopic.php?f=13&t=40675&start=0
Protected Length, n.l
Protected File.s
Protected *Memory.Character, *Linestart
Protected I
Protected JumpCR.i
If ReadFile(0, fname)
Length = Lof(0)
File = Space(Length)
ReadData(0, @File, Length) ; Read in the entire file at once
CloseFile(0)
n=CountString(File, #LF$)-1
Dim sarr(n)
*Memory = @File
*Linestart = *Memory
While *Memory\c
;Read until linefeed
If *Memory\c <> #LF
*Memory + 1
Else
; Handle the optional CR part of CRLF
*Memory - 1
If *Memory\c = #CR
JumpCR = 1
Else
*Memory + 1
JumpCR = 0
EndIf
; Copy string into array
If RemoveComments
;Trim out the whitespace and any comments, leading or trailing
sarr(I) = TrimComments(PeekS(*Linestart, *Memory-*Linestart),Commenter)
Else
;just trim the whitespace
sarr(I) = Trim(PeekS(*Linestart, *Memory-*Linestart))
EndIf
*Linestart = *Memory+1 + JumpCR
*Memory + 2 + JumpCR
If (sarr(I) <> "") : I + 1 : EndIf ;overwrite blank strings
EndIf
Wend
If n > (I-1)
;This means that blank lines were present, and overwritten.
;ReDimming will shorten the array, and eliminate the white space.
ReDim sarr(I-1)
EndIf
EndIf
EndProcedure
Procedure.i explodeStrArray(Array sArr.s(1), string.s,separator.s = ",", limit.l = 0) ; String to Array
;From Flype's Functions - http://www.purebasic.fr/english/viewtopic.php?t=21495
;takes a list of delimited string and explodes out into an array
Protected index.l, size.l = CountString(string, separator)
If (limit > 0)
size = limit - 1
ElseIf (limit < 0)
size + limit
EndIf
ReDim sArr.s(size)
For index = 0 To size
sArr(index) = StringField(string, index + 1, separator)
Next
ProcedureReturn size
EndProcedure
Procedure StoreFields (Array arr.s(1), sline.s, del.s = ",", limit.l = 0)
Protected i.l, uB.l
uB = explodeStrArray(arr(),sline,del)
For i = 0 To uB
arr(i) = Trim(arr(i))
Next i
EndProcedure
Procedure.s strTrim (s.s)
Define l.s, r.s
Define addChr.s
addChr = " "
Repeat
; 'grab first and last character
l = Left(s, 1)
r = Right(s, 1)
If l = #TAB$ Or l = " " Or l = "~" Or l = addChr
; 'if left character is one of these then strip it off ...loop continues
s = Mid(s, 2)
Else
; 'no more left side characters to strip off so now work on right side
If r = #TAB$ Or r = " "
; 'if right character is one of these then strip it off ...loop continues
s = Left(s, Len(s) - 1)
Else
; 'no more right side characters to strip off so exit the loop
Break
EndIf
EndIf
ForEver
;return the result
ProcedureReturn s ;return value
EndProcedure
Procedure.s GetStrBetween (WholeString.s, FirstVal.s, SecondVal.s)
WholeString = Right(WholeString, Len(WholeString) - (FindString(WholeString, FirstVal,1) + Len(FirstVal) - 1))
ProcedureReturn Left(WholeString, (FindString(wholeString, SecondVal,1) - 1))
EndProcedure
Procedure.s SelectFile(FilterMode.s = "", defaultDir.s = "C:\Testdata\")
Protected fname.s, fileFilter.s
Protected i.i, count.i
Select UCase(FilterMode)
Case "CS"
fileFilter = "CS Files (*.cs)|*.cs;*.*"
Case "SPEC"
fileFilter = "PRD/Spec (*.xls, *.xlsx, *.spec)|*.xls;*.xlsx;*.spec"
Case "DATA"
fileFilter = "Data Files (*.csv, *.asdb, *.asdb.zip)|*.csv;*.asdb;*.asdb.zip"
Case "TP"
fileFilter = "TP Files (*.tp)|*.tp"
Default
fileFilter = "All Files (*.*)|*.*"
EndSelect
fname = OpenFileRequester("Select " + FilterMode + " file", defaultDir, fileFilter, 0)
If fileExists(fname) >0 Or fname="" ;valid file, or cancel selected
ProcedureReturn fname
Else
MessageRequester(#AppTitle,"Please select a valid file")
ProcedureReturn ""
EndIf
EndProcedure
Procedure.s MyNow(mode.s = "YY.MM.DD")
mode = UCase(mode)
; Debug FormatDate("Y=%yyyy, M= %mm, D=%dd", Date()) ; Will display the actual date in
; ; the form "Y=2002, M=10, D=03"
;
; Debug FormatDate("%hh:%ii:%ss", Date()) ; Will display the time using the 00:00:00 format
Select mode
Case "DATE-TIME"
ProcedureReturn FormatDate("%yyyy%mm%dd%hh%ii%ss",Date())
Case "YYMMDD"
ProcedureReturn Str(Year(Date())) + Str(Month(Date())) + Str(Day(Date()))
Case "YYYY.MM.DD"
ProcedureReturn FormatDate("%yyyy.%mm.%dd",Date())
Default ;Case "YY.MM.DD"
ProcedureReturn FormatDate("%yy.%mm.%dd",Date())
EndSelect
EndProcedure
Procedure.s GetEXEdir()
Protected.s appdir$
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Protected.s a$
a$=Space(999) : GetModuleFileName_(0,@a$,999) : appdir$=GetPathPart(a$)
CompilerCase #PB_OS_Linux
appdir$ = GetHomeDirectory()
CompilerDefault
ProcedureReturn ""
CompilerEndSelect
ProcedureReturn appdir$
EndProcedure
Procedure.s GoBackOneDir(path.s)
Protected *Start.Character, *Stop.Character
Protected cSlash.c
*Start = CountString(path,"/")
*Stop = CountString(path,"\")
If *Start > *Stop
cSlash = '/'
Else
cSlash = '\'
EndIf
*Start = @path
*Stop = *Start + Len(path) -1
If *stop < *Start
ProcedureReturn ""
EndIf
If *Stop\c = cSlash
*Stop -1
EndIf
While *Stop And *Stop\c <> cSlash ;eliminate extra chars from the back
*Stop -1
Wend
ProcedureReturn PeekS(*Start,*Stop-*Start+1)
EndProcedure
Procedure.i StrArrayPosition(Array arr.s(1), value.s, CaseSensitive.i = #False)
; '=============================================================
; 'Searches array for value
; ' Returns Location of value if value is in array. -1 if not.
; '=============================================================
Protected i.l
If Not CaseSensitive
For i = 0 To ArraySize(arr()) Step 1
If LCase(arr(i)) = LCase(value)
ProcedureReturn i
EndIf
Next i
Else
For i = 0 To ArraySize(arr()) Step 1
If arr(i) = value
ProcedureReturn i
EndIf
Next i
EndIf
;'if this is accessed, then end of array was reached without finding the value
ProcedureReturn -1
EndProcedure
Procedure.i EnterDataInStrArray(Array arr.s(1),value.s, count.l)
Protected i.l
i = StrArrayPosition(arr(), value)
If i <0
If count > ArraySize(arr())
ReDim arr(count)
EndIf
arr(count) = value
count+1
EndIf
ProcedureReturn count
EndProcedure
Procedure.i ListEntryIsUnique_Str(List l.s(), entry.s)
If ListSize(l()) <=0
ProcedureReturn 1 ;entry is unique
EndIf
ResetList(l())
ForEach l()
If l() = entry
ProcedureReturn 0 ;non-unique
EndIf
Next
ProcedureReturn 1 ;entry is unique
EndProcedure
Procedure.i CrawlForIncludes(Array FileNames.s(1), mainPB.s)
;search for IncludeFile or XIncludeFile
;and builds file list in Array
; -- only lists each file once
Protected.s mainDir, sLine, dir
Protected.i i, lineCount
Protected Dim tempFiles.s(0)
Protected Dim sFile.s(0)
Protected.i fCount, *currElement, *newestElement
;{ Sample Includes from file:
; -----------------------
; XIncludeFile "modules\AS_Globals.pbi"
; XIncludeFile "modules\declarations.pbi"
;
; XIncludeFile "as_gui.pb"
; xincludefile "..\blah"
; IncludePath "modules\"
; XIncludeFile "window_events.pbi"
; XIncludeFile "AS_UI_mod.pbi"
; XIncludeFile "common_functions.pbi"
; XIncludeFile "database_mod.pbi"
; XIncludeFile "filesys_mod.pbi"
; XIncludeFile "cust_samp.pbi"
; XIncludeFile "string_functions.pbi"
; XIncludeFile "array_functions.pbi"
; XIncludeFile "math.pbi"
; XIncludeFile "file_conversion.pbi"
;} -----------------------
NewList pFiles.s()
AddElement(pFiles())
pFiles()=mainPB ;set first element to main file
mainDir= GetPathPart(mainPB)
dir = mainDir
*currElement= 0
*newestElement = 0
nProgramLines = 0
nProgramProcedures = 0
ForEach pFiles()
*currElement = @pFiles()
If Not *newestElement
*newestElement = *currElement
EndIf
ReadFile2Array(sFile(),pFiles(),1,";")
dir = GetPathPart(pFiles())
nProgramLines = nProgramLines + ArraySize(sFile()) ;increment global program lines counter
For lineCount = 0 To ArraySize(sFile())
sLine = sFile(lineCount)
If FindString(Left(sLine,12),"IncludeFile",1)>0 ;or "XIncludeFile"
sline = GetStrBetween(sline,#DQUOTE$,#DQUOTE$)
While FindString(sline,"..",1)>0
;would go up one directory
dir = GoBackOneDir(dir)
sline = Right(sline,Len(sline)-FindString(sline,#Slash,1))
Wend
If (ignoreDecsFile= #False And sline = outFile) Or Not sline = outFile ;ignore declarations file, unless forced
If ListEntryIsUnique_Str(pFiles(), dir + sLine)
AddElement(pFiles())
pFiles() = dir + sline
*newestElement = @pFiles()
EndIf
EndIf
ElseIf FindString(Left(sLine,12),"IncludePath",1)>0
sline = GetStrBetween(sline,#DQUOTE$,#DQUOTE$)
;change dir
If Left(sline,2) <> ".."
dir = dir + sline
Else
While FindString(sline,"..",1)>0
;would go up one directory
dir = GoBackOneDir(dir)
sline = Right(sline,Len(sline)-FindString(sline,#Slash,1))
Wend
dir = dir + sline
EndIf
ElseIf FindString(Left(sline,10),"Procedure ",1) Or FindString(Left(sLine,10),"Procedure.",1)
nProgramProcedures +1 ;increment global program procedures counter
EndIf
Next lineCount
ChangeCurrentElement(pFiles(),*currElement)
;SelectElement(pFiles(),currElement) ;with foreach/next, select element needs to happen BEFORE increment. NEXT also increments
Next ;element of list
;now transfer list to array,
;no reason other than the CreateDeclares Procedure calls For an Array
; also, when crawling we have no idea how many files there will be, so a list fits the bill perfectly.
SortList(pFiles(),#PB_Sort_Ascending)
FirstElement(pFiles())
fCount=0
Dim FileNames(ListSize(pFiles())-1)
ForEach pFiles()
FileNames(fCount) = pFiles()
fCount+1
;fCount = EnterDataInStrArray(FileNames(),pFiles(),fCount)
Next
ClearList(pFiles())
ProcedureReturn 1
EndProcedure
Procedure CreateDeclares(Array FileNames.s(1), prefix.s, nOutputGadget.i, OverWriteDuplicates.i = #False, isCLI.i =#False)
Protected fCount.i,z.i
Protected path.s, fname.s, outFile.s
Protected linecount.l
Protected sLine.s
Protected Dim sFile.s(0)
Protected ofn.i
Protected oCount.l
For fCount = 0 To ArraySize(FileNames())
path = GetPathPart(FileNames(fCount))
fname = GetFilePart(filenames(fCount))
If fCount = 0
outfile = path + "declarations.pbi"
EndIf
If FileExists(filenames(fCount))
oCount = 0
ReadFile2Array(sFile(),FileNames(fCount),#True,";") ;store file to array
For linecount = 0 To ArraySize(sFile())
sline = sFile(linecount)
If FindString(Left(sline,10),"Procedure ",1) Or FindString(Left(sline,10),"Procedure.",1)
If ofn=0
If FileExists(outFile)
If OverWriteDuplicates= #False
z = MessageRequester(#AppTitle,"File exists, overwrite?" + #NL + outFile,#PB_MessageRequester_YesNoCancel)
Else
z = #PB_MessageRequester_Yes
EndIf
If z = #PB_MessageRequester_No
z=1
While FileExists(outFile)
outfile = path + "declarations" + Str(z) + ".pbi"
z+1
Wend
ElseIf z = #PB_MessageRequester_Cancel
Goto Done
EndIf
EndIf
;create output file
ofn = CreateFile(#PB_Any,outFile)
If ofn
If isCLI = #False
SetGadgetText(nOutputGadget,outFile)
EndIf
WriteStringN(ofn, ";Automatically generated Declarations file")
WriteStringN(ofn, ";Created by " + #AppTitle + " v" + AppVersion)
WriteStringN(ofn, "; Date Created: " + mynow("YYYY.MM.DD"))
WriteStringN(ofn, ";One Declare file from " + Str(ArraySize(filenames()) +1 ) + " sources")
WriteStringN(ofn, "; (nothing is written if there is nothing to declare in a selected file)")
WriteStringN(ofn,";----------------------")
WriteStringN(ofn,";Additional Info:")
WriteStringN(ofn,"; Number of total compilable lines in source code: " + Str(nProgramLines))
WriteStringN(ofn,"; Number of procedures in source code: " + Str(nProgramProcedures))
WriteStringN(ofn,";-------------------------------------------------------------------------------")
WriteStringN(ofn, "")
EndIf
EndIf
If ofn
If DblSpace
WriteStringN(ofn, "")
EndIf
If oCount=0
WriteStringN(ofn,";- Src= " + GetFilePart(FileNames(fCount)) + " ------------------------------------------")
WriteStringN(ofn, ";{ Src= " + FileNames(fCount))
EndIf
sline = ReplaceString(sLine,"Procedure","Declare")
WriteStringN(ofn, sLine)
EndIf
oCount +1
EndIf ; "Procedure" found
sFile(linecount)=""
Next linecount
If ofn
If oCount > 0
WriteStringN(ofn, ";} /Src= " + FileNames(fCount))
WriteStringN(ofn,"; -----------------------------------------------------------------")
WriteStringN(ofn,"")
EndIf
EndIf
EndIf
Dim sFile(0)
Next fCount
If ofn : CloseFile(ofn) : EndIf
If isCLI = #False
MessageRequester(#AppTitle,"Finished!" + #NL + #NL + "Total Lines: " + Str(nProgramLines) + #NL + "Number of procedures: " + Str(nProgramProcedures))
EndIf
ProcedureReturn
Done:
If ofn : CloseFile(ofn) : EndIf
MessageRequester(#AppTitle,"User Exited")
EndProcedure
;}
; ########################################################################################
Define Overwrite.i
Define opt.s
Define nOpts.i, i.i
Dim Fnames.s(0)
;set defaults
Overwrite = 1
outFile = "declarations.pbi"
runQuiet = #False
DblSpace = #False
ignoreDecsFile= #True
OnlyCountStats = #False
;-{ CLI (non-GUI) operations
nOpts = CountProgramParameters() -1
opt = ProgramParameter()
If opt
For i = 0 To nOpts
opt = ProgramParameter(i)
Select opt
Case "-f" ;read main file
i+1 ;increment
opt=ProgramParameter(i)
If Not opt Or Not FileExists(opt)
MessageRequester("Error: Declarations Creator","error, invalid CLI option: " + opt)
End
EndIf
MainFile =opt
Case "-o" ;set output file name
i+1 ;increment
opt=ProgramParameter(i)
If Not opt Or Not FileExists(opt)
MessageRequester("Error: Declarations Creator","error, invalid CLI option: " + opt)
End
EndIf
outFile = opt
Case "-u" ;unique file name, don't overwrite existing
Overwrite = 0
Case "-q"
runQuiet = #True
Case "--dblspc"
DblSpace = #True
Case "--readdec"
ignoreDecsFile=#False
Case "-c" ;count lines and procedures only
OnlyCountStats = #True
Default
;skip?
EndSelect
Next i
If FileExists(GetPathPart(MainFile) + outFile) And Overwrite = #False ;make unique
outFile = MyNow("date-time") + "_" + outFile
EndIf
If CrawlForIncludes(Fnames(),MainFile)
;CountLinesAndProcs(Fnames())
If OnlyCountStats
MessageRequester(#AppTitle,"Total lines in source code: " + Str(nProgramLines) + #NL + "Number of procedures: " + Str(nProgramProcedures))
Else
CreateDeclares(Fnames(), outFile,0, Overwrite,#True)
If Not runQuiet
MessageRequester(#AppTitle, "Declarations file created: " + #NL + GetPathPart(MainFile) + outFile)
EndIf
EndIf
Else
MessageRequester(#AppTitle, "error!")
EndIf
End
EndIf
;}
;{- Enumerations
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Menu bars
Enumeration
#Menu_Window_0
EndEnumeration
;}
;{ Menu/Toolbar items
Enumeration
#Menu_Window_0_Exit
#Menu_Window_0_About
EndEnumeration
;}
;{ Gadgets
Enumeration
#BN_SelFiles
#BN_Clear
#BN_CreateDeclares
#BN_Exit
#STR_prefix
#Text_5
#CHK_Overwrite
#Text_10
#str_mainFile
#str_outFile
EndEnumeration
;}
;}
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 502, 116, 610, 175, #AppTitle, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If CreateImageMenu(#Menu_Window_0, WindowID(#Window_0), #PB_Menu_ModernLook)
MenuTitle("File")
MenuItem(#Menu_Window_0_Exit, "E&xit")
MenuTitle("Help")
MenuItem(#Menu_Window_0_About, "About")
EndIf
ButtonGadget(#BN_SelFiles, 5, 50, 125, 25, "Select MAIN File")
ButtonGadget(#BN_Clear, 135, 50, 160, 25, "Clear")
ButtonGadget(#BN_CreateDeclares, 475, 35, 125, 40, "Create Declares")
ButtonGadget(#BN_Exit, 475, 5, 125, 25, "Exit")
StringGadget(#STR_prefix, 135, 10, 165, 20, "declarations.pbi")
TextGadget(#Text_5, 5, 10, 125, 20, "Output file name:")
CheckBoxGadget(#CHK_Overwrite, 315, 50, 145, 25, "Overwrite Duplicates")
;CheckBoxGadget(#CHK_OneFile, 315, 20, 155, 20, "Merge all declares into 1 file")
TextGadget(#Text_10, 10, 105, 80, 20, "Outfile(s):")
StringGadget(#str_mainFile, 5, 80, 600, 20, "")
StringGadget(#str_outFile, 5, 125, 600, 20, "")
;:PureFORM:Window_0_1:End:
; Your code here ...
SetWindowTitle(#Window_0,"PB Declaration Creator [v" + AppVersion + "]")
;SetGadgetState(#CHK_OneFile,#PB_Checkbox_Checked)
SetGadgetState(#CHK_Overwrite,#PB_Checkbox_Checked)
;DisableGadget(#STR_prefix,1) ;disable prefix (w/ onefile)
;
;:PureFORM:Window_0_2:Start:
EndIf
EndProcedure
Procedure ExitProg()
CloseWindow(#Window_0)
End
EndProcedure
Define.i Event, EventGadget, EventType, EventMenu
OpenWindow_Window_0()
;-{ Event loop/ GUI operations
Repeat
Event = WaitWindowEvent()
;:PureFORM:Loop:Start:
Select Event
; ///////////////////
Case #PB_Event_Gadget
;{ Gadget Events
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #BN_SelFiles
If EventType = #PB_EventType_LeftClick
MainFile = SelectFile("",GetEXEdir())
If FileExists(MainFile)
SetGadgetText(#str_mainFile,MainFile)
Fnames(0) = MainFile
Else
MessageRequester(#AppTitle,"File does not exist: " + #NL + MainFile)
SetGadgetText(#str_mainFile,"")
EndIf
EndIf
ElseIf EventGadget = #BN_Clear And EventType = #PB_EventType_LeftClick
MainFile = ""
Dim Fnames(0)
SetGadgetText(#str_mainFile,"")
SetGadgetText(#str_outFile,"")
ElseIf EventGadget = #BN_CreateDeclares And EventType = #PB_EventType_LeftClick
If FileExists(Fnames(0))
If GetGadgetState(#CHK_Overwrite) = #PB_Checkbox_Checked
Overwrite = #True
Else
Overwrite= #False
EndIf
CrawlForIncludes(Fnames(),MainFile)
;CountLinesAndProcs(Fnames())
CreateDeclares(Fnames(), GetGadgetText(#STR_prefix),#str_outFile, Overwrite)
Else
MessageRequester(#AppTitle,"Please select one or more files")
EndIf
ElseIf EventGadget = #STR_prefix
ElseIf EventGadget = #BN_Exit And EventType = #PB_EventType_LeftClick
ExitProg()
EndIf
;} /Gadget Events
; /////////////////
Case #PB_Event_Menu
;{ Menu Events
EventMenu = EventMenu()
If EventMenu = #Menu_Window_0_Exit
ExitProg()
ElseIf EventMenu = #Menu_Window_0_About
MessageRequester(#AppTitle + " [" + AppVersion + "]",AppAbout)
EndIf
;} /Menu Events
; ////////////////////////
Case #PB_Event_CloseWindow
ExitProg()
EndSelect
;:PureFORM:Loop:End:
ForEver
;
;}