Cross Reference List (XRef)

Post your working scripts, libraries and tools
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Cross Reference List (XRef)

11 Mar 2016, 20:37

This 'XRef' program produces an alphabetical cross reference list of all the names, numbers, and words in an *.AHK file, showing the source line numbers where these items occurred. (XRef can also process DOS batch files, as well as C and JS files.) Any quoted information is also included.

A cross reference listing can be very useful for locating where program variables are set and used, and is also handy for determining unused variable names when allocating new ones.

An optional extra 'Function Map' can also be produced, showing where in the program functions and subroutines are defined, and where they are referenced. This map is only a part of the main report, however it displays the data in the same order that it occurs in the program being analysed.

There is an option to process a subset of the script; 'Get script subset'. When prompted, enter the starting and ending line numbers separated by a space. This facility can be used to analyse a self-contained portion of a script, such as a function definition.

A particular set of options plus setup can be saved as the default, and a different set of options can be saved for each script to be processed, if necessary.

As well, a different default set of options plus setup can be saved for a general subset-type report (select 'Get script subset' with any line numbers first), and yet another set of subset-type options can also be saved per script.

The type of default options in use is shown between hyphens in the title bar at the top of the window.

Any script options previously saved may be erased - click on the 'Update...' checkbox to see the different saving and erasing options. To access the subset-type defaults, first select 'Get script subset' (with any line numbers), then the 'Update...' checkbox and button will process the subset-type defaults.

The generated report is shown in Notepad and may be automatically printed to the default printer if required. If a 'page size' is supplied in the setup, the report can be formatted 'n/up' to take up less space.

To show the report correctly, Notepad should be set to use a mono-spaced font. This can be achieved by using the 'Mono' button to set Notepad to its defaults. The old position and size of Notepad's window is preserved.

Script comments are usually excluded from the report, however there is an option to include this information if required. (As syntax analysis is rudimentary in this program, it is possible that valid data in some scripts may be inadvertently flagged as comments.)

