HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2020
0424
こいる#includeしているファイルを開くツールを作成しました(HSPスクリプトエディタ用)6解決


こいる

リンク

2020/4/24(Fri) 15:30:33|NO.90166

HSPスクリプトエディタで#includeしているファイルを開くツールを作成しました。

#includeしているところにキャレットを合わせ(行にカーソルを移動させる)、
実行することで、#includeしているファイルを開いてくれます。

また、#additionしているファイルも同様に開いてくれます。


下のスクリプトをCtrl+F9で実行ファイルにし、
HSPのインストールフォルダ(hsed3.exeがあるフォルダ)に、作った実行ファイルを置いてください。

そうしたら、HSPスクリプトエディタの外部ツールに登録して使ってください。
(登録時に「ポップアップメニューに表示」にチェックを入れると便利)


良ければ、感想やバグ報告お願いします。
改造も自由にしてください。
要望も可能な範囲で受け付けます。

#packopt name "hsed_open_include_file" #packopt hide 1 #packopt xsize 1 #packopt ysize 1 #include "hsedsdk.as" #include "mod_regexp.as" // 指定したファイルが存在すれば開く #module #deffunc openIncludeFile str filePath exist filePath if strsize==-1 : return exist dir_exe+"\\hsed3.exe" if strsize==-1{ ; なければ既定のプログラム exec filePath,16 }else{ ; hsed3.exeがあれば、それで開く exec dir_exe+"\\hsed3.exe \""+filePath+"\"" } end #global hsed_exist: if stat==0: dialog "エディタが起動していません。",1,"エラー": end // エディタ起動確認 // 現在行のテキストを取得 ; アクティブタブのFootyのID取得 dim footyId hsed_getactfootyid footyId ; キャレット行取得 dim selLine hsed_capture sendmsg hIF@hsedsdk, _HSED_GETCARETLINE@hsedsdk, footyId selLine = stat ; 全体のテキスト取得 sdim text hsed_gettext text, footyId ; キャレット行のテキスト取得 sdim sTargetLine notesel text noteget sTargetLine, selLine // ファイルを開く ; ファイル名取得 sdim includeFilePath,256 includeFilePath = submatch(sTargetLine, "(?:#(?:include)|(?:addition))\\s+\"(.*?)\"") if includeFilePath!=""{ // 絶対パス (そのまま) openIncludeFile includeFilePath // ソースフォルダのパス(現在タブのファイルのディレクトリ情報)を取得 dim tabId hsed_gettabid tabId, footyId sdim sourceDir,256 hsed_getpath sourceDir, tabId sourceDir = getpath(sourceDir,32) ; 無題でなければ if sourceDir!=""{ // ソースフォルダからの相対パス&直下のファイル openIncludeFile sourceDir+"\\"+includeFilePath } // commonフォルダを検索 openIncludeFile dir_exe+"\\common\\"+getpath(includeFilePath,8) // 直下 openIncludeFile dir_exe+"\\common\\"+includeFilePath // 相対 } end

【メモ】
#includeのファイルの検索順。
数字の順にファイルを検索します。(HSP ver3.51で検証)

▼用語
・ソースフォルダ = include元のファイルがあるフォルダ
・commonフォルダ = HSPインストールフォルダ内にある"common"フォルダ

▼検証結果
ファイル名のみ 例:"test.as"
1.ソースフォルダ内
2.commonフォルダ内

相対パス "test\\test.as"
1.ソースフォルダからの相対パス
2.commonフォルダ内 ※1
3.commonフォルダからの相対パス

絶対パス "C:\\test.as"
1.絶対パス (そのまま)
2.commonフォルダ内 ※1

※1 = ファイルパスに含まれるファイルを検索 ("C:\\test.as"なら"test.as")



この記事に返信する


ふじこlp

リンク

2020/4/26(Sun) 11:13:35|NO.90198

今まではわざわざcommonフォルダを探していたのですが、
これならいちいちエクスプローラを開かなくてもよいので便利ですね!

ただ
#include
のある行にカーソルを合わせなければならないのは少し不便…
少し改造させていただきます。



