Index: base/applications/cmdutils/timeout/CMakeLists.txt =================================================================== --- base/applications/cmdutils/timeout/CMakeLists.txt (nonexistent) +++ base/applications/cmdutils/timeout/CMakeLists.txt (working copy) @@ -0,0 +1,8 @@ + +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + +add_executable(timeout timeout.c timeout.rc) +set_module_type(timeout win32cui UNICODE) +target_link_libraries(timeout conutils ${PSEH_LIB}) +add_importlibs(timeout msvcrt user32 kernel32) +add_cd_file(TARGET timeout DESTINATION reactos/system32 FOR all) Index: base/applications/cmdutils/timeout/lang/en-us.rc =================================================================== --- base/applications/cmdutils/timeout/lang/en-us.rc (nonexistent) +++ base/applications/cmdutils/timeout/lang/en-us.rc (working copy) @@ -0,0 +1,21 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE +BEGIN + IDS_USAGE "ReactOS Timeout Utility\n\ +\n\ +Usage: timeout [/?][/t time][/nobreak]\n\n\ + /?\t\tDisplay this help.\n\ + /t time\tSpecify the number of seconds to wait (-1 to 99999).\n\ + /nobreak\tIgnore all user input except for Ctrl+C.\n\n\ +NOTE: For /t, a value of -1 means the program will wait until a key is pressed.\n" + IDS_ERROR_OUT_OF_RANGE "ERROR: The timer value must be within range (-1 to 99999).\n" + IDS_ERROR_INVALID_HANDLE_VALUE "ERROR: Unable to get the standard handle for the console.\n" + IDS_ERROR_READ_INPUT "ERROR: Unable to read the console input.\n" + IDS_ERROR_NO_TIMER_VALUE "ERROR: The timer value must be specified (-1 to 99999).\n" + IDS_ERROR_ONE_TIME "ERROR: Only one timer value is needed.\n" + IDS_NOBREAK_INPUT "Press Ctrl+C to quit ..." + IDS_USER_INPUT "Press any key to continue ..." + IDS_NOBREAK_INPUT_FULL "Waiting for %d second(s). Press Ctrl+C to quit ..." + IDS_USER_INPUT_FULL "Waiting for %d second(s). Press any key to continue ..." +END Index: base/applications/cmdutils/timeout/resource.h =================================================================== --- base/applications/cmdutils/timeout/resource.h (nonexistent) +++ base/applications/cmdutils/timeout/resource.h (working copy) @@ -0,0 +1,15 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#define IDS_USAGE 0 +#define IDS_ERROR_OUT_OF_RANGE 1 +#define IDS_ERROR_INVALID_HANDLE_VALUE 2 +#define IDS_ERROR_READ_INPUT 3 +#define IDS_ERROR_NO_TIMER_VALUE 4 +#define IDS_ERROR_ONE_TIME 5 +#define IDS_NOBREAK_INPUT 6 +#define IDS_USER_INPUT 7 +#define IDS_NOBREAK_INPUT_FULL 8 +#define IDS_USER_INPUT_FULL 9 + +#endif /* RESOURCE_H */ \ No newline at end of file Index: base/applications/cmdutils/timeout/timeout.c =================================================================== --- base/applications/cmdutils/timeout/timeout.c (nonexistent) +++ base/applications/cmdutils/timeout/timeout.c (working copy) @@ -0,0 +1,205 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS timeout utility + * FILE: base/applications/cmdutils/timeout/timeout.c + * PURPOSE: An enhanced alternative to the pause command + * PROGRAMMERS: Lee Schroeder (spaceseel at gmail dot com) + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "resource.h" + +VOID DeleteLine(VOID) +{ + wprintf(L"\b \r"); +} + +BOOL InputWait(BOOL noBreak, int count) +{ + HANDLE stdInput; + INPUT_RECORD irBuffer; + DWORD dwRead; + int tmpCount = count; + BOOL useTimer = ((count != -1) ? TRUE : FALSE); + + /* Grabs the current input handle */ + stdInput = GetStdHandle(STD_INPUT_HANDLE); + if (stdInput == INVALID_HANDLE_VALUE) + { + ConResPrintf(StdOut, IDS_ERROR_INVALID_HANDLE_VALUE); + return FALSE; + } + + wprintf(L"\n"); + + /* If the key input has been disabled, then just wait for Ctrl+C input */ + if (noBreak) + { + /* If there is no timer, then just show the message */ + if (!useTimer) + ConResPrintf(StdOut, IDS_NOBREAK_INPUT); + + do + { + + if (useTimer) + { + DeleteLine(); + ConResPrintf(StdOut, IDS_NOBREAK_INPUT_FULL, tmpCount); + tmpCount--; + } + + if (tmpCount < 0) + { + DeleteLine(); + tmpCount = 0; + ConResPrintf(StdOut, IDS_NOBREAK_INPUT_FULL, tmpCount); + return FALSE; + } + + if(!PeekConsoleInput(stdInput, &irBuffer, 1, &dwRead)) + { + ConResPrintf(StdOut, IDS_ERROR_READ_INPUT); + return FALSE; + } + + if ((irBuffer.EventType == KEY_EVENT) && (irBuffer.Event.KeyEvent.bKeyDown == TRUE)) + { + if (irBuffer.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + { + if (irBuffer.Event.KeyEvent.wVirtualKeyCode == 'C') + break; + } + } + + if (tmpCount != -1) + Sleep(1000); + } + while(TRUE); + } + else + { + /* If there is no timer, then just show the message */ + if (!useTimer) + ConResPrintf(StdOut, IDS_USER_INPUT); + + do + { + if (useTimer) + { + DeleteLine(); + ConResPrintf(StdOut, IDS_USER_INPUT_FULL, tmpCount); + tmpCount--; + } + + if (tmpCount < 0) + { + DeleteLine(); + tmpCount = 0; + ConResPrintf(StdOut, IDS_USER_INPUT_FULL, tmpCount); + return FALSE; + } + + if(!PeekConsoleInput(stdInput, &irBuffer, 1, &dwRead)) + { + ConResPrintf(StdOut, IDS_ERROR_READ_INPUT); + break; + } + + if ((irBuffer.EventType == KEY_EVENT) && (irBuffer.Event.KeyEvent.bKeyDown == TRUE)) + { + wprintf(L"\n\n"); + break; + } + + if (useTimer) + Sleep(1000); + } + while(TRUE); + } + + return TRUE; +} + +int wmain(int argc, WCHAR *argv[]) +{ + int timerValue = 1; + BOOL disableInput = FALSE, isTimed = FALSE; + int index = 0; + + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + + if (argc == 1) + { + ConResPrintf(StdOut, IDS_USAGE); + return 0; + } + + for (index = 1; index < argc; index++) + { + if (argv[index][0] == L'-' || argv[index][0] == L'/') + { + switch (towlower(argv[index][1])) + { + case L'?': /* Help */ + { + ConResPrintf(StdOut, IDS_USAGE); + return 0; + } + case L't': /* Timer */ + { + /* The utility does not support more than one timer value */ + if (isTimed == TRUE) + { + ConResPrintf(StdOut, IDS_ERROR_ONE_TIME); + return 0; + } + + timerValue = _wtoi(argv[index+1]); + isTimed = TRUE; + break; + } + } + } + + /* This flag is used for making user input harder by strictly + limiting user input to Ctrl+C */ + if ((_wcsicmp(argv[index], L"/nobreak") == 0) || + (_wcsicmp(argv[index], L"-nobreak") == 0)) + disableInput = TRUE; + } + + /* The program needs a timer value in order to continue. */ + if (isTimed == FALSE) + { + ConResPrintf(StdOut, IDS_ERROR_NO_TIMER_VALUE); + return 0; + } + + /* Make sure the timer value is within range */ + if ((timerValue < -1) || (timerValue > 99999)) + { + ConResPrintf(StdOut, IDS_ERROR_OUT_OF_RANGE, timerValue); + return 1; + } + + /* If the value is zero, then don't bother to check user input */ + if (timerValue == 0) + { + wprintf(L"\n"); + ConResPrintf(StdOut, (disableInput ? IDS_NOBREAK_INPUT_FULL : IDS_USER_INPUT_FULL), timerValue); + wprintf(L"\n"); + return 0; + } + + return InputWait(disableInput, timerValue); +} Index: base/applications/cmdutils/timeout/timeout.rc =================================================================== --- base/applications/cmdutils/timeout/timeout.rc (nonexistent) +++ base/applications/cmdutils/timeout/timeout.rc (working copy) @@ -0,0 +1,19 @@ +#include +#include + +#include "resource.h" + +/* Define language neutral resources */ +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Timeout Utility" +#define REACTOS_STR_INTERNAL_NAME "timeout" +#define REACTOS_STR_ORIGINAL_FILENAME "timeout.exe" +#include + +/* UTF-8 */ +#pragma code_page(65001) + +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif Index: base/applications/cmdutils/timeout/CMakeLists.txt =================================================================== --- base/applications/cmdutils/timeout/CMakeLists.txt (nonexistent) +++ base/applications/cmdutils/timeout/CMakeLists.txt (working copy) @@ -0,0 +1,8 @@ + +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + +add_executable(timeout timeout.c timeout.rc) +set_module_type(timeout win32cui UNICODE) +target_link_libraries(timeout conutils ${PSEH_LIB}) +add_importlibs(timeout msvcrt user32 kernel32) +add_cd_file(TARGET timeout DESTINATION reactos/system32 FOR all) Index: base/applications/cmdutils/timeout/lang/en-us.rc =================================================================== --- base/applications/cmdutils/timeout/lang/en-us.rc (nonexistent) +++ base/applications/cmdutils/timeout/lang/en-us.rc (working copy) @@ -0,0 +1,21 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE +BEGIN + IDS_USAGE "ReactOS Timeout Utility\n\ +\n\ +Usage: timeout [/?][/t time][/nobreak]\n\n\ + /?\t\tDisplay this help.\n\ + /t time\tSpecify the number of seconds to wait (-1 to 99999).\n\ + /nobreak\tIgnore all user input except for Ctrl+C.\n\n\ +NOTE: For /t, a value of -1 means the program will wait until a key is pressed.\n" + IDS_ERROR_OUT_OF_RANGE "ERROR: The timer value must be within range (-1 to 99999).\n" + IDS_ERROR_INVALID_HANDLE_VALUE "ERROR: Unable to get the standard handle for the console.\n" + IDS_ERROR_READ_INPUT "ERROR: Unable to read the console input.\n" + IDS_ERROR_NO_TIMER_VALUE "ERROR: The timer value must be specified (-1 to 99999).\n" + IDS_ERROR_ONE_TIME "ERROR: Only one timer value is needed.\n" + IDS_NOBREAK_INPUT "Press Ctrl+C to quit ..." + IDS_USER_INPUT "Press any key to continue ..." + IDS_NOBREAK_INPUT_FULL "Waiting for %d second(s). Press Ctrl+C to quit ..." + IDS_USER_INPUT_FULL "Waiting for %d second(s). Press any key to continue ..." +END Index: base/applications/cmdutils/timeout/lang/en-us.rc =================================================================== --- base/applications/cmdutils/timeout/lang/en-us.rc (nonexistent) +++ base/applications/cmdutils/timeout/lang/en-us.rc (working copy) @@ -0,0 +1,21 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE +BEGIN + IDS_USAGE "ReactOS Timeout Utility\n\ +\n\ +Usage: timeout [/?][/t time][/nobreak]\n\n\ + /?\t\tDisplay this help.\n\ + /t time\tSpecify the number of seconds to wait (-1 to 99999).\n\ + /nobreak\tIgnore all user input except for Ctrl+C.\n\n\ +NOTE: For /t, a value of -1 means the program will wait until a key is pressed.\n" + IDS_ERROR_OUT_OF_RANGE "ERROR: The timer value must be within range (-1 to 99999).\n" + IDS_ERROR_INVALID_HANDLE_VALUE "ERROR: Unable to get the standard handle for the console.\n" + IDS_ERROR_READ_INPUT "ERROR: Unable to read the console input.\n" + IDS_ERROR_NO_TIMER_VALUE "ERROR: The timer value must be specified (-1 to 99999).\n" + IDS_ERROR_ONE_TIME "ERROR: Only one timer value is needed.\n" + IDS_NOBREAK_INPUT "Press Ctrl+C to quit ..." + IDS_USER_INPUT "Press any key to continue ..." + IDS_NOBREAK_INPUT_FULL "Waiting for %d second(s). Press Ctrl+C to quit ..." + IDS_USER_INPUT_FULL "Waiting for %d second(s). Press any key to continue ..." +END Index: base/applications/cmdutils/timeout/resource.h =================================================================== --- base/applications/cmdutils/timeout/resource.h (nonexistent) +++ base/applications/cmdutils/timeout/resource.h (working copy) @@ -0,0 +1,15 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#define IDS_USAGE 0 +#define IDS_ERROR_OUT_OF_RANGE 1 +#define IDS_ERROR_INVALID_HANDLE_VALUE 2 +#define IDS_ERROR_READ_INPUT 3 +#define IDS_ERROR_NO_TIMER_VALUE 4 +#define IDS_ERROR_ONE_TIME 5 +#define IDS_NOBREAK_INPUT 6 +#define IDS_USER_INPUT 7 +#define IDS_NOBREAK_INPUT_FULL 8 +#define IDS_USER_INPUT_FULL 9 + +#endif /* RESOURCE_H */ \ No newline at end of file Index: base/applications/cmdutils/timeout/timeout.c =================================================================== --- base/applications/cmdutils/timeout/timeout.c (nonexistent) +++ base/applications/cmdutils/timeout/timeout.c (working copy) @@ -0,0 +1,205 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS timeout utility + * FILE: base/applications/cmdutils/timeout/timeout.c + * PURPOSE: An enhanced alternative to the pause command + * PROGRAMMERS: Lee Schroeder (spaceseel at gmail dot com) + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "resource.h" + +VOID DeleteLine(VOID) +{ + wprintf(L"\b \r"); +} + +BOOL InputWait(BOOL noBreak, int count) +{ + HANDLE stdInput; + INPUT_RECORD irBuffer; + DWORD dwRead; + int tmpCount = count; + BOOL useTimer = ((count != -1) ? TRUE : FALSE); + + /* Grabs the current input handle */ + stdInput = GetStdHandle(STD_INPUT_HANDLE); + if (stdInput == INVALID_HANDLE_VALUE) + { + ConResPrintf(StdOut, IDS_ERROR_INVALID_HANDLE_VALUE); + return FALSE; + } + + wprintf(L"\n"); + + /* If the key input has been disabled, then just wait for Ctrl+C input */ + if (noBreak) + { + /* If there is no timer, then just show the message */ + if (!useTimer) + ConResPrintf(StdOut, IDS_NOBREAK_INPUT); + + do + { + + if (useTimer) + { + DeleteLine(); + ConResPrintf(StdOut, IDS_NOBREAK_INPUT_FULL, tmpCount); + tmpCount--; + } + + if (tmpCount < 0) + { + DeleteLine(); + tmpCount = 0; + ConResPrintf(StdOut, IDS_NOBREAK_INPUT_FULL, tmpCount); + return FALSE; + } + + if(!PeekConsoleInput(stdInput, &irBuffer, 1, &dwRead)) + { + ConResPrintf(StdOut, IDS_ERROR_READ_INPUT); + return FALSE; + } + + if ((irBuffer.EventType == KEY_EVENT) && (irBuffer.Event.KeyEvent.bKeyDown == TRUE)) + { + if (irBuffer.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + { + if (irBuffer.Event.KeyEvent.wVirtualKeyCode == 'C') + break; + } + } + + if (tmpCount != -1) + Sleep(1000); + } + while(TRUE); + } + else + { + /* If there is no timer, then just show the message */ + if (!useTimer) + ConResPrintf(StdOut, IDS_USER_INPUT); + + do + { + if (useTimer) + { + DeleteLine(); + ConResPrintf(StdOut, IDS_USER_INPUT_FULL, tmpCount); + tmpCount--; + } + + if (tmpCount < 0) + { + DeleteLine(); + tmpCount = 0; + ConResPrintf(StdOut, IDS_USER_INPUT_FULL, tmpCount); + return FALSE; + } + + if(!PeekConsoleInput(stdInput, &irBuffer, 1, &dwRead)) + { + ConResPrintf(StdOut, IDS_ERROR_READ_INPUT); + break; + } + + if ((irBuffer.EventType == KEY_EVENT) && (irBuffer.Event.KeyEvent.bKeyDown == TRUE)) + { + wprintf(L"\n\n"); + break; + } + + if (useTimer) + Sleep(1000); + } + while(TRUE); + } + + return TRUE; +} + +int wmain(int argc, WCHAR *argv[]) +{ + int timerValue = 1; + BOOL disableInput = FALSE, isTimed = FALSE; + int index = 0; + + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + + if (argc == 1) + { + ConResPrintf(StdOut, IDS_USAGE); + return 0; + } + + for (index = 1; index < argc; index++) + { + if (argv[index][0] == L'-' || argv[index][0] == L'/') + { + switch (towlower(argv[index][1])) + { + case L'?': /* Help */ + { + ConResPrintf(StdOut, IDS_USAGE); + return 0; + } + case L't': /* Timer */ + { + /* The utility does not support more than one timer value */ + if (isTimed == TRUE) + { + ConResPrintf(StdOut, IDS_ERROR_ONE_TIME); + return 0; + } + + timerValue = _wtoi(argv[index+1]); + isTimed = TRUE; + break; + } + } + } + + /* This flag is used for making user input harder by strictly + limiting user input to Ctrl+C */ + if ((_wcsicmp(argv[index], L"/nobreak") == 0) || + (_wcsicmp(argv[index], L"-nobreak") == 0)) + disableInput = TRUE; + } + + /* The program needs a timer value in order to continue. */ + if (isTimed == FALSE) + { + ConResPrintf(StdOut, IDS_ERROR_NO_TIMER_VALUE); + return 0; + } + + /* Make sure the timer value is within range */ + if ((timerValue < -1) || (timerValue > 99999)) + { + ConResPrintf(StdOut, IDS_ERROR_OUT_OF_RANGE, timerValue); + return 1; + } + + /* If the value is zero, then don't bother to check user input */ + if (timerValue == 0) + { + wprintf(L"\n"); + ConResPrintf(StdOut, (disableInput ? IDS_NOBREAK_INPUT_FULL : IDS_USER_INPUT_FULL), timerValue); + wprintf(L"\n"); + return 0; + } + + return InputWait(disableInput, timerValue); +} Index: base/applications/cmdutils/timeout/timeout.rc =================================================================== --- base/applications/cmdutils/timeout/timeout.rc (nonexistent) +++ base/applications/cmdutils/timeout/timeout.rc (working copy) @@ -0,0 +1,19 @@ +#include +#include + +#include "resource.h" + +/* Define language neutral resources */ +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Timeout Utility" +#define REACTOS_STR_INTERNAL_NAME "timeout" +#define REACTOS_STR_ORIGINAL_FILENAME "timeout.exe" +#include + +/* UTF-8 */ +#pragma code_page(65001) + +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif