1 | 'function.sbp
|
---|
2 |
|
---|
3 |
|
---|
4 | #ifndef _INC_FUNCTION
|
---|
5 | #define _INC_FUNCTION
|
---|
6 |
|
---|
7 |
|
---|
8 | Const _System_PI = 3.14159265358979323846264
|
---|
9 | Const _System_LOG2 = 0.6931471805599453094172321214581765680755
|
---|
10 | Const _System_SQRT2 = 1.41421356237309504880168872421
|
---|
11 | Const _System_Log_N = 7 As Long
|
---|
12 |
|
---|
13 |
|
---|
14 | #require <Classes/System/Math.ab>
|
---|
15 | #require <Classes/ActiveBasic/Math/Math.ab>
|
---|
16 |
|
---|
17 |
|
---|
18 | '------------- サポート関数の定義 -------------
|
---|
19 |
|
---|
20 | Function ldexp(x As Double, n As Long) As Double
|
---|
21 | If x = 0 Then
|
---|
22 | ldexp = 0
|
---|
23 | Exit Function
|
---|
24 | End If
|
---|
25 | Dim pSrc = VarPtr(x) As *QWord
|
---|
26 | Dim pDest = VarPtr(ldexp) As *QWord
|
---|
27 | n += (pSrc[0] >> 52) As DWord And &h7FF
|
---|
28 | pDest[0] = n << 52 Or (pSrc[0] And &h800FFFFFFFFFFFFF)
|
---|
29 | End Function
|
---|
30 |
|
---|
31 | Function frexp(x As Double, ByRef n As Long) As Double
|
---|
32 | If x = 0 Then
|
---|
33 | n = 0
|
---|
34 | frexp = 0
|
---|
35 | Exit Function
|
---|
36 | End If
|
---|
37 |
|
---|
38 | Dim pSrc = VarPtr(x) As *QWord
|
---|
39 | Dim pDest = VarPtr(frexp) As *QWord
|
---|
40 | n = ((pSrc[0] >> 52) As DWord And &h7FF) - 1022
|
---|
41 | pDest[0] = (pSrc[0] And &h800FFFFFFFFFFFFF) Or &h3FE0000000000000
|
---|
42 | End Function
|
---|
43 |
|
---|
44 | Function frexp(x As Single, ByRef n As Long) As Single
|
---|
45 | If x = 0 Then
|
---|
46 | n = 0
|
---|
47 | frexp = 0
|
---|
48 | Exit Function
|
---|
49 | End If
|
---|
50 |
|
---|
51 | Dim pSrc As *DWord, pDest As *DWord
|
---|
52 | pSrc = VarPtr(x) As *DWord
|
---|
53 | pDest = VarPtr(frexp) As *DWord
|
---|
54 | n = ((pSrc[0] >> 23) And &hFF) - 126
|
---|
55 | pDest[0] = (pSrc[0] And &h807FFFFF) Or &h7E000000
|
---|
56 | End Function
|
---|
57 |
|
---|
58 | Function ipow(x As Double, n As Long) As Double
|
---|
59 | Dim abs_n As Long
|
---|
60 | Dim r = 1 As Double
|
---|
61 |
|
---|
62 | abs_n=Abs(n) As Long
|
---|
63 | While abs_n<>0
|
---|
64 | If abs_n and 1 Then r *= x
|
---|
65 | x = x * x
|
---|
66 | abs_n >>= 1 ' abs_n \= 2
|
---|
67 | Wend
|
---|
68 |
|
---|
69 | If n>=0 Then
|
---|
70 | ipow=r
|
---|
71 | Else
|
---|
72 | ipow=1/r
|
---|
73 | End If
|
---|
74 | End Function
|
---|
75 |
|
---|
76 | Function pow(x As Double, y As Double) As Double
|
---|
77 | If -LONG_MAX<=y and y<=LONG_MAX and y=CDbl(Int(y)) Then
|
---|
78 | pow=ipow(x,y As Long)
|
---|
79 | Exit Function
|
---|
80 | End If
|
---|
81 |
|
---|
82 | If x>0 Then
|
---|
83 | pow=Exp(y*Log(x))
|
---|
84 | Exit Function
|
---|
85 | End If
|
---|
86 |
|
---|
87 | If x<>0 or y<=0 Then
|
---|
88 | 'error
|
---|
89 | End If
|
---|
90 |
|
---|
91 | pow=0
|
---|
92 | End Function
|
---|
93 |
|
---|
94 | Const RAND_MAX=&H7FFFFFFF
|
---|
95 | Dim _System_RndNext=1 As DWord
|
---|
96 |
|
---|
97 | Function rand() As Long
|
---|
98 | _System_RndNext = _System_RndNext * 1103515245 + 12345
|
---|
99 | rand = _System_RndNext >> 1
|
---|
100 | End Function
|
---|
101 |
|
---|
102 | Sub srand(dwSeek As DWord)
|
---|
103 | _System_RndNext = dwSeek
|
---|
104 | End Sub
|
---|
105 |
|
---|
106 |
|
---|
107 | '------------- ここからBasic標準関数の定義 -------------
|
---|
108 |
|
---|
109 | '------------------
|
---|
110 | ' データ型変換関数
|
---|
111 | '------------------
|
---|
112 |
|
---|
113 | Function CDbl(number As Double) As Double
|
---|
114 | CDbl=number
|
---|
115 | End Function
|
---|
116 |
|
---|
117 | Function _CUDbl(number As QWord) As Double
|
---|
118 | _CUDbl=number As Double
|
---|
119 | End Function
|
---|
120 |
|
---|
121 | Function CDWord(num As Double) As DWord
|
---|
122 | CDWord=num As DWord
|
---|
123 | End Function
|
---|
124 |
|
---|
125 | Function CInt(number As Double) As Long
|
---|
126 | CInt=number As Long
|
---|
127 | End Function
|
---|
128 |
|
---|
129 | Function CSng(number As Double) As Single
|
---|
130 | CSng=number As Single
|
---|
131 | End Function
|
---|
132 |
|
---|
133 | #ifdef _WIN64
|
---|
134 | Function Fix(number As Double) As Long
|
---|
135 | Fix=number As Long
|
---|
136 | End Function
|
---|
137 | #else
|
---|
138 | 'Fix関数はコンパイラに組み込まれている
|
---|
139 | 'Function Fix(number As Double) As Long
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | Function Int(number As Double) As Long
|
---|
143 | Int = Fix(number)
|
---|
144 | If number < 0 Then
|
---|
145 | If number < Fix(number) Then Int--
|
---|
146 | End If
|
---|
147 | End Function
|
---|
148 |
|
---|
149 |
|
---|
150 | '-------------------------------------
|
---|
151 | ' ポインタ関数(コンパイラに組み込み)
|
---|
152 | '-------------------------------------
|
---|
153 |
|
---|
154 | 'Function GetDouble(p As DWord) As Double
|
---|
155 | 'Function GetSingle(p As DWord) As Single
|
---|
156 | 'Function GetDWord(p As DWord) As DWord
|
---|
157 | 'Function GetWord(p As DWord) As Word
|
---|
158 | 'Function GetByte(p As DWord) As Byte
|
---|
159 | 'Sub SetDouble(p As DWord, dblData As Double)
|
---|
160 | 'Sub SetSingle(p As DWord, fltData As Single)
|
---|
161 | 'Sub SetDWord(p As DWord, dwData As DWord)
|
---|
162 | 'Sub SetWord(p As DWord, wData As Word)
|
---|
163 | 'Sub SetByte(p As DWord, byteData As Byte)
|
---|
164 |
|
---|
165 |
|
---|
166 | '----------
|
---|
167 | ' 算術関数
|
---|
168 | '----------
|
---|
169 |
|
---|
170 | Function Abs(number As Double) As Double
|
---|
171 | 'Abs = System.Math.Abs(number)
|
---|
172 | If number < 0 then
|
---|
173 | return -number
|
---|
174 | Else
|
---|
175 | return number
|
---|
176 | End If
|
---|
177 | End Function
|
---|
178 |
|
---|
179 | Function Exp(x As Double) As Double
|
---|
180 | Exp = System.Math.Exp(x)
|
---|
181 | End Function
|
---|
182 |
|
---|
183 | Function Log(x As Double) As Double
|
---|
184 | Log = System.Math.Log(x)
|
---|
185 | End Function
|
---|
186 |
|
---|
187 | Function Sgn(number As Double) As Long
|
---|
188 | Sgn = System.Math.Sign(number)
|
---|
189 | End Function
|
---|
190 |
|
---|
191 | Function Sqr(number As Double) As Double
|
---|
192 | Sqr = System.Math.Sqrt(number)
|
---|
193 | End Function
|
---|
194 |
|
---|
195 | Function Atn(number As Double) As Double
|
---|
196 | Atn = System.Math.Atan(number)
|
---|
197 | End Function
|
---|
198 |
|
---|
199 | Function Atn2(y As Double, x As Double) As Double
|
---|
200 | Atn2 = System.Math.Atan2(y, x)
|
---|
201 | End Function
|
---|
202 |
|
---|
203 | Function Sin(number As Double) As Double
|
---|
204 | Sin = System.Math.Sin(number)
|
---|
205 | End Function
|
---|
206 |
|
---|
207 | Function Cos(number As Double) As Double
|
---|
208 | Cos = System.Math.Cos(number)
|
---|
209 | End Function
|
---|
210 |
|
---|
211 | Function Tan(number As Double) As Double
|
---|
212 | Tan = System.Math.Tan(number)
|
---|
213 | End Function
|
---|
214 |
|
---|
215 | Const RAND_UNIT = (1.0 / (LONG_MAX + 1.0))
|
---|
216 | Function Rnd() As Double
|
---|
217 | Rnd = RAND_UNIT * rand()
|
---|
218 | End Function
|
---|
219 |
|
---|
220 | Const HIDWORD(qw) = (((qw As QWord) >> 32) And &HFFFFFFFF) As DWord
|
---|
221 | Const LODWORD(qw) = ((qw As QWord) And &HFFFFFFFF) As DWord
|
---|
222 |
|
---|
223 | Const MAKEDWORD(l, h) = (((l As DWord) And &HFFFF) Or (((h As DWord) And &HFFFF) << 16)) As DWord
|
---|
224 | Const MAKEQWORD(l, h) = (((l As QWord) And &HFFFFFFFF) Or (((h As QWord) And &HFFFFFFFF) << 32)) As QWord
|
---|
225 |
|
---|
226 | '------------
|
---|
227 | ' 文字列関数
|
---|
228 | '------------
|
---|
229 |
|
---|
230 | Function Asc(buf As *StrChar) As StrChar
|
---|
231 | Asc = buf[0]
|
---|
232 | End Function
|
---|
233 |
|
---|
234 | Function Chr$(code As StrChar) As String
|
---|
235 | Chr$ = ZeroString(1)
|
---|
236 | Chr$[0] = code
|
---|
237 | End Function
|
---|
238 |
|
---|
239 | #ifndef __STRING_IS_NOT_UNICODE
|
---|
240 | Function AscW(s As *WCHAR) As UCSCHAR
|
---|
241 | If s.Length = 0 Then
|
---|
242 | AscW = 0
|
---|
243 | Else
|
---|
244 | If _System_IsSurrogatePair(s[0], s[1]) Then
|
---|
245 | AscW = ((s[0] And &h3FF) As DWord << 10) Or (s[1] And &h3FF)
|
---|
246 | Else
|
---|
247 | AscW = s[0]
|
---|
248 | End If
|
---|
249 | End If
|
---|
250 | End Function
|
---|
251 |
|
---|
252 | Function ChrW(c As UCSCHAR) As String
|
---|
253 | If c <= &hFFFF Then
|
---|
254 | ChrW.ReSize(1)
|
---|
255 | ChrW[0] = c As WCHAR
|
---|
256 | ElseIf c < &h10FFFF Then
|
---|
257 | ChrW.ReSize(2)
|
---|
258 | ChrW[0] = &hD800 Or (c >> 10)
|
---|
259 | ChrW[1] = &hDC00 Or (c And &h3FF)
|
---|
260 | Else
|
---|
261 | ' OutOfRangeException
|
---|
262 | End If
|
---|
263 | End Function
|
---|
264 | #endif
|
---|
265 |
|
---|
266 | Function Date$() As String
|
---|
267 | Dim st As SYSTEMTIME
|
---|
268 | GetLocalTime(st)
|
---|
269 |
|
---|
270 | 'year
|
---|
271 | Date$=Str$(st.wYear)
|
---|
272 |
|
---|
273 | 'month
|
---|
274 | If st.wMonth<10 Then
|
---|
275 | Date$=Date$+"/0"
|
---|
276 | Else
|
---|
277 | Date$=Date$+"/"
|
---|
278 | End If
|
---|
279 | Date$=Date$+Str$(st.wMonth)
|
---|
280 |
|
---|
281 | 'day
|
---|
282 | If st.wDay<10 Then
|
---|
283 | Date$=Date$+"/0"
|
---|
284 | Else
|
---|
285 | Date$=Date$+"/"
|
---|
286 | End If
|
---|
287 | Date$=Date$+Str$(st.wDay)
|
---|
288 | End Function
|
---|
289 |
|
---|
290 | Dim _System_HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
|
---|
291 |
|
---|
292 | Function _System_Hex(x As DWord, zeroSuppress As Boolean) As String
|
---|
293 | Dim s[7] As StrChar
|
---|
294 | Dim i As Long
|
---|
295 | For i = 0 To ELM(Len (s) \ SizeOf (StrChar))
|
---|
296 | s[i] = _System_HexadecimalTable[x >> 28] As StrChar
|
---|
297 | x <<= 4
|
---|
298 | Next
|
---|
299 | If zeroSuppress Then
|
---|
300 | Dim i As Long
|
---|
301 | For i = 0 To 6
|
---|
302 | If s[i] <> &h30 Then 'Asc("0")
|
---|
303 | Exit For
|
---|
304 | End If
|
---|
305 | Next
|
---|
306 | Return New String(VarPtr(s[i]) As *StrChar, Len (s) \ SizeOf (StrChar) - i)
|
---|
307 | Else
|
---|
308 | Return New String(s As *StrChar, Len (s) \ SizeOf (StrChar))
|
---|
309 | End If
|
---|
310 | End Function
|
---|
311 |
|
---|
312 | Function Hex$(x As DWord) As String
|
---|
313 | Hex$ = _System_Hex(x, True)
|
---|
314 | End Function
|
---|
315 |
|
---|
316 | Function Hex$(x As QWord) As String
|
---|
317 | If HIDWORD(x) = 0 Then
|
---|
318 | Hex$ = _System_Hex(LODWORD(x), True)
|
---|
319 | Else
|
---|
320 | Hex$ = _System_Hex(HIDWORD(x), True) + _System_Hex(LODWORD(x), False)
|
---|
321 | End If
|
---|
322 | End Function
|
---|
323 |
|
---|
324 | Function InStr(StartPos As Long, buf1 As String, buf2 As String) As Long
|
---|
325 | Dim i As Long, i2 As Long, i3 As Long
|
---|
326 |
|
---|
327 | Dim len1 = buf1.Length
|
---|
328 | Dim len2 = buf2.Length
|
---|
329 |
|
---|
330 | If len2=0 Then
|
---|
331 | InStr=StartPos
|
---|
332 | Exit Function
|
---|
333 | End If
|
---|
334 |
|
---|
335 | StartPos--
|
---|
336 | If StartPos<0 Then
|
---|
337 | 'error
|
---|
338 | InStr=0
|
---|
339 | Exit Function
|
---|
340 | End If
|
---|
341 |
|
---|
342 | i=StartPos:InStr=0
|
---|
343 | While i<=len1-len2
|
---|
344 | i2=i:i3=0
|
---|
345 | Do
|
---|
346 | If i3=len2 Then
|
---|
347 | InStr=i+1
|
---|
348 | Exit Do
|
---|
349 | End If
|
---|
350 | If buf1[i2]<>buf2[i3] Then Exit Do
|
---|
351 |
|
---|
352 | i2++
|
---|
353 | i3++
|
---|
354 | Loop
|
---|
355 | If InStr Then Exit While
|
---|
356 | i++
|
---|
357 | Wend
|
---|
358 | End Function
|
---|
359 |
|
---|
360 | Function Left$(buf As String, length As Long) As String
|
---|
361 | Left$ = ZeroString(length)
|
---|
362 | memcpy(StrPtr(Left$), StrPtr(buf), SizeOf (StrChar) * length)
|
---|
363 | End Function
|
---|
364 |
|
---|
365 | Function Mid$(buf As String, StartPos As Long)(ReadLength As Long) As String
|
---|
366 | Dim length As Long
|
---|
367 |
|
---|
368 | StartPos--
|
---|
369 | If StartPos<0 Then
|
---|
370 | 'error
|
---|
371 | 'Debug
|
---|
372 | Exit Function
|
---|
373 | End If
|
---|
374 |
|
---|
375 | length=Len(buf)
|
---|
376 | If length<=StartPos Then Exit Function
|
---|
377 |
|
---|
378 | If ReadLength=0 Then
|
---|
379 | ReadLength=length-StartPos
|
---|
380 | End If
|
---|
381 |
|
---|
382 | If ReadLength>length-StartPos Then
|
---|
383 | ReadLength=length-StartPos
|
---|
384 | End If
|
---|
385 |
|
---|
386 | Mid$=ZeroString(ReadLength)
|
---|
387 | memcpy(StrPtr(Mid$), VarPtr(buf.Chars[StartPos]), SizeOf (StrChar) * ReadLength)
|
---|
388 | End Function
|
---|
389 |
|
---|
390 | Function Oct$(num As DWord) As String
|
---|
391 | Dim i As DWord, i2 As DWord
|
---|
392 |
|
---|
393 | For i=10 To 1 Step -1
|
---|
394 | If (num \ CDWord(8^i)) And &H07 Then
|
---|
395 | Exit For
|
---|
396 | End If
|
---|
397 | Next
|
---|
398 |
|
---|
399 | Oct$=ZeroString(i+1)
|
---|
400 | i2=0
|
---|
401 | Do
|
---|
402 | Oct$[i2] = &h30 + ((num \ CDWord(8 ^ i)) And &H07) As StrChar ' &h30 = Asc("0")
|
---|
403 | If i=0 Then Exit Do
|
---|
404 | i--
|
---|
405 | i2++
|
---|
406 | Loop
|
---|
407 | End Function
|
---|
408 |
|
---|
409 | Function Right$(buf As String, length As Long) As String
|
---|
410 | Dim i As Long
|
---|
411 |
|
---|
412 | i=Len(buf)
|
---|
413 | If i>length Then
|
---|
414 | Right$=ZeroString(length)
|
---|
415 | memcpy(StrPtr(Right$), VarPtr(buf.Chars[i-length]), SizeOf (StrChar) * length)
|
---|
416 | Else
|
---|
417 | Right$=buf
|
---|
418 | End If
|
---|
419 | End Function
|
---|
420 |
|
---|
421 | Function Space$(length As Long) As String
|
---|
422 | Return New String(&h20 As StrChar, length)
|
---|
423 | End Function
|
---|
424 |
|
---|
425 | Dim _System_ecvt_buffer[16] As StrChar
|
---|
426 | Sub _ecvt_support(count As Long)
|
---|
427 | Dim i As Long
|
---|
428 | If _System_ecvt_buffer[count]=9 Then
|
---|
429 | _System_ecvt_buffer[count]=0
|
---|
430 | If count=0 Then
|
---|
431 | For i=16 To 1 Step -1
|
---|
432 | _System_ecvt_buffer[i]=_System_ecvt_buffer[i-1]
|
---|
433 | Next
|
---|
434 | _System_ecvt_buffer[0]=1
|
---|
435 | Else
|
---|
436 | _ecvt_support(count-1)
|
---|
437 | End If
|
---|
438 | Else
|
---|
439 | _System_ecvt_buffer[count]++
|
---|
440 | End If
|
---|
441 | End Sub
|
---|
442 | Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar
|
---|
443 | Dim i As Long, i2 As Long
|
---|
444 |
|
---|
445 | _ecvt=_System_ecvt_buffer
|
---|
446 |
|
---|
447 | '値が0の場合
|
---|
448 | If value = 0 Then
|
---|
449 | _System_FillChar(_System_ecvt_buffer, count As SIZE_T, &H30 As StrChar)
|
---|
450 | _System_ecvt_buffer[count] = 0
|
---|
451 | dec = 0
|
---|
452 | sign = 0
|
---|
453 | Exit Function
|
---|
454 | End If
|
---|
455 |
|
---|
456 | '符号の判断(同時に符号を取り除く)
|
---|
457 | If value < 0 Then
|
---|
458 | sign = 1
|
---|
459 | value = -value
|
---|
460 | Else
|
---|
461 | sign = 0
|
---|
462 | End If
|
---|
463 |
|
---|
464 | '正規化
|
---|
465 | dec = 1
|
---|
466 | While value < 0.999999999999999 'value<1
|
---|
467 | value *= 10
|
---|
468 | dec--
|
---|
469 | Wend
|
---|
470 | While 9.99999999999999 <= value '10<=value
|
---|
471 | value /= 10
|
---|
472 | dec++
|
---|
473 | Wend
|
---|
474 |
|
---|
475 | For i=0 To count-1
|
---|
476 | _System_ecvt_buffer[i] = Int(value) As StrChar
|
---|
477 |
|
---|
478 | value = (value-CDbl(Int(value))) * 10
|
---|
479 | Next
|
---|
480 | _System_ecvt_buffer[i] = 0
|
---|
481 |
|
---|
482 | i--
|
---|
483 | If value >= 5 Then
|
---|
484 | '切り上げ処理
|
---|
485 | _ecvt_support(i)
|
---|
486 | End If
|
---|
487 |
|
---|
488 | For i=0 To ELM(count)
|
---|
489 | _System_ecvt_buffer[i] += &H30
|
---|
490 | Next
|
---|
491 | _System_ecvt_buffer[i] = 0
|
---|
492 | End Function
|
---|
493 |
|
---|
494 | Function Str$(dbl As Double) As String
|
---|
495 | If ActiveBasic.Math.IsNaN(dbl) Then
|
---|
496 | Return "NaN"
|
---|
497 | ElseIf ActiveBasic.Math.IsInf(dbl) Then
|
---|
498 | If dbl > 0 Then
|
---|
499 | Return "Infinity"
|
---|
500 | Else
|
---|
501 | Return "-Infinity"
|
---|
502 | End If
|
---|
503 | End If
|
---|
504 | Dim dec As Long, sign As Long
|
---|
505 | Dim buffer[32] As StrChar, temp As *StrChar
|
---|
506 | Dim i As Long, i2 As Long, i3 As Long
|
---|
507 |
|
---|
508 | '浮動小数点を文字列に変換
|
---|
509 | temp = _ecvt(dbl, 15, dec, sign)
|
---|
510 |
|
---|
511 | i=0
|
---|
512 |
|
---|
513 | '符号の取り付け
|
---|
514 | If sign Then
|
---|
515 | buffer[i] = Asc("-")
|
---|
516 | i++
|
---|
517 | End If
|
---|
518 |
|
---|
519 | If dec>15 Then
|
---|
520 | '指数表示(桁が大きい場合)
|
---|
521 | buffer[i] = temp[0]
|
---|
522 | i++
|
---|
523 | buffer[i] = Asc(".")
|
---|
524 | i++
|
---|
525 | memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (StrChar) * 14)
|
---|
526 | i += 14
|
---|
527 | buffer[i] = Asc("e")
|
---|
528 | i++
|
---|
529 | _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1)
|
---|
530 |
|
---|
531 | Return MakeStr(buffer)
|
---|
532 | End If
|
---|
533 |
|
---|
534 | If dec < -3 Then
|
---|
535 | '指数表示(桁が小さい場合)
|
---|
536 | buffer[i] = temp[0]
|
---|
537 | i++
|
---|
538 | buffer[i] = Asc(".")
|
---|
539 | i++
|
---|
540 | memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (StrChar) * 14)
|
---|
541 | i+=14
|
---|
542 | buffer[i] = Asc("e")
|
---|
543 | i++
|
---|
544 | _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1)
|
---|
545 |
|
---|
546 | Return MakeStr(buffer)
|
---|
547 | End If
|
---|
548 |
|
---|
549 | '整数部
|
---|
550 | i2=dec
|
---|
551 | i3=0
|
---|
552 | If i2>0 Then
|
---|
553 | While i2>0
|
---|
554 | buffer[i]=temp[i3]
|
---|
555 | i++
|
---|
556 | i3++
|
---|
557 | i2--
|
---|
558 | Wend
|
---|
559 | buffer[i]=Asc(".")
|
---|
560 | i++
|
---|
561 | Else
|
---|
562 | buffer[i]=&H30
|
---|
563 | i++
|
---|
564 | buffer[i]=Asc(".")
|
---|
565 | i++
|
---|
566 |
|
---|
567 | i2=dec
|
---|
568 | While i2<0
|
---|
569 | buffer[i]=&H30
|
---|
570 | i++
|
---|
571 | i2++
|
---|
572 | Wend
|
---|
573 | End If
|
---|
574 |
|
---|
575 | '小数部
|
---|
576 | While i3<15
|
---|
577 | buffer[i]=temp[i3]
|
---|
578 | i++
|
---|
579 | i3++
|
---|
580 | Wend
|
---|
581 |
|
---|
582 | While buffer[i-1]=&H30
|
---|
583 | i--
|
---|
584 | Wend
|
---|
585 | If buffer[i-1]=Asc(".") Then i--
|
---|
586 |
|
---|
587 | buffer[i]=0
|
---|
588 | Return MakeStr(buffer)
|
---|
589 | End Function
|
---|
590 |
|
---|
591 | Function Str$(i As Int64) As String
|
---|
592 | If i < 0 Then
|
---|
593 | Return "-" & Str$(-i As QWord)
|
---|
594 | Else
|
---|
595 | Return Str$(i As QWord)
|
---|
596 | End If
|
---|
597 | End Function
|
---|
598 |
|
---|
599 | Function Str$(x As QWord) As String
|
---|
600 | If x = 0 Then
|
---|
601 | Return "0"
|
---|
602 | End If
|
---|
603 |
|
---|
604 | Dim buf[20] As StrChar
|
---|
605 | buf[20] = 0
|
---|
606 | Dim i = 19 As Long
|
---|
607 | Do
|
---|
608 | buf[i] = (x Mod 10 + &h30) As StrChar
|
---|
609 | x \= 10
|
---|
610 | If x = 0 Then
|
---|
611 | Exit Do
|
---|
612 | End If
|
---|
613 | i--
|
---|
614 | Loop
|
---|
615 | Return New String(VarPtr(buf[i]), 20 - i)
|
---|
616 | End Function
|
---|
617 |
|
---|
618 | Function Str$(x As Long) As String
|
---|
619 | #ifdef _WIN64
|
---|
620 | Return Str$(x As Int64)
|
---|
621 | #else
|
---|
622 | If x < 0 Then
|
---|
623 | Return "-" & Str$(-x As DWord)
|
---|
624 | Else
|
---|
625 | Return Str$(x As DWord)
|
---|
626 | End If
|
---|
627 | #endif
|
---|
628 | End Function
|
---|
629 |
|
---|
630 | Function Str$(x As DWord) As String
|
---|
631 | #ifdef _WIN64
|
---|
632 | Return Str$(x As QWord)
|
---|
633 | #else
|
---|
634 | If x = 0 Then
|
---|
635 | Return "0"
|
---|
636 | End If
|
---|
637 |
|
---|
638 | Dim buf[10] As StrChar
|
---|
639 | buf[10] = 0
|
---|
640 | Dim i = 9 As Long
|
---|
641 | Do
|
---|
642 | buf[i] = (x Mod 10 + &h30) As StrChar
|
---|
643 | x \= 10
|
---|
644 | If x = 0 Then
|
---|
645 | Exit Do
|
---|
646 | End If
|
---|
647 | i--
|
---|
648 | Loop
|
---|
649 | Return New String(VarPtr(buf[i]), 10 - i)
|
---|
650 | #endif
|
---|
651 | End Function
|
---|
652 |
|
---|
653 | Function Str$(x As Word) As String
|
---|
654 | Return Str$(x As ULONG_PTR)
|
---|
655 | End Function
|
---|
656 |
|
---|
657 | Function Str$(x As Integer) As String
|
---|
658 | Return Str$(x As LONG_PTR)
|
---|
659 | End Function
|
---|
660 |
|
---|
661 | Function Str$(x As Byte) As String
|
---|
662 | Return Str$(x As ULONG_PTR)
|
---|
663 | End Function
|
---|
664 |
|
---|
665 | Function Str$(x As SByte) As String
|
---|
666 | Return Str$(x As LONG_PTR)
|
---|
667 | End Function
|
---|
668 |
|
---|
669 | Function Str$(x As Single) As String
|
---|
670 | Return Str$(x As Double)
|
---|
671 | End Function
|
---|
672 |
|
---|
673 | Function Str$(b As Boolean) As String
|
---|
674 | If b Then
|
---|
675 | Return "True"
|
---|
676 | Else
|
---|
677 | Return "False"
|
---|
678 | End If
|
---|
679 | End Function
|
---|
680 |
|
---|
681 | Function String$(num As Long, buf As String) As String
|
---|
682 | Dim dwStrPtr As DWord
|
---|
683 | Dim length As Long
|
---|
684 |
|
---|
685 | length=Len(buf)
|
---|
686 |
|
---|
687 | 'バッファ領域を確保
|
---|
688 | String$=ZeroString(length*num)
|
---|
689 |
|
---|
690 | '文字列をコピー
|
---|
691 | Dim i As Long
|
---|
692 | For i=0 To num-1
|
---|
693 | memcpy(VarPtr(String$.Chars[i*length]), StrPtr(buf), SizeOf (StrChar) * length)
|
---|
694 | Next
|
---|
695 | End Function
|
---|
696 |
|
---|
697 | Function Time$() As String
|
---|
698 | Dim st As SYSTEMTIME
|
---|
699 |
|
---|
700 | GetLocalTime(st)
|
---|
701 |
|
---|
702 | 'hour
|
---|
703 | If st.wHour<10 Then
|
---|
704 | Time$="0"
|
---|
705 | End If
|
---|
706 | Time$=Time$+Str$(st.wHour)
|
---|
707 |
|
---|
708 | 'minute
|
---|
709 | If st.wMinute<10 Then
|
---|
710 | Time$=Time$+":0"
|
---|
711 | Else
|
---|
712 | Time$=Time$+":"
|
---|
713 | End If
|
---|
714 | Time$=Time$+Str$(st.wMinute)
|
---|
715 |
|
---|
716 | 'second
|
---|
717 | If st.wSecond<10 Then
|
---|
718 | Time$=Time$+":0"
|
---|
719 | Else
|
---|
720 | Time$=Time$+":"
|
---|
721 | End If
|
---|
722 | Time$=Time$+Str$(st.wSecond)
|
---|
723 | End Function
|
---|
724 |
|
---|
725 | Function Val(buf As *StrChar) As Double
|
---|
726 | Dim i As Long, i2 As Long, i3 As Long, i4 As Long
|
---|
727 | Dim temporary As String
|
---|
728 | Dim TempPtr As *StrChar
|
---|
729 | Dim dbl As Double
|
---|
730 | Dim i64data As Int64
|
---|
731 |
|
---|
732 | Val=0
|
---|
733 |
|
---|
734 | While buf[0]=Asc(" ") or buf[0]=Asc(Ex"\t")
|
---|
735 | buf = VarPtr(buf[1])
|
---|
736 | Wend
|
---|
737 |
|
---|
738 | If buf[0]=Asc("&") Then
|
---|
739 | temporary = New String( buf )
|
---|
740 | temporary.ToUpper()
|
---|
741 | TempPtr = StrPtr(temporary)
|
---|
742 | If TempPtr(1)=Asc("O") Then
|
---|
743 | '8進数
|
---|
744 | i=2
|
---|
745 | While 1
|
---|
746 | '数字以外の文字の場合は抜け出す
|
---|
747 | i3=TempPtr[i]-&H30
|
---|
748 | If Not (0<=i3 And i3<=7) Then Exit While
|
---|
749 |
|
---|
750 | TempPtr[i]=i3 As StrChar
|
---|
751 | i++
|
---|
752 | Wend
|
---|
753 | i--
|
---|
754 |
|
---|
755 | i64data=1
|
---|
756 | While i>=2
|
---|
757 | Val += ( i64data * TempPtr[i] ) As Double
|
---|
758 |
|
---|
759 | i64data *= &O10
|
---|
760 | i--
|
---|
761 | Wend
|
---|
762 | ElseIf TempPtr(1)=Asc("H") Then
|
---|
763 | '16進数
|
---|
764 | i=2
|
---|
765 | While 1
|
---|
766 | '数字以外の文字の場合は抜け出す
|
---|
767 | i3=TempPtr[i]-&H30
|
---|
768 | If Not(0<=i3 and i3<=9) Then
|
---|
769 | i3=TempPtr[i]-&H41+10
|
---|
770 | If Not(&HA<=i3 and i3<=&HF) Then Exit While
|
---|
771 | End If
|
---|
772 |
|
---|
773 | TempPtr[i]=i3 As StrChar
|
---|
774 | i++
|
---|
775 | Wend
|
---|
776 | i--
|
---|
777 |
|
---|
778 | i64data=1
|
---|
779 | While i>=2
|
---|
780 | Val += (i64data*TempPtr[i]) As Double
|
---|
781 |
|
---|
782 | i64data *= &H10
|
---|
783 | i--
|
---|
784 | Wend
|
---|
785 | End If
|
---|
786 | Else
|
---|
787 | '10進数
|
---|
788 | sscanf(buf,"%lf",VarPtr(Val))
|
---|
789 | End If
|
---|
790 | End Function
|
---|
791 |
|
---|
792 |
|
---|
793 | '--------------
|
---|
794 | ' ファイル関数
|
---|
795 | '--------------
|
---|
796 |
|
---|
797 | Function Eof(FileNum As Long) As Long
|
---|
798 | Dim dwCurrent As DWord, dwEnd As DWord
|
---|
799 |
|
---|
800 | FileNum--
|
---|
801 |
|
---|
802 | dwCurrent=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_CURRENT)
|
---|
803 | dwEnd=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_END)
|
---|
804 | SetFilePointer(_System_hFile(FileNum),dwCurrent,NULL,FILE_BEGIN)
|
---|
805 |
|
---|
806 | If dwCurrent>=dwEnd Then
|
---|
807 | Eof=-1
|
---|
808 | Else
|
---|
809 | Eof=0
|
---|
810 | End If
|
---|
811 | End Function
|
---|
812 |
|
---|
813 | Function Lof(FileNum As Long) As Long
|
---|
814 | Lof = GetFileSize(_System_hFile(FileNum-1), 0)
|
---|
815 | End Function
|
---|
816 |
|
---|
817 | Function Loc(FileNum As Long) As Long
|
---|
818 | Dim NowPos As Long, BeginPos As Long
|
---|
819 |
|
---|
820 | FileNum--
|
---|
821 |
|
---|
822 | NowPos=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_CURRENT)
|
---|
823 | BeginPos=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_BEGIN)
|
---|
824 | SetFilePointer(_System_hFile(FileNum),NowPos-BeginPos,NULL,FILE_BEGIN)
|
---|
825 |
|
---|
826 | Loc=NowPos-BeginPos
|
---|
827 | End Function
|
---|
828 |
|
---|
829 |
|
---|
830 | '------------------
|
---|
831 | ' メモリ関連の関数
|
---|
832 | '------------------
|
---|
833 |
|
---|
834 | Function malloc(stSize As SIZE_T) As VoidPtr
|
---|
835 | Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC)
|
---|
836 | End Function
|
---|
837 |
|
---|
838 | Function calloc(stSize As SIZE_T) As VoidPtr
|
---|
839 | Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC or _System_GC_FLAG_INITZERO)
|
---|
840 | End Function
|
---|
841 |
|
---|
842 | Function realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
|
---|
843 | If lpMem = 0 Then
|
---|
844 | Return malloc(stSize)
|
---|
845 | Else
|
---|
846 | Return _System_pGC->__realloc(lpMem,stSize)
|
---|
847 | End If
|
---|
848 | End Function
|
---|
849 |
|
---|
850 | Sub free(lpMem As VoidPtr)
|
---|
851 | _System_pGC->__free(lpMem)
|
---|
852 | End Sub
|
---|
853 |
|
---|
854 |
|
---|
855 | Function _System_malloc(stSize As SIZE_T) As VoidPtr
|
---|
856 | Return HeapAlloc(_System_hProcessHeap,0,stSize)
|
---|
857 | End Function
|
---|
858 |
|
---|
859 | Function _System_calloc(stSize As SIZE_T) As VoidPtr
|
---|
860 | Return HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,stSize)
|
---|
861 | End Function
|
---|
862 |
|
---|
863 | Function _System_realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
|
---|
864 | If lpMem = 0 Then
|
---|
865 | Return HeapAlloc(_System_hProcessHeap, 0, stSize)
|
---|
866 | Else
|
---|
867 | Return HeapReAlloc(_System_hProcessHeap, 0, lpMem, stSize)
|
---|
868 | End If
|
---|
869 | End Function
|
---|
870 |
|
---|
871 | Sub _System_free(lpMem As VoidPtr)
|
---|
872 | HeapFree(_System_hProcessHeap,0,lpMem)
|
---|
873 | End Sub
|
---|
874 |
|
---|
875 |
|
---|
876 | '--------
|
---|
877 | ' その他
|
---|
878 | '--------
|
---|
879 |
|
---|
880 | Sub _splitpath(path As PCSTR, drive As PSTR, dir As PSTR, fname As PSTR, ext As PSTR)
|
---|
881 | Dim i As Long, i2 As Long, i3 As Long, length As Long
|
---|
882 | Dim buffer[MAX_PATH] As SByte
|
---|
883 |
|
---|
884 | '":\"をチェック
|
---|
885 | If not(path[1]=&H3A and path[2]=&H5C) Then Exit Sub
|
---|
886 |
|
---|
887 | 'ドライブ名をコピー
|
---|
888 | If drive Then
|
---|
889 | drive[0]=path[0]
|
---|
890 | drive[1]=path[1]
|
---|
891 | drive[2]=0
|
---|
892 | End If
|
---|
893 |
|
---|
894 | 'ディレクトリ名をコピー
|
---|
895 | i=2
|
---|
896 | i2=0
|
---|
897 | Do
|
---|
898 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
899 | If dir Then
|
---|
900 | dir[i2]=path[i]
|
---|
901 | dir[i2+1]=path[i+1]
|
---|
902 | End If
|
---|
903 |
|
---|
904 | i += 2
|
---|
905 | i2 += 2
|
---|
906 | Continue
|
---|
907 | End If
|
---|
908 |
|
---|
909 | If path[i]=0 Then Exit Do
|
---|
910 |
|
---|
911 | If path[i]=&H5C Then '"\"記号であるかどうか
|
---|
912 | i3=i2+1
|
---|
913 | End If
|
---|
914 |
|
---|
915 | If dir Then dir[i2]=path[i]
|
---|
916 |
|
---|
917 | i++
|
---|
918 | i2++
|
---|
919 | Loop
|
---|
920 | If dir Then dir[i3]=0
|
---|
921 | i3 += i-i2
|
---|
922 |
|
---|
923 | 'ファイル名をコピー
|
---|
924 | i=i3
|
---|
925 | i2=0
|
---|
926 | i3=-1
|
---|
927 | Do
|
---|
928 | '#ifdef UNICODE
|
---|
929 | ' If _System_IsSurrogatePair(path[i], path[i + 1]) Then
|
---|
930 | '#else
|
---|
931 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
932 | '#endif
|
---|
933 | If fname Then
|
---|
934 | fname[i2]=path[i]
|
---|
935 | fname[i2+1]=path[i+1]
|
---|
936 | End If
|
---|
937 |
|
---|
938 | i += 2
|
---|
939 | i2 += 2
|
---|
940 | Continue
|
---|
941 | End If
|
---|
942 |
|
---|
943 | If path[i]=0 Then Exit Do
|
---|
944 |
|
---|
945 | If path[i]=&H2E Then '.'記号であるかどうか
|
---|
946 | i3=i2
|
---|
947 | End If
|
---|
948 |
|
---|
949 | If fname Then fname[i2]=path[i]
|
---|
950 |
|
---|
951 | i++
|
---|
952 | i2++
|
---|
953 | Loop
|
---|
954 | If i3=-1 Then i3=i2
|
---|
955 | If fname Then fname[i3]=0
|
---|
956 | i3 += i-i2
|
---|
957 |
|
---|
958 | '拡張子名をコピー
|
---|
959 | If ext Then
|
---|
960 | If i3 Then
|
---|
961 | lstrcpy(ext,path+i3)
|
---|
962 | End If
|
---|
963 | else ext[0]=0
|
---|
964 | End If
|
---|
965 | End Sub
|
---|
966 |
|
---|
967 | Function GetBasicColor(ColorCode As Long) As Long
|
---|
968 | Select Case ColorCode
|
---|
969 | Case 0
|
---|
970 | GetBasicColor=RGB(0,0,0)
|
---|
971 | Case 1
|
---|
972 | GetBasicColor=RGB(0,0,255)
|
---|
973 | Case 2
|
---|
974 | GetBasicColor=RGB(255,0,0)
|
---|
975 | Case 3
|
---|
976 | GetBasicColor=RGB(255,0,255)
|
---|
977 | Case 4
|
---|
978 | GetBasicColor=RGB(0,255,0)
|
---|
979 | Case 5
|
---|
980 | GetBasicColor=RGB(0,255,255)
|
---|
981 | Case 6
|
---|
982 | GetBasicColor=RGB(255,255,0)
|
---|
983 | Case 7
|
---|
984 | GetBasicColor=RGB(255,255,255)
|
---|
985 | End Select
|
---|
986 | End Function
|
---|
987 |
|
---|
988 | Function _System_BSwap(x As Word) As Word
|
---|
989 | Dim src = VarPtr(x) As *Byte
|
---|
990 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
991 | dst[0] = src[1]
|
---|
992 | dst[1] = src[0]
|
---|
993 | End Function
|
---|
994 |
|
---|
995 | Function _System_BSwap(x As DWord) As DWord
|
---|
996 | Dim src = VarPtr(x) As *Byte
|
---|
997 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
998 | dst[0] = src[3]
|
---|
999 | dst[1] = src[2]
|
---|
1000 | dst[2] = src[1]
|
---|
1001 | dst[3] = src[0]
|
---|
1002 | End Function
|
---|
1003 |
|
---|
1004 | Function _System_BSwap(x As QWord) As QWord
|
---|
1005 | Dim src = VarPtr(x) As *Byte
|
---|
1006 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
1007 | dst[0] = src[7]
|
---|
1008 | dst[1] = src[6]
|
---|
1009 | dst[2] = src[5]
|
---|
1010 | dst[3] = src[4]
|
---|
1011 | dst[4] = src[3]
|
---|
1012 | dst[5] = src[2]
|
---|
1013 | dst[6] = src[1]
|
---|
1014 | dst[7] = src[0]
|
---|
1015 | End Function
|
---|
1016 |
|
---|
1017 | Function _System_HashFromPtr(p As VoidPtr) As Long
|
---|
1018 | #ifdef _WIN64
|
---|
1019 | Dim qw = p As QWord
|
---|
1020 | Return (HIDWORD(qw) Xor LODWORD(qw)) As Long
|
---|
1021 | #else
|
---|
1022 | Return p As Long
|
---|
1023 | #endif
|
---|
1024 | End Function
|
---|
1025 |
|
---|
1026 | '--------
|
---|
1027 | ' 文字列関数その2
|
---|
1028 | '--------
|
---|
1029 | Function _System_IsSurrogatePair(wcHigh As WCHAR, wcLow As WCHAR) As Boolean
|
---|
1030 | If &hD800 <= wcHigh And wcHigh < &hDC00 Then
|
---|
1031 | If &hDC00 <= wcLow And wcLow < &hE000 Then
|
---|
1032 | Return True
|
---|
1033 | End If
|
---|
1034 | End If
|
---|
1035 | Return False
|
---|
1036 | End Function
|
---|
1037 |
|
---|
1038 | Function _System_IsDoubleUnitChar(lead As WCHAR, trail As WCHAR) As Boolean
|
---|
1039 | Return _System_IsSurrogatePair(lead, trail)
|
---|
1040 | End Function
|
---|
1041 |
|
---|
1042 | Function _System_IsDoubleUnitChar(lead As SByte, trail As SByte) As Boolean
|
---|
1043 | Return IsDBCSLeadByte(lead) <> FALSE
|
---|
1044 | End Function
|
---|
1045 |
|
---|
1046 | Sub _System_FillChar(p As PWSTR, n As SIZE_T, c As WCHAR)
|
---|
1047 | Dim i As SIZE_T
|
---|
1048 | For i = 0 To ELM(n)
|
---|
1049 | p[i] = c
|
---|
1050 | Next
|
---|
1051 | End Sub
|
---|
1052 |
|
---|
1053 | Sub _System_FillChar(p As PSTR, n As SIZE_T, c As SByte)
|
---|
1054 | Dim i As SIZE_T
|
---|
1055 | For i = 0 To ELM(n)
|
---|
1056 | p[i] = c
|
---|
1057 | Next
|
---|
1058 | End Sub
|
---|
1059 |
|
---|
1060 | Function _System_ASCII_IsUpper(c As WCHAR) As Boolean
|
---|
1061 | Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
|
---|
1062 | End Function
|
---|
1063 |
|
---|
1064 | Function _System_ASCII_IsUpper(c As SByte) As Boolean
|
---|
1065 | Return _System_ASCII_IsUpper(c As Byte As WCHAR)
|
---|
1066 | End Function
|
---|
1067 |
|
---|
1068 | Function _System_ASCII_IsLower(c As WCHAR) As Boolean
|
---|
1069 | Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
|
---|
1070 | End Function
|
---|
1071 |
|
---|
1072 | Function _System_ASCII_IsLower(c As SByte) As Boolean
|
---|
1073 | Return _System_ASCII_IsLower(c As Byte As WCHAR)
|
---|
1074 | End Function
|
---|
1075 |
|
---|
1076 | Function _System_ASCII_ToLower(c As WCHAR) As WCHAR
|
---|
1077 | If _System_ASCII_IsUpper(c) Then
|
---|
1078 | Return c Or &h20
|
---|
1079 | Else
|
---|
1080 | Return c
|
---|
1081 | End If
|
---|
1082 | End Function
|
---|
1083 |
|
---|
1084 | Function _System_ASCII_ToLower(c As SByte) As SByte
|
---|
1085 | Return _System_ASCII_ToLower(c As Byte As WCHAR) As Byte As SByte
|
---|
1086 | End Function
|
---|
1087 |
|
---|
1088 | Function _System_ASCII_ToUpper(c As WCHAR) As WCHAR
|
---|
1089 | If _System_ASCII_IsLower(c) Then
|
---|
1090 | Return c And (Not &h20)
|
---|
1091 | Else
|
---|
1092 | Return c
|
---|
1093 | End If
|
---|
1094 | End Function
|
---|
1095 |
|
---|
1096 | Function _System_ASCII_ToUpper(c As SByte) As SByte
|
---|
1097 | Return _System_ASCII_ToUpper(c As Byte As WCHAR) As Byte As SByte
|
---|
1098 | End Function
|
---|
1099 |
|
---|
1100 | Function _System_ChrCpy(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
|
---|
1101 | memcpy(dst, src, size * SizeOf (WCHAR))
|
---|
1102 | Return dst
|
---|
1103 | End Function
|
---|
1104 |
|
---|
1105 | Function _System_ChrCpy(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
|
---|
1106 | memcpy(dst, src, size)
|
---|
1107 | Return dst
|
---|
1108 | End Function
|
---|
1109 |
|
---|
1110 | Function _System_StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
|
---|
1111 | Dim i = 0 As SIZE_T
|
---|
1112 | While s1[i] = s2[i]
|
---|
1113 | If s1[i] = 0 Then
|
---|
1114 | Exit While
|
---|
1115 | End If
|
---|
1116 | i++
|
---|
1117 | Wend
|
---|
1118 | _System_StrCmp = s1[i] - s2[i]
|
---|
1119 | End Function
|
---|
1120 |
|
---|
1121 | Function _System_StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
|
---|
1122 | Dim i = 0 As SIZE_T
|
---|
1123 | While s1[i] = s2[i]
|
---|
1124 | If s1[i] = 0 Then
|
---|
1125 | Exit While
|
---|
1126 | End If
|
---|
1127 | i++
|
---|
1128 | Wend
|
---|
1129 | _System_StrCmp = s1[i] - s2[i]
|
---|
1130 | End Function
|
---|
1131 |
|
---|
1132 | Function _System_StrCmpN(s1 As PCSTR, s2 As PCSTR, size As SIZE_T) As Long
|
---|
1133 | Dim i = 0 As SIZE_T
|
---|
1134 | For i = 0 To ELM(size)
|
---|
1135 | _System_StrCmpN = s1[i] - s2[i]
|
---|
1136 | If _System_StrCmpN <> 0 Then
|
---|
1137 | Exit Function
|
---|
1138 | End If
|
---|
1139 | Next
|
---|
1140 | End Function
|
---|
1141 |
|
---|
1142 | Function _System_StrCmpN(s1 As PCWSTR, s2 As PCWSTR, size As SIZE_T) As Long
|
---|
1143 | Dim i = 0 As SIZE_T
|
---|
1144 | For i = 0 To ELM(size)
|
---|
1145 | _System_StrCmpN = s1[i] - s2[i]
|
---|
1146 | If _System_StrCmpN <> 0 Then
|
---|
1147 | Exit Function
|
---|
1148 | End If
|
---|
1149 | Next
|
---|
1150 | End Function
|
---|
1151 |
|
---|
1152 | Function _System_MemChr(s As PCSTR, c As CHAR, size As SIZE_T) As PCSTR
|
---|
1153 | Dim i As SIZE_T
|
---|
1154 | For i = 0 To ELM(size)
|
---|
1155 | If s[i] = c Then
|
---|
1156 | Return VarPtr(s[i])
|
---|
1157 | End If
|
---|
1158 | Next
|
---|
1159 | Return 0
|
---|
1160 | End Function
|
---|
1161 |
|
---|
1162 | Function _System_MemChr(s As PCWSTR, c As WCHAR, size As SIZE_T) As PCWSTR
|
---|
1163 | Dim i As SIZE_T
|
---|
1164 | For i = 0 To ELM(size)
|
---|
1165 | If s[i] = c Then
|
---|
1166 | Return VarPtr(s[i])
|
---|
1167 | End If
|
---|
1168 | Next
|
---|
1169 | Return 0
|
---|
1170 | End Function
|
---|
1171 |
|
---|
1172 | Function _System_MemPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As PCSTR
|
---|
1173 | Dim i As SIZE_T
|
---|
1174 | For i = 0 To ELM(cStr)
|
---|
1175 | If _System_MemChr(Chars, str[i], cChars) Then
|
---|
1176 | Return VarPtr(str[i])
|
---|
1177 | End If
|
---|
1178 | Next
|
---|
1179 | Return 0
|
---|
1180 | End Function
|
---|
1181 |
|
---|
1182 | Function _System_MemPBrk(str As PCWSTR, cStr As SIZE_T, Chars As PCWSTR, cChars As SIZE_T) As PCWSTR
|
---|
1183 | Dim i As SIZE_T
|
---|
1184 | For i = 0 To ELM(cStr)
|
---|
1185 | If _System_MemChr(Chars, str[i], cChars) Then
|
---|
1186 | Return VarPtr(str[i])
|
---|
1187 | End If
|
---|
1188 | Next
|
---|
1189 | Return 0
|
---|
1190 | End Function
|
---|
1191 |
|
---|
1192 | Function _System_GetHashFromWordArray(p As *Word, n As SIZE_T) As Long
|
---|
1193 | Dim hash = 0 As DWord
|
---|
1194 | Dim i As Long
|
---|
1195 | For i = 0 To ELM(n)
|
---|
1196 | hash = ((hash << 16) + p[i]) Mod &h7fffffff
|
---|
1197 | Next
|
---|
1198 | _System_GetHashFromWordArray = hash As Long
|
---|
1199 | End Function
|
---|
1200 |
|
---|
1201 | #endif '_INC_FUNCTION
|
---|