| 225 | |
| 226 | #ifndef SILENT |
| 227 | bool getwstr(wchar *str,size_t n) |
| 228 | { |
| 229 | // Print buffered prompt title function before waiting for input. |
| 230 | fflush(stderr); |
| 231 | |
| 232 | *str=0; |
| 233 | #if defined(_WIN_ALL) |
| 234 | // fgetws does not work well with non-English text in Windows, |
| 235 | // so we do not use it. |
| 236 | if (StdinRedirected) // ReadConsole does not work if redirected. |
| 237 | { |
| 238 | // fgets does not work well with pipes in Windows in our test. |
| 239 | // Let's use files. |
| 240 | Array<char> StrA(n*4); // Up to 4 UTF-8 characters per wchar_t. |
| 241 | File SrcFile; |
| 242 | SrcFile.SetHandleType(FILE_HANDLESTD); |
| 243 | int ReadSize=SrcFile.Read(&StrA[0],StrA.Size()-1); |
| 244 | if (ReadSize<=0) |
| 245 | { |
| 246 | // Looks like stdin is a null device. We can enter to infinite loop |
| 247 | // calling Ask(), so let's better exit. |
| 248 | ErrHandler.Exit(RARX_USERBREAK); |
| 249 | } |
| 250 | StrA[ReadSize]=0; |
| 251 | CharToWide(&StrA[0],str,n); |
| 252 | cleandata(&StrA[0],StrA.Size()); // We can use this function to enter passwords. |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | DWORD ReadSize=0; |
| 257 | if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE),str,DWORD(n-1),&ReadSize,NULL)==0) |
| 258 | return false; |
| 259 | str[ReadSize]=0; |
| 260 | } |
| 261 | #else |
| 262 | if (fgetws(str,n,stdin)==NULL) |
| 263 | ErrHandler.Exit(RARX_USERBREAK); // Avoid infinite Ask() loop. |
| 264 | #endif |
| 265 | RemoveLF(str); |
| 266 | return true; |
| 267 | } |
| 268 | #endif |
| 269 | |
| 270 |
no test coverage detected