source: trunk/Include/basic/dos_console.sbp@ 465

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

StreamReaderの完成。StringReaderの追加。
Consoleの追加(現在入力関係の一部のみ)。

File size: 2.3 KB
Line 
1'dos_console.sbp
2'このファイルには、コンソール アプリケーション用のサポート プログラムが記載されます。
3
4
5#ifndef _INC_DOS_CONSOLE
6#define _INC_DOS_CONSOLE
7
8
9Dim _System_hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
10Dim _System_hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
11System.Console.SetIn(
12 New System.IO.StreamReader(
13 New System.IO.FileStream(_System_hConsoleIn, System.IO.FileAccess.Read, False)))
14
15'---------- command.sbp内で定義済み ----------
16'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
17'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
18'---------------------------------------------
19Sub INPUT_FromPrompt(ShowStr As String)
20*InputReStart '多重Continueがあるので、これはループ構文に直せない。
21 PRINT_ToPrompt(ShowStr)
22
23 '入力
24 Dim input = System.Console.ReadLine()
25 If ActiveBasic.IsNothing(input) Then
26 Exit Sub
27 End If
28
29 If input.Length = 0 Then Goto *InputReStart
30
31 'データを変数に格納
32 Const comma = &h2c As StrChar 'Asc(",")
33 Dim broken = ActiveBasic.Strings.Detail.Split(input, comma)
34 Dim i As Long
35 For i = 0 To ELM(broken.Count)
36 If _System_InputDataPtr[i] = 0 Then
37 PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
38 Goto *InputReStart
39 End If
40 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], broken[i])
41 Next
42
43 If _System_InputDataPtr[i]<>0 Then
44 PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
45 Goto *InputReStart
46 End If
47End Sub
48
49Macro LOCATE(x As Long, y As Long)
50 SetConsoleCursorPosition(_System_hConsoleOut, MAKELONG(x, y))
51End Macro
52
53Sub PRINT_ToPrompt(buf As String)
54 If String.IsNullOrEmpty(buf) Then
55 Exit Sub
56 End If
57
58 Dim dwAccessBytes As DWord
59#ifdef __STRING_UNICODE_WINDOWS_ANSI
60' Debug
61 Dim oldAlloc = _System_AllocForConvertedString
62 _System_AllocForConvertedString = AddressOf (_System_malloc)
63 Dim pszOut As PCSTR
64 Dim len = GetStr(buf, pszOut)
65 _System_AllocForConvertedString = oldAlloc
66 WriteConsole(_System_hConsoleOut, pszOut, len, dwAccessBytes, 0)
67 _System_free(pszOut)
68#else
69 WriteConsole(_System_hConsoleOut, buf.StrPtr, buf.Length, dwAccessBytes, 0)
70#endif
71End Sub
72/* TODO: _System_GetUsingFormatを用意して実装する
73Sub PRINTUSING_ToPrompt(UsingStr As String)
74 PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
75End Sub
76*/
77
78#endif '_INC_DOS_CONSOLE
Note: See TracBrowser for help on using the repository browser.