We allow this function to return 0 in case of invalid input, because it might be convenient to press Enter to some not dangerous prompts like "insert disk with next volume". We should call this function again in case of 0 in dangerous prompt such as overwriting file.
| 274 | // prompts like "insert disk with next volume". We should call this function |
| 275 | // again in case of 0 in dangerous prompt such as overwriting file. |
| 276 | int Ask(const wchar *AskStr) |
| 277 | { |
| 278 | uiAlarm(UIALARM_QUESTION); |
| 279 | |
| 280 | const int MaxItems=10; |
| 281 | wchar Item[MaxItems][40]; |
| 282 | int ItemKeyPos[MaxItems],NumItems=0; |
| 283 | |
| 284 | for (const wchar *NextItem=AskStr;NextItem!=NULL;NextItem=wcschr(NextItem+1,'_')) |
| 285 | { |
| 286 | wchar *CurItem=Item[NumItems]; |
| 287 | wcsncpyz(CurItem,NextItem+1,ASIZE(Item[0])); |
| 288 | wchar *EndItem=wcschr(CurItem,'_'); |
| 289 | if (EndItem!=NULL) |
| 290 | *EndItem=0; |
| 291 | int KeyPos=0,CurKey; |
| 292 | while ((CurKey=CurItem[KeyPos])!=0) |
| 293 | { |
| 294 | bool Found=false; |
| 295 | for (int I=0;I<NumItems && !Found;I++) |
| 296 | if (toupperw(Item[I][ItemKeyPos[I]])==toupperw(CurKey)) |
| 297 | Found=true; |
| 298 | if (!Found && CurKey!=' ') |
| 299 | break; |
| 300 | KeyPos++; |
| 301 | } |
| 302 | ItemKeyPos[NumItems]=KeyPos; |
| 303 | NumItems++; |
| 304 | } |
| 305 | |
| 306 | for (int I=0;I<NumItems;I++) |
| 307 | { |
| 308 | eprintf(I==0 ? (NumItems>4 ? L"\n":L" "):L", "); |
| 309 | int KeyPos=ItemKeyPos[I]; |
| 310 | for (int J=0;J<KeyPos;J++) |
| 311 | eprintf(L"%c",Item[I][J]); |
| 312 | eprintf(L"[%c]%ls",Item[I][KeyPos],&Item[I][KeyPos+1]); |
| 313 | } |
| 314 | eprintf(L" "); |
| 315 | wchar Str[50]; |
| 316 | getwstr(Str,ASIZE(Str)); |
| 317 | wchar Ch=toupperw(Str[0]); |
| 318 | for (int I=0;I<NumItems;I++) |
| 319 | if (Ch==Item[I][ItemKeyPos[I]]) |
| 320 | return I+1; |
| 321 | return 0; |
| 322 | } |
| 323 | #endif |
| 324 | |
| 325 |