-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcon_lineinp_wstr.bas
102 lines (67 loc) · 2.39 KB
/
con_lineinp_wstr.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/' console line input function for wstrings '/
#include "fb.bi"
'' This already exists in the non-wstr version
extern as zString ptr pszDefaultQuestion
extern "C"
#if defined( HOST_WIN32 ) or defined( HOST_DOS )
function fb_ConsoleLineInputWstr( text as const FB_WCHAR ptr, dst as FB_WCHAR ptr, max_chars as ssize_t, addquestion as long, addnewline as long ) as long
dim as FBSTRING ptr tmp_result
/' !!!FIXME!!! no support for unicode input '/
FB_LOCK()
fb_PrintBufferEx( NULL, 0, FB_PRINT_FORCE_ADJUST )
if ( text <> NULL ) then
fb_PrintWstr( 0, text, 0 )
if ( addquestion <> FB_FALSE ) then
fb_PrintFixString( 0, pszDefaultQuestion, 0 )
end if
end if
FB_UNLOCK()
tmp_result = fb_ConReadLine( FALSE )
if ( addnewline <> NULL ) then
fb_PrintVoid( 0, FB_PRINT_NEWLINE )
end if
if ( tmp_result = NULL ) then
return fb_ErrorSetNum( FB_RTERROR_OUTOFMEM )
end if
fb_WstrAssignFromA( dst, max_chars, tmp_result, -1 )
return fb_ErrorSetNum( FB_RTERROR_OK )
end function
#else
private function hWrapper( buffer as ubyte ptr, count as size_t, fp as FILE ptr ) as ubyte ptr
return fb_ReadString( buffer, count, fp )
end function
function fb_ConsoleLineInputWstr( text as const FB_WCHAR ptr, dst as FB_WCHAR ptr, max_chars as ssize_t, addquestion as long, addnewline as long ) as long
dim as size_t _len
dim as long res, old_x, old_y
/' !!!FIXME!!! no support for unicode input '/
fb_PrintBufferEx( NULL, 0, FB_PRINT_FORCE_ADJUST )
fb_GetXY( @old_x, @old_y )
FB_LOCK()
if ( text <> NULL ) then
fb_PrintWstr( 0, text, 0 )
if ( addquestion <> FB_FALSE ) then
fb_PrintFixString( 0, pszDefaultQuestion, 0 )
end if
end if
scope
dim as FBSTRING str_result = ( 0, 0, 0 )
res = fb_DevFileReadLineDumb( stdin, @str_result, @hWrapper )
_len = FB_STRSIZE(@str_result)
if ( addnewline = 0 ) then
dim as long cols, rows, old_y
fb_GetSize( @cols, @rows )
fb_GetXY( NULL, @old_y )
old_x += _len - 1
old_x mod= cols
old_x += 1
old_y -= 1
fb_Locate( old_y, old_x, -1, 0, 0 )
end if
fb_WstrAssignFromA( dst, max_chars, cast(any ptr, @str_result), -1 )
fb_StrDelete( @str_result )
end scope
FB_UNLOCK()
return res
end function
#endif
end extern