FreeBASIC  0.91.0
dev_scrn_read_wstr.c
Go to the documentation of this file.
1 /* file device */
2 
3 #include "fb.h"
4 
5 int fb_DevScrnReadWstr( FB_FILE *handle, FB_WCHAR *dst, size_t *pchars )
6 {
7  size_t chars, copy_chars;
8  DEV_SCRN_INFO *info;
9 
10  /* !!!FIXME!!! no unicode input supported */
11 
12  FB_LOCK();
13 
14  chars = *pchars;
15 
16  info = (DEV_SCRN_INFO*) FB_HANDLE_DEREF(handle)->opaque;
17 
18  while( chars > 0 )
19  {
20  size_t len = info->length / sizeof( FB_WCHAR );
21  copy_chars = (chars > len) ? len : chars;
22  if( copy_chars == 0 )
23  {
24  while( fb_KeyHit( ) == 0 )
25  fb_Delay( 25 ); /* release time slice */
26 
27  fb_DevScrnFillInput( info );
28  if( info->length != 0 )
29  continue;
30 
31  break;
32  }
33 
34  fb_wstr_ConvFromA( dst, chars, info->buffer );
35 
36  info->length -= copy_chars * sizeof( FB_WCHAR );
37  if( info->length != 0 )
38  {
39  memmove( info->buffer,
40  info->buffer + copy_chars * sizeof( FB_WCHAR ),
41  info->length );
42  }
43 
44  chars -= copy_chars;
45  dst += copy_chars;
46  }
47 
48  FB_UNLOCK();
49 
50  if( chars != 0 )
51  memset( dst, 0, chars * sizeof( FB_WCHAR ) );
52 
53  *pchars -= chars;
54 
55  return fb_ErrorSetNum( FB_RTERROR_OK );
56 }
57 
58 static int hReadFromStdin( FB_FILE *handle, FB_WCHAR *dst, size_t *pchars )
59 {
60  return fb_DevFileReadWstr( NULL, dst, pchars );
61 }
62 
64 {
66 
67  if( FB_HANDLE_SCREEN->hooks->pfnReadWstr == NULL )
68  {
69  FB_HANDLE_SCREEN->hooks->pfnReadWstr =
71  }
72 }