teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コメントを受けて、回答内容の追加。

2017/02/23 11:24

投稿

KenjiToriumi
KenjiToriumi

スコア344

answer CHANGED
@@ -7,4 +7,78 @@
7
7
  $xmlResult = [xml](Get-Content cppcheck.xml)
8
8
  $xmlResult.results.error | Select file,line,id,severity,msg | Export-Csv -Path cppcheck.csv -NoTypeInformation
9
9
 
10
- ```
10
+ ```
11
+
12
+ ---
13
+ 【追記】
14
+ CppCheckは私もたまに使用するので、結果のXML->CSV変換BATを作成してみました。
15
+ 「severity と id でのソート」と「msg内のエスケープ文字のデコード」処理を追加しています。
16
+
17
+ BATファイルに対して、XMLファイルをドロップすれば、同じ場所にCSVファイるが出力されます。
18
+
19
+ ご参考までに。
20
+
21
+ ※ BATファイル内にPowerShellスクリプト埋め込むテクニックを使用しているので、PowerShellスクリプトの位置(行数)を変更すると、正しく動作しません。
22
+
23
+ ```BAT
24
+ @echo off
25
+
26
+ setlocal
27
+
28
+ setlocal enabledelayedexpansion
29
+
30
+ title CppCheck結果 XML⇒CSV変換
31
+
32
+ if "%~1"=="" goto :EXIT
33
+
34
+ set SRC_FILE=%~f1
35
+ set DST_FILE=%~dpn1.csv
36
+
37
+ echo %SRC_FILE%
38
+
39
+ if not exist !SRC_FILE! echo is not exist! & goto :EXIT
40
+
41
+ echo ⇒ %DST_FILE%
42
+
43
+ rem PowerShellScript Line 50-60
44
+ powershell -NoLogo -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\" | ?{ ($_.readcount -ge 50) -and ($_.readcount -le 60) })-join \"`n\");&$s" """%SRC_FILE%""" """%DST_FILE%"""
45
+
46
+ start "" "%DST_FILE%"
47
+
48
+
49
+ :EXIT
50
+
51
+ echo -------------------------------------------------------------------------------
52
+ echo 処理結果を確認した後、何かキーを押してください . . .
53
+ echo.
54
+ pause >NUL
55
+
56
+ endlocal
57
+ goto :EOF
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ # ------------------------------------------------------------------------------
74
+ # PowerShellScript Line 50-60
75
+ # ------------------------------------------------------------------------------
76
+ Add-Type -AssemblyName System.Web
77
+ $xmlResult = [xml](Get-Content $Args[0])
78
+ $xmlResult.results.error `
79
+ | Select-Object file,line,severity,id,msg `
80
+ | Sort-Object severity,id `
81
+ | %{ $_.msg = [System.Web.HttpUtility]::HtmlDecode($_.msg); return $_ } `
82
+ | Export-Csv -Path cppcheck.csv -NoTypeInformation
83
+ # ------------------------------------------------------------------------------
84
+ ```