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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
-
|
|
!
-
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
!
|
-
|
|
!
|
|
|
!
-
|
!
-
|
|
|
|
|
!
-
|
|
|
|
!
-
|
|
!
| #include "hsedsdk.as"
#include "user32.as"
#include "kernel32.as"
#packopt name "hsed_Tab2Space"
#packopt hide 1
#packopt runtime "runtime/hsp3c.hrt"
#module
#uselib "Psapi.dll"
#func GetModuleFileNameEx "GetModuleFileNameExA" int, int, sptr, sptr
#defcfunc hsed_interface
hsed_capture
if stat {
dialog "エディタが起動していません。",,"中断"
end
}
return hIF@hsedsdk
#defcfunc hsed_getconfig str s1, str s2, int p3
if hsed_ini = 0 {
sdim hsed_path, 260
dim osinf, 37: osinf.0 = 148
GetVersionEx varptr(osinf)
if( osinf.4 = 2 && osinf.1 > 3 ){
GetWindowThreadProcessID@hsedsdk hIF@, dwProcessID
OpenProcess@hsedsdk PROCESS_ALL_ACCESS@hsedsdk, 0, dwProcessID
hHsedProc = stat
GetModuleFileNameEx hHsedProc, 0, varptr(hsed_path), 260
ret = stat
CloseHandle@hsedsdk hHsedProc
}else{
GetWindowModuleFileNameA hIF@, varptr(hsed_path), 260
ret = stat
}
if ret = 0 {
dialog "モジュールを取得できませんでした。",,"中断"
end
}
hsed_ini = getpath(hsed_path,32) + "hsp3config.ini"
}
GetPrivateProfileInt s1, s2, p3, hsed_ini
return stat
#deffunc hsed_getscript var v1, var v2
sendmsg hIF@, HSED_GETTEXTLENGTH, -1, 0
if stat = 0: end
sendmsg hIF@, HSED_SELECTALL, -1, 0
sendmsg hIF@, HSED_COPY, -1, 0
IsClipboardFormatAvailable 1: if stat = 0: goto *@f
OpenClipboard hIF@ : if stat = 0: goto *@f
GetClipboardData 1: hMem = stat
if hMem = 0 {
CloseClipboard: goto *@f
}
GlobalLock hMem: pScript = stat
lstrlen pScript: lenScript = stat
sdim v1, lenScript + 1
lstrcpy varptr( v1 ), pScript
GlobalUnlock hMem: dim script
CloseClipboard
v2 = lenScript
return 0
*@
dialog "クリップボードを読み取れません。",,"中断"
end
#deffunc ClientToClient int hw_from, var v2, int hw_to
ClientToScreen hw_from, varptr(v2)
ScreenToClient hw_to, varptr(v2)
return
#global
hIF = hsed_interface()
sendmsg hIF, HSED_GETWND, HGW_STATUSBAR, 0: hStatus = stat
sendmsg hIF, HSED_GETWND, HGW_MAIN, 0 : hMain = stat
dim rc, 4: GetClientRect hStatus, varptr(rc)
ClientToClient hStatus, rc, hMain
winobj "msctls_progress32", "実行中", 0, $40000000, 0, 0
hProg = objinfo(stat,2)
SetWindowLong hProg, $FFFFFFF8, hMain
SetWindowPos hProg, 0, rc.0, rc.1, rc.2, rc.3, $0020
tabsize = hsed_getconfig( "Edit", "tabsize", 4 )
hsed_getscript oldScript, oldLength
sendmsg hProg, $00000406, 0, oldLength
newScript = ""
newLength = 0 bufsize = 0
IsWindowVisible hStatus
if stat: ShowWindow hProg, 5
repeat
getstr lbuf, oldScript, lcnt lsize = strsize if lsize = 0: break
lcnt += lsize
sendmsg hProg, $00000404, lsize, 0 sendmsg hProg, $00000405, 0, 0
sdim wbuf, lsize * tabsize + 3
wcnt = 0 repeat
c = peek( lbuf, cnt )
if c = 0: break
if (( c >= $81 ) & ( c <= $9F )) | (( c >= $E0 ) & ( c <= $FC )) {
poke wbuf, wcnt, c : wcnt++
poke wbuf, wcnt, peek( lbuf, cnt+1 ) : wcnt++
continue cnt + 2
}
if c = '\t' {
repeat tabsize - ( wcnt \ tabsize )
poke wbuf, wcnt, ' ' : wcnt++
loop
continue
}
poke wbuf, wcnt, c: wcnt++
loop
wpoke wbuf, wcnt, $0A0D: wcnt += 2
newLength += wcnt
if bufsize <= newLength {
bufsize += ( newLength * 2 )
memexpand newScript, bufsize
}
memcpy newScript, wbuf, wcnt, newLength-wcnt, 0
await 0
loop
hsed_sendstr newScript
wait 100
end
|