Jump to content

Function Name Lister 06/27/2014


jaberwacky
 Share

Recommended Posts

Hi. Have you ever tried to manually maintain a list of function names for your various projects? What I mean is when you start an AutoIt project you might have tried to maintain a running list of all of the functions that are in your project. This is fine when your project is small. When the project grows out of control then you may be like me and you simply stop maintaining that list. So I am hacking together a simple script to automate that process.

Instructions:
1) Paste this into your user options file (Scite -> Options -> Open User Options File):

# 37 FunctionNameLister
command.37.$(au3)="$(SciteDefaultHome)\FunctionNameLister\FunctionNameLister.exe" "$(FilePath)"
command.name.37.$(au3)=FunctionNameLister
command.shortcut.37.$(au3)=Ctrl+Shift+Alt+f
command.save.before.37.$(au3)=1
command.is.filter.37.$(au3)=1

    Note: the number 37 may be changed to a number which suits you.

2) Create a folder named FunctionNameLister in the "...AutoIt3SciTE" directory.

3) Place the FunctionNameLister.exe into the folder that was created in step 2.

    FunctionNameLister.zip

        downloads:26

4) Browse to an AutoIt source. Paste the following two lines wherever you would like for your list of function names to appear in your source:

#region ; Functions
#endregion ; Functions

    Press Ctrl + Shift + Alt + f.

Updates:

[06/27/2014] -- A: Fixed a fairly obvious bug.

B: Implemented features as requested by mLipok and added more error checking.

[06/23/2014] -- OK.  A version which seems to work well and consistently.

[08/09/2013] -- Fixed bugs.  Actually works now.

[01/19/2013] -- Fairly major refactoring.

[04-01-2012] -- Code cleanup.

[12-10-2011] -- Cleaned up the code considerably.

[01-29-2011] -- Minor bug fixes and source code improvements. Modified the tag ever so slightly. Sort ordering now works correctly.

[01-26-2011] -- The most exciting update yet! Fixed an issue with the list when Tidy was used that caused the first function to be printed twice. Now you can simply insert the tag were you want the list to appear and then press Ctrl + Shift + Alt + f. No more browsing to your source through a file dialog! Yes, I did lean on Xenobiologist's OrganizeIncludes.au3 fairly heavily. There are still some issues though so just erase the list leaving the tag in place when ever you run this script.

[01-10-2011] -- Now pastes the function list wherever you want the list to appear! I finally got around to updating this script as I had promised many moons ago. To use this just put this tag wherever you want to list to show up: ";**** Begin Function Name List". You can customize the tag too. This needs a bit of work and it's a big mess but it's usable.

[10-16-2010] Now pastes the function list to the bottom of your au3. Also copies the list to your clipboard.

Here is just the main code for those interested.  The zip file contains the required exe.

#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d -q

#Region ; Functions
; alert
; backup_original_copy
; create_function_list_string
; erase_function_list
; file_stream_read_line
; get_source_path
; main
; write_function_list_to_string
#EndRegion ; Functions

#include-once

#include "SciTE Director.au3"

#include <Array.au3>

#include <File.au3>

#include <String.au3>

; These tags are required to be in the au3 source in order for FunctionNameLister to work properly.  
; They may be changed by editing the settings.ini file.
Const $tag_begin = IniRead(@ScriptDir & "\settings.ini", "Tags", "TagBegin", "#Region ; Functions")
Const $tag_end   = IniRead(@ScriptDir & "\settings.ini", "Tags", "TagEnd",   "#EndRegion ; Functions")

; Constants for FileStream functionality.
Const $file_stream_eof         = -1
Const $file_stream_other_error = 1

main()

Switch @error
  Case 0
    alert("FunctionNameLister was successful.")
    
  Case 1
    alert("You must provide a path to an au3 source.", True)
    
  Case 2
    alert("Could not make a back up of the original file.", True)
    
  Case 3
    alert("Could not find the required tags.", True)
EndSwitch

Func main()
  Local Const $source_path = get_source_path()
 
  If @error Then    
    Return SetError(1, 0, False)
  EndIf
 
  Switch backup_original_copy($source_path)
    Case True
      Local Const $autoit_source = erase_function_list($source_path)

      ; find the function names and write them to an array -- thanks Yashied
      Local Const $func_list = StringRegExp(StringRegExpReplace($autoit_source, "(?ims)#c[^#]+#c", ''), "(?ims)^\s*func\s*([^(]*)", 3)

      Local Const $func_string = create_function_list_string($func_list, True)

      Local Const $file_overwrite = FileOpen($source_path, $FO_OVERWRITE)

      Switch $file_overwrite <> -1
        Case True
          Local Const $new_au3 = write_function_list_to_string($func_string, $autoit_source)
          
          If @error Then
            Return SetError(3, 0, False)
          EndIf
          
          FileWrite($file_overwrite, $new_au3)

          FileClose($file_overwrite)

          scite_close($source_path)

          scite_open($source_path)
      EndSwitch

    Case False
      Return SetError(2, 0, False)
  EndSwitch

  Return True
EndFunc

Func get_source_path()
  Local $source_path
 
  Select
    Case UBound($cmdline) <= 1
      $source_path = FileOpenDialog("Browse to an au3 source.", '', "AU3 (*.au3)" )
      
      If @error Then
        Return SetError(1, 0, False)
      EndIf
      
    Case Else
      $source_path = $cmdline[1]
  EndSelect
 
  Return $source_path
EndFunc

Func backup_original_copy(Const $source_path)
  Local $drive, $dir, $name, $ext

  _PathSplit($source_path, $drive, $dir, $name, $ext)

  Local Const $backup_path = _PathMake($drive, $dir, $name, ".BAK")

  Return FileCopy($source_path, $backup_path, 1) ? True : SetError(1, 0, False)
EndFunc

Func write_function_list_to_string(Const $func_string, Const $autoit_source)
  Local Const $tag_position = StringInStr($autoit_source, $tag_begin)
 
  If Not $tag_position Then
    Return SetError(1, 0, False)
  EndIf
 
  Local Const $tag_length = StringLen($tag_begin)

  Local Const $insert_string = ((StringInStr($func_string, $tag_end) > 0) ? $func_string : ($func_string & $tag_end))

  Return _StringInsert($autoit_source, $insert_string & @CRLF, ($tag_position + $tag_length + 1))
EndFunc

