⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfc2mib.au3

📁 用于snmp协议的mib管理软件
💻 AU3
字号:
; 
; AutoIt Version: 3.1.1
; Platform:       Win2000
; Version:        0.1.0
; Author:         Robie Zhou (robiezhou@gmail.com)
;
; Script Function:
;   Convert RFC document to MIB file
;

Dim $logfile = "rfc2mib.log"

MsgBox(0, "rfc2mib v0.1", "Start convert...")
If find2go($logfile) Then
    Run("notepad " & $logfile)
EndIf
Exit

Func find2go($logfile = "rfc2mib.log", $dir = @ScriptDir)
    Local $search, $rfcfile, $mibfile
    Local $logfd

    If $logfile <> "" Then
        $logfd = FileOpen($logfile, 2)
        If $logfd = -1 Then
            Return 0
        EndIf
    EndIf

    If $dir <> @ScriptDir Then
        FileChangeDir($dir)
    EndIf

    $search = FileFindFirstFile("*.txt")  
    If $search = -1 Then
        FileClose($logfd)
        Return 0
    EndIf
    
    ; Rename each searched file
    While 1
        $rfcfile = FileFindNextFile($search) 
        If @error Then ExitLoop

        If $rfcfile = @ScriptName Then ContinueLoop
		$mibfile = rfc2mib($rfcfile)
        If $mibfile <> "" Then
            FileWriteline($logfd, $rfcfile & " --> " & $mibfile)
        EndIf
    WEnd

    FileClose($search)
    FileClose($logfd)

    Return 1
EndFunc

Func rfc2mib($rfcfile)
    Local $rfcfd, $mibfd
    Local $mibfile
    Local $pos, $hasmib, $inquot, $ispb
    Local $line
    
    $pos = StringInStr($rfcfile, ".", 1, -1)
    If $pos > 1 Then
        $mibfile = StringLeft($rfcfile, $pos - 1) & ".mib"
    Else
        $mibfile = $rfcfile & ".mib"
    EndIf
    
    $rfcfd = FileOpen($rfcfile, 0)
    If $rfcfd = -1 Then
        Return ""
    EndIf
    
    $mibfd = FileOpen($mibfile, 2)
    If $mibfd = -1 Then
        FileClose($rfcfd)
        Return ""
    EndIf
    
    $hasmib = 0
    $inquot = 0
    While 1
        $line = FileReadLine($rfcfd)
        If @error = -1 Then ExitLoop
            
        If StringInStr($line, "DEFINITIONS ::= BEGIN", 1) > 1 Then
            $hasmib = 1
            FileWriteLine($mibfd, $line)
            ContinueLoop
        EndIf
        
        If StringInStr($line, "END", 1) == (StringLen($line) - 2) Then
            FileWriteLine($mibfd, $line)
            ExitLoop
        EndIf
        
        If $hasmib = 1 Then
            If StringLen($line) == 0 Then
                FileWriteLine($mibfd, $line)
                ContinueLoop
            EndIf
            #cs
            $pos = StringInStr($line, '"', 0, 1)
            If $pos <> 0 Then
                If StringInStr($line, '"', 0, -1) == $pos Then
                    If $inquot = 1 Then 
                        $inquot = 0
                    Else
                        $inquot = 1 
                    EndIf
                EndIf
            EndIf
            #ce
            $ispb = 0
            If StringInStr($line, "[Page ", 1, -1) < StringInStr($line, "]", 1, -1) Then
                $ispb = 1
            EndIf
            If StringLeft($line, 4) == "RFC " AND StringIsDigit(StringRight($line, 4)) Then
                $ispb = 1
            EndIf
            
            If $ispb = 0 Then
                FileWriteLine($mibfd, $line)
            EndIf
        EndIf
    WEnd
    
    FileClose($mibfd)
    FileClose($rfcfd)
    
    If $hasmib = 0 Then
        FileDelete($mibfile)
        Return ""
    EndIf

    Return $mibfile
EndFunc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -