source: trunk/ab5.0/ablib/src/basic/function.sbp@ 589

Last change on this file since 589 was 589, checked in by イグトランス (egtra), 16 years ago

数学関数をActiveBasic.Mathへ統合

File size: 19.8 KB
RevLine 
[1]1'function.sbp
2
3Const _System_PI = 3.14159265358979323846264
4Const _System_SQRT2 = 1.41421356237309504880168872421
5
6'------------- サポート関数の定義 -------------
7
8Function ipow(x As Double, n As Long) As Double
[589]9 ipow = ActiveBasic.Math.pow(x, n)
[1]10End Function
11
12Function pow(x As Double, y As Double) As Double
[589]13 pow = ActiveBasic.Math.pow(x, y)
[1]14End Function
15
[272]16Const RAND_MAX = &H7FFFFFFF
17Dim _System_RndNext = 1 As DWord
[1]18
19Function rand() As Long
20 _System_RndNext = _System_RndNext * 1103515245 + 12345
[272]21 rand = (_System_RndNext >> 1) As Long
[1]22End Function
23
24Sub srand(dwSeek As DWord)
25 _System_RndNext = dwSeek
26End Sub
27
28'------------- ここからBasic標準関数の定義 -------------
29
30'------------------
31' データ型変換関数
32'------------------
33
34Function CDbl(number As Double) As Double
35 CDbl=number
36End Function
37
38Function _CUDbl(number As QWord) As Double
39 _CUDbl=number As Double
40End Function
41
42Function CDWord(num As Double) As DWord
[92]43 CDWord=num As DWord
[1]44End Function
45
46Function CInt(number As Double) As Long
[92]47 CInt=number As Long
[1]48End Function
49
50Function CSng(number As Double) As Single
[92]51 CSng=number As Single
[1]52End Function
53
54#ifdef _WIN64
55Function Fix(number As Double) As Long
56 Fix=number As Long
57End Function
58#else
59'Fix関数はコンパイラに組み込まれている
60'Function Fix(number As Double) As Long
61#endif
62
63Function Int(number As Double) As Long
[269]64 Int = Fix(number)
65 If number < 0 Then
66 If number < Fix(number) Then Int--
[1]67 End If
68End Function
69
70
71'-------------------------------------
72' ポインタ関数(コンパイラに組み込み)
73'-------------------------------------
74
75'Function GetDouble(p As DWord) As Double
76'Function GetSingle(p As DWord) As Single
77'Function GetDWord(p As DWord) As DWord
78'Function GetWord(p As DWord) As Word
79'Function GetByte(p As DWord) As Byte
80'Sub SetDouble(p As DWord, dblData As Double)
81'Sub SetSingle(p As DWord, fltData As Single)
82'Sub SetDWord(p As DWord, dwData As DWord)
83'Sub SetWord(p As DWord, wData As Word)
84'Sub SetByte(p As DWord, byteData As Byte)
85
86
87'----------
88' 算術関数
89'----------
90
[589]91/*
92Function Abs(n As Double) As Double
93 Abs = ActiveBasic.Math.Abs(n)
[1]94End Function
95
[589]96Function Abs(n As Single) As Single
97 Abs = ActiveBasic.Math.Abs(n)
[383]98End Function
99
[589]100Function Abs(n As Int64) As Int64
101 Abs = ActiveBasic.Math.Abs(n)
[383]102End Function
103
[589]104Function Abs(n As Long) As Long
105 Abs = ActiveBasic.Math.Abs(n)
106End Function
107
108Function Abs(n As Integer) As Integer
109 Abs = ActiveBasic.Math.Abs(n)
110End Function
111
112Function Abs(n As SByte) As SByte
113 Abs = ActiveBasic.Math.Abs(n)
114End Function
115
[1]116Function Exp(x As Double) As Double
[589]117 Exp = ActiveBasic.Math.Exp(x)
[1]118End Function
119
120Function Log(x As Double) As Double
[589]121 Log = ActiveBasic.Math.Log(x)
[1]122End Function
[589]123*/
124Function Sgn(n As Double) As Long
125' Sgn = ActiveBasic..Math.Sign(n)
[1]126End Function
127
[589]128Function Sqr(x As Double) As Double
129 Sqr = ActiveBasic.Math.Sqrt(x)
[1]130End Function
131
[589]132Function Atn(x As Double) As Double
133 Atn = ActiveBasic.Math.Atan(x)
[1]134End Function
135
136Function Atn2(y As Double, x As Double) As Double
[589]137 Atn2 = ActiveBasic.Math.Atan2(y, x)
[1]138End Function
[589]139/*
140Function Sin(x As Double) As Double
141 Sin = ActiveBasic.Math.Sin(x)
[1]142End Function
143
[589]144Function Cos(x As Double) As Double
145 Cos = ActiveBasic.Math.Cos(x)
[1]146End Function
147
[589]148Function Tan(x As Double) As Double
149 Tan = ActiveBasic.Math.Tan(x)
[1]150End Function
[589]151*/
[1]152Const RAND_UNIT = (1.0 / (LONG_MAX + 1.0))
153Function Rnd() As Double
154 Rnd = RAND_UNIT * rand()
155End Function
156
[167]157Const HIDWORD(qw) = (((qw As QWord) >> 32) And &HFFFFFFFF) As DWord
158Const LODWORD(qw) = ((qw As QWord) And &HFFFFFFFF) As DWord
[1]159
[167]160Const MAKEDWORD(l, h) = (((l As DWord) And &HFFFF) Or (((h As DWord) And &HFFFF) << 16)) As DWord
161Const MAKEQWORD(l, h) = (((l As QWord) And &HFFFFFFFF) Or (((h As QWord) And &HFFFFFFFF) << 32)) As QWord
[1]162
163'------------
164' 文字列関数
165'------------
166
[497]167Function Asc(buf As String) As Char
[1]168 Asc = buf[0]
169End Function
170
[497]171Function Chr$(code As Char) As String
[272]172 Chr$ = New String(code, 1)
[1]173End Function
174
[497]175#ifdef UNICODE
[383]176Function AscW(s As String) As UCSCHAR
[394]177 If String.IsNullOrEmpty(s) Then
[121]178 AscW = 0
[394]179 'ArgumentNullExceptionに変えるかも
[121]180 Else
[394]181 If _System_IsHighSurrogate(s[0]) Then
182 '有効なサロゲートペアになっていない場合には、
183 '例外を投げるようにしたほうがよいかもしれない。
184 If s.Length > 1 Then
185 If _System_IsLowSurrogate(s[0]) Then
186 AscW = ((s[0] And &h3FF) As DWord << 10) Or (s[1] And &h3FF)
[400]187 AscW += &h10000
[394]188 Exit Function
189 End If
190 End If
[121]191 Else
192 AscW = s[0]
193 End If
194 End If
195End Function
196
197Function ChrW(c As UCSCHAR) As String
198 If c <= &hFFFF Then
[497]199 Return New String(c As Char, 1)
[394]200 ElseIf c <= &h10FFFF Then
[400]201 c -= &h10000
[394]202 Dim t[1] As WCHAR
203 t[0] = (&hD800 Or (c >> 10)) As WCHAR
204 t[1] = (&hDC00 Or (c And &h3FF)) As WCHAR
[272]205 Return New String(t, 2)
[121]206 Else
[394]207 Throw New System.ArgumentOutOfRangeException("ChrW: c is invalid Unicode code point.", "c")
[121]208 End If
209End Function
210#endif
211
[1]212Function Date$() As String
[289]213 Dim date = System.DateTime.Now
[272]214 Dim buf = New System.Text.StringBuilder(10)
[1]215
216 'year
[272]217 buf.Append(date.Year)
[1]218
219 'month
[272]220 If date.Month < 10 Then
221 buf.Append("/0")
[1]222 Else
[272]223 buf.Append("/")
[1]224 End If
[272]225 buf.Append(date.Month)
[1]226
227 'day
[272]228 If date.Day < 10 Then
229 buf.Append("/0")
[1]230 Else
[272]231 buf.Append("/")
[1]232 End If
[272]233 buf.Append(date.Day)
234
235 Date$ = buf.ToString
[1]236End Function
237
[167]238Function Hex$(x As DWord) As String
[388]239 Imports ActiveBasic.Strings.Detail
240 Hex$ = FormatIntegerX(x, 1, 0, None)
[167]241End Function
242
[121]243Function Hex$(x As QWord) As String
[388]244 Imports ActiveBasic.Strings.Detail
245 Hex$ = FormatIntegerLX(x, 1, 0, None)
[1]246End Function
247
248Function InStr(StartPos As Long, buf1 As String, buf2 As String) As Long
[167]249 Dim i As Long, i2 As Long, i3 As Long
[1]250
[514]251 Dim len1 = 0 As Long
252 Dim len2 = 0 As Long
253 If Not ActiveBasic.IsNothing(buf1) Then len1 = buf1.Length
254 If Not ActiveBasic.IsNothing(buf2) Then len2 = buf2.Length
[1]255
[514]256 If len2 = 0 Then
257 InStr = StartPos
[1]258 Exit Function
259 End If
260
[10]261 StartPos--
[514]262 If StartPos < 0 Then
[1]263 'error
[514]264 InStr = 0
[1]265 Exit Function
266 End If
267
268 i=StartPos:InStr=0
269 While i<=len1-len2
270 i2=i:i3=0
271 Do
272 If i3=len2 Then
273 InStr=i+1
274 Exit Do
275 End If
276 If buf1[i2]<>buf2[i3] Then Exit Do
277
[10]278 i2++
279 i3++
[1]280 Loop
281 If InStr Then Exit While
[10]282 i++
[1]283 Wend
284End Function
285
[272]286Function Left$(s As String, length As Long) As String
[514]287 If Not ActiveBasic.IsNothing(s) Then
288 Left$ = s.Substring(0, System.Math.Min(s.Length, length))
289 Else
290 Left$ = ""
291 End If
[1]292End Function
293
[272]294Function Mid$(s As String, startPos As Long) As String
[514]295 If Not ActiveBasic.IsNothing(s) Then
296 startPos--
297 Mid$ = s.Substring(startPos)
298 Else
299 Mid$ = ""
300 End If
[272]301End Function
[1]302
[272]303Function Mid$(s As String, startPos As Long, readLength = 0 As Long) As String
[514]304 If Not ActiveBasic.IsNothing(s) Then
305 startPos--
306 Dim length = s.Length
307 Mid$ = s.Substring(System.Math.Min(startPos, length), System.Math.Min(readLength, length - startPos))
308 Else
309 Mid$ = ""
310 End If
[1]311End Function
312
[272]313Function Oct$(n As QWord) As String
[388]314 Imports ActiveBasic.Strings.Detail
315 Oct$ = FormatIntegerLO(n, 1, 0, None)
[272]316End Function
[1]317
[272]318Function Oct$(n As DWord) As String
[388]319 Imports ActiveBasic.Strings.Detail
320 Oct$ = FormatIntegerO(n, 1, 0, None)
[1]321End Function
322
[272]323Function Right$(s As String, length As Long) As String
[514]324 If Not ActiveBasic.IsNothing(s) Then
325 Right$ = s.Substring(System.Math.Max(0, s.Length - length), s.Length)
326 Else
327 Right$ = ""
328 End If
[1]329End Function
330
331Function Space$(length As Long) As String
[497]332 Return New String(&h20 As Char, length)
[1]333End Function
334
[497]335Sub _ecvt_support(buf As *Char, count As Long, size As Long)
[1]336 Dim i As Long
[385]337 If buf[count] = 9 Then
338 buf[count] = 0
339 If count = 0 Then
340 For i = size To 1 Step -1
341 buf[i] = buf[i-1]
[1]342 Next
[385]343 buf[0] = 1
[1]344 Else
[385]345 _ecvt_support(buf, count-1, size)
[1]346 End If
347 Else
[385]348 buf[count]++
[1]349 End If
350End Sub
[385]351
[497]352Sub _ecvt(buffer As *Char, value As Double, count As Long, ByRef dec As Long, ByRef sign As Boolean)
[1]353 Dim i As Long, i2 As Long
354
355 '値が0の場合
[167]356 If value = 0 Then
[497]357 ActiveBasic.Strings.ChrFill(buffer, count As SIZE_T, &h30 As Char)
[385]358 buffer[count] = 0
[123]359 dec = 0
360 sign = 0
[1]361 Exit Function
362 End If
363
364 '符号の判断(同時に符号を取り除く)
[167]365 If value < 0 Then
[385]366 sign = True
[167]367 value = -value
[1]368 Else
[385]369 sign = False
[1]370 End If
371
372 '正規化
[167]373 dec = 1
374 While value < 0.999999999999999 'value<1
[119]375 value *= 10
376 dec--
[1]377 Wend
[167]378 While 9.99999999999999 <= value '10<=value
[119]379 value /= 10
380 dec++
[1]381 Wend
382
[385]383 For i = 0 To count - 1
[497]384 buffer[i] = Int(value) As Char
[167]385 value = (value-CDbl(Int(value))) * 10
[1]386 Next
387
[119]388 i--
[167]389 If value >= 5 Then
[1]390 '切り上げ処理
[385]391 _ecvt_support(buffer, i, count)
[1]392 End If
393
[385]394 For i = 0 To count - 1
395 buffer[i] += &H30
[1]396 Next
[385]397 buffer[i] = 0
398End Sub
[1]399
400Function Str$(dbl As Double) As String
[388]401 Imports ActiveBasic.Math
402 Imports ActiveBasic.Strings
403 If IsNaN(dbl) Then
[1]404 Return "NaN"
[388]405 ElseIf IsInf(dbl) Then
[1]406 If dbl > 0 Then
407 Return "Infinity"
408 Else
409 Return "-Infinity"
410 End If
411 End If
[385]412 Dim dec As Long, sign As Boolean
[497]413 Dim buffer[32] As Char, temp[15] As Char
[385]414 Dim i = 0 As Long
[1]415
416 '浮動小数点を文字列に変換
[385]417 _ecvt(temp, dbl, 15, dec, sign)
[1]418
419 '符号の取り付け
420 If sign Then
[167]421 buffer[i] = Asc("-")
[10]422 i++
[1]423 End If
424
[385]425 If dec > 15 Or dec < -3 Then
426 '指数表示
[167]427 buffer[i] = temp[0]
[10]428 i++
[167]429 buffer[i] = Asc(".")
[10]430 i++
[388]431 ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
[167]432 i += 14
[385]433 buffer[i] = 0
[388]434 Return MakeStr(buffer) + SPrintf("e%+03d", New System.Int32(dec - 1))
[1]435 End If
436
437 '整数部
[385]438 Dim i2 = dec
439 Dim i3 = 0
[1]440 If i2>0 Then
441 While i2>0
442 buffer[i]=temp[i3]
[10]443 i++
444 i3++
445 i2--
[1]446 Wend
447 buffer[i]=Asc(".")
[10]448 i++
[1]449 Else
450 buffer[i]=&H30
[10]451 i++
[1]452 buffer[i]=Asc(".")
[10]453 i++
[1]454
455 i2=dec
456 While i2<0
457 buffer[i]=&H30
[10]458 i++
459 i2++
[1]460 Wend
461 End If
462
463 '小数部
464 While i3<15
465 buffer[i]=temp[i3]
[10]466 i++
467 i3++
[1]468 Wend
469
470 While buffer[i-1]=&H30
[10]471 i--
[1]472 Wend
[10]473 If buffer[i-1]=Asc(".") Then i--
[1]474
475 buffer[i]=0
476 Return MakeStr(buffer)
477End Function
[167]478
[385]479Function Str$(x As Int64) As String
480 Imports ActiveBasic.Strings.Detail
481 Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, 1, 0, None)
[1]482End Function
483
[269]484Function Str$(x As QWord) As String
[385]485 Imports ActiveBasic.Strings.Detail
486 Return FormatIntegerEx(TraitsIntegerU[1], x, 1, 0, None)
[269]487End Function
488
489Function Str$(x As Long) As String
[385]490 Imports ActiveBasic.Strings.Detail
491 Return FormatIntegerEx(TraitsIntegerD[0], x, 1, 0, None)
[269]492End Function
493
494Function Str$(x As DWord) As String
[385]495 Imports ActiveBasic.Strings.Detail
496 Return FormatIntegerEx(TraitsIntegerU[0], x, 1, 0, None)
[269]497End Function
498
499Function Str$(x As Word) As String
[385]500 Return Str$(x As DWord)
[269]501End Function
502
503Function Str$(x As Integer) As String
[385]504 Return Str$(x As Long)
[269]505End Function
506
507Function Str$(x As Byte) As String
[385]508 Return Str$(x As DWord)
[269]509End Function
510
511Function Str$(x As SByte) As String
[385]512 Return Str$(x As Long)
[269]513End Function
514
515Function Str$(x As Single) As String
516 Return Str$(x As Double)
517End Function
518
519Function Str$(b As Boolean) As String
520 If b Then
521 Return "True"
522 Else
523 Return "False"
524 End If
525End Function
526
[536]527Function Str$(s As String) As String
528 Str$ = s
529End Function
530
[497]531Function String$(n As Long, s As Char) As String
[272]532 Return New String(s, n)
533End Function
[497]534
[272]535#ifdef _AB4_COMPATIBILITY_STRING$_
536Function String$(n As Long, s As String) As String
537 If n < 0 Then
538 'Throw ArgumentOutOfRangeException
539 End If
540 Dim buf = New System.Text.StringBuilder(s.Length * n)
[1]541 Dim i As Long
[497]542 For i = 1 To n
[272]543 buf.Append(s)
[1]544 Next
545End Function
[272]546#else
547Function String$(n As Long, s As String) As String
[497]548 Dim c As Char
[272]549 If String.IsNullOrEmpty(s) Then
[497]550 c = 0
[388]551 Else
[497]552 c = s[0]
[272]553 End If
[497]554 String$ = New String(c, n)
[272]555End Function
556#endif
[1]557
558Function Time$() As String
[289]559 Dim time = System.DateTime.Now
[272]560 Dim buf = New System.Text.StringBuilder(8)
[1]561 'hour
[272]562 If time.Hour < 10 Then
563 buf.Append("0")
[1]564 End If
[272]565 buf.Append(time.Hour)
[1]566
567 'minute
[272]568 If time.Minute < 10 Then
569 buf.Append(":0")
[1]570 Else
[272]571 buf.Append(":")
[1]572 End If
[272]573 buf.Append(time.Minute)
[1]574
575 'second
[272]576 If time.Second < 10 Then
577 buf.Append(":0")
[1]578 Else
[272]579 buf.Append(":")
[1]580 End If
[272]581 buf.Append(time.Second)
582 Time$ = buf.ToString
[1]583End Function
584
[497]585Function Val(buf As *Char) As Double
[514]586 If buf = 0 Then
587 Exit Function
588 End If
589
[1]590 Dim i As Long, i2 As Long, i3 As Long, i4 As Long
591 Dim temporary As String
[497]592 Dim TempPtr As *Char
[1]593 Dim dbl As Double
594 Dim i64data As Int64
595
596 Val=0
597
[400]598 While ActiveBasic.CType.IsSpace(buf[0])
[269]599 buf = VarPtr(buf[1])
[1]600 Wend
601
602 If buf[0]=Asc("&") Then
[145]603 temporary = New String( buf )
[272]604 temporary = temporary.ToUpper()
[123]605 TempPtr = StrPtr(temporary)
[400]606 If TempPtr(1) = Asc("O") Then
[1]607 '8進数
608 i=2
609 While 1
610 '数字以外の文字の場合は抜け出す
611 i3=TempPtr[i]-&H30
612 If Not (0<=i3 And i3<=7) Then Exit While
613
[497]614 TempPtr[i]=i3 As Char
[1]615 i++
616 Wend
617 i--
618
619 i64data=1
620 While i>=2
[214]621 Val += ( i64data * TempPtr[i] ) As Double
[1]622
[123]623 i64data *= &O10
[10]624 i--
[1]625 Wend
626 ElseIf TempPtr(1)=Asc("H") Then
627 '16進数
628 i=2
629 While 1
630 '数字以外の文字の場合は抜け出す
631 i3=TempPtr[i]-&H30
632 If Not(0<=i3 and i3<=9) Then
633 i3=TempPtr[i]-&H41+10
634 If Not(&HA<=i3 and i3<=&HF) Then Exit While
635 End If
636
[497]637 TempPtr[i]=i3 As Char
[1]638 i++
639 Wend
640 i--
641
642 i64data=1
643 While i>=2
[22]644 Val += (i64data*TempPtr[i]) As Double
[1]645
[10]646 i64data *= &H10
[1]647 i--
648 Wend
649 End If
650 Else
651 '10進数
[497]652#ifdef UNICODE
653 swscanf(buf,"%lf",VarPtr(Val))
654#else
[251]655 sscanf(buf,"%lf",VarPtr(Val))
[394]656#endif
[1]657 End If
658End Function
659
660
661'--------------
662' ファイル関数
663'--------------
664
665Function Eof(FileNum As Long) As Long
666 FileNum--
[400]667 Dim dwCurrent = SetFilePointer(_System_hFile(FileNum), 0,NULL, FILE_CURRENT)
668 Dim dwEnd = SetFilePointer(_System_hFile(FileNum), 0, NULL, FILE_END)
669 SetFilePointer(_System_hFile(FileNum), dwCurrent, NULL, FILE_BEGIN)
[1]670
671 If dwCurrent>=dwEnd Then
672 Eof=-1
673 Else
674 Eof=0
675 End If
676End Function
677
678Function Lof(FileNum As Long) As Long
[142]679 Lof = GetFileSize(_System_hFile(FileNum-1), 0)
[1]680End Function
681
682Function Loc(FileNum As Long) As Long
[10]683 FileNum--
[1]684
[272]685 Dim NowPos = SetFilePointer(_System_hFile(FileNum), 0, 0, FILE_CURRENT)
686 Dim BeginPos = SetFilePointer(_System_hFile(FileNum), 0, 0, FILE_BEGIN)
687 SetFilePointer(_System_hFile(FileNum), NowPos - BeginPos, 0, FILE_BEGIN)
[1]688
[272]689 Loc = NowPos - BeginPos
[1]690End Function
691
692
693'------------------
694' メモリ関連の関数
695'------------------
696
697Function malloc(stSize As SIZE_T) As VoidPtr
[145]698 Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC)
[1]699End Function
700
701Function calloc(stSize As SIZE_T) As VoidPtr
[145]702 Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC or _System_GC_FLAG_INITZERO)
[1]703End Function
704
705Function realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
706 If lpMem = 0 Then
707 Return malloc(stSize)
708 Else
[145]709 Return _System_pGC->__realloc(lpMem,stSize)
[1]710 End If
711End Function
712
713Sub free(lpMem As VoidPtr)
[145]714 _System_pGC->__free(lpMem)
[1]715End Sub
716
717Function _System_malloc(stSize As SIZE_T) As VoidPtr
[400]718 Return HeapAlloc(_System_hProcessHeap, 0, stSize)
[1]719End Function
720
721Function _System_calloc(stSize As SIZE_T) As VoidPtr
[400]722 Return HeapAlloc(_System_hProcessHeap, HEAP_ZERO_MEMORY, stSize)
[1]723End Function
724
725Function _System_realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
726 If lpMem = 0 Then
727 Return HeapAlloc(_System_hProcessHeap, 0, stSize)
728 Else
729 Return HeapReAlloc(_System_hProcessHeap, 0, lpMem, stSize)
730 End If
731End Function
732
733Sub _System_free(lpMem As VoidPtr)
[400]734 HeapFree(_System_hProcessHeap, 0, lpMem)
[1]735End Sub
736
737
738'--------
739' その他
740'--------
741
[123]742Sub _splitpath(path As PCSTR, drive As PSTR, dir As PSTR, fname As PSTR, ext As PSTR)
[1]743 Dim i As Long, i2 As Long, i3 As Long, length As Long
[167]744 Dim buffer[MAX_PATH] As SByte
[1]745
746 '":\"をチェック
747 If not(path[1]=&H3A and path[2]=&H5C) Then Exit Sub
748
749 'ドライブ名をコピー
750 If drive Then
751 drive[0]=path[0]
752 drive[1]=path[1]
753 drive[2]=0
754 End If
755
756 'ディレクトリ名をコピー
757 i=2
758 i2=0
759 Do
[123]760 If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
[1]761 If dir Then
762 dir[i2]=path[i]
763 dir[i2+1]=path[i+1]
764 End If
765
[10]766 i += 2
767 i2 += 2
[1]768 Continue
769 End If
770
771 If path[i]=0 Then Exit Do
772
773 If path[i]=&H5C Then '"\"記号であるかどうか
774 i3=i2+1
775 End If
776
777 If dir Then dir[i2]=path[i]
778
[10]779 i++
780 i2++
[1]781 Loop
782 If dir Then dir[i3]=0
[22]783 i3 += i-i2
[1]784
785 'ファイル名をコピー
786 i=i3
787 i2=0
788 i3=-1
789 Do
[123]790'#ifdef UNICODE
791' If _System_IsSurrogatePair(path[i], path[i + 1]) Then
792'#else
793 If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
794'#endif
[1]795 If fname Then
796 fname[i2]=path[i]
797 fname[i2+1]=path[i+1]
798 End If
799
[10]800 i += 2
801 i2 += 2
[1]802 Continue
803 End If
804
805 If path[i]=0 Then Exit Do
806
807 If path[i]=&H2E Then '.'記号であるかどうか
808 i3=i2
809 End If
810
811 If fname Then fname[i2]=path[i]
812
[10]813 i++
814 i2++
[1]815 Loop
816 If i3=-1 Then i3=i2
817 If fname Then fname[i3]=0
[10]818 i3 += i-i2
[1]819
820 '拡張子名をコピー
821 If ext Then
822 If i3 Then
[581]823 ActiveBasic.Strings.StrCpy(ext,path+i3)
[1]824 End If
825 else ext[0]=0
826 End If
827End Sub
828
829Function GetBasicColor(ColorCode As Long) As Long
830 Select Case ColorCode
831 Case 0
832 GetBasicColor=RGB(0,0,0)
833 Case 1
834 GetBasicColor=RGB(0,0,255)
835 Case 2
836 GetBasicColor=RGB(255,0,0)
837 Case 3
838 GetBasicColor=RGB(255,0,255)
839 Case 4
840 GetBasicColor=RGB(0,255,0)
841 Case 5
842 GetBasicColor=RGB(0,255,255)
843 Case 6
844 GetBasicColor=RGB(255,255,0)
845 Case 7
846 GetBasicColor=RGB(255,255,255)
847 End Select
848End Function
849
[167]850Function _System_BSwap(x As Word) As Word
851 Dim src = VarPtr(x) As *Byte
[223]852 Dim dst = VarPtr(_System_BSwap) As *Byte
[167]853 dst[0] = src[1]
854 dst[1] = src[0]
855End Function
856
857Function _System_BSwap(x As DWord) As DWord
858 Dim src = VarPtr(x) As *Byte
[223]859 Dim dst = VarPtr(_System_BSwap) As *Byte
[167]860 dst[0] = src[3]
861 dst[1] = src[2]
862 dst[2] = src[1]
863 dst[3] = src[0]
864End Function
865
866Function _System_BSwap(x As QWord) As QWord
867 Dim src = VarPtr(x) As *Byte
[223]868 Dim dst = VarPtr(_System_BSwap) As *Byte
[167]869 dst[0] = src[7]
870 dst[1] = src[6]
871 dst[2] = src[5]
872 dst[3] = src[4]
873 dst[4] = src[3]
874 dst[5] = src[2]
875 dst[6] = src[1]
876 dst[7] = src[0]
877End Function
878
[394]879Function _System_HashFromUInt(x As QWord) As Long
880 Return (HIDWORD(x) Xor LODWORD(x)) As Long
881End Function
882
883Function _System_HashFromUInt(x As DWord) As Long
884 Return x As Long
885End Function
886
[175]887Function _System_HashFromPtr(p As VoidPtr) As Long
[394]888 Return _System_HashFromUInt(p As ULONG_PTR)
[175]889End Function
890
[355]891/*!
[388]892@brief ObjPtrの逆。ABオブジェクトを指すポインタをObject型へ変換。
[355]893@author Egtra
894@date 2007/08/24
[457]895@param[in] p オブジェクトを指すポインタ
[355]896@return Object参照型
897*/
[303]898Function _System_PtrObj(p As VoidPtr) As Object
899 SetPointer(VarPtr(_System_PtrObj), p)
900End Function
901
[355]902/*!
903@brief IUnknownその他COMインタフェースを指すポインタをIUnknown参照型へ変換。
904@author Egtra
905@date 2007/09/24
906@param[in] p COMインタフェースを指すポインタ
907@return IUnknown参照型
908*/
909Function _System_PtrUnknown(p As VoidPtr) As IUnknown
910 SetPointer(VarPtr(_System_PtrUnknown), p)
911End Function
912
[142]913'--------
914' 文字列関数その2
915'--------
[119]916Function _System_IsSurrogatePair(wcHigh As WCHAR, wcLow As WCHAR) As Boolean
[394]917 If _System_IsHighSurrogate(wcHigh) Then
918 If _System_IsLowSurrogate(wcLow) Then
[119]919 Return True
920 End If
921 End If
922 Return False
923End Function
[1]924
[394]925Function _System_IsHighSurrogate(c As WCHAR) As Boolean
926 Return &hD800 <= c And c < &hDC00
927End Function
928
929Function _System_IsLowSurrogate(c As WCHAR) As Boolean
[497]930 Return &hDC00 <= c And c < &hE000
[394]931End Function
932
[142]933Function _System_IsDoubleUnitChar(lead As WCHAR, trail As WCHAR) As Boolean
[126]934 Return _System_IsSurrogatePair(lead, trail)
[142]935End Function
936
937Function _System_IsDoubleUnitChar(lead As SByte, trail As SByte) As Boolean
[126]938 Return IsDBCSLeadByte(lead) <> FALSE
939End Function
940
[175]941Function _System_GetHashFromWordArray(p As *Word, n As SIZE_T) As Long
942 Dim hash = 0 As DWord
943 Dim i As Long
944 For i = 0 To ELM(n)
945 hash = ((hash << 16) + p[i]) Mod &h7fffffff
946 Next
947 _System_GetHashFromWordArray = hash As Long
948End Function
Note: See TracBrowser for help on using the repository browser.