-
Notifications
You must be signed in to change notification settings - Fork 11
/
dev_scrn_read_wstr.bas
70 lines (50 loc) · 1.75 KB
/
dev_scrn_read_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
/' file device '/
#include "fb.bi"
extern "C"
function fb_DevScrnReadWstr( handle as FB_FILE ptr, dst as FB_WCHAR ptr, pchars as size_t ptr ) as long
dim as size_t chars, copy_chars
dim as DEV_SCRN_INFO ptr info
/' !!!FIXME!!! no unicode input supported '/
FB_LOCK()
chars = *pchars
info = cast(DEV_SCRN_INFO ptr, FB_HANDLE_DEREF(handle)->opaque)
while ( chars > 0 )
dim as size_t _len = info->length / sizeof( FB_WCHAR )
copy_chars = iif(chars > _len, _len, chars)
if ( copy_chars = 0 ) then
while ( fb_KeyHit( ) = 0 )
fb_Delay( 25 ) /' release time slice '/
wend
fb_DevScrnFillInput( info )
if ( info->length <> 0 ) then
continue while
end if
exit while
end if
fb_wstr_ConvFromA( dst, chars, @info->buffer(0) )
info->length -= copy_chars * sizeof( FB_WCHAR )
if ( info->length <> 0 ) then
memmove( @info->buffer(0), @info->buffer(copy_chars * sizeof( FB_WCHAR )),info->length )
end if
chars -= copy_chars
dst += copy_chars
wend
FB_UNLOCK()
if ( chars <> 0 ) then
memset( dst, 0, chars * sizeof( FB_WCHAR ) )
end if
*pchars -= chars
return fb_ErrorSetNum( FB_RTERROR_OK )
end function
private function hReadFromStdin( handle as FB_FILE ptr, dst as FB_WCHAR ptr, pchars as size_t ptr ) as long
return fb_DevFileReadWstr( NULL, dst, pchars )
end function
sub fb_DevScrnInit_ReadWstr( )
fb_DevScrnInit_NoOpen( )
FB_LOCK( )
if ( FB_HANDLE_SCREEN->hooks->pfnReadWstr = NULL ) then
FB_HANDLE_SCREEN->hooks->pfnReadWstr = iif(fb_IsRedirected( TRUE ), @hReadFromStdin, @fb_DevScrnReadWstr)
end if
FB_UNLOCK( )
end sub
end extern