-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_tool.hsp
More file actions
57 lines (53 loc) · 1.79 KB
/
script_tool.hsp
File metadata and controls
57 lines (53 loc) · 1.79 KB
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
#ifndef script_tool_hsp_included
#define script_tool_hsp_included
#module
/*
引数で渡されたHSP3スクリプトからアノテーション以外のコメントを省いたものを作成する
引数
out_buf: コメントを省いたスクリプトが格納される変数
script_buf: 元のスクリプトが格納された変数
*/
#deffunc remove_unused_data var out_buf, var script_buf
comment_mode = 0 // 0: not comment, 1: one line comment, 2: multiline comment
string_mode = 0
sdim buf, varsize(script_buf)
read_index = 0
write_index = 0
repeat
if read_index >= strlen(script_buf) : break
ch1 = peek(script_buf, read_index)
ch2 = peek(script_buf, read_index + 1)
if ch2 == 0 : break
if comment_mode == 0 && string_mode == 0{
if (ch1 == ';' && ch2 != '@') || (ch1 == '/' && ch2 == '/') : comment_mode = 1 : read_index++ : continue
if (ch1 == '/' && ch2 == '*') : comment_mode = 2 : read_index++ : continue
if (ch1 == '\"') : string_mode = 1
} else : if comment_mode == 1 {
if ch1 == '\n' : comment_mode = 0 : else : read_index++ : continue
} else : if comment_mode == 2 {
if (ch1 == '*' && ch2 == '/') {
comment_mode = 0
read_index += 2
continue
} else : if (ch1 != '\n' && ch1 != '\r') {
read_index++
continue
}
} else : if string_mode {
if (ch1 != '\\' && ch2 == '\"') {
string_mode = 0
read_index += 1
ch1 = '\"'
} else : if (ch1 != '\n' && ch1 != '\r') {
read_index++
continue
}
}
poke buf, write_index, ch1
write_index++
read_index++
loop
out_buf = buf
return
#global
#endif