Cross Reference List (XRef)

Post your working scripts, libraries and tools for AHK v1.1 and older
stealzy
Posts: 91
Joined: 01 Nov 2015, 13:43

Re: Cross Reference List (XRef)

12 Jan 2018, 10:10

Great obfuscation, it looks crazy ;) ! Just a small piece of your script if you don't mind:

Code: Select all

Loop Read,%fi%
{ If (ex="c")
{ L:="",z:=A_LoopReadLine,x=1,c1:=z~="^[^\s#]"
IfEqual true,% !(z~="/\*|\*/|//")&&cm!=2,SetEnv L,%z%
else while x<=StrLen(z)
{ y:=SubStr(z,x,2),(cm=2&&y="*/")?(cm:=0,L.=" ",x++)
: (cm=0&&y="/*")?(cm:=2, L.=" ",x++):0
IfEqual cm,0,IfEqual y,//,break
(cm=2)?x++:L.=SubStr(z,x++,1)
} } else { L:=A_LoopReadLine, ln:=cm=1?"":SubStr(LTrim(L),1,2)
cm:=ex="a"&&ln="/*"?2:cm
IfEqual true,% ex="d"&&ln="::"||ex="a"&&cm=2&&L~="\*/"&&!(cm:=0)||cm=2,continue
} L:=rr(rr(L,":="," "),":",ex="d"?" :":ex="a"?": ":" ")
L:=rr(rr(ex="c"?rr(L,"\s+\(","("):L,"(;|\()","$1 "),"((``.)|{|\)|,)"," $1 ")
L:=Trim(rr(L,"[^\w#@$;" co "``]+"," ")),ln#=A_Index,cr=0
Loop Parse,L,%A_Space% ; ^^ c?[ (=>(] [;(=>$1 ] [`?{),=> $1 ]
{ z:=A_LoopField,y:=SubStr(z,1,1),cr:=ex!="a"||cr?cr:y=";"
IfEqual true,% (ex="d"&&z="rem"||ex="a"&&y=";"), IfNotEqual cm,1,break
(ex="a"&&A_Index=1&&z<>","&&z<>"{")?f#:=0:0
fr:=ex="d"?y=":"?A_Index=1?"F":lw="call"?"R":" ":" "
:ex="c"? SubStr(z,0)="("?c1&&!cr++&&!(nf[z]&2)? "F":"R":" "
:ex="a"&&SubStr(z,0)="("&&!(nf[z]&1)?"R":" "
(ex="a"&&SubStr(z,0)="("&&A_Index>1)?f#:=0:0
(ex="a"&&z="{"&&lw=")"&&f#&&fu)?fu:=SubStr(fu,1,f#) "F" SubStr(fu,f#+2):0
(ex="a")?(SubStr(z,0)=":"&&A_Index=1?fr:="F":lw="gosub"?fr:="R"):0
lw:=cr?lw:z,x:=rr(z,"(^[{:]+)|([({;:,)]+$)")
IfEqual x,,continue
fu.=ln#>=lb&&(ln#<=le||!le)?x "/" ln# "/" ++ic "/" fr "|":""
(ex="a"&&SubStr(z,0)="("&&A_Index=1&&!(nf[z]&1))?f#:=StrLen(fu)-2:0
IfEqual ex,d,IfEqual A_Index,1,IfEqual y,:,IfNotEqual cm,1,break
} } SplashTextOff
nz:=StrLen(ln#)+1,s:=dp(nz),wz=0,b2=2*10**9,int=""
IfLess lz,% nz*4,MsgBox 8240,,% "Characters/line must be " nz*4 " or greater!"
IfLess lz,% nz*4,goto rpt
How do you do this?

I use Notepad++ Ctrl+F → "Find all in current document" button for this goal.
Little bug: function map display hotkeys like a:: as function.
Last edited by stealzy on 12 Jan 2018, 14:35, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Cross Reference List (XRef)

12 Jan 2018, 10:38

@ stealzy see, someone else had similar questions ;). I reacted similarily to ReClip source code, but I found it quite easy to modify because the code was well commented, much more than your snippet, it looks a bit daunting indeed ;).

@ TAC109, I'm still using ReClip quite often, XRef, occasionally. :thumbup:

Cheers :wave:.
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

12 Jan 2018, 18:12

@stealzy - Well, my code is not quite as confusing as you portray, as you've lost the comments and indents in your shown example! Many short variable names are simple contractions of a longer more meaningful name (saves typing). The single character names near the end of the alphabet (z, y, x, etc) are like localised working registers (contents used within a few lines only).

Anyway, thanks for trying XRef. I'll look into the bug you found.

@Helgef - I haven't progressed much with the '#include' enhancement we discussed a while ago as there doesn't seem to be much demand for this facility, and I don't need it myself. I've mentally planned the method I would use, but not coded anything.

Thanks for your comments.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

12 Jan 2018, 18:44

stealzy wrote:Little bug: function map display hotkeys like a:: as function.
Actually, that's not a bug. For AHK scripts, XRef includes functions and labels in the 'Function Map'. As hotkeys can be the subject of 'goto' and 'gosub' commands, they are included in the report.

Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

13 Nov 2018, 21:59

Update 14 November 2018 -
  • The subset lines input box must now be completed or dismissed before continuing.
  • Subset XRef files created now have the supplied line number range in the file name.
  • Analysis of large scripts will now cause a readable progress tool tip to be shown.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

15 Nov 2018, 18:11

Update 16 November 2018 - n/up reports will now show the page number of the report in the 'page top' line.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

06 Jan 2019, 18:17

Update 07 January 2019 -
On recent versions of Windows 10, pressing the XRef Mono button would mistakenly clear Notepad's header and footer fields.
Now, pressing the Mono button will only:-
  • Set Notepad's margins to the defaults.
  • Set the Notepad font to mono.
  • (All other Notepad properties will remain unchanged.)
XRef is described in this post, where you can find the download link.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

04 Apr 2019, 22:05

Update 5 April 2019 -
  • Now can process AHK '#Include's to produce consolidated reports. (See the updated documentation for details.)
  • The Function Map now incorporates 'goto's.
  • The detection of comments in AHK and DOS scripts has been greatly improved.
  • Now handles AHK '#CommentFlag's and '#EscapeChar's directives.
  • Certain checkboxes in the 'Options' window now have a 3-way state for mutually exclusive or additive actions.
  • The text associated with these checkboxes will change to indicate the option selected.
XRef is described in this post, where you can find the download link.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

14 Apr 2019, 23:09

Update 15 April 2019 - Provide for the correct working directory defaults when processing '#Include' directives for AHK v2 (as well as v1).

XRef is described in this post, where you can find the download link.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Cross Reference List (XRef)

19 Apr 2019, 02:10

Excellent! It works well with v2 now, thanks for sharing this.

Cheers!
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

19 Apr 2019, 03:28

@Helgef Thanks for the confirmation!
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

02 Jun 2019, 19:01

Update 03 June 2019 -
  • Modified print commands for Notepad, to work with Windows 10, 1903 version.
  • Note:- Do not use this version unless your Windows 10 version is 1903 or later.
XRef is described in this post, where you can find the download link.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Cross Reference List (XRef)

20 Jun 2019, 22:56

The download link from OP leads to an error ... "Error (404) - We can't find the page you're looking for." (https://bit.ly/2nmi8Id -> https://www.dropbox.com/s/dl/ast2uf4e7uzrxg9/XRef.zip)

You should consider, hosting it on github (or similar)
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

21 Jun 2019, 00:58

Update 21 June 2019 - Fixed download link.
(Thanks @hoppfrosch)
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

03 Sep 2019, 18:24

Update 04 September 2019 -
  • Any ;@Ahk2Exe compiler directives encountered will have their data included in the reports.
  • Progress messages, etc. will now be shown in the status area of the Options window.
  • Any error messages generated by AutoHotkey.exe will now appear in the '#Include List'.
XRef is described in this post, where you can find the download link.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
DaveT1
Posts: 224
Joined: 07 Oct 2014, 11:23

Re: Cross Reference List (XRef)

23 Mar 2021, 05:47

@TAC109 only just come across this and it's great - thanks for developing. Couple of quick Qs (and apologies if they are already there and I've missed it):
  1. I would use this all the time to find vars, funcs, labels (v,f,l) that have ended up not used (=I'm a sloppy code developer!). Would it be possible to add a symbol on any line in the output where a v,f,l has only one line number (assuming that identifies it as something used only once)? Then I could search the XRef output file for this symbol and find all single-use v,f,ls.
  2. In the function map (brilliant by the way), would it be possible to match a 'label' with it's corresponding 'g-label'? For example, one line from the XRef output shows 492 HLGuiLV1Lbl . But this is actually a g-label gHLGuiLV1Lbl defined in my code on line 462. I think it would be massively helpful to have the outut as 492 HLGuiLV1Lbl(g) 462 (where the "(g)" indicates that this is a glabel).
Thanks again for a great tool.
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

23 Mar 2021, 16:32

@DaveT1 Thanks for your interest in XRef and your suggestions.

Dealing with them separately:

1) Unfortunately XRef doesn’t distinguish between vars, functions and labels, and all the other words that appear in the script being analysed, so there could be many false positives flagged. (For the most part, XRef works in a generalised way to allow it to also process other types of files such as batch, C, and JS.)

2) In the past I have also looked at implementing this suggestion, but in the end rejected it, again because of the “false positive” aspect. (Similarly for v-variables in GUI statements.) so I have left it up to the user to “know” that certain labels and variables could appear in GUI statements, and check the listing under “g” and “v” appropriately.

Sorry for the bad news, but still hope that you find XRef useful.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
DaveT1
Posts: 224
Joined: 07 Oct 2014, 11:23

Re: Cross Reference List (XRef)

24 Mar 2021, 04:43

Many thanks for the quick and informative response- much appreciated :thumbup:
TAC109 wrote:
23 Mar 2021, 16:32
1) Unfortunately XRef doesn’t distinguish between vars, functions and labels, and all the other words that appear in the script being analysed, so there could be many false positives flagged. (For the most part, XRef works in a generalised way to allow it to also process other types of files such as batch, C, and JS.)
Sorry, I may have caused a confusion. I didn't mean to suggest that vars, functions and labels should be distinguished from one another. Rather I was thinking that if any of these appear in the XRef output with only one number on the same line, this means that they have been defined in the source script but not subsequently used (I think?). If these lines in the XRef output could be marked with a common symbol (eg., say '$'), then I could quickly search the XRef output for this symbol and find all such situations. As I'm not a good programmer this would help me to keep scripts clean of unnecessary mistakes.

If this couldn't be implemented, then it should be possible for me to write an XRef post-processing script to do this. For each line in the XRef output, eg., *click 496 585 , would I search for the first space (that would be at the end of the *click part, and then test to see if there are numbers after this?
TAC109 wrote:
23 Mar 2021, 16:32
2) In the past I have also looked at implementing this suggestion, but in the end rejected it, again because of the “false positive” aspect. (Similarly for v-variables in GUI statements.) so I have left it up to the user to “know” that certain labels and variables could appear in GUI statements, and check the listing under “g” and “v” appropriately.
Agreed there would be a risk of false-positives. Again if I wanted to try this I could write a post-processor to parse the XRef output to note the 'Labels' from all the gLabels. Then this list could be cross-refed with any other '*text' looking for matches?

3) One additional Q (sorry for the nuisance) - if I wanted to limit XRef output (the List part not the Function Map) to only include the variables from the script it is analysing, is there a simple way to get a list of vars from a script? If so, I could then have my post-processor scan the XRef output, compare each text element from there with the list of vars, and only re-write, to another output file, those lines for which there was a match.

Sorry, hope these thoughts arn't too non-sensical!! Any thoughts much appreciated.
TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Cross Reference List (XRef)

24 Mar 2021, 15:49

1 & 2) Yes, the post-processor idea could give you the output you want.

3) I’m not sure what you are getting at, here as variables are not distinguished from other 'words' by XRef. (There is little syntax checking apart from detecting '#Include's, comments, Ahk2Exe directives, and function definitions.) You could eliminate numbers and command words I suppose, but it is more difficult to distinguish between commands and variables that have the same name. (The language allows you to have a variable called FileAppend, for example.) In general I have felt that it is best to include too much information rather than too little in the reports.

Thanks again for your interest.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Cross Reference List (XRef)

25 Mar 2021, 00:12

First of all ...! :salute:
TAC109 wrote:
21 Mar 2017, 00:25
I suppose my coding style could be regarded as 'normalised'.
I think :think: you code normally and then make it look like puzzle, I am inspired ....! :bravo:
I never seen AHK code like this, and I am surprised I can read it and understand it just like the way you solve puzzles :HeHe:
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 71 guests