McDeeD Posted December 9, 2009 Share Posted December 9, 2009 Hi there,I am new to this forum and need some help I couldn't find by using search function or FAQ.This nice piece of code by Thorsten shows an interesting way to describe each function. Just as in AutoIt original *.au3 files there is following header structure:expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _FileCountLines ; Description ...: Returns the number of lines in the specified file. ; Syntax.........: _FileCountLines($sFilePath) ; Parameters ....: $sFilePath - Path and filename of the file to be read ; Return values .: Success - Returns number of lines in the file. ; Failure - Returns a 0 ; @Error - 0 = No error. ; |1 = File cannot be opened or found. ; Author ........: Tylo <tylo at start dot no> ; Modified.......: Xenobiologist, Gary ; Remarks .......: It does not count a final @LF as a line. ; Related .......: ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _FileCountLines($sFilePath) ;~ Local $N = FileGetSize($sFilePath) - 1 ;~ If @error Or $N = -1 Then Return 0 ;~ Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1 Local $hFile, $sFileContent, $aTmp $hFile = FileOpen($sFilePath, 0) If $hFile = -1 Then Return SetError(1, 0, 0) $sFileContent = StringStripWS(FileRead($hFile), 2) FileClose($hFile) If StringInStr($sFileContent, @LF) Then $aTmp = StringSplit(StringStripCR($sFileContent), @LF) ElseIf StringInStr($sFileContent, @CR) Then $aTmp = StringSplit($sFileContent, @CR) Else If StringLen($sFileContent) Then Return 1 Else Return SetError(2, 0, 0) EndIf EndIf Return $aTmp[0] EndFunc ;==>_FileCountLinesIs there a way to automatically insert that header into my code? Or is it just copy and paste?Cheers,Mc Link to comment Share on other sites More sharing options...
BugFix Posted December 9, 2009 Share Posted December 9, 2009 If you use SciTE than type in: setupudf and than an space. Now you get an predefined function header. You can change this in file "abbrev.properties". Best Regards BugFix Link to comment Share on other sites More sharing options...
McDeeD Posted December 9, 2009 Author Share Posted December 9, 2009 (edited) Now that is sweet! Thanks a lot, Bugfix.Edit: I've found a quite useful link with all current abbreviations available. Enjoy! Edited December 9, 2009 by McDeeD Link to comment Share on other sites More sharing options...
taietel Posted April 11, 2010 Share Posted April 11, 2010 (edited) I wrote a script for that, which extracts the functions from a file and put them in another one, in the current directory. First it generates a list with all the functions and then the header. I'm new to this forum but I have to say that AutoIt is a wonderful tool!!! expandcollapse popup#include <Array.au3> #include <String.au3> #include <Date.au3> ;Description: This script will extract the functions from an .au3 file to a new one ; and it generates a list and header for those. ;Useful for UDF's ;taietel@yahoo.com Local $numefunc, $autorfunc, $modificatfunc, $link, $exemplufunc $autorfunc = "taietel@yahoo.com" ;<-- replace here $modificatfunc = _Now() ;<-- replace here $link = "@@MsdnLink@@" ;<-- replace here $exemplufunc = "No" ;<-- replace here Local $titluopen = "Choose .au3 file..." Local $fisierul = FileOpenDialog($titluopen, @ScriptDir & "\", "AutoIt File (*.au3)", 1) If @error Then MsgBox(48, "We have a problem...", "You have to choose a file first!") Else Local $parametri Local $fisier = FileRead($fisierul) Local $antetfunctie = StringRegExp($fisier, "(?-i:(Func (.*(?:[)]))))", 4) Local $corpfunctie = _StringBetween($fisier, "Func", "EndFunc") Local $efx = "; #CURRENT# =================================================================================" & @CRLF Local $functia ;the new file which will store the extracted functions (you may want to save it elsewhere, ;or append it or ...): Local $funcsalvate = FileOpen(@ScriptDir & "\" & "ExtractedFunctions.au3", 2) For $i = 0 To UBound($antetfunctie) - 1 $a = $antetfunctie[$i] $end = StringSplit(StringTrimLeft($a[0], 5), "(") $parametri = "" $pp = StringSplit($a[0], "(") $ppp = StringSplit(StringReplace($pp[2], ")", ""), ",") For $py = 1 to UBound($ppp)-1 $parametri &= StringStripWS($ppp[$py], 8) & " - " & @CRLF & "; " Next $functia &= Antet($end[1], StringTrimLeft($a[0], 5), $parametri) $functia &= "Func" $functia &= $corpfunctie[$i] $functia &= "EndFunc ;==>" & $end[1] & @CRLF & @CRLF $efx &= "; " & $end[1] & @CRLF Next $efx &= ";============================================================================================" & @CRLF & @CRLF FileWrite($funcsalvate, $efx & @CRLF & $functia) FileClose($fisier) FileClose($funcsalvate) ShellExecute("ExtractedFunctions.au3") EndIf Func Antet($numefunctie, $syntax, $paramfunc) Local $antetfunc = "; #FUNCTION# ================================================================================" & @CRLF $antetfunc &= "; Name............: " & $numefunctie & @CRLF $antetfunc &= "; Description ....: " & @CRLF $antetfunc &= "; Syntax..........: " & $syntax & @CRLF $antetfunc &= "; Parameters .....: " & $paramfunc & @CRLF $antetfunc &= "; Return value(s).: Success - " & @CRLF $antetfunc &= "; Failure - " & @CRLF $antetfunc &= "; Author .........: " & $autorfunc & @CRLF $antetfunc &= "; Modified........: " & $modificatfunc & @CRLF $antetfunc &= "; Remarks ........: " & @CRLF $antetfunc &= "; Related ........: " & @CRLF $antetfunc &= "; Link ...........: " & $link & @CRLF $antetfunc &= "; Example ........: " & $exemplufunc & @CRLF $antetfunc &= ";============================================================================================" & @CRLF Return $antetfunc EndFunc ;==>Antet I put the file in attachment for fast downloading. Edited April 11, 2010 by taietel Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now