kanamaru

リンク

2020/4/26(Sun) 11:27:50|NO.90199

実行ファイルにせずエディタで実行したからかもしれませんが、
hsedsdk.asにキャレットがある状態で実行したら、
mod_regexp.asが開きました。
また、その状態でもう一度挑戦したら、
mod_regexp.asが見つかりませんというエラーが発生しました。
使いかたが違うからかもしれませんが、報告しておきます



こいる

リンク

2020/4/29(Wed) 19:23:05|NO.90233

>ふじこlpさん
>これならいちいちエクスプローラを開かなくてもよいので便利ですね!
ありがとうございます!


>kanamaruさん
>hsedsdk.asにキャレットがある状態で実行したら、mod_regexp.asが開きました。
HSP3.6β2のエディタで実行したところ、同じ現象が起きました。
どうやら3.62でキャレット行取得をした場合、行番号が1行ずれてしまうのが原因みたいです。

>その状態でもう一度挑戦したら、mod_regexp.asが見つかりませんというエラーが発生しました。
これはHSP3.51でも3.6β2でも同じ現象が起きました。

一度目実行したときになぜかcommonフォルダがカレントディレクトリになってしまい、
絶対パス判定でexistにファイル名のみを指定したとき、existがカレントディレクトリを検索して見つけるが、
開くときはファイル名しか指定しなかったため、エディタがファイルを見つけられなかったのだと思います。
ただ、これはエディタ上で実行したときしか起きないです。


とりあえず、この2つの問題を修正したものをあげておきます。
ついでにdir_exeの部分を定数に置き換えました。

ちなみに、HSP3.6β2で使用すると、動作が遅かったり、
実行ファイルがなぜか大きくなってしまう問題があるので、
HSP3.51で実行ファイルにすることをお勧めします。

#packopt name "hsed_open_include_file" #packopt hide 1 #packopt xsize 1 #packopt ysize 1 #include "hsedsdk.as" #include "mod_regexp.as" #define global dir_hsp dir_exe // 指定したファイルが存在すれば開く #module #deffunc openIncludeFile str filePath exist filePath if strsize==-1 : return exist dir_hsp+"\\hsed3.exe" if strsize==-1{ ; なければ既定のプログラム exec filePath,16 }else{ ; hsed3.exeがあれば、それで開く exec dir_hsp+"\\hsed3.exe \""+filePath+"\"" } end #global hsed_exist: if stat==0: dialog "エディタが起動していません。",1,"エラー": end // エディタ起動確認 // 現在行のテキストを取得 ; アクティブタブのFootyのID取得 dim footyId hsed_getactfootyid footyId ; キャレット行番号取得 dim selLine hsed_capture sendmsg hIF@hsedsdk, _HSED_GETCARETLINE@hsedsdk, footyId selLine = stat ; エディタのバージョンが3.62の場合に行番号を-1 dim hsedVer hsed_getver hsedVer, HGV_PUBLICVER if strf("%x",hsedVer)==3602 : selLine-=1 ; 全体のテキスト取得 sdim text hsed_gettext text, footyId ; キャレット行のテキスト取得 sdim sTargetLine notesel text noteget sTargetLine, selLine // ファイルを開く ; ファイル名取得 sdim includeFilePath,256 includeFilePath = submatch(sTargetLine, "(?:#(?:include)|(?:addition))\\s+\"(.*?)\"") if includeFilePath!=""{ // 絶対パス (ドライブ名があれば) if match(includeFilePath,"^\\w:\\\\")!="" : openIncludeFile includeFilePath // ソースフォルダのパス(現在タブのファイルのディレクトリ情報)を取得 dim tabId hsed_gettabid tabId, footyId sdim sourceDir,256 hsed_getpath sourceDir, tabId sourceDir = getpath(sourceDir,32) ; 無題でなければ if sourceDir!=""{ // ソースフォルダからの相対パス&直下のファイル openIncludeFile sourceDir+"\\"+includeFilePath } // commonフォルダを検索 openIncludeFile dir_hsp+"\\common\\"+getpath(includeFilePath,8) // 直下 openIncludeFile dir_hsp+"\\common\\"+includeFilePath // 相対 } end



