[1] | 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
|
---|
[257] | 11 | Const _System_Log_N = 7 As Long
|
---|
[1] | 12 |
|
---|
| 13 |
|
---|
[167] | 14 | #require <Classes/System/Math.ab>
|
---|
[269] | 15 | #require <Classes/ActiveBasic/Math/Math.ab>
|
---|
[16] | 16 |
|
---|
| 17 |
|
---|
[1] | 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
|
---|
[257] | 25 | Dim pSrc = VarPtr(x) As *QWord
|
---|
| 26 | Dim pDest = VarPtr(ldexp) As *QWord
|
---|
[1] | 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 |
|
---|
[257] | 38 | Dim pSrc = VarPtr(x) As *QWord
|
---|
| 39 | Dim pDest = VarPtr(frexp) As *QWord
|
---|
[1] | 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
|
---|
[10] | 60 | Dim r = 1 As Double
|
---|
[1] | 61 |
|
---|
| 62 | abs_n=Abs(n) As Long
|
---|
| 63 | While abs_n<>0
|
---|
[10] | 64 | If abs_n and 1 Then r *= x
|
---|
[1] | 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
|
---|
[92] | 122 | CDWord=num As DWord
|
---|
[1] | 123 | End Function
|
---|
| 124 |
|
---|
| 125 | Function CInt(number As Double) As Long
|
---|
[92] | 126 | CInt=number As Long
|
---|
[1] | 127 | End Function
|
---|
| 128 |
|
---|
| 129 | Function CSng(number As Double) As Single
|
---|
[92] | 130 | CSng=number As Single
|
---|
[1] | 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
|
---|
[269] | 143 | Int = Fix(number)
|
---|
| 144 | If number < 0 Then
|
---|
| 145 | If number < Fix(number) Then Int--
|
---|
[1] | 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
|
---|
[269] | 171 | 'Abs = System.Math.Abs(number)
|
---|
[1] | 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
|
---|
[269] | 180 | Exp = System.Math.Exp(x)
|
---|
[1] | 181 | End Function
|
---|
| 182 |
|
---|
| 183 | Function Log(x As Double) As Double
|
---|
[269] | 184 | Log = System.Math.Log(x)
|
---|
[1] | 185 | End Function
|
---|
| 186 |
|
---|
| 187 | Function Sgn(number As Double) As Long
|
---|
[269] | 188 | Sgn = System.Math.Sign(number)
|
---|
[1] | 189 | End Function
|
---|
| 190 |
|
---|
| 191 | Function Sqr(number As Double) As Double
|
---|
[269] | 192 | Sqr = System.Math.Sqrt(number)
|
---|
[1] | 193 | End Function
|
---|
| 194 |
|
---|
| 195 | Function Atn(number As Double) As Double
|
---|
[269] | 196 | Atn = System.Math.Atan(number)
|
---|
[1] | 197 | End Function
|
---|
| 198 |
|
---|
| 199 | Function Atn2(y As Double, x As Double) As Double
|
---|
[269] | 200 | Atn2 = System.Math.Atan2(y, x)
|
---|
[1] | 201 | End Function
|
---|
| 202 |
|
---|
| 203 | Function Sin(number As Double) As Double
|
---|
[269] | 204 | Sin = System.Math.Sin(number)
|
---|
[1] | 205 | End Function
|
---|
| 206 |
|
---|
| 207 | Function Cos(number As Double) As Double
|
---|
[269] | 208 | Cos = System.Math.Cos(number)
|
---|
[1] | 209 | End Function
|
---|
| 210 |
|
---|
| 211 | Function Tan(number As Double) As Double
|
---|
[269] | 212 | Tan = System.Math.Tan(number)
|
---|
[1] | 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 |
|
---|
[167] | 220 | Const HIDWORD(qw) = (((qw As QWord) >> 32) And &HFFFFFFFF) As DWord
|
---|
| 221 | Const LODWORD(qw) = ((qw As QWord) And &HFFFFFFFF) As DWord
|
---|
[1] | 222 |
|
---|
[167] | 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
|
---|
[1] | 225 |
|
---|
| 226 | '------------
|
---|
| 227 | ' 文字列関数
|
---|
| 228 | '------------
|
---|
| 229 |
|
---|
[142] | 230 | Function Asc(buf As *StrChar) As StrChar
|
---|
[1] | 231 | Asc = buf[0]
|
---|
| 232 | End Function
|
---|
| 233 |
|
---|
[142] | 234 | Function Chr$(code As StrChar) As String
|
---|
[121] | 235 | Chr$ = ZeroString(1)
|
---|
| 236 | Chr$[0] = code
|
---|
[1] | 237 | End Function
|
---|
| 238 |
|
---|
[142] | 239 | #ifndef __STRING_IS_NOT_UNICODE
|
---|
[133] | 240 | Function AscW(s As *WCHAR) As UCSCHAR
|
---|
[121] | 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 |
|
---|
[1] | 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 |
|
---|
[121] | 290 | Dim _System_HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
|
---|
| 291 |
|
---|
[167] | 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
|
---|
[121] | 297 | x <<= 4
|
---|
[167] | 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
|
---|
[1] | 310 | End Function
|
---|
| 311 |
|
---|
[167] | 312 | Function Hex$(x As DWord) As String
|
---|
| 313 | Hex$ = _System_Hex(x, True)
|
---|
| 314 | End Function
|
---|
| 315 |
|
---|
[121] | 316 | Function Hex$(x As QWord) As String
|
---|
[269] | 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
|
---|
[1] | 322 | End Function
|
---|
| 323 |
|
---|
| 324 | Function InStr(StartPos As Long, buf1 As String, buf2 As String) As Long
|
---|
[167] | 325 | Dim i As Long, i2 As Long, i3 As Long
|
---|
[1] | 326 |
|
---|
[167] | 327 | Dim len1 = buf1.Length
|
---|
| 328 | Dim len2 = buf2.Length
|
---|
[1] | 329 |
|
---|
| 330 | If len2=0 Then
|
---|
| 331 | InStr=StartPos
|
---|
| 332 | Exit Function
|
---|
| 333 | End If
|
---|
| 334 |
|
---|
[10] | 335 | StartPos--
|
---|
[1] | 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 |
|
---|
[10] | 352 | i2++
|
---|
| 353 | i3++
|
---|
[1] | 354 | Loop
|
---|
| 355 | If InStr Then Exit While
|
---|
[10] | 356 | i++
|
---|
[1] | 357 | Wend
|
---|
| 358 | End Function
|
---|
| 359 |
|
---|
| 360 | Function Left$(buf As String, length As Long) As String
|
---|
[121] | 361 | Left$ = ZeroString(length)
|
---|
[167] | 362 | memcpy(StrPtr(Left$), StrPtr(buf), SizeOf (StrChar) * length)
|
---|
[1] | 363 | End Function
|
---|
| 364 |
|
---|
| 365 | Function Mid$(buf As String, StartPos As Long)(ReadLength As Long) As String
|
---|
| 366 | Dim length As Long
|
---|
| 367 |
|
---|
[10] | 368 | StartPos--
|
---|
[1] | 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)
|
---|
[167] | 387 | memcpy(StrPtr(Mid$), VarPtr(buf.Chars[StartPos]), SizeOf (StrChar) * ReadLength)
|
---|
[1] | 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
|
---|
[269] | 394 | If (num \ CDWord(8^i)) And &H07 Then
|
---|
[1] | 395 | Exit For
|
---|
| 396 | End If
|
---|
| 397 | Next
|
---|
| 398 |
|
---|
| 399 | Oct$=ZeroString(i+1)
|
---|
| 400 | i2=0
|
---|
| 401 | Do
|
---|
[269] | 402 | Oct$[i2] = &h30 + ((num \ CDWord(8 ^ i)) And &H07) As StrChar ' &h30 = Asc("0")
|
---|
[1] | 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)
|
---|
[167] | 415 | memcpy(StrPtr(Right$), VarPtr(buf.Chars[i-length]), SizeOf (StrChar) * length)
|
---|
[1] | 416 | Else
|
---|
| 417 | Right$=buf
|
---|
| 418 | End If
|
---|
| 419 | End Function
|
---|
| 420 |
|
---|
| 421 | Function Space$(length As Long) As String
|
---|
[208] | 422 | Return New String(&h20 As StrChar, length)
|
---|
[1] | 423 | End Function
|
---|
| 424 |
|
---|
[167] | 425 | Dim _System_ecvt_buffer[16] As StrChar
|
---|
[1] | 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
|
---|
[123] | 439 | _System_ecvt_buffer[count]++
|
---|
[1] | 440 | End If
|
---|
| 441 | End Sub
|
---|
[167] | 442 | Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar
|
---|
[1] | 443 | Dim i As Long, i2 As Long
|
---|
| 444 |
|
---|
| 445 | _ecvt=_System_ecvt_buffer
|
---|
| 446 |
|
---|
| 447 | '値が0の場合
|
---|
[167] | 448 | If value = 0 Then
|
---|
[192] | 449 | _System_FillChar(_System_ecvt_buffer, count As SIZE_T, &H30 As StrChar)
|
---|
[123] | 450 | _System_ecvt_buffer[count] = 0
|
---|
| 451 | dec = 0
|
---|
| 452 | sign = 0
|
---|
[1] | 453 | Exit Function
|
---|
| 454 | End If
|
---|
| 455 |
|
---|
| 456 | '符号の判断(同時に符号を取り除く)
|
---|
[167] | 457 | If value < 0 Then
|
---|
| 458 | sign = 1
|
---|
| 459 | value = -value
|
---|
[1] | 460 | Else
|
---|
[167] | 461 | sign = 0
|
---|
[1] | 462 | End If
|
---|
| 463 |
|
---|
| 464 | '正規化
|
---|
[167] | 465 | dec = 1
|
---|
| 466 | While value < 0.999999999999999 'value<1
|
---|
[119] | 467 | value *= 10
|
---|
| 468 | dec--
|
---|
[1] | 469 | Wend
|
---|
[167] | 470 | While 9.99999999999999 <= value '10<=value
|
---|
[119] | 471 | value /= 10
|
---|
| 472 | dec++
|
---|
[1] | 473 | Wend
|
---|
| 474 |
|
---|
| 475 | For i=0 To count-1
|
---|
[167] | 476 | _System_ecvt_buffer[i] = Int(value) As StrChar
|
---|
[1] | 477 |
|
---|
[167] | 478 | value = (value-CDbl(Int(value))) * 10
|
---|
[1] | 479 | Next
|
---|
[167] | 480 | _System_ecvt_buffer[i] = 0
|
---|
[1] | 481 |
|
---|
[119] | 482 | i--
|
---|
[167] | 483 | If value >= 5 Then
|
---|
[1] | 484 | '切り上げ処理
|
---|
| 485 | _ecvt_support(i)
|
---|
| 486 | End If
|
---|
| 487 |
|
---|
[167] | 488 | For i=0 To ELM(count)
|
---|
[119] | 489 | _System_ecvt_buffer[i] += &H30
|
---|
[1] | 490 | Next
|
---|
[167] | 491 | _System_ecvt_buffer[i] = 0
|
---|
[1] | 492 | End Function
|
---|
| 493 |
|
---|
| 494 | Function Str$(dbl As Double) As String
|
---|
[269] | 495 | If ActiveBasic.Math.IsNaN(dbl) Then
|
---|
[1] | 496 | Return "NaN"
|
---|
[269] | 497 | ElseIf ActiveBasic.Math.IsInf(dbl) Then
|
---|
[1] | 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
|
---|
[167] | 505 | Dim buffer[32] As StrChar, temp As *StrChar
|
---|
[1] | 506 | Dim i As Long, i2 As Long, i3 As Long
|
---|
| 507 |
|
---|
| 508 | '浮動小数点を文字列に変換
|
---|
[167] | 509 | temp = _ecvt(dbl, 15, dec, sign)
|
---|
[1] | 510 |
|
---|
| 511 | i=0
|
---|
| 512 |
|
---|
| 513 | '符号の取り付け
|
---|
| 514 | If sign Then
|
---|
[167] | 515 | buffer[i] = Asc("-")
|
---|
[10] | 516 | i++
|
---|
[1] | 517 | End If
|
---|
| 518 |
|
---|
| 519 | If dec>15 Then
|
---|
| 520 | '指数表示(桁が大きい場合)
|
---|
[167] | 521 | buffer[i] = temp[0]
|
---|
[10] | 522 | i++
|
---|
[167] | 523 | buffer[i] = Asc(".")
|
---|
[10] | 524 | i++
|
---|
[167] | 525 | memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (StrChar) * 14)
|
---|
| 526 | i += 14
|
---|
| 527 | buffer[i] = Asc("e")
|
---|
[10] | 528 | i++
|
---|
[167] | 529 | _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1)
|
---|
[1] | 530 |
|
---|
| 531 | Return MakeStr(buffer)
|
---|
| 532 | End If
|
---|
| 533 |
|
---|
[167] | 534 | If dec < -3 Then
|
---|
[1] | 535 | '指数表示(桁が小さい場合)
|
---|
[167] | 536 | buffer[i] = temp[0]
|
---|
[10] | 537 | i++
|
---|
[167] | 538 | buffer[i] = Asc(".")
|
---|
[10] | 539 | i++
|
---|
[167] | 540 | memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (StrChar) * 14)
|
---|
[10] | 541 | i+=14
|
---|
[167] | 542 | buffer[i] = Asc("e")
|
---|
[10] | 543 | i++
|
---|
[167] | 544 | _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1)
|
---|
[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]
|
---|
[10] | 555 | i++
|
---|
| 556 | i3++
|
---|
| 557 | i2--
|
---|
[1] | 558 | Wend
|
---|
| 559 | buffer[i]=Asc(".")
|
---|
[10] | 560 | i++
|
---|
[1] | 561 | Else
|
---|
| 562 | buffer[i]=&H30
|
---|
[10] | 563 | i++
|
---|
[1] | 564 | buffer[i]=Asc(".")
|
---|
[10] | 565 | i++
|
---|
[1] | 566 |
|
---|
| 567 | i2=dec
|
---|
| 568 | While i2<0
|
---|
| 569 | buffer[i]=&H30
|
---|
[10] | 570 | i++
|
---|
| 571 | i2++
|
---|
[1] | 572 | Wend
|
---|
| 573 | End If
|
---|
| 574 |
|
---|
| 575 | '小数部
|
---|
| 576 | While i3<15
|
---|
| 577 | buffer[i]=temp[i3]
|
---|
[10] | 578 | i++
|
---|
| 579 | i3++
|
---|
[1] | 580 | Wend
|
---|
| 581 |
|
---|
| 582 | While buffer[i-1]=&H30
|
---|
[10] | 583 | i--
|
---|
[1] | 584 | Wend
|
---|
[10] | 585 | If buffer[i-1]=Asc(".") Then i--
|
---|
[1] | 586 |
|
---|
| 587 | buffer[i]=0
|
---|
| 588 | Return MakeStr(buffer)
|
---|
| 589 | End Function
|
---|
[167] | 590 |
|
---|
[269] | 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
|
---|
[1] | 597 | End Function
|
---|
| 598 |
|
---|
[269] | 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 |
|
---|
[1] | 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
|
---|
[237] | 693 | memcpy(VarPtr(String$.Chars[i*length]), StrPtr(buf), SizeOf (StrChar) * length)
|
---|
[1] | 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 |
|
---|
[167] | 725 | Function Val(buf As *StrChar) As Double
|
---|
[1] | 726 | Dim i As Long, i2 As Long, i3 As Long, i4 As Long
|
---|
| 727 | Dim temporary As String
|
---|
[167] | 728 | Dim TempPtr As *StrChar
|
---|
[1] | 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")
|
---|
[269] | 735 | buf = VarPtr(buf[1])
|
---|
[1] | 736 | Wend
|
---|
| 737 |
|
---|
| 738 | If buf[0]=Asc("&") Then
|
---|
[145] | 739 | temporary = New String( buf )
|
---|
[123] | 740 | temporary.ToUpper()
|
---|
| 741 | TempPtr = StrPtr(temporary)
|
---|
[1] | 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 |
|
---|
[167] | 750 | TempPtr[i]=i3 As StrChar
|
---|
[1] | 751 | i++
|
---|
| 752 | Wend
|
---|
| 753 | i--
|
---|
| 754 |
|
---|
| 755 | i64data=1
|
---|
| 756 | While i>=2
|
---|
[214] | 757 | Val += ( i64data * TempPtr[i] ) As Double
|
---|
[1] | 758 |
|
---|
[123] | 759 | i64data *= &O10
|
---|
[10] | 760 | i--
|
---|
[1] | 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 |
|
---|
[167] | 773 | TempPtr[i]=i3 As StrChar
|
---|
[1] | 774 | i++
|
---|
| 775 | Wend
|
---|
| 776 | i--
|
---|
| 777 |
|
---|
| 778 | i64data=1
|
---|
| 779 | While i>=2
|
---|
[22] | 780 | Val += (i64data*TempPtr[i]) As Double
|
---|
[1] | 781 |
|
---|
[10] | 782 | i64data *= &H10
|
---|
[1] | 783 | i--
|
---|
| 784 | Wend
|
---|
| 785 | End If
|
---|
| 786 | Else
|
---|
| 787 | '10進数
|
---|
[251] | 788 | sscanf(buf,"%lf",VarPtr(Val))
|
---|
[1] | 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
|
---|
[142] | 814 | Lof = GetFileSize(_System_hFile(FileNum-1), 0)
|
---|
[1] | 815 | End Function
|
---|
| 816 |
|
---|
| 817 | Function Loc(FileNum As Long) As Long
|
---|
| 818 | Dim NowPos As Long, BeginPos As Long
|
---|
| 819 |
|
---|
[10] | 820 | FileNum--
|
---|
[1] | 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
|
---|
[145] | 835 | Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC)
|
---|
[1] | 836 | End Function
|
---|
| 837 |
|
---|
| 838 | Function calloc(stSize As SIZE_T) As VoidPtr
|
---|
[145] | 839 | Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC or _System_GC_FLAG_INITZERO)
|
---|
[1] | 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
|
---|
[145] | 846 | Return _System_pGC->__realloc(lpMem,stSize)
|
---|
[1] | 847 | End If
|
---|
| 848 | End Function
|
---|
| 849 |
|
---|
| 850 | Sub free(lpMem As VoidPtr)
|
---|
[145] | 851 | _System_pGC->__free(lpMem)
|
---|
[1] | 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 |
|
---|
[123] | 880 | Sub _splitpath(path As PCSTR, drive As PSTR, dir As PSTR, fname As PSTR, ext As PSTR)
|
---|
[1] | 881 | Dim i As Long, i2 As Long, i3 As Long, length As Long
|
---|
[167] | 882 | Dim buffer[MAX_PATH] As SByte
|
---|
[1] | 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
|
---|
[123] | 898 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
[1] | 899 | If dir Then
|
---|
| 900 | dir[i2]=path[i]
|
---|
| 901 | dir[i2+1]=path[i+1]
|
---|
| 902 | End If
|
---|
| 903 |
|
---|
[10] | 904 | i += 2
|
---|
| 905 | i2 += 2
|
---|
[1] | 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 |
|
---|
[10] | 917 | i++
|
---|
| 918 | i2++
|
---|
[1] | 919 | Loop
|
---|
| 920 | If dir Then dir[i3]=0
|
---|
[22] | 921 | i3 += i-i2
|
---|
[1] | 922 |
|
---|
| 923 | 'ファイル名をコピー
|
---|
| 924 | i=i3
|
---|
| 925 | i2=0
|
---|
| 926 | i3=-1
|
---|
| 927 | Do
|
---|
[123] | 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
|
---|
[1] | 933 | If fname Then
|
---|
| 934 | fname[i2]=path[i]
|
---|
| 935 | fname[i2+1]=path[i+1]
|
---|
| 936 | End If
|
---|
| 937 |
|
---|
[10] | 938 | i += 2
|
---|
| 939 | i2 += 2
|
---|
[1] | 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 |
|
---|
[10] | 951 | i++
|
---|
| 952 | i2++
|
---|
[1] | 953 | Loop
|
---|
| 954 | If i3=-1 Then i3=i2
|
---|
| 955 | If fname Then fname[i3]=0
|
---|
[10] | 956 | i3 += i-i2
|
---|
[1] | 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 |
|
---|
[167] | 988 | Function _System_BSwap(x As Word) As Word
|
---|
| 989 | Dim src = VarPtr(x) As *Byte
|
---|
[223] | 990 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
[167] | 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
|
---|
[223] | 997 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
[167] | 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
|
---|
[223] | 1006 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
[167] | 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 |
|
---|
[175] | 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 |
|
---|
[142] | 1026 | '--------
|
---|
| 1027 | ' 文字列関数その2
|
---|
| 1028 | '--------
|
---|
[119] | 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
|
---|
[1] | 1037 |
|
---|
[142] | 1038 | Function _System_IsDoubleUnitChar(lead As WCHAR, trail As WCHAR) As Boolean
|
---|
[126] | 1039 | Return _System_IsSurrogatePair(lead, trail)
|
---|
[142] | 1040 | End Function
|
---|
| 1041 |
|
---|
| 1042 | Function _System_IsDoubleUnitChar(lead As SByte, trail As SByte) As Boolean
|
---|
[126] | 1043 | Return IsDBCSLeadByte(lead) <> FALSE
|
---|
| 1044 | End Function
|
---|
| 1045 |
|
---|
[142] | 1046 | Sub _System_FillChar(p As PWSTR, n As SIZE_T, c As WCHAR)
|
---|
[123] | 1047 | Dim i As SIZE_T
|
---|
| 1048 | For i = 0 To ELM(n)
|
---|
| 1049 | p[i] = c
|
---|
| 1050 | Next
|
---|
[125] | 1051 | End Sub
|
---|
| 1052 |
|
---|
[142] | 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
|
---|
[125] | 1061 | Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
|
---|
[123] | 1062 | End Function
|
---|
| 1063 |
|
---|
[142] | 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
|
---|
[125] | 1069 | Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
|
---|
| 1070 | End Function
|
---|
| 1071 |
|
---|
[164] | 1072 | Function _System_ASCII_IsLower(c As SByte) As Boolean
|
---|
[142] | 1073 | Return _System_ASCII_IsLower(c As Byte As WCHAR)
|
---|
| 1074 | End Function
|
---|
| 1075 |
|
---|
| 1076 | Function _System_ASCII_ToLower(c As WCHAR) As WCHAR
|
---|
[125] | 1077 | If _System_ASCII_IsUpper(c) Then
|
---|
| 1078 | Return c Or &h20
|
---|
| 1079 | Else
|
---|
| 1080 | Return c
|
---|
| 1081 | End If
|
---|
| 1082 | End Function
|
---|
| 1083 |
|
---|
[142] | 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 |
|
---|
[164] | 1088 | Function _System_ASCII_ToUpper(c As WCHAR) As WCHAR
|
---|
[125] | 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 |
|
---|
[142] | 1096 | Function _System_ASCII_ToUpper(c As SByte) As SByte
|
---|
| 1097 | Return _System_ASCII_ToUpper(c As Byte As WCHAR) As Byte As SByte
|
---|
[125] | 1098 | End Function
|
---|
| 1099 |
|
---|
[269] | 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 |
|
---|
[132] | 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
|
---|
[142] | 1131 |
|
---|
[203] | 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)
|
---|
[237] | 1135 | _System_StrCmpN = s1[i] - s2[i]
|
---|
| 1136 | If _System_StrCmpN <> 0 Then
|
---|
[203] | 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)
|
---|
[237] | 1145 | _System_StrCmpN = s1[i] - s2[i]
|
---|
| 1146 | If _System_StrCmpN <> 0 Then
|
---|
[203] | 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 |
|
---|
[175] | 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 |
|
---|
[1] | 1201 | #endif '_INC_FUNCTION
|
---|