Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sakura.hhpsakura_core\sakura.hh` を参照するのをやめてコメントをカットした sakura.hh を使うようにする (python 版) #930

Merged
merged 5 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.vs
/cppcheck-*.xml
/cppcheck-install.log
/help/sakura/sakura.hh
/tests/build
/Win32
/x64
Expand Down
1 change: 1 addition & 0 deletions appveyor.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ APPVEYOR_REPO_TAG_NAME は利用をやめて 代わりに GIT_TAG_NAME を使う
- [appveyor_env.py](appveyor_env.py)
- [build-gnu.bat](build-gnu.bat) : (Platform="MinGW"のみ) Makefileをビルドしてbuild-all.batの処理を終了する
- [build-chm.bat](build-chm.bat) : HTML Help をビルドする
- [remove-comment.py](help/remove-comment.py) : UTF-8 でのコンパイルエラーの回避のために日本語を削除するために [sakura.hh](sakura_core/sakura.hh) から一行コメントを削除する
- hhc.exe (Visual Studio 2017 に同梱)
- [run-cppcheck.bat](run-cppcheck.bat) : cppcheck を実行する
- cppcheck.exe
Expand Down
6 changes: 6 additions & 0 deletions build-chm.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ set HHP_SAKURA=help\sakura\sakura.hhp
set CHM_MACRO=help\macro\macro.chm
set CHM_PLUGIN=help\plugin\plugin.chm
set CHM_SAKURA=help\sakura\sakura.chm
set HH_SCRIPT=%~dp0help\remove-comment.py
set HH_INPUT=sakura_core\sakura.hh
set HH_OUTPUT=help\sakura\sakura.hh

del /F "%HH_OUTPUT%"
python "%HH_SCRIPT%" "%HH_INPUT%" "%HH_OUTPUT%" || (echo error && exit /b 1)

call :BuildChm %HHP_MACRO% %CHM_MACRO% || (echo error && exit /b 1)
call :BuildChm %HHP_PLUGIN% %CHM_PLUGIN% || (echo error && exit /b 1)
Expand Down
33 changes: 33 additions & 0 deletions help/remove-comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import os
import sys
import re
import codecs

# 引数で指定した文字列から改行コードを取り除く
def clipEndOfLine(line):
return line.rstrip('\r\n')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

関数名には突っ込まない方針がいいのかな?と思いつつ・・・。

ニュアンス的には trimかstripじゃないのかな、と。


# 行からコメントを削除する
def clipCommet(line):
return re.sub(r'//.*', r'', line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw文字列。C++的にも LR"(//.*)" と書けるようになってますね。


# ファイルからコメントを削除する
def removeComment(inFile, outFile):
with codecs.open(inFile, "r", "utf_8_sig") as fin:
with codecs.open(outFile, "w", "utf_8_sig") as fout:
for line in fin:
text = clipEndOfLine(line)
text = clipCommet(text)
fout.write(text + "\r\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ん?と思いましたが、生成された help/sakura.hh の行末は正しく出力されていました。


if __name__ == '__main__':
if len(sys.argv) < 3:
print ("usage: " + os.path.basename(sys.argv[0]) + " <src file> <dst file>")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あえて 2系&3系 両対応で書いてある雰囲気を感じました。
個人的には python3 専用でいいような気がしますが。

sys.exit(1)

if not os.path.exists(sys.argv[1]):
print (sys.argv[1] + " doesn't exist")
sys.exit(1)

removeComment(sys.argv[1], sys.argv[2])
2 changes: 1 addition & 1 deletion help/sakura/sakura.hhp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ HLP_UR001=res\HLP_UR001.html
HLP_HISTORY=res\HLP_HISTORY.html

[MAP]
#include ../../sakura_core/sakura.hh
#include sakura.hh

[TEXT POPUPS]
Cshelp.txt
Expand Down