Macro/投稿/86

http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2F86


Top > Macro > 投稿 > 86

現在行の #include で指定されたファイルを開く

  • ページ: Macro/投稿
  • 作者: まくろ初心者?
  • カテゴリー: vbs
  • 投稿日: 2006-07-02 (日) 16:14:21

メッセージ

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
' OpenIncludeFile.vbs
' 
' 現在行にある #include <file.h>、#include "file.h" のfile.hを開く。
' 検索対象は環境変数の INCLUDE と現在開いているファイルのフォルダ内
 
Call Main
 
' メイン処理
Sub Main()
    Dim objShell
    Dim sDistFileName, sCurDirName
    Dim i, pos
 
    Set objShell = CreateObject("Wscript.Shell")
    sIncPath = objShell.ExpandEnvironmentStrings("%INCLUDE%")
 
    sDistFileName = getIncludeFileName(Editor.GetLineStr(0))
    sCurDirName = getCurrentFolderName()
 
    If openFile(sCurDirName & sDistFileName) Then Exit Sub
 
    i = 1
    Do While True
        pos = InStr(i, sIncPath, ";")
        If IsNull(pos) Then Exit Do
        If pos = 0 Then
            If openFile(Mid(sIncPath, i)) Then Exit Sub
            Exit Do
        End If
        If openFile(Mid(sIncPath, i, pos - i)) Then Exit Sub
        i = pos + 1
    Loop
End Sub
 
' インクルードファイル名取得
Function getIncludeFileName(sLine)
    Dim pos, endpos
 
    getIncludeFileName = ""
    pos = InStr(1, sLine, "<")
    If pos = 0 Then
        pos = InStr(1, sLine, """")
        endpos = InStr(pos + 1, sLine, """")
    Else
        endpos = InStr(pos + 1, sLine, ">")
    End If
 
    If pos = 0 Or endpos = 0 Then Exit Function
    pos = pos + 1
    getIncludeFileName = Mid(sLine, pos, endpos - pos)
 
End Function
 
' 現在のフォルダ名取得
Function getCurrentFolderName()
    Dim pos
    Dim sCurFileName
 
    getCurrentFolderName = ""
 
    sCurFileName = GetFileName()
    pos = InStrRev(sCurFileName, "\")
    If pos = 0 Then Exit Function
    getCurrentFolderName = Mid(sCurFileName, 1, pos)
End Function
 
' ファイルが存在していたら開く
Function openFile(sPath)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
 
    openFile = False
    If (fso.FileExists(sPath)) Then
        Editor.FileOpen (sPath)
        openFile = True
    End If
 
End Function


URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

リロード   新規 編集 凍結 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2006-07-30 (日) 00:59:18 (6452d)