while (context -> skip_rest == FALSE) {
CMD_LIST *toExecute = NULL; /* Commands left to be executed */
- if (WCMD_ReadAndParseLine(NULL, &toExecute, h) == NULL)
+ if (!WCMD_ReadAndParseLine(NULL, &toExecute, h, FALSE))
break;
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
WCMD_free_commands(toExecute);
* the LF (or CRLF) from the line.
*/
-WCHAR *WCMD_fgets (WCHAR *s, int noChars, HANDLE h)
+WCHAR *WCMD_fgets(WCHAR *s, int noChars, HANDLE h, BOOL is_console_handle)
{
DWORD bytes, charsRead;
BOOL status;
WCHAR *p;
p = s;
- if ((status = ReadConsoleW(h, s, noChars, &charsRead, NULL))) {
+ if (is_console_handle) {
+ status = ReadConsoleW(h, s, noChars, &charsRead, NULL);
+ if (!status) return NULL;
s[charsRead-2] = '\0'; /* Strip \r\n */
return p;
}
- /* Continue only if we have no console (i.e. a file) handle */
- if (GetLastError() != ERROR_INVALID_HANDLE)
- return NULL;
-
/* TODO: More intelligent buffering for reading lines from files */
do {
status = WCMD_ReadFile (h, s, 1, &bytes, NULL);
WCHAR buffer[MAXSTRING] = {'\0'};
WCHAR *where, *parm;
- while (WCMD_fgets (buffer, sizeof(buffer)/sizeof(WCHAR), input)) {
+ while (WCMD_fgets(buffer, sizeof(buffer)/sizeof(WCHAR), input, FALSE)) {
/* Skip blank lines*/
parm = WCMD_parameter (buffer, 0, &where, NULL);
if (*paramStart == ':') paramStart++;
SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
- while (WCMD_fgets (string, sizeof(string)/sizeof(WCHAR), context -> h)) {
+ while (WCMD_fgets (string, sizeof(string)/sizeof(WCHAR), context -> h, FALSE)) {
str = string;
while (isspaceW (*str)) str++;
if (*str == ':') {
void WCMD_version (void);
int WCMD_volume (BOOL set_label, const WCHAR *command);
-WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream);
+WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream, const BOOL is_console_handle);
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end);
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars,
LPDWORD charsRead, const LPOVERLAPPED unused);
-WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom);
+WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output,
+ HANDLE readFrom, const BOOL is_console_handle);
CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
const WCHAR *var, const WCHAR *val);
void WCMD_free_commands(CMD_LIST *cmds);
* - Anything else gets put into the command string (including
* redirects)
*/
-WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE readFrom) {
-
+WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output,
+ HANDLE readFrom, const BOOL is_console_handle)
+{
WCHAR *curPos;
int inQuotes = 0;
WCHAR curString[MAXSTRING];
} else if (readFrom == INVALID_HANDLE_VALUE) {
WINE_FIXME("No command nor handle supplied\n");
} else {
- if (WCMD_fgets(extraSpace, MAXSTRING, readFrom) == NULL) return NULL;
+ if (!WCMD_fgets(extraSpace, MAXSTRING, readFrom, is_console_handle))
+ return NULL;
}
curPos = extraSpace;
/* Read more, skipping any blank lines */
while (*extraSpace == 0x00) {
if (!context) WCMD_output_asis( WCMD_LoadMessage(WCMD_MOREPROMPT));
- if (WCMD_fgets(extraSpace, MAXSTRING, readFrom) == NULL) break;
+ if (!WCMD_fgets(extraSpace, MAXSTRING, readFrom, is_console_handle))
+ break;
}
curPos = extraSpace;
if (context) handleExpansion(extraSpace, FALSE, NULL, NULL);
WCHAR string[1024];
WCHAR envvar[4];
int opt_q;
+ BOOL is_console;
+ DWORD dummy;
int opt_t = 0;
static const WCHAR promptW[] = {'P','R','O','M','P','T','\0'};
static const WCHAR defaultpromptW[] = {'$','P','$','G','\0'};
*/
/* Parse the command string, without reading any more input */
- WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE);
+ WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE, FALSE);
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
WCMD_free_commands(toExecute);
toExecute = NULL;
if (opt_k) {
/* Parse the command string, without reading any more input */
- WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE);
+ WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE, FALSE);
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
WCMD_free_commands(toExecute);
toExecute = NULL;
SetEnvironmentVariableW(promptW, defaultpromptW);
WCMD_version ();
+ is_console = !!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dummy);
while (TRUE) {
/* Read until EOF (which for std input is never, but if redirect
in place, may occur */
if (echo_mode) WCMD_show_prompt();
- if (WCMD_ReadAndParseLine(NULL, &toExecute,
- GetStdHandle(STD_INPUT_HANDLE)) == NULL)
+ if (!WCMD_ReadAndParseLine(NULL, &toExecute, GetStdHandle(STD_INPUT_HANDLE), is_console))
break;
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
WCMD_free_commands(toExecute);