FreeBASIC  0.91.0
con_lineinp_wstr.c
Go to the documentation of this file.
1 /* console line input function for wstrings */
2 
3 #include "fb.h"
4 
5 static const char *pszDefaultQuestion = "? ";
6 
7 #if defined( HOST_WIN32 ) || defined( HOST_DOS )
8 
10  (
11  const FB_WCHAR *text,
12  FB_WCHAR *dst,
13  ssize_t max_chars,
14  int addquestion,
15  int addnewline
16  )
17 {
18  FBSTRING *tmp_result;
19 
20  /* !!!FIXME!!! no support for unicode input */
21 
22  FB_LOCK();
23 
25 
26  if( text != NULL )
27  {
28  fb_PrintWstr( 0, text, 0 );
29 
30  if( addquestion != FB_FALSE )
32  }
33 
34  FB_UNLOCK();
35 
36  tmp_result = fb_ConReadLine( FALSE );
37 
38  if( addnewline )
40 
41  if( tmp_result == NULL )
43 
44  fb_WstrAssignFromA( dst, max_chars, tmp_result, -1 );
45 
46  return fb_ErrorSetNum( FB_RTERROR_OK );
47 }
48 
49 #else
50 
51 static char *hWrapper( char *buffer, size_t count, FILE *fp )
52 {
53  return fb_ReadString( buffer, count, fp );
54 }
55 
57  (
58  const FB_WCHAR *text,
59  FB_WCHAR *dst,
60  ssize_t max_chars,
61  int addquestion,
62  int addnewline
63  )
64 {
65  size_t len;
66  int res, old_x, old_y;
67 
68  /* !!!FIXME!!! no support for unicode input */
69 
71  fb_GetXY( &old_x, &old_y );
72 
73  FB_LOCK();
74 
75  if( text != NULL )
76  {
77  fb_PrintWstr( 0, text, 0 );
78 
79  if( addquestion != FB_FALSE )
81  }
82 
83  {
84  FBSTRING str_result = { 0 };
85 
86  res = fb_DevFileReadLineDumb( stdin, &str_result, hWrapper );
87 
88  len = FB_STRSIZE(&str_result);
89 
90  if( !addnewline )
91  {
92  int cols, rows, old_y;
93 
94  fb_GetSize( &cols, &rows );
95  fb_GetXY( NULL, &old_y );
96 
97  old_x += len - 1;
98  old_x %= cols;
99  old_x += 1;
100  old_y -= 1;
101 
102  fb_Locate( old_y, old_x, -1, 0, 0 );
103  }
104 
105  fb_WstrAssignFromA( dst, max_chars, (void *)&str_result, -1 );
106 
107  fb_StrDelete( &str_result );
108  }
109 
110  FB_UNLOCK();
111 
112  return res;
113 }
114 
115 #endif