こいる

リンク

2020/5/3(Sun) 14:43:29|NO.90277

エディタのハンドルからファイルパスを取得することで、
HSPのインストールフォルダに実行ファイルを置かなくてもいいようにしました。
その他一部変数名の変更など。

#packopt name "hsed_open_include_file" #packopt hide 1 #packopt xsize 1 #packopt ysize 1 #include "hsedsdk.as" #include "mod_regexp.as" #uselib "kernel32.dll" #cfunc OpenProcess "OpenProcess" sptr, sptr, sptr #func CloseHandle "CloseHandle" sptr #func QueryFullProcessImageName "QueryFullProcessImageNameA" sptr, sptr, var, var #uselib "user32.dll" #func GetWindowThreadProcessId "GetWindowThreadProcessId" sptr, var // 指定したファイルが存在すれば開く #module #deffunc openIncludeFile str filePath exist filePath if strsize==-1 : return exec hsedPath@+" \""+filePath+"\"" end #global hsed_exist : if stat==0 : dialog "エディタが起動していません。",1,"エラー" : end // エディタ起動確認 // 現在行のテキストを取得 ; アクティブタブのFootyのID取得 dim footyId hsed_getactfootyid footyId ; キャレット行番号取得 dim selLine hsed_capture sendmsg hIF@hsedsdk, _HSED_GETCARETLINE@hsedsdk, footyId selLine = stat ; エディタのバージョンが3.62の場合、行番号を-1 dim hsedVer hsed_getver hsedVer, HGV_PUBLICVER if strf("%x",hsedVer)==3602 : selLine-=1 ; 全体のテキスト取得 sdim text hsed_gettext text, footyId ; キャレット行のテキスト取得 sdim sTargetLine,256 notesel text noteget sTargetLine, selLine // ファイルを開く ; ファイル名取得 sdim includeFilePath,256 includeFilePath = submatch(sTargetLine, "(?:#(?:include)|(?:addition))\\s+\"(.*?)\"") if includeFilePath!=""{ // エディタのファイルパス取得 dim hHsed : dim pid : dim hProcess : sdim hsedPath,256 : dim size size = 256 hsed_getwnd hHsed, HGW_MAIN GetWindowThreadProcessId hHsed, pid hProcess = OpenProcess(0x001F0FFF, 1, pid) QueryFullProcessImageName hProcess, 0, hsedPath, size CloseHandle hProcess // HSPのインストールディレクトリ取得 sdim hspDir,256 hspDir = getpath(hsedPath,32) // 絶対パス (ドライブ名があれば) if match(includeFilePath,"^\\w:\\\\")!="" : openIncludeFile includeFilePath // ソースフォルダのパスを取得 dim tabId sdim srcDir,256 hsed_gettabid tabId, footyId hsed_getpath srcDir, tabId srcDir = getpath(srcDir,32) // ソースフォルダ 相対&直下 (無題でなければ) if srcDir!="" : openIncludeFile srcDir+"\\"+includeFilePath // commonフォルダ openIncludeFile hspDir+"\\common\\"+getpath(includeFilePath,8) // 直下 openIncludeFile hspDir+"\\common\\"+includeFilePath // 相対 } end



こいる

リンク

2020/6/7(Sun) 16:12:12|NO.90713

#includeや#addtionと引用符の間に空白がなかった場合に、開くことができないことに気が付きました。

// こういったものが開けない #include"user32.as"

NO.90277のスクリプトの55行目の
includeFilePath = submatch(sTargetLine, "(?:#(?:include)|(?:addition))\\s+\"(.*?)\"")

を、↓に置き換えることで解消するはずです。
includeFilePath = submatch(sTargetLine, "(?:#(?:include)|(?:addition))\\s*\"(.*?)\"")



ZAP

リンク

2020/6/14(Sun) 22:36:15|NO.90778

これは便利ですね!活用させていただきます!



ONION software Copyright 1997-2023(c) All rights reserved.