Problems related to v2 docs compile_chm.ahk

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
crocodile
Posts: 100
Joined: 28 Dec 2020, 13:41

Problems related to v2 docs compile_chm.ahk

Post by crocodile » 10 Dec 2022, 02:37

I'm trying to make v2 latest docs files, but I'm having two problems with compile_chm.ahk.
This is a v1 script, and my system does not have v1.
ComObjCreate("ScriptControl") requires 32-bit AutoHotkey, which my system also does not have.
Does anyone have the compile_chm.ahk file for this v2 version?
Is there any way to replace ComObjCreate("ScriptControl")?

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problems related to v2 docs compile_chm.ahk

Post by lexikos » 10 Dec 2022, 07:51

Why not just install v1?
This installer and related scripts are designed to permit multiple versions of AutoHotkey to coexist.
Source: Using the Program | AutoHotkey v2
See Installing with v1.


ScriptControl is used to parse the index data. There are multiple alternatives:
  • Use MSHTML or IE via COM.

    Code: Select all

    htmlfile := ComObject('htmlfile')
    htmlfile.write('<meta http-equiv="X-UA-Compatible" content="IE=edge">')
    MsgBox htmlfile.parentWindow.eval('indexdata = ["Hello"];').0  ; Shows Hello
  • Use IActiveScript via COM (ActiveScript.ahk contains an implementation for v2).
  • Use JsRT via DllCall (JsRT.ahk contains an implementation for v2).
  • Use ChakraCore via DllCall (I don't think anyone has done this yet).
  • Use V8 or some other engine via DllCall...?
  • Remove the leading indexData = and trailing ; and then use one of the existing JSON parsers for AutoHotkey v2.

ComObjCreate("ScriptControl") requires 32-bit AutoHotkey, which my system also does not have.
Your system has only 64-bit AutoHotkey v2? Did you download v2 and then delete the 32-bit exe? Or build it from source code... but you can't build a 32-bit binary? Your admin approved the 64-bit exe but not the 32-bit one? All of these possibilities seem strange.

crocodile
Posts: 100
Joined: 28 Dec 2020, 13:41

Re: Problems related to v2 docs compile_chm.ahk

Post by crocodile » 10 Dec 2022, 21:55

Ah thanks, that helped me. I removed v1 when the ".ahk" faced a conflict with v1\V2. I used a script to update AutoHotkey, which only downloads 64-bit versions. But these really don't cause any substantial trouble, I just wish the v2 documentation could be made using v2.

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problems related to v2 docs compile_chm.ahk

Post by lexikos » 10 Dec 2022, 23:35

All you need to run a v1 script is a v1 EXE. It does not need to be installed or handle .ahk files by default. For instance, you can copy it to the same directory and run AutoHotkeyU32.exe compile_chm.ahk or rename AutoHotkeyU32.exe to compile_chm.exe and run it.
I used a script to update AutoHotkey, which only downloads 64-bit versions.
There is no official download which includes only a 64-bit binary. I guess that it would be downloading both versions, and then discarding the 32-bit version.
I just wish the v2 documentation could be made using v2.
It should probably be updated at some point, but I personally have other priorities (that's an understatement).

ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: Problems related to v2 docs compile_chm.ahk

Post by ludamo » 12 Dec 2022, 04:46

I have been compiling v2 docs with v2 AHK now for a while with the following script adapted from the original CreateFiles4Help.ahk and including ActiveScript by Lexikos from https://github.com/Lexikos/ActiveScript.ahk/blob/master/ActiveScript.ahk.

Code: Select all

#Requires AutoHotkey v2.0-a
#Warn VarUnset	;, OutputDebug
#Warn LocalSameAsGlobal	;, OutputDebug
#Warn Unreachable	;, OutputDebug

#SingleInstance

ListLines False							; turn on in specific area to debug 

; #NoTrayIcon
#Include "C:\Program Files\AutoHotkey\Lib\2-ActiveScript.ahk"

/* ****************************************************************
; Preamble - ScriptControl requires a 32-bit version of AutoHotkey.
;		BUT can use ActiveScript to run in 64 bit mode.
;   ****************************************************************
*/

TocJS := FileRead(A_ScriptDir "\data_toc.js")
IndexJS := FileRead(A_ScriptDir "\data_index.js")

SetWorkingDir A_ScriptDir "\..\..\.."

Overwrite("Table of Contents.hhc", TOC_CreateHHC(TocJS))
Overwrite("Index.hhk", INDEX_CreateHHK(IndexJS))

SetWorkingDir A_ScriptDir "\..\.."

/*
the following can be omitted 
_scripts_htm := FileRead( "Scripts.htm", "`n" )    ; modify file otherwise it gives a trivial error message when compiling
_needle := "scripts/" . Chr(34)
_scripts_htm := RegExReplace(_scripts_htm, _needle, 'scripts/index.htm"', &n, 1, -84)

_index_htm := FileRead("scripts\index.htm")	; delete javascript section as it gives errors when viewing this page
_index_htm := RegExReplace(_index_htm, "is)<script>.*</script>", "", &p, 1, 11300)	; uses only LFs

MsgBox n " replacement(s) for 'scripts.htm' made.`n" p " replacement(s) for 'index.htm' made."
if n > 0
{
	oFile :=	FileOpen("Scripts.htm", "w", "UTF-8")
	oFile.Write(_scripts_htm)
	oFile.Close
}
if p > 0
{
	oFile :=	FileOpen("scripts\index.htm", "w", "UTF-8")
	oFile.Write(_index_htm)
	oFile.Close
}
*/

Return

Overwrite(File, Text)
{
    FileOpen(File, "w").Write(Text)
}

TOC_CreateHHC(data)
{	global output
    ; ComObjError(false)
    ; sc := ComObjCreate("ScriptControl")
	js := ActiveScript("JScript")
    ; sc.Language := "JScript"
    ; sc.ExecuteStatement(data)
    js.Exec(data)
    output := '
    ( LTrim
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <HTML>
    <BODY>
    <OBJECT type="text/site properties">
    <param name="Window Styles" value="0x800625">
    <param name="ImageType" value="Folder">
    </OBJECT>
    )'
    ; output .= TOC_CreateListCallback("", sc.Eval("tocData"))
    output .= TOC_CreateListCallback(js.Eval("tocData"))
    output .= "`r`n</BODY>`r`n</HTML>`r`n"
    return output
}

TOC_CreateListCallback(data)
{	
	global output .= "`r`n<UL>`r`n"
	Loop data.length
	{
		r := A_Index - 1		; r = row
		output .= '<LI> <OBJECT type="text/sitemap">'
		; MsgBox data.%r%.length
		if data.%r%.length = 2			; usual rows
		{
			param_name := EncodeHTML(data.%r%.0)
			output .= '<param name="Name" value="' param_name '">'
			param_local := EncodeHTML(data.%r%.1)
			output .= '<param name="Local" value="docs/' param_local '">'
			output .= "</OBJECT>"
		}
		else if data.%r%.length = 3	; first row with sub-rows
		{
			param_name := EncodeHTML(data.%r%.0)
			output .= '<param name="Name" value="' param_name '">'
			param_local := EncodeHTML(data.%r%.1)
			output .= '<param name="Local" value="">'
			output .= "</OBJECT>"
			output .= TOC_CreateListCallback( data.%r%.2 )
		}

	output .= "`r`n"
	}
	output .= "</UL>"
	; return output
}

INDEX_CreateHHK(data)
{
    ; ComObjError(false)
    ; sc := ComObjCreate("ScriptControl")
	js := ActiveScript("JScript")
    ; sc.Language := "JScript"
    ; sc.ExecuteStatement(data)
    js.Exec(data)
    ; data := sc.Eval("indexData")
    data := js.Eval("indexData")
    global output := '
    ( LTrim
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <HTML>
    <BODY>
    )'
    output .= "`r`n<UL>`r`n"
    Loop data.length
    {
		r := A_Index - 1		; r = row

		output .= '<LI><OBJECT type="text/sitemap">'
		
		param_name := EncodeHTML(data.%r%.0)
		output .= '<param name="Name" value="' param_name '">'
		
		param_local := EncodeHTML(data.%r%.1)
		output .= '<param name="Local" value="docs/' param_local '">'

		output .= "</OBJECT>`r`n"
    }
    output .= "</UL>"
    output .= "`r`n</BODY>`r`n</HTML>`r`n"
	; output := StrReplace(output,"()","",,, -1)		; greater compatibility with NP++ Language Help plugin e.g. DllCall() -> DllCall
    return output
}

; HTML Entities Encoding
; https://www.autohotkey.com
; Similar to the Transform's HTML sub-command, this function converts a
; string into its HTML equivalent by translating characters whose ASCII
; values are above 127 to their HTML names (e.g. £ becomes &pound;). In
; addition, the four characters "&<> are translated to &quot;&amp;&lt;&gt;.
; Finally, each linefeed (`n) is translated to <br>`n (i.e. <br> followed
; by a linefeed).

; In addition of the functionality above, Flags can be zero or a
; combination (sum) of the following values. If omitted, it defaults to 1.

; - 1: Converts certain characters to named expressions. e.g. € is
;      converted to &euro;
; - 2: Converts certain characters to numbered expressions. e.g. € is
;      converted to &#8364;

; Only non-ASCII characters are affected. If Flags is the number 3,
; numbered expressions are used only where a named expression is not
; available. The following characters are always converted: <>"& and `n
; (line feed).

EncodeHTML(String, Flags := 1)
{
    static TRANS_HTML_NAMED := 1
    static TRANS_HTML_NUMBERED := 2
    static ansi := ["euro", "#129", "sbquo", "fnof", "bdquo", "hellip", "dagger", "Dagger", "circ", "permil", "Scaron", "lsaquo", "OElig", "#141", "#381", "#143", "#144", "lsquo", "rsquo", "ldquo", "rdquo", "bull", "ndash", "mdash", "tilde", "trade", "scaron", "rsaquo", "oelig", "#157", "#382", "Yuml", "nbsp", "iexcl", "cent", "pound", "curren", "yen", "brvbar", "sect", "uml", "copy", "ordf", "laquo", "not", "shy", "reg", "macr", "deg", "plusmn", "sup2", "sup3", "acute", "micro", "para", "middot", "cedil", "sup1", "ordm", "raquo", "frac14", "frac12", "frac34", "iquest", "Agrave", "Aacute", "Acirc", "Atilde", "Auml", "Aring", "AElig", "Ccedil", "Egrave", "Eacute", "Ecirc", "Euml", "Igrave", "Iacute", "Icirc", "Iuml", "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc", "Otilde", "Ouml", "times", "Oslash", "Ugrave", "Uacute", "Ucirc", "Uuml", "Yacute", "THORN", "szlig", "agrave", "aacute", "acirc", "atilde", "auml", "aring", "aelig", "ccedil", "egrave", "eacute", "ecirc", "euml", "igrave", "iacute", "icirc", "iuml", "eth", "ntilde", "ograve", "oacute", "ocirc", "otilde", "ouml", "divide", "oslash", "ugrave", "uacute", "ucirc", "uuml", "yacute", "thorn", "yuml"]
    static unicode := {0x20AC:1, 0x201A:3, 0x0192:4, 0x201E:5, 0x2026:6, 0x2020:7, 0x2021:8, 0x02C6:9, 0x2030:10, 0x0160:11, 0x2039:12, 0x0152:13, 0x2018:18, 0x2019:19, 0x201C:20, 0x201D:21, 0x2022:22, 0x2013:23, 0x2014:24, 0x02DC:25, 0x2122:26, 0x0161:27, 0x203A:28, 0x0153:29, 0x0178:32}

    out  := ""
    for i, char in StrSplit(String)
    {
        code := Ord(char)
        switch code
        {
            case 10: out .= "<br>`n"
            case 34: out .= "&quot;"
            case 38: out .= "&amp;"
            case 60: out .= "&lt;"
            case 62: out .= "&gt;"
            default:
            if (code >= 160 && code <= 255)
            {
                if (Flags & TRANS_HTML_NAMED)
                    out .= "&" ansi[code-127] ";"
                else if (Flags & TRANS_HTML_NUMBERED)
                    out .= "&#" code ";"
                else
                    out .= char
            }
            else if (code > 255)
            {
                if (Flags & TRANS_HTML_NAMED && unicode.HasOwnProp(code))
                    out .= "&" ansi[unicode.%code%] ";"
                else if (Flags & TRANS_HTML_NUMBERED)
                    out .= "&#" code ";"
                else
                    out .= char
            }
            else
            {
                if (code >= 128 && code <= 159)
                    out .= "&" ansi[code-127] ";"
                else
                    out .= char
            }
        }
    }
    return out
}

Post Reply

Return to “Ask for Help (v2)”