cmd: Infer handle type from handle value in WCMD_fgets and WCMD_ReadAndParseLine.
This commit is contained in:
parent
ea35386b2b
commit
5e3cb1867b
|
@ -89,7 +89,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN
|
||||||
|
|
||||||
while (context -> skip_rest == FALSE) {
|
while (context -> skip_rest == FALSE) {
|
||||||
CMD_LIST *toExecute = NULL; /* Commands left to be executed */
|
CMD_LIST *toExecute = NULL; /* Commands left to be executed */
|
||||||
if (!WCMD_ReadAndParseLine(NULL, &toExecute, h, FALSE))
|
if (!WCMD_ReadAndParseLine(NULL, &toExecute, h))
|
||||||
break;
|
break;
|
||||||
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
||||||
WCMD_free_commands(toExecute);
|
WCMD_free_commands(toExecute);
|
||||||
|
@ -186,7 +186,7 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end) {
|
||||||
* NULL on error or EOF
|
* NULL on error or EOF
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WCHAR *WCMD_fgets(WCHAR *buf, int noChars, HANDLE h, const BOOL is_console_handle)
|
WCHAR *WCMD_fgets(WCHAR *buf, int noChars, HANDLE h)
|
||||||
{
|
{
|
||||||
DWORD bytes, charsRead;
|
DWORD bytes, charsRead;
|
||||||
BOOL status;
|
BOOL status;
|
||||||
|
@ -196,7 +196,7 @@ WCHAR *WCMD_fgets(WCHAR *buf, int noChars, HANDLE h, const BOOL is_console_handl
|
||||||
between DOS and Unix. Also need to lose the LF (or CRLF) from the line. */
|
between DOS and Unix. Also need to lose the LF (or CRLF) from the line. */
|
||||||
|
|
||||||
p = buf;
|
p = buf;
|
||||||
if (is_console_handle) {
|
if (WCMD_is_console_handle(h)) {
|
||||||
status = ReadConsoleW(h, buf, noChars, &charsRead, NULL);
|
status = ReadConsoleW(h, buf, noChars, &charsRead, NULL);
|
||||||
if (!status) return NULL;
|
if (!status) return NULL;
|
||||||
if (buf[charsRead-2] == '\r')
|
if (buf[charsRead-2] == '\r')
|
||||||
|
|
|
@ -1133,7 +1133,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
|
||||||
WCHAR buffer[MAXSTRING] = {'\0'};
|
WCHAR buffer[MAXSTRING] = {'\0'};
|
||||||
WCHAR *where, *parm;
|
WCHAR *where, *parm;
|
||||||
|
|
||||||
while (WCMD_fgets(buffer, sizeof(buffer)/sizeof(WCHAR), input, FALSE)) {
|
while (WCMD_fgets(buffer, sizeof(buffer)/sizeof(WCHAR), input)) {
|
||||||
|
|
||||||
/* Skip blank lines*/
|
/* Skip blank lines*/
|
||||||
parm = WCMD_parameter (buffer, 0, &where, NULL);
|
parm = WCMD_parameter (buffer, 0, &where, NULL);
|
||||||
|
@ -1393,7 +1393,7 @@ void WCMD_goto (CMD_LIST **cmdList) {
|
||||||
if (*paramStart == ':') paramStart++;
|
if (*paramStart == ':') paramStart++;
|
||||||
|
|
||||||
SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
|
SetFilePointer (context -> h, 0, NULL, FILE_BEGIN);
|
||||||
while (WCMD_fgets (string, sizeof(string)/sizeof(WCHAR), context -> h, FALSE)) {
|
while (WCMD_fgets (string, sizeof(string)/sizeof(WCHAR), context -> h)) {
|
||||||
str = string;
|
str = string;
|
||||||
while (isspaceW (*str)) str++;
|
while (isspaceW (*str)) str++;
|
||||||
if (*str == ':') {
|
if (*str == ':') {
|
||||||
|
|
|
@ -97,7 +97,11 @@ void WCMD_verify (const WCHAR *command);
|
||||||
void WCMD_version (void);
|
void WCMD_version (void);
|
||||||
int WCMD_volume (BOOL set_label, const WCHAR *command);
|
int WCMD_volume (BOOL set_label, const WCHAR *command);
|
||||||
|
|
||||||
WCHAR *WCMD_fgets (WCHAR *buf, int n, HANDLE stream, const BOOL is_console_handle);
|
static inline BOOL WCMD_is_console_handle(HANDLE h)
|
||||||
|
{
|
||||||
|
return (((DWORD_PTR)h) & 3) == 3;
|
||||||
|
}
|
||||||
|
WCHAR *WCMD_fgets (WCHAR *buf, int n, HANDLE stream);
|
||||||
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end);
|
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end);
|
||||||
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
|
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
|
||||||
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
|
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
|
||||||
|
@ -110,8 +114,7 @@ WCHAR *WCMD_strdupW(const WCHAR *input);
|
||||||
void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len);
|
void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len);
|
||||||
BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWORD charsRead);
|
BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWORD charsRead);
|
||||||
|
|
||||||
WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output,
|
WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom);
|
||||||
HANDLE readFrom, const BOOL is_console_handle);
|
|
||||||
CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
|
CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
|
||||||
const WCHAR *var, const WCHAR *val);
|
const WCHAR *var, const WCHAR *val);
|
||||||
void WCMD_free_commands(CMD_LIST *cmds);
|
void WCMD_free_commands(CMD_LIST *cmds);
|
||||||
|
|
|
@ -233,11 +233,6 @@ void WCMD_leave_paged_mode(void)
|
||||||
pagedMessage = NULL;
|
pagedMessage = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BOOL is_console_handle(HANDLE h)
|
|
||||||
{
|
|
||||||
return (((DWORD_PTR)h) & 3) == 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* WCMD_Readfile
|
* WCMD_Readfile
|
||||||
*
|
*
|
||||||
|
@ -248,7 +243,7 @@ BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWO
|
||||||
DWORD numRead;
|
DWORD numRead;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
|
||||||
if (is_console_handle(hIn))
|
if (WCMD_is_console_handle(hIn))
|
||||||
/* Try to read from console as Unicode */
|
/* Try to read from console as Unicode */
|
||||||
return ReadConsoleW(hIn, intoBuf, maxChars, charsRead, NULL);
|
return ReadConsoleW(hIn, intoBuf, maxChars, charsRead, NULL);
|
||||||
|
|
||||||
|
@ -1781,8 +1776,7 @@ static BOOL WCMD_IsEndQuote(const WCHAR *quote, int quoteIndex)
|
||||||
* - Anything else gets put into the command string (including
|
* - Anything else gets put into the command string (including
|
||||||
* redirects)
|
* redirects)
|
||||||
*/
|
*/
|
||||||
WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output,
|
WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE readFrom)
|
||||||
HANDLE readFrom, const BOOL is_console_handle)
|
|
||||||
{
|
{
|
||||||
WCHAR *curPos;
|
WCHAR *curPos;
|
||||||
int inQuotes = 0;
|
int inQuotes = 0;
|
||||||
|
@ -1827,7 +1821,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output,
|
||||||
} else if (readFrom == INVALID_HANDLE_VALUE) {
|
} else if (readFrom == INVALID_HANDLE_VALUE) {
|
||||||
WINE_FIXME("No command nor handle supplied\n");
|
WINE_FIXME("No command nor handle supplied\n");
|
||||||
} else {
|
} else {
|
||||||
if (!WCMD_fgets(extraSpace, MAXSTRING, readFrom, is_console_handle))
|
if (!WCMD_fgets(extraSpace, MAXSTRING, readFrom))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
curPos = extraSpace;
|
curPos = extraSpace;
|
||||||
|
@ -2188,7 +2182,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output,
|
||||||
/* Read more, skipping any blank lines */
|
/* Read more, skipping any blank lines */
|
||||||
while (*extraSpace == 0x00) {
|
while (*extraSpace == 0x00) {
|
||||||
if (!context) WCMD_output_asis( WCMD_LoadMessage(WCMD_MOREPROMPT));
|
if (!context) WCMD_output_asis( WCMD_LoadMessage(WCMD_MOREPROMPT));
|
||||||
if (!WCMD_fgets(extraSpace, MAXSTRING, readFrom, is_console_handle))
|
if (!WCMD_fgets(extraSpace, MAXSTRING, readFrom))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
curPos = extraSpace;
|
curPos = extraSpace;
|
||||||
|
@ -2280,8 +2274,6 @@ int wmain (int argc, WCHAR *argvW[])
|
||||||
WCHAR string[1024];
|
WCHAR string[1024];
|
||||||
WCHAR envvar[4];
|
WCHAR envvar[4];
|
||||||
int opt_q;
|
int opt_q;
|
||||||
BOOL is_console;
|
|
||||||
DWORD dummy;
|
|
||||||
int opt_t = 0;
|
int opt_t = 0;
|
||||||
static const WCHAR promptW[] = {'P','R','O','M','P','T','\0'};
|
static const WCHAR promptW[] = {'P','R','O','M','P','T','\0'};
|
||||||
static const WCHAR defaultpromptW[] = {'$','P','$','G','\0'};
|
static const WCHAR defaultpromptW[] = {'$','P','$','G','\0'};
|
||||||
|
@ -2497,7 +2489,7 @@ int wmain (int argc, WCHAR *argvW[])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Parse the command string, without reading any more input */
|
/* Parse the command string, without reading any more input */
|
||||||
WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE, FALSE);
|
WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE);
|
||||||
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
||||||
WCMD_free_commands(toExecute);
|
WCMD_free_commands(toExecute);
|
||||||
toExecute = NULL;
|
toExecute = NULL;
|
||||||
|
@ -2593,7 +2585,7 @@ int wmain (int argc, WCHAR *argvW[])
|
||||||
|
|
||||||
if (opt_k) {
|
if (opt_k) {
|
||||||
/* Parse the command string, without reading any more input */
|
/* Parse the command string, without reading any more input */
|
||||||
WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE, FALSE);
|
WCMD_ReadAndParseLine(cmd, &toExecute, INVALID_HANDLE_VALUE);
|
||||||
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
||||||
WCMD_free_commands(toExecute);
|
WCMD_free_commands(toExecute);
|
||||||
toExecute = NULL;
|
toExecute = NULL;
|
||||||
|
@ -2606,13 +2598,12 @@ int wmain (int argc, WCHAR *argvW[])
|
||||||
|
|
||||||
SetEnvironmentVariableW(promptW, defaultpromptW);
|
SetEnvironmentVariableW(promptW, defaultpromptW);
|
||||||
WCMD_version ();
|
WCMD_version ();
|
||||||
is_console = !!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dummy);
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
|
||||||
/* Read until EOF (which for std input is never, but if redirect
|
/* Read until EOF (which for std input is never, but if redirect
|
||||||
in place, may occur */
|
in place, may occur */
|
||||||
if (echo_mode) WCMD_show_prompt();
|
if (echo_mode) WCMD_show_prompt();
|
||||||
if (!WCMD_ReadAndParseLine(NULL, &toExecute, GetStdHandle(STD_INPUT_HANDLE), is_console))
|
if (!WCMD_ReadAndParseLine(NULL, &toExecute, GetStdHandle(STD_INPUT_HANDLE)))
|
||||||
break;
|
break;
|
||||||
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
WCMD_process_commands(toExecute, FALSE, NULL, NULL);
|
||||||
WCMD_free_commands(toExecute);
|
WCMD_free_commands(toExecute);
|
||||||
|
|
Loading…
Reference in New Issue