To process one or more scripts without any user intervention, you can drag and drop the scripts onto XRef.exe (or a shortcut pointing to XRef.exe), and the scripts will be processed automatically using the default options (script or overall). The same will happen if you run XRef.exe supplying the script names as parameters. (If a script can't be found, an error message is shown, then the usual file selection dialog will be displayed.)

AHK '#include's are not processed. For the cross reference list this doesn't really matter, as each library file can be processed separately, and they don't usually change often. Any optional function maps generated, however, will be incomplete if the '#include'd files contain function definitions. I have no plans to change this at present.

Screen shot and output snippets:-

Download:-
XRef can be downloaded from here. The zip file includes source and executable.

Upgrade History:-
11 Mar 2016 - Initial release.

19 May 2016 -
The 'mono' button now doesn't generate a UAC prompt and keeps Notepad's previous position and size.
The 'Print Report' option has been updated.

11 July 2016 -
Added two options for 'tighter' formatting, which will generate more compact reports.
Separated out the 'Exit Notepad' option from 'Print report'.
The Notepad window now comes to the front after a report is generated.
Can select a new file to process from the Options window.
Eliminated the possibility of some incorrect references when generating a Function Map.

12 July 2016 -
Fixed a bug when generating a Function Map for some .js scripts.
Fixed a bug when generating a Function Map for .ahk scripts when including comments.

12 August 2016 - Fixed a formatting issue when generating a Function Map and Lines/page is zero.

02 November 2016 -
Added an option to analyse a subset of the script.
The Cross Reference List file is now saved as Unicode (UTF-8).

15 January 2017 -
Can save separate defaults for the 'Get script subset' option - see amended documentation.
Supports AHK2 Unicode variable names.

17 February 2017 - Added drag and drop facility and updated documentation.

19 March 2017 - Updated download link.

12 May 2017 - An error message is shown if the script file cannot be found when in automatic mode.
Last edited by TAC109 on 12 May 2017, 01:26, edited 31 times in total.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

18 May 2016, 22:45

Updated 19 May 2016 -
The 'mono' button now doesn't generate a UAC prompt and keeps Notepad's previous position and size.
The 'Print Report' option has been updated.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

19 May 2016, 19:52

One of the last changes I made was to the 'Print Report' facility to try and make it work correctly on non-English versions of Windows. I would be interested to hear back from anyone using this option of XRef under these circumstances. (There may be a pause of 4 seconds while the 'print' Windows of Notepad are shown.)

So, any comments on this from users would be helpful.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

10 Jul 2016, 19:12

Updated 11 July 2016 -
Added two options for 'tighter' formatting, which will generate more compact reports.
Separated out the 'Exit Notepad' option from 'Print report'.
The Notepad window now comes to the front after a report is generated.
Can select a new file to process from the Options window.
Eliminated the possibility of some incorrect references when generating a Function Map.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

12 Jul 2016, 02:51

Updated 12 July 2016 -
Fixed a bug when generating a Function Map for some .js scripts.
Fixed a bug when generating a Function Map for .ahk scripts when including comments.
Last edited by TAC109 on 16 Feb 2017, 18:26, edited 1 time in total.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

11 Aug 2016, 20:09

Updated 12 August 2016 -
Fixed a formatting issue when generating a Function Map and Lines/page is zero.
Last edited by TAC109 on 16 Feb 2017, 18:27, edited 1 time in total.
Helgef
Posts: 1547
Joined: 17 Jul 2016, 01:02

Re: Cross Reference List (XRef)

11 Aug 2016, 23:51

Could be very useful, I'm going to try this when I get the chance. Does it include content in #include
files?
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

12 Aug 2016, 00:12

No, just the file selected. You can process the #include files separately, as they may not change frequently and thus not need to be reprocessed.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

14 Aug 2016, 01:20

Amended and added to the description in the first post.
Helgef
Posts: 1547
Joined: 17 Jul 2016, 01:02

Re: Cross Reference List (XRef)

14 Aug 2016, 11:38

Hello TAC109. I did a breif test, it looks good and is quick! On the #include matter, for me it would be useful since I often split my (slightly bigger) projects into quite a few files, basically one main script with just a bunch of #include.
Great job though, thanks.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

14 Aug 2016, 18:53

Thanks for your kind comments.

I've read up on #include in the help and the rules are quite complex. The 'file/dir' parameter can include various 'A_' type references, many of which relate to the script's actual location. The related 'libraries of functions' section introduces further complexities where functions can be implicitly included from various folder locations.

Then there is the question of how this extra data should be included in the report. One large combined list with the current neat line numbers list replaced by file/line number references, or many separate reports, one for each file.

I don't see that all the extra programming required as yielding many advantages over what I've suggested, that is to just sequentially select the files to be processed as needed. If you change a couple of files in your program suite, then just run XRef on those files.

The only deficiency is with the optional 'Function Map' report which will be incomplete without the included files. This is not a report I use very often, as this data is also embedded in the main report.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

01 Nov 2016, 20:56

Updated 02 November 2016 -
Added an option to analyse a subset of the script.
The Cross Reference List file is now saved as Unicode (UTF-8).
Last edited by TAC109 on 16 Feb 2017, 18:26, edited 1 time in total.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

14 Jan 2017, 21:31

Updated 15 January 2017 -
Can save separate defaults for the 'Get script subset' option - see amended documentation.
Supports AHK2 Unicode variable names.
Last edited by TAC109 on 16 Feb 2017, 18:25, edited 1 time in total.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

16 Feb 2017, 18:25

Updated 17 February 2017 -
Added drag and drop facility and updated documentation.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

18 Mar 2017, 17:20

19 March 2017 - updated download link.
IMEime
Posts: 332
Joined: 20 Sep 2014, 06:15

Re: Cross Reference List (XRef)

20 Mar 2017, 19:34

I've tried it.
Working well and looks nice.

Interesting..

I have a question.
Your coding style is so unfamiliar to me.
Lots lots of commas and not much spaces.
I'm using Notepad++ and I concluded, it is not human readable codes.
How do you write, edit and debug it ?
Do you use something special method to compress it after you completed ? If so, why ?
And for the exe file.
Do you use your own method to compile it ?
If I open it with Notepad++ (usually, it shows the codes cleaner than mine) I've failed to see the source codes within it.

Thanks for the nice codes.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

21 Mar 2017, 00:25

Thanks for your kind comments!

I suppose my coding style could be regarded as 'normalised'. You will have heard of data normalisation, where basically, any duplicate data is removed and replaced by a reference to a single occurrence (see Date & Codd normalisation). Well, I like to do similar by normalising my code. Not to everyone's taste but it suits me.

I just use SCiTE4AHK as my editor and debugger.

You'll see that my code is very modular. The tricky code I often debug by creating a simple test harness for each routine to ensure that it works correctly. Many routines start with basic code and then are enhanced incrementally, with testing after each amendment.

(Using XRef on itself will reveal a lot.)

I use fincs' AHK2EXE (preview2a) to compile my source and UPX to compress it. (I have found that Mpress can occasionally generate corrupt .exe's.)

As a diagnostic, if you press Win+F2 after generating a cross reference, you will see the structure of the 'q' object which holds the various 'n/up' report data items. (The program uses the 'q' object to produce and select the most compact report.) This diagnostic was a great help when debugging this part of the program.
IMEime
Posts: 332
Joined: 20 Sep 2014, 06:15

Re: Cross Reference List (XRef)

21 Mar 2017, 06:07

Thanks reply.
TAC109
Posts: 164
Joined: 02 Oct 2013, 19:41

Re: Cross Reference List (XRef)

12 May 2017, 01:19

Updated 12 May 2017 -
An error message is shown if the script file cannot be found when in automatic mode.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Teekanne and 17 guests