Sign in to follow this  
Followers 0
E1M1

[Solved] Need help with my help generator

1 post in this topic

#1 ·  Posted (edited)

I am trying to make program to generate help file but for some reason it gets stuck at first function.

I have function file contains about 30 functions formatted like following:

; #FUNCTION# ;===============================================================================
;
; Name...........: _DateDiff
; Description ...: Returns the difference between 2 dates, expressed in the type requested
; Syntax.........: _DateDiff($sType, $sStartDate, $sEndDate)
; Parameters ....: $sType - One of the following:
;                  |D = Difference in days between the given dates
;                  |M = Difference in months between the given dates
;                  |Y = Difference in years between the given dates
;                  |w = Difference in Weeks between the given dates
;                  |h = Difference in hours between the given dates
;                  |n = Difference in minutes between the given dates
;                  |s = Difference in seconds between the given dates
;                   $sStartDate  - Input Start date in the format "YYYY/MM/DD[ HH:MM:SS]"
;                   $sEndDate    - Input End date in the format "YYYY/MM/DD[ HH:MM:SS]"
; Return values .: Success - Difference between the 2 dates.
;                  Failure - Returns 0 and Sets @Error:
;                  |0 - No error.
;                  |1 - Invalid $sType
;                  |2 - Invalid $sStartDate
;                  |3 - Invalid $sEndDate
; Author ........: Jos van der Zande
; Modified.......:
; Remarks .......:
; Related .......: _DateAdd
; Link ..........:
; Example .......: Yes
;
;
;====================================================================================================

My help generator generates 30 diferntly named html files. But file data is always the same for some reason. Does anyone know why file content doesn't change?

I have code above at the beginning of my script. I used this example to make headers for my own functions. But for some reason all html help files I get are about _DateDiff, but none of them are about my own funcs.

Here's my help generator

$HelpSource = FileRead("SomeScript.au3")
$HelpDest = @ScriptDir & "\help"
$HelpTemplate = @ScriptDir & "\hemptemplate"
$TemplateHTML = FileRead($HelpTemplate & "\template.html")
$functionstart = "; #FUNCTION# ;==============================================================================="
$functionend = ";============================================================================================"
$name = "; Name...........:"
$description = "; Description ...:"
$syntax = "; Syntax.........:"
$parameters = "; Parameters ....:"
$returnValues = "; Return values .:"
$remarks = "; Remarks .......:"
$related = "; Related .......:"
FileCopy($HelpTemplate & "\default.css", $HelpDest, 1)
FileCopy($HelpTemplate & "\blue_gradient_1024x24.jpg", $HelpDest, 1)

While StringInStr($HelpSource, $functionstart) > 0

$find = StringInStr($HelpSource, $functionstart)
$HelpSource = StringTrimLeft($HelpSource, $find)

$find = StringInStr($HelpSource, $name)
$NameData = StringTrimLeft($HelpSource, $find + StringLen($name))
$NameData = StringLeft($NameData, StringInStr($NameData, @CRLF) - 1)
$TemplateHTML = StringReplace($TemplateHTML, "%name", ToHtml($NameData))

