source: Include/basic/dos_console.sbp@ 268

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

StringのResizeを呼ぶコンストラクタでメモリ確保されない場合を排除、ほか微修正

File size: 2.5 KB
Line 
1'dos_console.sbp
2'このファイルには、コンソール アプリケーション用のサポート プログラムが記載されます。
3
4
5#ifndef _INC_DOS_CONSOLE
6#define _INC_DOS_CONSOLE
7
8
9#include <api_console.sbp>
10
11Dim _System_hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
12Dim _System_hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
13
14'---------- command.sbp内で定義済み ----------
15'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
16'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
17'---------------------------------------------
18Sub INPUT_FromPrompt(ShowStr As String)
19 Dim i As Long, i2 As Long, i3 As Long
20 Dim buf As String
21 Dim InputBuf[1023] As TCHAR
22 Dim dwAccessBytes As DWord
23
24*InputReStart
25
26 PRINT_ToPrompt(ShowStr)
27
28 '入力
29 ReadConsole(_System_hConsoleIn, InputBuf, Len(InputBuf), dwAccessBytes, 0)
30 If InputBuf[dwAccessBytes-2] = &h0d And InputBuf[dwAccessBytes-1] = &h0a Then
31 InputBuf[dwAccessBytes-2] = 0
32 End If
33 Dim InputStr As String(InputBuf)
34
35 'データを変数に格納
36 i=0
37 i2=0
38 buf.ReSize(lstrlen(InputStr) + 1, 0)
39 Dim comma As Char
40 comma = &h2c 'Asc(",")
41 While 1
42 i3=0
43 While 1
44 If InputStr[i2]=comma Then
45 buf[i3]=0
46 Exit While
47 End If
48
49 buf[i3]=InputStr[i2]
50
51 If InputStr[i2]=0 Then Exit While
52
53 i2++
54 i3++
55 Wend
56
57 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], buf, i3)
58
59 i++
60 If _System_InputDataPtr[i]=0 And InputStr[i2]=comma Then
61 PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
62 Goto *InputReStart
63 ElseIf InputStr[i2]=0 Then
64 If _System_InputDataPtr[i]<>0 Then
65 PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
66 Goto *InputReStart
67 Else
68 Exit While
69 End If
70 End If
71
72 i2++
73 Wend
74End Sub
75
76Macro LOCATE(x As Long, y As Long)
77 SetConsoleCursorPosition(_System_hConsoleOut, MAKELONG(x, y))
78End Macro
79
80Sub PRINT_ToPrompt(buf As String)
81 Dim dwAccessBytes As DWord
82#ifdef __STRING_UNICODE_WINDOWS_ANSI
83' Debug
84 Dim oldAlloc = _System_AllocForConvertedString
85 _System_AllocForConvertedString = AddressOf (_System_malloc)
86 Dim pszOut As PCSTR
87 Dim len = GetStr(buf, pszOut)
88 _System_AllocForConvertedString = oldAlloc
89 WriteConsole(_System_hConsoleOut, pszOut, len, dwAccessBytes, 0)
90 _System_free(pszOut)
91#else
92 WriteConsole(_System_hConsoleOut, buf.Chars, buf.Length, dwAccessBytes, 0)
93#endif
94End Sub
95
96Sub PRINTUSING_ToPrompt(UsingStr As String)
97 PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
98End Sub
99
100
101#endif '_INC_DOS_CONSOLE
Note: See TracBrowser for help on using the repository browser.