Jump to content

msdn constants importer


GtaSpider
 Share

Recommended Posts

Hi there,

Well, perhaps some of you know that problem: You just wanna create a new amazing UDF and recive your informations from msdn. Well, ok exporting functions is not that problem, but its quite horrible to expand all the struct-constants from msdn in your script and format it in the way you want to.

So i wrote a little automation, so you just have to run this script, copy the link from msdn in your clip and the script will automatically write the constant in a file you specified before. Quite simple, isnt it?

Here is an example link: http://msdn.microsoft.com/en-us/library/ms941841.aspx

Hope you enjoy it!

;==================
;msdn constants importer
;by GtaSpider
;==================


;PLEASE CHANGE IF YOU WANT
Global Const $sVarBefore = "$tag" ; will be: $tagTITLE_OF_THE_CONSTANT
Global Const $sConstFileToWrite = @ScriptDir&"\Clip_Constants.au3"; the Constants will be written in the next line of the file
;STOP CHANGE

FileWrite($sConstFileToWrite,";Constants importet from msdn with 'msdn constants importer' by GtaSpider'"&@CRLF&@CRLF)

HotKeySet("^c","_clip")
HotKeySet("^C","_clip")
HotKeySet("^{ins}","_clip")

While 1
    Sleep(500)
WEnd

Func _clip()
    HotKeySet(@HotKeyPressed)
    Send(@HotKeyPressed)
    Local $sURL = ClipGet()
    If StringInStr($sURL,"msdn.microsoft.com") Then
        TrayTip("Clip",$sURL,2)
        Local $sSource = BinaryToString(InetRead($sURL))
        Local $aRegExp = StringRegExp($sSource,'(?s)<div class="title">(.*?)</div>.*?<pre class="libCScode".*?>.*?\{(.*?)}.*?</pre>',3)
        If UBound($aRegExp) < 2 Then
            MsgBox(16,"Clip","Error, RegExp returnd bad values")
        Else
            Local $sTitle = $aRegExp[0]
            Local $sData = $aRegExp[1]

            $sData = StringStripCR(StringReplace(StringReplace($sData,@LF,''),@CRLF,''))
            Local $sNewLine = 'Global Const '&$sVarBefore&$sTitle&' = "',$sRet
            Local $aData = StringSplit($sData,";"),$i
            For $i = 1 To $aData[0]
                If Not StringLen($aData[$i]) Then ContinueLoop
                $sNewLine &= $aData[$i]&"; "
                If StringLen($sNewLine) > 100 Then
                    $sRet &= $sNewLine& '" & _'&@CRLF
                    $sNewLine = @TAB&@TAB&'"'
                EndIf
            Next
            $sRet &= $sNewLine&'"'
            If StringRight($sRet,10) = ' & _'&@CRLF&@TAB&@TAB&'""' Then $sRet = StringTrimRight($sRet,10)
            FileWrite($sConstFileToWrite,$sRet&@CRLF)
            TrayTip($sTitle,"Successful insertet to"&@CRLF&$sConstFileToWrite,2)
        EndIf
    EndIf
    HotKeySet(@HotKeyPressed,"_clip")
EndFunc

Greetings

Spider

msdn constants importer.au3

Edited by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

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...