Func create_function_list_string($func_array, Const $sort)
  If Not IsArray($func_array) Then Return SetError(1, 0, False)

  If $sort Then _ArraySort($func_array, 0)

  Local $func_string = ''

  For $function In $func_array
    $func_string &= "; " & $function & @CRLF
  Next

  Return $func_string
EndFunc

Func erase_function_list(Const $source_path)
  Local $line = ''

  Local $autoit_source = ''

  Local $within_func_list = False

  Do
    $line = file_stream_read_line($source_path)

    Switch @error
      Case 0
        Switch $line
          Case $tag_begin
            $within_func_list = True
            $autoit_source &= $tag_begin & @CRLF
            ContinueLoop

          Case $tag_end
            Switch $within_func_list
              Case True
                $within_func_list = False
                ContinueLoop
            EndSwitch
        EndSwitch

      Case $file_stream_eof, $file_stream_other_error
        ExitLoop
    EndSwitch

    Switch $within_func_list
      Case False
        $autoit_source &= $line & @CRLF

      Case True
        Select
          Case StringLeft($line, 1) <> ';'
            $within_func_list = False
        EndSelect
    EndSwitch
  Until False

  Return $autoit_source
EndFunc

Func file_stream_read_line(Const $path)
  Local Const $file_stream_close      = -2
  Local Const $file_stream_ready      = -3
  Local Const $file_stream_open_error = -1

  Local Static $file_open = FileOpen($path, $FO_READ)

    Switch $path
        Case $file_stream_close
      FileClose($file_open)
      $file_open = $file_stream_ready
      Return True
    EndSwitch

  Select
        Case $file_open = $file_stream_open_error
            $file_open = $file_stream_ready
            Return SetError(2, 1, False)

        Case $file_open = $file_stream_ready
      $file_open = FileOpen($path, $FO_READ)

      Switch $file_open
                Case $file_stream_open_error
                    $file_open = $file_stream_ready
          Return SetError(2, 2, False)
      EndSwitch

      ContinueCase

    Case $file_open >= 0
      Local Const $file_line = FileReadLine($file_open)

      Switch @error
        Case 0
          Return $file_line

        Case $file_stream_eof
          FileClose($file_open)
          $file_open = $file_stream_ready
          Return SetError($file_stream_eof, 0, False)

        Case $file_stream_other_error
          FileClose($file_open)
          $file_open = $file_stream_ready
          Return SetError($file_stream_other_error, 0, False)
            EndSwitch
  EndSelect
EndFunc

Func alert(Const $message, Const $error = False)
  Switch @Compiled
    Case True
      Switch $error          
        Case False
          MsgBox($MB_OK, "FunctionNameLister", $message)
          
        Case True
          MsgBox($MB_OK + $MB_ICONERROR, "FunctionNameLister", $message)
      EndSwitch
      
    Case False
      Switch $error          
        Case False
          ConsoleWrite(@CRLF & "> " & $message & @CRLF & @CRLF)
          
        Case True
          ConsoleWrite(@CRLF & "! " & $message & @CRLF & @CRLF)
      EndSwitch
  EndSwitch
EndFunc
Edited by jaberwacky
Link to comment
Share on other sites

Or you could use tidy to generate a cross reference listing of variables and functions used in the script.

Insert

#Tidy_Parameters=/gd /gds

and press Ctrl-T in SciTE to see what I mean.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This can be done in a single line by using regular expressions.

#Include <Array.au3>

$sPath = FileOpenDialog('Select File', '', 'AutoIt v3 Script (*.au3)', 3)
If $sPath Then
    $aList = StringRegExp(StringRegExpReplace(FileRead($sPath), '(?ims)#c[^#]+#c', ''), '(?ims)^\s*Func\s*([^(]*)', 3)
    _ArrayDisplay($aList)
EndIf
Link to comment
Share on other sites

Or you could use tidy to generate a cross reference listing of variables and functions used in the script.

Insert

#Tidy_Parameters=/gd /gds

and press Ctrl-T in SciTE to see what I mean.

Water, that gave me this:

========================================================================================================
=== Tidy report for :D:\AutoIt\AutoIt Scripts\My Scripts\RegisterDeviceNotifications\RegisterDeviceNotifications.au3
========================================================================================================