$find = StringInStr($HelpSource, $description)
$descriptionData = StringTrimLeft($HelpSource, $find + StringLen($description))
$descriptionData = StringLeft($descriptionData, StringInStr($descriptionData, $syntax) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%Description", ToHtml($descriptionData))

$find = StringInStr($HelpSource, $syntax)
$syntaxData = StringTrimLeft($HelpSource, $find + StringLen($syntax))
$syntaxData = StringLeft($syntaxData, StringInStr($syntaxData, $parameters) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%Syntax", ToHtml($syntaxData))

$find = StringInStr($HelpSource, $parameters)
$parametersData = StringTrimLeft($HelpSource, $find + StringLen($parameters))
$parametersData = StringLeft($parametersData, StringInStr($parametersData, $returnValues) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%param", ToHtml(ParametersToTable(RemoveOverhead($parametersData))))

$find = StringInStr($HelpSource, $returnValues)
$returnValuesData = StringTrimLeft($HelpSource, $find + StringLen($returnValues))
$returnValuesData = StringLeft($returnValuesData, StringInStr($returnValuesData, "; Author ........:") - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%ret", ToHtml(RemoveCrap(RemoveCrap($returnValuesData))))

$find = StringInStr($HelpSource, $remarks)
$remarksData = StringTrimLeft($HelpSource, $find + StringLen($remarks))
$remarksData = StringLeft($remarksData, StringInStr($remarksData, $related) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%remarks", ToHtml($remarksData))

$find = StringInStr($HelpSource, $related)
$relatedData = StringTrimLeft($HelpSource, $find + StringLen($remarks))
$relatedData = StringLeft($relatedData, StringInStr($relatedData, "; Link ..........:"))
$TemplateHTML = StringReplace($TemplateHTML, "%related", ToHtml(RelatedLinks($relatedData)))

$replacement = StringReplace($TemplateHTML,"<br><tr>","<tr>")
$replacement2 = StringReplace($replacement,"</tr><br>","</tr>")

;~ MsgBox(0,0,$HelpDest&"\"&$NameData&".html")
FileDelete($HelpDest & "\" & $NameData & ".html")
FileWrite($HelpDest & "\" & $NameData & ".html", $replacement2)
$replacement2 = ""

$HelpSource = StringTrimLeft($HelpSource,$functionend)
WEnd

Func RelatedLinks($sData)
    $sData = StringReplace($sData, @CRLF,"")
    $sData = StringReplace($sData, " ","")
    $a = StringSplit($sData,",")
    $link = '<a href="./%f">%s</a>'
    $data = ""
    For $i = 1 to $a[0]
        $data &= StringReplace(StringReplace($link,"%f",$a[$i]&".html"),"%s",$a[$i])&", "
    Next
    Return $data
EndFunc

Func ToHtml($sData)
    $sData = RemoveOverhead($sData)
    Return StringReplace($sData, @CRLF, "<br>")
EndFunc   ;==>ToHtml

Func ParametersToTable($sData)
    $data = ""
    While StringInStr($sData, "$")
        $find = StringInStr($sData, "$")
        $str = StringTrimLeft($sData, $find - 1)
        $str2 = StringLeft($str, StringInStr($str, " "))
        $str3 = StringTrimLeft($sData, StringLen($str2) + 2)
        $str4 = StringLeft($str3, StringInStr($str3, "$") - 1)
        If $str4 = "" Then
            $str4 = $str3
        EndIf
        $data &= "<tr><td>" & $str2 & "</td><td>" & RemoveCrap($str4) & "</td></tr>" & @CRLF
;~      MsgBox(0, 4, $str4)
        $sData = StringReplace($sData, $str4, "", 1)
        $sData = StringReplace($sData, $str2, "", 1)
    WEnd
    $tableend = '</tbody></table>'
    $stablestart = '<table border="1" bordercolor="#c0c0c0" cellpadding="3" cellspacing="0" width="100%"><tbody>'
    $tabledata = $stablestart & $data & $tableend
    $tabledata1 =  StringReplace($tabledata,@CRLF&"</td>","</td>")
    $tabledata2 =  StringReplace($tabledata1,@CR&"</td>","</td>")
;~  MsgBox(0,0,$tabledata2)
    Return $tabledata2
EndFunc   ;==>ParametersToTable

Func RemoveOverhead($sData)
    While StringInStr($sData, @TAB)
        $sData = StringReplace($sData, @TAB, " ")
    WEnd
    While StringInStr($sData, "  ")
        $sData = StringReplace($sData, "  ", " ")
    WEnd
    Return $sData
EndFunc   ;==>RemoveOverhead

Func RemoveCrap($sData)
    $sData = RemoveOverhead($sData)
    $a = StringSplit($sData, @CRLF, 1)
    $s = ""
    For $i = 1 To $a[0]
        If StringLeft($a[$i], 3) = " - " Then
            $a[$i] = StringTrimLeft($a[$i], 3)
        EndIf
        If StringLeft($a[$i], 2) = "- " Then
            $a[$i] = StringTrimLeft($a[$i], 2)
        EndIf
        If StringLeft($a[$i], 1) = " " Then
            $a[$i] = StringTrimLeft($a[$i], 1)
        EndIf
        If StringLeft($a[$i], 1) = ";" Then
            $a[$i] = StringTrimLeft($a[$i], 1)
        EndIf
        If StringLeft($a[$i], 1) = "|" Then
            $a[$i] = StringTrimLeft($a[$i], 1)
        EndIf
        If StringLen($a[$i]) > 2 Then
            $s &= $a[$i]& @CRLF
        EndIf
    Next
;~  MsgBox(0,1,$s)
    Return $s
EndFunc   ;==>RemoveCrap

And here's my html template

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Function GUICreate</title>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <link href="default.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Function Reference</h1>
<big><big>%Name</big></big>
<hr size="2">
<p>%Description<br>
</p>
<p class="codeheader"> #Include
<SomeScript.au3><br>
%Syntax<br>
</p>
<p> </p>
<p><b>Parameters</b></p>
%param
<p><b><br>Return
values</b></p>
%ret
<br><p><b>Remarks</b></p>
%remarks<br>
<br><p><b>Related</b></p>
%related
</body>
</html>

Is there any way to make it generate files with unique content instead of files with exactly the same content?

Solution:

$HelpSource = FileRead("SomeScript.au3")
$HelpDest = @ScriptDir & "\help"
$HelpTemplate = @ScriptDir & "\hemptemplate"
$TemplateHTML = FileRead($HelpTemplate & "\template.html")
$functionstart = "; #FUNCTION# ;==============================================================================="
$functionend = ";============================================================================================"
$name = "; Name...........:"
$description = "; Description ...:"
$syntax = "; Syntax.........:"
$parameters = "; Parameters ....:"
$returnValues = "; Return values .:"
$remarks = "; Remarks .......:"
$related = "; Related .......:"
FileCopy($HelpTemplate & "\default.css", $HelpDest, 1)
FileCopy($HelpTemplate & "\blue_gradient_1024x24.jpg", $HelpDest, 1)

While StringInStr($HelpSource, $functionstart) > 0
    $TemplateHTML = FileRead($HelpTemplate & "\template.html")

$find = StringInStr($HelpSource, $functionstart)
$HelpSource = StringTrimLeft($HelpSource, $find)

$find = StringInStr($HelpSource, $name)
;~ Consolewrite($find&@CRLF)
$NameData = StringTrimLeft($HelpSource, $find + StringLen($name))
$NameData = StringLeft($NameData, StringInStr($NameData, @CRLF) - 1)
$TemplateHTML = StringReplace($TemplateHTML, "%name", ToHtml($NameData))

;~ MsgBox(0,0,$TemplateHTML)
$find = StringInStr($HelpSource, $description)
$descriptionData = StringTrimLeft($HelpSource, $find + StringLen($description))
$descriptionData = StringLeft($descriptionData, StringInStr($descriptionData, $syntax) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%Description", ToHtml($descriptionData))

$find = StringInStr($HelpSource, $syntax)
$syntaxData = StringTrimLeft($HelpSource, $find + StringLen($syntax))
$syntaxData = StringLeft($syntaxData, StringInStr($syntaxData, $parameters) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%Syntax", ToHtml($syntaxData))

$find = StringInStr($HelpSource, $parameters)
$parametersData = StringTrimLeft($HelpSource, $find + StringLen($parameters))
$parametersData = StringLeft($parametersData, StringInStr($parametersData, $returnValues) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%param", ToHtml(ParametersToTable(RemoveOverhead($parametersData))))

$find = StringInStr($HelpSource, $returnValues)
$returnValuesData = StringTrimLeft($HelpSource, $find + StringLen($returnValues))
$returnValuesData = StringLeft($returnValuesData, StringInStr($returnValuesData, "; Author ........:") - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%ret", ToHtml(RemoveCrap(RemoveCrap($returnValuesData))))

$find = StringInStr($HelpSource, $remarks)
$remarksData = StringTrimLeft($HelpSource, $find + StringLen($remarks))
$remarksData = StringLeft($remarksData, StringInStr($remarksData, $related) - 2)
$TemplateHTML = StringReplace($TemplateHTML, "%remarks", ToHtml($remarksData))

$find = StringInStr($HelpSource, $related)
$relatedData = StringTrimLeft($HelpSource, $find + StringLen($remarks))
$relatedData = StringLeft($relatedData, StringInStr($relatedData, "; Link ..........:"))
$TemplateHTML = StringReplace($TemplateHTML, "%related", ToHtml(RelatedLinks($relatedData)))

$replacement = StringReplace($TemplateHTML,"<br><tr>","<tr>")
$replacement2 = StringReplace($replacement,"</tr><br>","</tr>")

;~ MsgBox(0,0,$HelpDest&"\"&$NameData&".html")
FileDelete($HelpDest & "\" & $NameData & ".html")
FileWrite($HelpDest & "\" & $NameData & ".html", $replacement2)
$replacement2 = ""

$HelpSource = StringTrimLeft($HelpSource,$functionend)
WEnd

Func RelatedLinks($sData)
    $sData = StringReplace($sData, @CRLF,"")
    $sData = StringReplace($sData, " ","")
    $a = StringSplit($sData,",")
    $link = '<a href="./%f">%s</a>'
    $data = ""
    For $i = 1 to $a[0]
        $data &= StringReplace(StringReplace($link,"%f",$a[$i]&".html"),"%s",$a[$i])&", "
    Next
    Return $data
EndFunc

Func ToHtml($sData)
    $sData = RemoveOverhead($sData)
    Return StringReplace($sData, @CRLF, "<br>")
EndFunc   ;==>ToHtml

Func ParametersToTable($sData)
    $data = ""
    While StringInStr($sData, "$")
        $find = StringInStr($sData, "$")
        $str = StringTrimLeft($sData, $find - 1)
        $str2 = StringLeft($str, StringInStr($str, " "))
        $str3 = StringTrimLeft($sData, StringLen($str2) + 2)
        $str4 = StringLeft($str3, StringInStr($str3, "$") - 1)
        If $str4 = "" Then
            $str4 = $str3
        EndIf
        $data &= "<tr><td>" & $str2 & "</td><td>" & RemoveCrap($str4) & "</td></tr>" & @CRLF
;~      MsgBox(0, 4, $str4)
        $sData = StringReplace($sData, $str4, "", 1)
        $sData = StringReplace($sData, $str2, "", 1)
    WEnd
    $tableend = '</tbody></table>'
    $stablestart = '<table border="1" bordercolor="#c0c0c0" cellpadding="3" cellspacing="0" width="100%"><tbody>'
    $tabledata = $stablestart & $data & $tableend
    $tabledata1 =  StringReplace($tabledata,@CRLF&"</td>","</td>")
    $tabledata2 =  StringReplace($tabledata1,@CR&"</td>","</td>")
;~  MsgBox(0,0,$tabledata2)
    Return $tabledata2
EndFunc   ;==>ParametersToTable

Func RemoveOverhead($sData)
    While StringInStr($sData, @TAB)
        $sData = StringReplace($sData, @TAB, " ")
    WEnd
    While StringInStr($sData, "  ")
        $sData = StringReplace($sData, "  ", " ")
    WEnd
    Return $sData
EndFunc   ;==>RemoveOverhead

Func RemoveCrap($sData)
    $sData = RemoveOverhead($sData)
    $a = StringSplit($sData, @CRLF, 1)
    $s = ""
    For $i = 1 To $a[0]
        If StringLeft($a[$i], 3) = " - " Then
            $a[$i] = StringTrimLeft($a[$i], 3)
        EndIf
        If StringLeft($a[$i], 2) = "- " Then
            $a[$i] = StringTrimLeft($a[$i], 2)
        EndIf
        If StringLeft($a[$i], 1) = " " Then
            $a[$i] = StringTrimLeft($a[$i], 1)
        EndIf
        If StringLeft($a[$i], 1) = ";" Then
            $a[$i] = StringTrimLeft($a[$i], 1)
        EndIf
        If StringLeft($a[$i], 1) = "|" Then
            $a[$i] = StringTrimLeft($a[$i], 1)
        EndIf
        If StringLen($a[$i]) > 2 Then
            $s &= $a[$i]& @CRLF
        EndIf
    Next
;~  MsgBox(0,1,$s)
    Return $s
EndFunc   ;==>RemoveCrap
Edited by E1M1

edited

Share this post


Link to post
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
Sign in to follow this  
Followers 0