00001   #region ;**** Directives created by AutoIt3Wrapper_GUI ****
00002   #AutoIt3Wrapper_UseX64=n
00003   #AutoIt3Wrapper_Res_Description=Registers a device to receive device change notifications.
00004   #AutoIt3Wrapper_Res_Fileversion=0.0.0.0
00005   #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
00006   #AutoIt3Wrapper_Res_Language=1033
00007   #AutoIt3Wrapper_Add_Constants=n
00008   #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
00009   #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -q -d
00010   #AutoIt3Wrapper_Run_Tidy=y
00011   ;~ #Tidy_Parameters=/tc 0 /kv 0
00012   #Tidy_Parameters=/gd /gds
00013   #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
00014   
00015   #include <Misc.au3>
00016   _Singleton(@ScriptName)
00017   
00018   Opt("TrayIconHide", 1)
00019   
00020   #include <WinAPI.au3>
00021   #include <AutoItObject.au3>
00022   #include <FileConstants.au3>
00023   #include <GUIConstantsEX.au3>
00024   #include <RDN Constants.au3>
00025   
00026   #region GUI
00027   Opt("GUIOnEventMode", 1)
00028   
00029   Global Const $hRecipient = GUICreate("USB Handler", 400, 400, -1, -1)
00030   GUISetOnEvent($GUI_EVENT_CLOSE, "term", $hRecipient)
00031   
00032   Global Const $WM_DEVICECHANGE = 0x0219
00033   Global Const $RegisterStatus = GUIRegisterMsg($WM_DEVICECHANGE, "MY_WM_DEVICECHANGE")
00034   
00035   Global Const $EditBox = GUICtrlCreateEdit('', 5, 5, 350, 350)
00036   
00037   Global Const $AllowDenyCheckBox = GUICtrlCreateCheckbox("Check to deny device removal.", 5, 355, 162, 40)
00038   GUICtrlSetState($AllowDenyCheckBox, $GUI_CHECKED)
00039   
00040   GUISetState()
00041   #endregion GUI
00042   
00043   _AutoItObject_Startup()
00044   
00045   HotKeySet("{ESC}", "term")
00046   OnAutoItExitRegister("_exit")
00047   
00048   Global $hDevNotify
00049   Global $DriveLetter
00050   Global $FileHandle
00051   Global $LastError
00052   
00053 +-While 1
00054 |     Sleep(100)
00055 +-WEnd
00056   
00057 +-Func MY_WM_DEVICECHANGE($hWnd, $msg, $wParam, $lParam)
00058 | +-  Switch $msg
00059 | | +-        Case $WM_DEVICECHANGE
00060 | | | +-          Switch $wParam
00061 | | | | +-                Case $DBT_DEVICEARRIVAL
00062 | | | | |                     Local $DeviceType = GetDeviceType($lParam)
00063 | | | | | 
00064 | | | | | +-                  If $DeviceType = $DBT_DEVTYP_VOLUME Then
00065 | | | | | |                           Write("DEVICEARRIVAL")
00066 | | | | | |                           Write("$lParam: " & $lParam)
00067 | | | | | |   
00068 | | | | | |                           Local $UnitMask = GetUnitMask($lParam)
00069 | | | | | |                           Local $tmpDriveLetter = GetDriveLetterFromUnitMask($UnitMask)
00070 | | | | | |   
00071 | | | | | | +-                        Switch @error
00072 | | | | | | | +-                          Case 0
00073 | | | | | | | |                                   $DriveLetter = $tmpDriveLetter
00074 | | | | | | | |   
00075 | | | | | | | |                                   ; open a file on the USB device
00076 | | | | | | | |                                   Local Const $FileHandleTMP = OpenFile("F:\Text.txt")
00077 | | | | | | | |   
00078 | | | | | | | | +-                                Switch @error
00079 | | | | | | | | | +-                                  Case 0
00080 | | | | | | | | | |                                           $FileHandle = $FileHandleTMP
00081 | | | | | | | | | +-                                  Case 1
00082 | | | | | | | | | |                                           Write("OpenDirectory failed.")
00083 | | | | | | | | | |                                           Return True
00084 | | | | | | | | +-                                EndSwitch
00085 | | | | | | | |   
00086 | | | | | | | |                                   Local Const $hDevNotifyTMP = DoRegisterDeviceInterfaceToHwnd($FileHandle, True)
00087 | | | | | | | |   
00088 | | | | | | | | +-                                Switch @error
00089 | | | | | | | | | +-                                  Case 0
00090 | | | | | | | | | |                                           $hDevNotify = $hDevNotifyTMP
00091 | | | | | | | | | +-                                  Case 1
00092 | | | | | | | | | |                                           Return True
00093 | | | | | | | | +-                                EndSwitch
00094 | | | | | | | +-                          Case 1
00095 | | | | | | | |                                   Return True
00096 | | | | | | +-                        EndSwitch
00097 | | | | | +-                  EndIf
00098 | | | | +-                Case $DBT_DEVICEQUERYREMOVE
00099 | | | | |                     Write("DEVICEQUERYREMOVE")
00100 | | | | | 
00101 | | | | |                     $DeviceType = GetDeviceType($lParam)
00102 | | | | | 
00103 | | | | | +-                  If $DeviceType = $DBT_DEVTYP_HANDLE Then
00104 | | | | | |                           ; Check/Uncheck to allow/disallow device removal
00105 | | | | | | +-                        Switch GUICtrlRead($AllowDenyCheckBox)
00106 | | | | | | | +-                          Case $GUI_UNCHECKED ; allow
00107 | | | | | | | | +-                                Switch CloseFile($FileHandle, True)
00108 | | | | | | | | | +-                                  Case True
00109 | | | | | | | | | |                                           UnregisterDeviceNotification($FileHandle, True)
00110 | | | | | | | | | +-                                  Case False
00111 | | | | | | | | | |                                           Return $BROADCAST_QUERY_DENY
00112 | | | | | | | | +-                                EndSwitch
00113 | | | | | | | |   
00114 | | | | | | | +-                          Case $GUI_CHECKED ; deny
00115 | | | | | | | |                                   Return $BROADCAST_QUERY_DENY
00116 | | | | | | +-                        EndSwitch
00117 | | | | | +-                  EndIf
00118 | | | | | 
00119 | | | | +-                Case $DBT_DEVICEREMOVECOMPLETE
00120 | | | | |                     Write("DEVICEREMOVECOMPLETE")
00121 | | | | | 
00122 | | | | |                     Return True
00123 | | | | | 
00124 | | | | +-                Case $DBT_CONFIGCHANGECANCELED
00125 | | | | |                     Write("CONFIGCHANGECANCELED")
00126 | | | | | 
00127 | | | | |                     Return True
00128 | | | | | 
00129 | | | | +-                Case $DBT_CONFIGCHANGED
00130 | | | | |                     Write("CONFIGCHANGED")
00131 | | | | | 
00132 | | | | |                     Return True
00133 | | | | | 
00134 | | | | +-                Case $DBT_CUSTOMEVENT
00135 | | | | |                     Write("CUSTOMEVENT")
00136 | | | | | 
00137 | | | | |                     Return True
00138 | | | | | 
00139 | | | | +-                Case $DBT_DEVICEQUERYREMOVEFAILED
00140 | | | | |                     Write("DEVICEQUERYREMOVEFAILED")
00141 | | | | | 
00142 | | | | |                     Return True
00143 | | | | | 
00144 | | | | +-                Case $DBT_DEVICEREMOVEPENDING
00145 | | | | |                     Write("DEVICEREMOVEPENDING")
00146 | | | | | 
00147 | | | | |                     Return True
00148 | | | | | 
00149 | | | | +-                Case $DBT_DEVICETYPESPECIFIC
00150 | | | | |                     Write("DEVICETYPESPECIFIC")
00151 | | | | | 
00152 | | | | |                     Return True
00153 | | | | | 
00154 | | | | +-                Case $DBT_DEVNODES_CHANGED
00155 | | | | | ;~                  Write("DEVNODES_CHANGED")
00156 | | | | | 
00157 | | | | |                     Return True
00158 | | | | | 
00159 | | | | +-                Case $DBT_QUERYCHANGECONFIG
00160 | | | | |                     Write("QUERYCHANGECONFIG")
00161 | | | | | 
00162 | | | | |                     Return True
00163 | | | | | 
00164 | | | | +-                Case $DBT_USERDEFINED
00165 | | | | |                     Write("USERDEFINED")
00166 | | | | | 
00167 | | | | |                     Return True
00168 | | | +-          EndSwitch
00169 | +-  EndSwitch
00170 +-EndFunc ;==>MY_WM_DEVICECHANGE
00171   
00172   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00173   
00174 +-Func CLoseFile($Handle, $CheckError = False)
00175 |     Local Const $Result = _WinAPI_CloseHandle($Handle)
00176 |     $LastError = _WinAPI_GetLastErrorMessage()
00177 | 
00178 | +-  If $Result Then
00179 | |           Return $Result
00180 | +-  Else
00181 | |           If $CheckError Then ShowError("CLoseFile")
00182 | |           Return SetError(1, 0, 1)
00183 | +-  EndIf
00184 +-EndFunc ;==>CLoseFile
00185   
00186   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00187   
00188 +-Func DEV_BROADCAST_HANDLE($Handle, $CheckError = False)
00189 |     Local Const $DEV_BROADCAST_HANDLE = DllStructCreate($tagDEV_BROADCAST_HANDLE)
00190 |     $LastError = _WinAPI_GetLastErrorMessage()
00191 | 
00192 | +-  If IsDllStruct($DEV_BROADCAST_HANDLE) Then
00193 | |           Local Const $Size = DllStructGetSize($DEV_BROADCAST_HANDLE)
00194 | |   
00195 | |           Local Const $EventGUID = _WinAPI_GUIDFromString("{25dbce51-6c8f-4a72-8a6d-b54c2b4fc835}")
00196 | |   
00197 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_size"     , $Size)
00198 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_devicetype", $DBT_DEVTYP_HANDLE)
00199 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_reserved" , 0)
00200 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_handle"   , $Handle)
00201 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_hdevnotify", 0)
00202 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_eventguid" , $EventGUID)
00203 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_nameoffset", 0)
00204 | |           DllStructSetData($DEV_BROADCAST_HANDLE, "dbch_data"     , 0)
00205 | |   
00206 | |           Return $DEV_BROADCAST_HANDLE
00207 | +-  Else
00208 | |           If $CheckError Then ShowError("DEV_BROADCAST_HANDLE")
00209 | |           Return SetError(1, 0, 1)
00210 | +-  EndIf
00211 +-EndFunc ;==>DEV_BROADCAST_HANDLE
00212   
00213   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00214   
00215 +-Func DEV_BROADCAST_HDR($lParam, $CheckError = False)
00216 |     Local Const $DEV_BROADCAST_HDR = _AutoitObject_DllStructCreate($tagDEV_BROADCAST_HDR, Number($lParam))
00217 | 
00218 | +-  If IsObj($DEV_BROADCAST_HDR) Then
00219 | |           Return $DEV_BROADCAST_HDR
00220 | +-  Else
00221 | |           If $CheckError Then Write("DEV_BROADCAST_HDR: Fail")
00222 | |           Return SetError(1, 0, 1)
00223 | +-  EndIf
00224 +-EndFunc ;==>DEV_BROADCAST_HDR
00225   
00226   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00227   
00228 +-Func DEV_BROADCAST_VOLUME($lParam, $CheckError = False)
00229 |     Local Const $DEV_BROADCAST_VOLUME = _AutoitObject_DllStructCreate($tagDEV_BROADCAST_VOLUME, Number($lParam))
00230 | 
00231 | +-  If IsObj($DEV_BROADCAST_VOLUME) Then
00232 | |           Return $DEV_BROADCAST_VOLUME
00233 | +-  Else
00234 | |           If $CheckError Then Write("DEV_BROADCAST_VOLUME: Fail")
00235 | |           Return SetError(1, 0, 1)
00236 | +-  EndIf
00237 +-EndFunc ;==>DEV_BROADCAST_VOLUME
00238   
00239   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00240   
00241 +-Func DoRegisterDeviceInterfaceToHwnd($Handle, $CheckError = False)
00242 |     Local Const $DEV_BROADCAST_HANDLE = DEV_BROADCAST_HANDLE($Handle)
00243 | 
00244 |     Local Const $ptrDEV_BROADCAST_HANDLE = DllStructGetPtr($DEV_BROADCAST_HANDLE)
00245 | 
00246 |     ; tells RegisterDeviceNotifications to send notices to a window
00247 |     Local Const $Flags = $DEVICE_NOTIFY_WINDOW_HANDLE
00248 | 
00249 |     Local Const $RDNhandle = DllCall("User32.dll", "handle", "RegisterDeviceNotification", "hwnd", $hRecipient, "ptr", $ptrDEV_BROADCAST_HANDLE, "uint", $Flags)
00250 |     $LastError = _WinAPI_GetLastErrorMessage()
00251 | 
00252 | +-  If $RDNhandle[0] Then
00253 | |           Return $RDNhandle[0]
00254 | +-  Else
00255 | |           If $CheckError Then ShowError("RegisterDeviceNotification")
00256 | |           Return SetError(1, 0, 1)
00257 | +-  EndIf
00258 +-EndFunc ;==>DoRegisterDeviceInterfaceToHwnd
00259   
00260   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00261   
00262 +-Func GetDeviceType($lParam, $CheckError = False)
00263 |     Local Const $DEV_BROADCAST_HDR = DEV_BROADCAST_HDR($lParam)
00264 | 
00265 | +-  If IsObj($DEV_BROADCAST_HDR) Then
00266 | |           Return $DEV_BROADCAST_HDR.dbch_devicetype
00267 | +-  Else
00268 | |           If $CheckError Then Write("GetDeviceType: Fail")
00269 | |           Return SetError(1, 0, 1)
00270 | +-  EndIf
00271 +-EndFunc ;==>GetDeviceType
00272   
00273   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00274   
00275 +-Func GetDriveLetterFromUnitMask($UnitMask, $CheckError = False)
00276 |     Local Const $Drives = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00277 |     Local $Count = 1
00278 |     Local $Pom = $UnitMask / 2
00279 | 
00280 | +-  While $Pom <> 0
00281 | |           $Pom = BitShift($Pom, 1)
00282 | |           $Count += 1
00283 | +-  WEnd
00284 | 
00285 | +-  If $Count >= 1 And $Count <= 26 Then
00286 | |           Return StringMid($Drives, $Count, 1)
00287 | +-  Else
00288 | |           If $CheckError Then Write("Error in getting drive letter.")
00289 | |           Return SetError(1, 0, '?')
00290 | +-  EndIf
00291 +-EndFunc ;==>GetDriveLetterFromUnitMask
00292   
00293   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00294   
00295 +-Func GetUnitMask($lParam, $CheckError = False)
00296 |     Local Const $DEV_BROADCAST_HDR = DEV_BROADCAST_HDR($lParam)
00297 | 
00298 |     Local Const $DeviceType = $DEV_BROADCAST_HDR.dbch_devicetype
00299 | 
00300 | +-  Switch $DeviceType
00301 | | +-        Case $DBT_DEVTYP_VOLUME
00302 | | |             Local Const $DEV_BROADCAST_VOLUME = DEV_BROADCAST_VOLUME($lParam)
00303 | | | 
00304 | | | +-          If IsObj($DEV_BROADCAST_VOLUME) Then
00305 | | | |                   Return $DEV_BROADCAST_VOLUME.dbcv_unitmask
00306 | | | +-          Else
00307 | | | |                   If $CheckError Then Write("GetUnitMask: Fail")
00308 | | | |                   Return SetError(1, 0, 1)
00309 | | | +-          EndIf
00310 | | | 
00311 | | +-        Case $DBT_DEVTYP_HANDLE
00312 | | |             Local Const $DEV_BROADCAST_HANDLE = DEV_BROADCAST_HANDLE($lParam)
00313 | | | 
00314 | | | +-          If IsObj($DEV_BROADCAST_HANDLE) Then
00315 | | | |                   Return $DEV_BROADCAST_HANDLE.dbcv_unitmask
00316 | | | +-          Else
00317 | | | |                   If $CheckError Then Write("GetUnitMask: Fail")
00318 | | | |                   Return SetError(2, 0, 1)
00319 | | | +-          EndIf
00320 | +-  EndSwitch
00321 +-EndFunc ;==>GetUnitMask
00322   
00323   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00324   
00325 +-Func OpenFileDialog($Creation = 2, $Access = 4, $Share = 0, $Flags = 0, $Security = 0, $CheckError = False)
00326 | +-  If $Creation = $OPEN_EXISTING Then
00327 | |           Local $File = FileOpenDialog("Open file...", '', "All (*.*)", 1 + 2)
00328 | +-  Else
00329 | |           $File = FileOpenDialog("Open file...", '', "All (*.*)")
00330 | +-  EndIf
00331 | 
00332 |     Local Const $FileHandleTMP = _WinAPI_CreateFile("\\?\" & $File, $Creation, $Access, $Share, $Flags, $Security)
00333 |     $LastError = _WinAPI_GetLastErrorMessage()
00334 | 
00335 | +-  If IsPtr($FileHandleTMP) Then
00336 | |           Return $FileHandleTMP
00337 | +-  Else
00338 | |           If $CheckError Then ShowError("OpenFileDialog")
00339 | |           Return SetError(1, $LastError, 1)
00340 | +-  EndIf
00341 +-EndFunc ;==>OpenFileDialog
00342   
00343   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00344   
00345 +-Func OpenFile($File, $Creation = $OPEN_EXISTING, $Access = 6, $Share = 7, $Flags = 0, $Security = 0, $CheckError = False)
00346 |     Local Const $FileHandleTMP = _WinAPI_CreateFile("\\?\" & $File, $Creation, $Access, $Share, $Flags, $Security)
00347 |     $LastError = _WinAPI_GetLastErrorMessage()
00348 | 
00349 | +-  If IsPtr($FileHandleTMP) Then
00350 | |           Return $FileHandleTMP
00351 | +-  Else
00352 | |           If $CheckError Then ShowError("OpenFile")
00353 | |           Return SetError(1, 0, 1)
00354 | +-  EndIf
00355 +-EndFunc ;==>OpenFile
00356   
00357   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00358   
00359 +-Func UnregisterDeviceNotification($Handle, $CheckError = False)
00360 |     Local Const $Check = DllCall("User32.dll", "bool", "UnregisterDeviceNotification", "handle", $Handle)
00361 |     $LastError = _WinAPI_GetLastErrorMessage()
00362 | 
00363 | +-  If $Check = False Then
00364 | | +-        If $CheckError Then
00365 | | |             If $CheckError Then ShowError("UnregisterDeviceNotification")
00366 | | |             Return SetError(1, 0, 1)
00367 | | +-        EndIf
00368 | +-  EndIf
00369 +-EndFunc ;==>UnregisterDeviceNotification
00370   
00371   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00372   
00373   #region Communication
00374 +-Func ShowError($Function)
00375 |     Write($Function & ": " & $LastError, True)
00376 | ;~  DllCall("Kernel32.dll", "none", "SetLastError", "dword", 0)
00377 |     $LastError = 0
00378 +-EndFunc ;==>ShowError
00379   
00380   ; -----------------------------------------------------------------------------
00381   
00382 +-Func Write($message, $CRLF = True)
00383 | +-  If $CRLF Then
00384 | |           GUICtrlSetData($EditBox, $message & @CRLF, ' ')
00385 | +-  Else
00386 | |           GUICtrlSetData($EditBox, $message, ' ')
00387 | +-  EndIf
00388 +-EndFunc ;==>Write
00389   #endregion Communication
00390   
00391   ; ------------------------------------------------------------------------------------------------------------------------------------------------------
00392   
00393   #region Clean_up
00394 +-Func _exit()
00395 |     If $RegisterStatus Then GUIRegisterMsg($WM_DEVICECHANGE, "")
00396 |     If IsHWnd($hRecipient) Then GUIDelete()
00397 |     _AutoItObject_Shutdown()
00398 |     OnAutoItExitUnregister("_exit")
00399 +-EndFunc ;==>_exit
00400   
00401   ; -----------------------------------------------------------------------------
00402   
00403 +-Func term()
00404 |     Exit
00405 +-EndFunc ;==>term
00406   #endregion Clean_up

======================
=== xref reports =====
======================

== User functions =================================================================================================
    Func
Function name   Row     Referenced at Row(s)
========================= ====== ==================================================================================
CLoseFile   00219 
DEV_BROADCAST_HANDLE    00233 
DEV_BROADCAST_HDR   00260 
DEV_BROADCAST_VOLUME    00273 
DoRegisterDeviceInterfaceToHwnd 00286 
GetDeviceType   00307 
GetDriveLetterFromUnitMask 00320 
GetUnitMask     00340 
MY_WM_DEVICECHANGE  00102 
OpenFile    00390 
OpenFileDialog  00370 
ShowError   00419 
UnregisterDeviceNotification 00404 
Write   00427 
_exit   00439 00394
term    00448 00403

#### indicates that this specific variable only occurs one time in the script.
---- indicates that this specific variable isn't declared with Dim/Local/Global/Const.

== Variables ======================================================================================================
Variable name   Dim Used in Row(s)
========================= ===== ===================================================================================
$Access     ----- 00325 00332 00345 00346
$AllowDenyCheckBox  00082 00037 00038 00105
$BROADCAST_QUERY_DENY   ----- 00111 00115
$CRLF   ----- 00382 00383
$Check  00405 00360 00363
$CheckError     ----- 00174 00181 00188 00208 00215 00221 00228 00234 00241 00255 00262 00268 00275 00288 
    00295 00307 00317 00325 00338 00345 00352 00359 00364 00365
$Count  00322 00277 00282 00285 00286
$Creation   ----- 00325 00326 00332 00345 00346
$DBT_CONFIGCHANGECANCELED ----- 00124
$DBT_CONFIGCHANGED  ----- 00129
$DBT_CUSTOMEVENT    ----- 00134
$DBT_DEVICEARRIVAL  ----- 00061
$DBT_DEVICEQUERYREMOVE  ----- 00098
$DBT_DEVICEQUERYREMOVEFAILED ----- 00139
$DBT_DEVICEREMOVECOMPLETE ----- 00119
$DBT_DEVICEREMOVEPENDING ----- 00144
$DBT_DEVICETYPESPECIFIC ----- 00149
$DBT_DEVNODES_CHANGED   ----- 00154
$DBT_DEVTYP_HANDLE  ----- 00103 00198 00311
$DBT_DEVTYP_VOLUME  ----- 00064 00301
$DBT_QUERYCHANGECONFIG  ----- 00159
$DBT_USERDEFINED    ----- 00164
$DEVICE_NOTIFY_WINDOW_HANDLE ----- 00247
$DEV_BROADCAST_HANDLE   00234 00287 00357 00189 00192 00193 00197 00198 00199 00200 00201 00202 00203 00204 00206 
    00242 00244 00312 00314 00315
$DEV_BROADCAST_HDR  00261 00308 00341 00216 00218 00219 00263 00265 00266 00296 00298
$DEV_BROADCAST_VOLUME   00274 00347 00229 00231 00232 00302 00304 00305
$DeviceType     00107 00343 00062 00064 00101 00103 00298 00300
$DriveLetter    00094 00049 00073
$Drives     00321 00276 00286
$EditBox    00080 00035 00384 00386
$EventGUID  00240 00195 00202
$File   00372 00327 00329 00332 00345 00346
$FileHandle     00095 00050 00080 00086 00107 00109
$FileHandleTMP  00121 00377 00391 00076 00080 00332 00335 00336 00346 00349 00350
$Flags  00292 00247 00249 00325 00332 00345 00346
$Function   ----- 00374 00375
$GUI_CHECKED    ----- 00038 00114
$GUI_EVENT_CLOSE    ----- 00030
$GUI_UNCHECKED  ----- 00106
$Handle     ----- 00174 00175 00188 00200 00241 00242 00359 00360
$LastError  00096 00051 00176 00190 00250 00333 00339 00347 00361 00375 00377
$OPEN_EXISTING  ----- 00326 00345
$Pom    00323 00278 00280 00281
$RDNhandle  00294 00249 00252 00253
$RegisterStatus     00078 00033 00395
$Result     00220 00175 00178 00179
$Security   ----- 00325 00332 00345 00346
$Share  ----- 00325 00332 00345 00346
$Size   00238 00193 00197
$UnitMask   00113 00068 00069 00275 00278
$WM_DEVICECHANGE    00077 00032 00033 00059 00395
$hDevNotify     00093 00048 00090
$hDevNotifyTMP  00131 00086 00090
$hRecipient     00074 00029 00030 00249 00396
$hWnd   ----- 00057
$lParam     ----- 00057 00062 00066 00068 00101 00215 00216 00228 00229 00262 00263 00295 00296 00302 
    00312
$message    ----- 00382 00384 00386
$msg    ----- 00057 00058
$ptrDEV_BROADCAST_HANDLE 00289 00244 00249
$tagDEV_BROADCAST_HANDLE ----- 00189
$tagDEV_BROADCAST_HDR   ----- 00216
$tagDEV_BROADCAST_VOLUME ----- 00229
$tmpDriveLetter     00114 00069 00073
$wParam     ----- 00057 00060
@CRLF   ----- 00384
@ScriptName     ----- 00016
@error  ----- 00071 00078 00088

This can be done in a single line by using regular expressions.

#Include <Array.au3>

$sPath = FileOpenDialog('Select File', '', 'AutoIt v3 Script (*.au3)', 3)
If $sPath Then
    $aList = StringRegExp(StringRegExpReplace(FileRead($sPath), '(?ims)#c[^#]+#c', ''), '(?ims)^\s*Func\s*([^(]*)', 3)
    _ArrayDisplay($aList)
EndIf

That gave me an array yes, but I then I would need code to paste the contents of the array into the au3. Edited by jaberwocky6669
Link to comment
Share on other sites

That's fine. You get a cross reference listing of all used variables and functions plus a beautified script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I've started to keep a listing of all the functions I use in a script at the end of the script. I have a macro set up in my editor that when I click on the line it jumps to where the function starts. This might come in handy.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That gave me an array yes, but I then I would need code to paste the contents of the array into the au3.

You can easily modify it to use StringRegExpReplace, and that would be easy enough. The main point is that your nested If's are not very nice. You could at least use:

If StringLeft(StringStripWS($SourceArray[$i], 3), 4) = 'Func' Then ...

That would make it easier to see what you are doing. Of course you should also use:

StringStripWS(StringLeft(StringTrimLeft($SourceArray[$i], 4), StringInStr($SourceArray[$i], "(") - 1), 8)

None of that is tested as I don't autoit at the moment, but thats a nicer way than using _StringBetween.

Of course you should then add error checks to make sure that at least the start of the function definition is correct... Then you expand it to include support for the standard include header kind of thing: CURRENT etc... Youcould even see if it's an internal of deprecated function based on how they've declared is (__MyFunc is internal etc.). Then instead of making a new list all the time make it so it updates the same list at the top of the script... Lots to od eh?

Link to comment
Share on other sites

Ok, Thanks Mat, I see now the wisdom in using a regexp! Yes, there's quite a bit to be done but I like to grow things from the bottom up. I plan now to also make this into a script that will make calltips from scripts. Oh well, I probably won't. I'm a big thinker, too big. I have too many projects in rotation.

Edited by jaberwocky6669
Link to comment
Share on other sites

Never really thought about something like this before, either existing or new, and I like it.

An advancement on the idea might to consider the users includes into the bargain. Not the standard udfs, but those like #include "myinclude.au3".

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I've started to keep a listing of all the functions I use in a script at the end of the script. I have a macro set up in my editor that when I click on the line it jumps to where the function starts. This might come in handy.

Never really thought about something like this before, either existing or new, and I like it.

An advancement on the idea might to consider the users includes into the bargain. Not the standard udfs, but those like #include "myinclude.au3".

Thank you both and to all who posted. I have your suggestions in a To-Do list.

Link to comment
Share on other sites

  • 2 months later...

I've hacked together something for my Console UDF the other day to do something similar to this, but working on the UDF headers instead of the function definitions. It assumes that you have added the headers and that they are correct of course, but it can be used to generate calltips for SciTE etc.

Func _GenFuncList()
    $a = StringSplit(FileRead(@ScriptDir & "\Console.au3"), @CRLF, 1)
    If @error Then Exit 1

    Local $aRet[1][3] = [[0, 0, 0]] ; [*][0] => Name, [*][1] => Description, [*][2] => Syntax

    For $i = 1 To $a[0]
        If StringLeft($a[$i], 13) = "; #FUNCTION# " Then
            $aRet[0][0] += 1
            ReDim $aRet[$aRet[0][0] + 1][3]

            $n = 0
            While $n < 3
                $i += 1

                If StringInStr(StringLeft($a[$i], 19), ".") Then
                    $aRet[$aRet[0][0]][$n] = StringTrimLeft($a[$i], 19)
                    $n += 1
                Else
                    $aRet[$aRet[0][0]][$n - 1] &= " " & StringTrimLeft($a[$i], 19)
                EndIf
            WEnd
        EndIf
    Next

    Return $aRet
EndFunc   ;==>_GenFuncList

And this is my replacement for the built in (albeit hidden) default udf header maker. I think Valik wrote the original if I remember rightly, but it didn't give quite what I wanted, so I tweaked it, then rewrote it adding loads of useless bit's that noone really needs like predicting the type and adding breaks if the syntax line is too long and other really stupid stuff that I did when I got bored. It's useful though.

function AutoItTools:CreateFunctionHeader(s)
    -- Change these <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />
    local defAuthor = "Matt Diesel (Mat)"    -- Initial Author value
    local defLineMax = 129                   -- Max length of line. AutoIt standard is 129.
    local defSplit = 21                      -- Default index for '-' after param.

    local nl = self:NewLineInUse()

    local outStart   = "FUNCTION"
    local outName    = ""
    local outDesc    = ""
    local outSyntax  = ""
    local outParams  = ""
    local outReturn  = "None"
    local outAuthor  = defAuthor
    local outModify  = ""
    local outRemarks = ""
    local outRelated = ""
    local outLink    = ""
    local outExample = "No"

    local f,t,name,params = s:find("^%s*[Ff][Uu][Nn][Cc]%s+(.+)%s*(%b())")

    outName = name
    if name:sub(0, 2) == "__" then
        outStart = "INTERNAL_USE_ONLY"
    end

    outSyntax = name .. "( "

    local paramSynt = ""
    local iOptionals = 0
    local fBroken = false
    if params ~= "" and params ~= nil then
        for byref, parameter, optional in string.gfind(params, "(%w-)%s*($[%w_]+)%s*([=]?)") do
            if parameter ~= "" and parameter ~= nil then
                if outParams ~= "" then
                    outParams = outParams .. nl .. ";" .. string.rep(" ", 18)
                end

                outParams = outParams .. parameter .. string.rep(" ", defSplit - string.len(parameter)) .. "- "

                if optional ~= "" and optional ~= nil then
                    outParams = outParams .. "[optional] "

                    if paramSynt ~= "" then
                        paramSynt = paramSynt .. "[, "
                    else
                        paramSynt = paramSynt .. "[ "
                    end

                    iOptionals = iOptionals + 1
                else
                    if byref ~= "" and byref ~= nil then
                        outParams = outParams .. "[in/out] "
                    end

                    if paramSynt ~= "" then
                        paramSynt = paramSynt .. ", "
                    end
                end

                if fBroken then
                    if string.len(paramSynt) + string.len(parameter) + iOptionals + 2 + 19 > defLineMax then
                        outSyntax = outSyntax .. paramSynt .. nl .. ";" .. string.rep(" ", 18)
                        paramSynt = ""
                        fBroken = true
                    end
                else
                    if string.len(outSyntax) + string.len(paramSynt) + string.len(parameter) + iOptionals + 2 + 19 > defLineMax then
                        outSyntax = outSyntax .. paramSynt .. nl .. ";" .. string.rep(" ", 18)
                        paramSynt = ""
                        fBroken = true
                    end
                end
                paramSynt = paramSynt .. parameter .. " "

                local paramtype = parameter:sub(2, 2)
                local isarray = false
                if paramtype == "a" then
                    paramtype = parameter:sub(3, 3)
                    isarray = true
                end

                local sAdd
                if paramtype == "i" then
                    sAdd = "integer"
                elseif paramtype == "f" then
                    sAdd = "boolean"
                elseif paramtype == "b" then
                    sAdd = "binary"
                elseif paramtype == "n" then
                    sAdd = "floating point number"
                elseif paramtype == "s" then
                    sAdd = "string"
                elseif paramtype == "h" then
                    sAdd = "handle"
                elseif paramtype == "v" then
                    sAdd = "variant"
                elseif paramtype == "p" then
                    sAdd = "pointer"
                elseif paramtype == "t" then
                    sAdd = "dll struct"
                else
                    sAdd = "unknown"
                end

                if isarray then
                    outParams = outParams .. "An array of " .. sAdd .. "s."
                else
                    outParams = outParams .. "A " .. sAdd .. " value."
                end
            end
        end
    else
        outParams = "None"
    end

    outSyntax = outSyntax .. paramSynt .. string.rep("]", iOptionals) .. " )"

    local res = "; #" .. outStart .. "# " .. string.rep("=", defLineMax - 5 - outStart:len()) .. nl
    res = res .. "; Name ..........: " .. outName .. nl
    res = res .. "; Description ...: " .. outDesc .. nl
    res = res .. "; Syntax ........: " .. outSyntax .. nl
    res = res .. "; Parameters ....: " .. outParams .. nl
    res = res .. "; Return values .: " .. outReturn .. nl
    res = res .. "; Author(s) .....: " .. outAuthor .. nl
    res = res .. "; Modified ......: " .. outModify .. nl
    res = res .. "; Remarks .......: " .. outRemarks .. nl
    res = res .. "; Related .......: " .. outRelated .. nl
    res = res .. "; Link ..........: " .. outLink .. nl
    res = res .. "; Example .......: " .. outExample .. nl
    res = res .. "; " .. string.rep("=", defLineMax - 2) .. nl

    return res
end -- CreateFunctionHeader()

function AutoItTools:InsertUDFHeader()
    local line, pos = editor:GetCurLine()
    local pos = editor.CurrentPos - pos
    local lineNum = editor:LineFromPosition(pos)
    local from, to, name = line:find("[Ff][Uu][Nn][Cc][%s]*([%w%s_]*)")
    if to ~= nil then
        local pfrom, pto, pname = line:find("(%(.-[%)_])")
        local i = 0
        if pto ~= nil then
            while pname:find("_%s*$") do    -- Found an underscore, so need to get the next line, too
                i = i + 1
                line = line .. editor:GetLine(lineNum+i)
            end
            editor:Home()
            editor:AddText(self:CreateFunctionHeader(line))
        else
            print("Argument list not found, unable to insert header.")
        end
    else
        print("Function definition not found, unable to insert header.")
    end
end -- InsertUDFHeader()
.

Might help somebody :x

Mat

Link to comment
Share on other sites

  • 3 weeks later...

Very Good!

A program/script I wrote some time ago (Declare All Variables), helps me keep tabs on variables & functions, which when run, appends them to the foot of the current script.

I then relocate them to just after the description section at the top of the script. I also then separate the functions out as either GUI ones or not (see below).

All listed alphabetically of course.

This is very handy for quick jumping straight to any function, after highlighting the one I want.

Of course I use these features from buttons on my Toolbar For Any program in SciTE.

;; ;;

;; SCRIPT FUNCTION: Update, Add or Remove artwork (.jpg) to Mp3 files in a folder ;;

;; ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#region --- GuiBuilder code Start ---

; Script generated by AutoBuilder 0.8 Prototype

; GUI FUNCTIONS

; AddEditComments(), AddSomeTextGUI(), BackupRemovalGUI(), ID3TagsGUI()

; FUNCTIONS

; AddComment($add), BackUpTagsAndProps(), BatchModeUpdate(), CheckForExistingArtwork()

; CheckLastPath(), ClearAllOtherFields(), ClearTagFields(), ClearAllTagInputs(), CreateRegEntry()

; DisableControlsForBatch(), DisableTagFields(), DisableWhileUpdating(), EnableAfterUpdating()

; EnableControls(), EnableUpdateButton(), FillInTagDetails($Label), FillListWithMp3s()

; FindDefaultJpg(), FixRomanNumerals($txt, $rom), GetAllTagValues($vers)

; GetAlternateTagInfoAndUpdate($a), GetFolderPath(), GetFolderAndFiles($path)

; GrabTitleFromFilename($grab), LockTag($Label), ProperCase($txt), RefreshenToolTips()

; RemoveIllegalCharacters($txt), RemoveMp3FileExtracts(), ReplaceForeign($txt)

; ReplaceSpecialCharacters($txt), RestoreTagsFromBackUp(), SetTheJpgImage(), StopUpdating()

; UndoAllBatchSettings(), UndoBatchSettings(), UndoEditSettings(), UpdateArtwork()

; UpdateSelectedTrackArtwork(), UpdateTagsWithEditValues(), UpdateTheCase($Input)

#include <Constants.au3>

#include <GUIConstantsEx.au3>

etc

Sadly I've not yet uploaded the latest versions to my Toolbox ... but you get the idea, etc. :)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

  • 5 months later...

Please post the results of your research when you finish.

I analyzed Xenobiologist's OrganizeIncludes to figure out how to do this script actually.

Edited by LaCastiglione
Link to comment
Share on other sites

Ok, I will do... also, if you take a look at that forum page, you will notice that I have added a few things in. The only thing that I have not had time for was the last bit... deleting the existing includes.

EDIT

Ok, I just ran it, and a problem that I found, is that it inserts itself inside the first include.

Edited by Mikeman27294
Link to comment
Share on other sites

  • 2 years later...

there is some issue:

SciTE Director.au3

"z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\SciTE Director.au3"(8) : ### Tidy Warning -> #Region statements without #EndRegion.

FunctionNameLister.au3

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /prod /AU3Check /in "Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3"
+>01:31:00 Starting AutoIt3Wrapper v.2.2.0.4 SciTE v.3.4.3.0   Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0415)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\user\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\user\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.13.0)  params:-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d -q  from:C:\Program Files (x86)\AutoIt3  input:Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3
"Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3"(127,28) : warning: $file_stream_eof: possibly used before declaration.
      Case $file_stream_eof,
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3"(127,54) : warning: $file_stream_other_error: possibly used before declaration.
      Case $file_stream_eof, $file_stream_other_error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3"(127,28) : error: $file_stream_eof: undeclared global variable.
      Case $file_stream_eof,
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3"(127,54) : error: $file_stream_other_error: undeclared global variable.
      Case $file_stream_eof, $file_stream_other_error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Z:\TOOLs\Macro\    FORUM\_UDF_MAKERs\FunctionNameLister.au3 - 2 error(s), 2 warning(s)
!>01:31:00 AU3Check ended. Press F4 to jump to next error.rc:2
+>01:31:00 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.4173

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

At that time there was a required include attached at the bottom of the post.  I have just now completely revamped the OP for clarity and ease of use.  Just download the attached zip which contains FunctionNameLister.exe please.

Edited by jaberwacky
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...