Esempio n. 1
0
/*********************************************************************
 *		_cgets (MSVCRT.@)
 */
char* CDECL _cgets(char* str)
{
  char *buf = str + 2;
  DWORD got;
  DWORD conmode = 0;

  TRACE("(%p)\n", str);
  str[1] = 0; /* Length */
  LOCK_CONSOLE;
  GetConsoleMode(MSVCRT_console_in, &conmode);
  SetConsoleMode(MSVCRT_console_in, ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT);

  if(ReadConsoleA(MSVCRT_console_in, buf, str[0], &got, NULL)) {
    if(buf[got-2] == '\r') {
      buf[got-2] = 0;
      str[1] = got-2;
    }
    else if(got == 1 && buf[got-1] == '\n') {
      buf[0] = 0;
      str[1] = 0;
    }
    else if(got == str[0] && buf[got-1] == '\r') {
      buf[got-1] = 0;
      str[1] = got-1;
    }
    else
      str[1] = got;
  }
  else
    buf = NULL;
  SetConsoleMode(MSVCRT_console_in, conmode);
  UNLOCK_CONSOLE;
  return buf;
}
Esempio n. 2
0
u32 WINAPI win32_scanf_pro( LPVOID lpParameter )
{
    u32 num;
    while(1)
    {
        ReadConsoleA( hStdIn, // screen buffer to write to
                        &scanf_buf,        // buffer to copy from
                        256,     // col-row size of chiBuffer
                        (PDWORD)&num,    // top left src cell in chiBuffer
                        NULL);  // dest. screen buffer rectangle
        scanf_buf[num] = '\0';
        Int_TapLine(cn_int_line_cmd);
/*        do
        {
//            scanf("%c",&ch);
            r =ReadConsoleA( hStdIn, // screen buffer to write to
                            &scanf_buf,        // buffer to copy from
                            256,     // col-row size of chiBuffer
                            &num,    // top left src cell in chiBuffer
                            NULL);  // dest. screen buffer rectangle
            if(num != 0)
            {
                scanf_buf[len] = ch;
                len++;
            }
            if(r == 0)
                r = GetLastError();
        }while(ch != '\r');
        scanf_buf[len] = '\0';
        len = 0;
        Int_TapLine(cn_int_line_cmd);
*/    }
}
Esempio n. 3
0
__integer __INTERNAL_FUNC__ PrintDbgInfo_DebugerBreakPoint(__char *pInfo, __void *pParam) {
    __integer iReads = 0;
    __char *pText = NULL;

    if ((!g_hWriteConsole) || (!g_hReadConsole)) return 0;//退出

    if (g_bSkipAllBreakPoint) return 0;

    PrintDbgInfo_DebugerWriteLine(pInfo);

    pText = (__char *)__logic_new_size__(__PRINTDBGINFO_READCONSOLE_BUFFER_SIZE__);

    while (1) {
        // 输出命令行
        PrintDbgInfo_DebugerWrite(__PRINTDBGINFO_DEBUGER_TITLE__);
        // 接收命令
        if (!ReadConsoleA(g_hReadConsole, (__void *)pText, __PRINTDBGINFO_READCONSOLE_BUFFER_SIZE__, &iReads, NULL))
            return 0;

        // 是否继续
        if ((__logic_memcmp__(pText, "\x0d\x0a", 2) == 0) ||
                (__logic_strncmp__(pText, "#continue", __logic_strlen__("#continue")) == 0)) {
            break;//跳出循环
        } else if (__logic_memcmp__(pText, "#break", 6) == 0) {
            __asm int 3;
            break;
        } else {
            if (g_pDebuger)
Esempio n. 4
0
__integer __INTERNAL_FUNC__ PrintDbgInfo_DebugerReadLine(__memory pOutBuffer, __integer iMaxSize) {
    __integer iRet = 0;
    // 接受数据
    if (!ReadConsoleA(g_hReadConsole, (__void *)pOutBuffer, iMaxSize, &iRet, NULL))
        return 0;
    return iRet;
}
Esempio n. 5
0
int main()
{
	char szLine[80]; DWORD nRead;
	printf("Started: %s\nPress Enter to continue: ", GetCommandLineA());
	ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), szLine, ARRAYSIZE(szLine), &nRead, NULL);
	ExitProcess(1);
	printf("Must not get here!!!\n");
    return 0;
}
Esempio n. 6
0
int main(int argc, char* argv[])
{
  char Buffer[10];
  DWORD Result;

  AllocConsole();
  InputHandle = GetStdHandle(STD_INPUT_HANDLE);
  OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
  while(1)
  {
    dprintf("choose test :\n");
    dprintf("  0 = Exit\n");
    dprintf("  1 = Create key\n");
    dprintf("  2 = Delete key\n");
    dprintf("  3 = Enumerate key\n");
    dprintf("  4 = Set value (REG_SZ)\n");
    dprintf("  5 = Set value (REG_DWORD)\n");
    dprintf("  6 = Delete value\n");
    dprintf("  7 = Enumerate value\n");
    ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
    switch (Buffer[0])
    {
     case '0':
      return(0);

     case '1':
      CreateKeyTest();
      break;

     case '2':
      DeleteKeyTest();
      break;

     case '3':
      EnumerateKeyTest();
      break;

     case '4':
      SetValueTest1();
      break;

     case '5':
      SetValueTest2();
      break;

     case '6':
      DeleteValueTest();
      break;

     case '7':
      EnumerateValueTest();
      break;
    }
  }
  return(0);
}
Esempio n. 7
0
string getInput()
{
    char* buffer = new char[1024];
    DWORD written;
    ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), buffer, 1023, &written, 0);
    buffer[written - 2] = 0;
    string result = string(buffer);
    delete[] buffer;
    return result;
}
Esempio n. 8
0
void test3(void)
{
 HANDLE hKey;
 OBJECT_ATTRIBUTES ObjectAttributes;
 UNICODE_STRING KeyName;
 NTSTATUS Status;
 char Buffer[10];
 DWORD Result;
  dprintf("NtCreateKey non volatile: \n");
  dprintf("  \\Registry\\Machine\\Software\\test3reactos: ");
  RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
  InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE
				, NULL, NULL);
  Status = NtCreateKey ( &hKey, KEY_ALL_ACCESS , &ObjectAttributes
		,0,NULL,REG_OPTION_NON_VOLATILE,NULL);
  dprintf("\t\tStatus=%x\n",Status);
  NtClose(hKey);

  dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
  ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
  if (Buffer[0] != 'y' && Buffer[0] != 'Y') return;

  dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
  RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\Software\\test3reactos");
  InitializeObjectAttributes(&ObjectAttributes,
                               &KeyName,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL);
  dprintf("NtOpenKey : ");
  Status=NtOpenKey( &hKey, KEY_ALL_ACCESS, &ObjectAttributes);
  dprintf("\t\t\t\tStatus =%x\n",Status);
  dprintf("NtDeleteKey : ");
  Status=NtDeleteKey(hKey);
  dprintf("\t\t\t\tStatus =%x\n",Status);
  NtClose(hKey);
}
Esempio n. 9
0
File: tty.c Progetto: hghazal/node
static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
  uv_loop_t* loop;
  uv_tty_t* handle;
  uv_req_t* req;
  DWORD bytes, read_bytes;

  assert(data);

  req = (uv_req_t*) data;
  handle = (uv_tty_t*) req->data;
  loop = handle->loop;

  assert(handle->read_line_buffer.base != NULL);
  assert(handle->read_line_buffer.len > 0);

  /* ReadConsole can't handle big buffers. */
  if (handle->read_line_buffer.len < 8192) {
    bytes = handle->read_line_buffer.len;
  } else {
    bytes = 8192;
  }

  /* Todo: Unicode */
  if (ReadConsoleA(handle->read_line_handle,
                   (void*) handle->read_line_buffer.base,
                   bytes,
                   &read_bytes,
                   NULL)) {
    SET_REQ_SUCCESS(req);
    req->overlapped.InternalHigh = read_bytes;
  } else {
    SET_REQ_ERROR(req, GetLastError());
  }

  POST_COMPLETION_FOR_REQ(loop, req);
  return 0;
}
Esempio n. 10
0
static THREAD_RET readInput(void* in)
{
    byte buf[256];
    int  bufSz = sizeof(buf);
    thread_args* args = (thread_args*)in;
    int ret = 0;
    word32 sz = 0;
#ifdef USE_WINDOWS_API
    HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
#endif

    while (ret >= 0) {
        WMEMSET(buf, 0, bufSz);
    #ifdef USE_WINDOWS_API
        /* Using A version to avoid potential 2 byte chars */
        ret = ReadConsoleA(stdinHandle, (void*)buf, bufSz - 1, (DWORD*)&sz,
                NULL);
    #else
        ret = (int)read(STDIN_FILENO, buf, bufSz -1);
        sz  = (word32)ret;
    #endif
        if (ret <= 0) {
            err_sys("Error reading stdin");
        }
        /* lock SSH structure access */
        wc_LockMutex(&args->lock);
        ret = wolfSSH_stream_send(args->ssh, buf, sz);
        wc_UnLockMutex(&args->lock);
        if (ret <= 0)
            err_sys("Couldn't send data");
    }
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
    wc_ecc_fp_free();  /* free per thread cache */
#endif
    return THREAD_RET_SUCCESS;
}
Esempio n. 11
0
	BOOL basic_win32console_streambuf<char>::_ReadConsole(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, PCONSOLE_READCONSOLE_CONTROL pInputControl)
	{
		return ReadConsoleA(hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, pInputControl);
	}
Esempio n. 12
0
char* win32_cgets (char* buffer, int len)
{
	/* We use console ReadConsoleA / ReadConsoleW to be able to read
	   unicode from the win32 console and fallback if seomething fails. */

	HANDLE hIn=GetStdHandle (STD_INPUT_HANDLE);
	if(hIn
	  && (hIn!=INVALID_HANDLE_VALUE)
	    && p_WideCharToMultiByte && p_MultiByteToWideChar)
	{
		DWORD dwRead;
		wchar_t wszBuf[1024];
		char  szBuf[1024];

		// NT and unicode conversion.
		if(ReadConsoleW(hIn, wszBuf, 1024, &dwRead, NULL))
		{
			// Null terminate at end.
			if(wszBuf[dwRead-1]==L'\n')
			{
				wszBuf[dwRead-1]=L'\0';
				dwRead--;
			}

			if(wszBuf[dwRead-1]==L'\r')
			{
				wszBuf[dwRead-1]=L'\0';
				dwRead--;
			}

			wchar_2_UTF8(buffer, wszBuf, len);
			return buffer;
		}

		// Win 9x and unicode conversion.
		if(ReadConsoleA(hIn, szBuf, 1024, &dwRead, NULL))
		{
			// Null terminate at end.
			if(szBuf[dwRead-1]==L'\n')
			{
				szBuf[dwRead-1]=L'\0';
				dwRead--;
			}

			if(szBuf[dwRead-1]==L'\r')
			{
				szBuf[dwRead-1]=L'\0';
				dwRead--;
			}

			// Convert from ansii to wchar_t.
			p_MultiByteToWideChar(GetConsoleCP(),
				0, szBuf, -1, wszBuf, 1024);
			// Convert from wchar_t to UTF-8.
			if(wchar_2_UTF8(buffer, wszBuf, len))
				return buffer;
		}
	}

	// Fallback.
	if(fgets(buffer, len, stdin)) return buffer;
	return NULL;
}
Esempio n. 13
0
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
{
    static int ps;
    int ok;
    char result[BUFSIZ];
    int maxsize = BUFSIZ - 1;
#if !defined(OPENSSL_SYS_WINCE)
    char *p = NULL;
    int echo_eol = !echo;

    intr_signal = 0;
    ok = 0;
    ps = 0;

    pushsig();
    ps = 1;

    if (!echo && !noecho_console(ui))
        goto error;
    ps = 2;

    result[0] = '\0';
# if defined(_WIN32)
    if (is_a_tty) {
        DWORD numread;
#  if defined(CP_UTF8)
        if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) != 0) {
            WCHAR wresult[BUFSIZ];

            if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE),
                         wresult, maxsize, &numread, NULL)) {
                if (numread >= 2 &&
                    wresult[numread-2] == L'\r' &&
                    wresult[numread-1] == L'\n') {
                    wresult[numread-2] = L'\n';
                    numread--;
                }
                wresult[numread] = '\0';
                if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1,
                                        result, sizeof(result), NULL, 0) > 0)
                    p = result;

                OPENSSL_cleanse(wresult, sizeof(wresult));
            }
        } else
#  endif
        if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE),
                         result, maxsize, &numread, NULL)) {
            if (numread >= 2 &&
                result[numread-2] == '\r' && result[numread-1] == '\n') {
                result[numread-2] = '\n';
                numread--;
            }
            result[numread] = '\0';
            p = result;
        }
    } else
# elif defined(OPENSSL_SYS_MSDOS)
    if (!echo) {
        noecho_fgets(result, maxsize, tty_in);
        p = result;             /* FIXME: noecho_fgets doesn't return errors */
    } else
# endif
    p = fgets(result, maxsize, tty_in);
    if (p == NULL)
        goto error;
    if (feof(tty_in))
        goto error;
    if (ferror(tty_in))
        goto error;
    if ((p = (char *)strchr(result, '\n')) != NULL) {
        if (strip_nl)
            *p = '\0';
    } else if (!read_till_nl(tty_in))
        goto error;
    if (UI_set_result(ui, uis, result) >= 0)
        ok = 1;

 error:
    if (intr_signal == SIGINT)
        ok = -1;
    if (echo_eol)
        fprintf(tty_out, "\n");
    if (ps >= 2 && !echo && !echo_console(ui))
        ok = 0;

    if (ps >= 1)
        popsig();
#else
    ok = 1;
#endif

    OPENSSL_cleanse(result, BUFSIZ);
    return ok;
}
Esempio n. 14
0
void debugger_do()
{
        int c, d, e, f;
        int params;
        uint8_t temp;
        char outs[256];
        char ins[256];
        if (!opcode)
        {
                sprintf(outs, "BRK %04X! %04X %04X\n", pc, oldpc, oldoldpc);
                debug_out(outs);
        }
        if (!opcode) debug = 1;

        for (c = 0; c < 8; c++)
        {
                if (breakpoints[c] == pc)
                {
                        debug = 1;
                        sprintf(outs, "    Break at %04X\n", pc);
                        debug_out(outs);
                }
        }
        if (!debug) return;
//        if (!opcode) printf("BRK at %04X\n",pc);
        if (debugstep)
        {
                debugstep--;
                if (debugstep) return;
        }
        indebug = 1;
        while (1)
        {
                d = debug_disaddr;
                debug_disaddr = pc;
                debug_disassemble();
                debug_disaddr = d;
                sprintf(outs, "  >");
                debug_out(outs);
#ifdef WIN32
                c = ReadConsoleA(cinf, ins, 255, (LPDWORD)&d, NULL);
                ins[d] = 0;
#else
                d = (int)fgets(ins, 255, stdin);
#endif
                d = 0;
                while (ins[d] != 32 && ins[d] != 0xA && ins[d] != 0xD && ins[d] != 0) d++;
                while (ins[d] == 32) d++;
                if (ins[d] == 0xA || ins[d] == 0xD || ins[d] == 0) params = 0;
                else                                               params = 1;

                if (ins[0] == 0xA || ins[0] == 0xD) ins[0] = debug_lastcommand;
//debug_out("Processing!\n");
                switch (ins[0])
                {
                        case 'c': case 'C':
                        debug = 0;
                        indebug = 0;
                        return;
                        case 'm': case 'M':
                        if (params) sscanf(&ins[d], "%X", (unsigned int *)&debug_memaddr);
                        for (c = 0; c < 16; c++)
                        {
                                sprintf(outs, "    %04X : ", debug_memaddr);
                                debug_out(outs);
                                for (d = 0; d < 16; d++)
                                {
                                        sprintf(outs, "%02X ", debug_readmem(debug_memaddr + d));
                                        debug_out(outs);
                                }
                                debug_out("  ");
                                for (d = 0; d < 16; d++)
                                {
                                        temp = debug_readmem(debug_memaddr + d);
                                        if (temp < 32) sprintf(outs, ".");
                                        else           sprintf(outs, "%c", temp);
                                        debug_out(outs);
                                }
                                debug_memaddr += 16;
                                debug_out("\n");
                        }
                        break;
                        case 'd': case 'D':
                        if (params) sscanf(&ins[d], "%X", (unsigned int *)&debug_disaddr);
                        for (c = 0; c < 12; c++)
                        {
                                debug_out("    ");
                                debug_disassemble();
                                debug_out("\n");
                        }
                        break;
                        case 'r': case 'R':
                        if (params)
                        {
                                if (!strncasecmp(&ins[d], "sysvia", 6))
                                {
                                        sprintf(outs, "    System VIA registers :\n");
                                        debug_out(outs);
                                        sprintf(outs, "    ORA  %02X ORB  %02X IRA %02X IRB %02X\n", sysvia.ora,  sysvia.orb,  sysvia.ira, sysvia.irb);
                                        debug_out(outs);
                                        sprintf(outs, "    DDRA %02X DDRB %02X ACR %02X PCR %02X\n", sysvia.ddra, sysvia.ddrb, sysvia.acr, sysvia.pcr);
                                        debug_out(outs);
                                        sprintf(outs, "    Timer 1 latch %04X   count %04X\n", sysvia.t1l / 2, (sysvia.t1c / 2) & 0xFFFF);
                                        debug_out(outs);
                                        sprintf(outs, "    Timer 2 latch %04X   count %04X\n", sysvia.t2l / 2, (sysvia.t2c / 2) & 0xFFFF);
                                        debug_out(outs);
                                        sprintf(outs, "    IER %02X IFR %02X\n", sysvia.ier, sysvia.ifr);
                                        debug_out(outs);
                                }
                                if (!strncasecmp(&ins[d], "uservia", 7))
                                {
                                        sprintf(outs, "    User VIA registers :\n");
                                        debug_out(outs);
                                        sprintf(outs, "    ORA  %02X ORB  %02X IRA %02X IRB %02X\n", uservia.ora,  uservia.orb,  uservia.ira, uservia.irb);
                                        debug_out(outs);
                                        sprintf(outs, "    DDRA %02X DDRB %02X ACR %02X PCR %02X\n", uservia.ddra, uservia.ddrb, uservia.acr, uservia.pcr);
                                        debug_out(outs);
                                        sprintf(outs, "    Timer 1 latch %04X   count %04X\n", uservia.t1l / 2, (uservia.t1c / 2) & 0xFFFF);
                                        debug_out(outs);
                                        sprintf(outs, "    Timer 2 latch %04X   count %04X\n", uservia.t2l / 2, (uservia.t2c / 2) & 0xFFFF);
                                        debug_out(outs);
                                        sprintf(outs, "    IER %02X IFR %02X\n", uservia.ier, uservia.ifr);
                                        debug_out(outs);
                                }
                                if (!strncasecmp(&ins[d], "crtc", 4))
                                {
                                        sprintf(outs, "    CRTC registers :\n");
                                        debug_out(outs);
                                        sprintf(outs, "    Index=%i\n", crtc_i);
                                        debug_out(outs);
                                        sprintf(outs, "    R0 =%02X  R1 =%02X  R2 =%02X  R3 =%02X  R4 =%02X  R5 =%02X  R6 =%02X  R7 =%02X  R8 =%02X\n", crtc[0], crtc[1],  crtc[2],  crtc[3],  crtc[4],  crtc[5],  crtc[6],  crtc[7],  crtc[8]);
                                        debug_out(outs);
                                        sprintf(outs, "    R9 =%02X  R10=%02X  R11=%02X  R12=%02X  R13=%02X  R14=%02X  R15=%02X  R16=%02X  R17=%02X\n", crtc[9], crtc[10], crtc[11], crtc[12], crtc[13], crtc[14], crtc[15], crtc[16], crtc[17]);
                                        debug_out(outs);
                                        sprintf(outs, "    VC=%i SC=%i HC=%i MA=%04X\n", vc, sc, hc, ma);
                                        debug_out(outs);
                                }
                                if (!strncasecmp(&ins[d],"vidproc",7))
                                {
                                        sprintf(outs, "    VIDPROC registers :\n");
                                        debug_out(outs);
                                        sprintf(outs, "    Control=%02X\n", ula_ctrl);
                                        debug_out(outs);
                                        sprintf(outs, "    Palette entries :\n");
                                        debug_out(outs);
                                        sprintf(outs, "     0=%01X   1=%01X   2=%01X   3=%01X   4=%01X   5=%01X   6=%01X   7=%01X\n", ula_palbak[0], ula_palbak[1], ula_palbak[2],  ula_palbak[3],  ula_palbak[4],  ula_palbak[5],  ula_palbak[6],  ula_palbak[7]);
                                        debug_out(outs);
                                        sprintf(outs, "     8=%01X   9=%01X  10=%01X  11=%01X  12=%01X  13=%01X  14=%01X  15=%01X\n", ula_palbak[8], ula_palbak[9], ula_palbak[10], ula_palbak[11], ula_palbak[12], ula_palbak[13], ula_palbak[14], ula_palbak[15]);
                                        debug_out(outs);
                                }
                                if (!strncasecmp(&ins[d],"sound",5))
                                {
                                        sprintf(outs, "    Sound registers :\n");
                                        debug_out(outs);
                                        sprintf(outs, "    Voice 0 frequency = %04X   volume = %i  control = %02X\n", sn_latch[0] >> 6, sn_vol[0], sn_noise);
                                        debug_out(outs);
                                        sprintf(outs, "    Voice 1 frequency = %04X   volume = %i\n", sn_latch[1] >> 6, sn_vol[1]);
                                        debug_out(outs);
                                        sprintf(outs, "    Voice 2 frequency = %04X   volume = %i\n", sn_latch[2] >> 6, sn_vol[2]);
                                        debug_out(outs);
                                        sprintf(outs, "    Voice 3 frequency = %04X   volume = %i\n", sn_latch[3] >> 6, sn_vol[3]);
                                        debug_out(outs);
                                }
                        }
                        else
                        {
                                sprintf(outs, "    6502 registers :\n");
                                debug_out(outs);
                                sprintf(outs, "    A=%02X X=%02X Y=%02X S=01%02X PC=%04X\n", a, x, y, s, pc);
                                debug_out(outs);
                                sprintf(outs, "    Status : %c%c%c%c%c%c\n", (p.n) ? 'N' : ' ', (p.v) ? 'V' : ' ', (p.d) ? 'D' : ' ', (p.i) ? 'I' : ' ', (p.z) ? 'Z' : ' ', (p.c) ? 'C' : ' ');
                                debug_out(outs);
                        }
                        break;
                        case 's': case 'S':
                        if (params) sscanf(&ins[d], "%i", &debugstep);
                        else        debugstep = 1;
                        debug_lastcommand = ins[0];
                        indebug = 0;
                        return;
                        case 'b': case 'B':
                        if (!strncasecmp(ins, "breakr", 6))
                        {
                                if (!params) break;
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakpoints[c] == -1)
                                        {
                                                sscanf(&ins[d], "%X", &breakr[c]);
                                                sprintf(outs, "    Read breakpoint %i set to %04X\n", c, breakr[c]);
                                                debug_out(outs);
                                                break;
                                        }
                                }
                        }
                        else if (!strncasecmp(ins, "breakw", 6))
                        {
                                if (!params) break;
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakpoints[c] == -1)
                                        {
                                                sscanf(&ins[d], "%X", &breakw[c]);
                                                sprintf(outs, "    Write breakpoint %i set to %04X\n", c, breakw[c]);
                                                debug_out(outs);
                                                break;
                                        }
                                }
                        }
                        else if (!strncasecmp(ins, "break", 5))
                        {
                                if (!params) break;
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakpoints[c] == -1)
                                        {
                                                sscanf(&ins[d], "%X", &breakpoints[c]);
                                                sprintf(outs, "    Breakpoint %i set to %04X\n", c, breakpoints[c]);
                                                debug_out(outs);
                                                break;
                                        }
                                }
                        }
                        if (!strncasecmp(ins, "blist", 5))
                        {
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakpoints[c] != -1)
                                        {
                                                sprintf(outs, "    Breakpoint %i : %04X\n", c, breakpoints[c]);
                                                debug_out(outs);
                                        }
                                }
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakr[c] != -1)
                                        {
                                                sprintf(outs, "    Read breakpoint %i : %04X\n", c, breakr[c]);
                                                debug_out(outs);
                                        }
                                }
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakw[c] != -1)
                                        {
                                                sprintf(outs, "    Write breakpoint %i : %04X\n", c, breakw[c]);
                                                debug_out(outs);
                                        }
                                }
                        }
                        if (!strncasecmp(ins, "bclearr", 7))
                        {
                                if (!params) break;
                                sscanf(&ins[d], "%X", &e);
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakr[c] == e) breakr[c] = -1;
                                        if (c == e) breakr[c] = -1;
                                }
                        }
                        else if (!strncasecmp(ins, "bclearw", 7))
                        {
                                if (!params) break;
                                sscanf(&ins[d], "%X", &e);
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakw[c] == e) breakw[c] = -1;
                                        if (c == e) breakw[c] = -1;
                                }
                        }
                        else if (!strncasecmp(ins, "bclear", 6))
                        {
                                if (!params) break;
                                sscanf(&ins[d], "%X", &e);
                                for (c = 0; c < 8; c++)
                                {
                                        if (breakpoints[c] == e) breakpoints[c] = -1;
                                        if (c == e) breakpoints[c] = -1;
                                }
                        }
                        break;
                        case 'w': case 'W':
                        if (!strncasecmp(ins, "watchr", 6))
                        {
                                if (!params) break;
                                for (c = 0; c < 8; c++)
                                {
                                        if (watchr[c] == -1)
                                        {
                                                sscanf(&ins[d], "%X", &watchr[c]);
                                                sprintf(outs, "    Read watchpoint %i set to %04X\n", c, watchr[c]);
                                                debug_out(outs);
                                                break;
                                        }
                                }
                                break;
                        }
                        if (!strncasecmp(ins, "watchw", 6))
                        {
                                if (!params) break;
                                for (c = 0; c < 8; c++)
                                {
                                        if (watchw[c] == -1)
                                        {
                                                sscanf(&ins[d], "%X", &watchw[c]);
                                                sprintf(outs, "    Write watchpoint %i set to %04X\n", c, watchw[c]);
                                                debug_out(outs);
                                                break;
                                        }
                                }
                                break;
                        }
                        if (!strncasecmp(ins, "wlist", 5))
                        {
                                for (c = 0; c < 8; c++)
                                {
                                        if (watchr[c] != -1)
                                        {
                                                sprintf(outs, "    Read watchpoint %i : %04X\n", c, watchr[c]);
                                                debug_out(outs);
                                        }
                                }
                                for (c = 0; c < 8; c++)
                                {
                                        if (watchw[c] != -1)
                                        {
                                                sprintf(outs, "    Write watchpoint %i : %04X\n", c, watchw[c]);
                                                debug_out(outs);
                                        }
                                }
                        }
                        if (!strncasecmp(ins, "wclearr", 7))
                        {
                                if (!params) break;
                                sscanf(&ins[d], "%X", &e);
                                for (c = 0; c < 8; c++)
                                {
                                        if (watchr[c] == e) watchr[c] = -1;
                                        if (c == e) watchr[c] = -1;
                                }
                        }
                        else if (!strncasecmp(ins, "wclearw", 7))
                        {
                                if (!params) break;
                                sscanf(&ins[d], "%X", &e);
                                for (c = 0; c < 8; c++)
                                {
                                        if (watchw[c] == e) watchw[c] = -1;
                                        if (c == e) watchw[c] = -1;
                                }
                        }
                        else if (!strncasecmp(ins, "writem", 6))
                        {
                                if (!params) break;
                                sscanf(&ins[d], "%X %X", &e, &f);
                                rpclog("WriteM %04X %04X\n", e, f);
                                writemem(e, f);
                        }
                        break;
                        case 'q': case 'Q':
                        setquit();
                        while (1);
                        break;
                        case 'h': case 'H': case '?':
                        sprintf(outs, "\n    Debugger commands :\n\n");
                        debug_out(outs);
                        sprintf(outs, "    bclear n   - clear breakpoint n or breakpoint at n\n");
                        debug_out(outs);
                        sprintf(outs, "    bclearr n  - clear read breakpoint n or read breakpoint at n\n");
                        debug_out(outs);
                        sprintf(outs, "    bclearw n  - clear write breakpoint n or write breakpoint at n\n");
                        debug_out(outs);
                        sprintf(outs, "    blist      - list current breakpoints\n");
                        debug_out(outs);
                        sprintf(outs, "    break n    - set a breakpoint at n\n");
                        debug_out(outs);
                        sprintf(outs, "    breakr n   - break on reads from address n\n");
                        debug_out(outs);
                        sprintf(outs, "    breakw n   - break on writes to address n\n");
                        debug_out(outs);
                        sprintf(outs, "    c          - continue running indefinitely\n");
                        debug_out(outs);
                        sprintf(outs, "    d [n]      - disassemble from address n\n");
                        debug_out(outs);
                        sprintf(outs, "    m [n]      - memory dump from address n\n");
                        debug_out(outs);
                        sprintf(outs, "    q          - force emulator exit\n");
                        debug_out(outs);
                        sprintf(outs, "    r          - print 6502 registers\n");
                        debug_out(outs);
                        sprintf(outs, "    r sysvia   - print System VIA registers\n");
                        debug_out(outs);
                        sprintf(outs, "    r uservia  - print User VIA registers\n");
                        debug_out(outs);
                        sprintf(outs, "    r crtc     - print CRTC registers\n");
                        debug_out(outs);
                        sprintf(outs, "    r vidproc  - print VIDPROC registers\n");
                        debug_out(outs);
                        sprintf(outs, "    r sound    - print Sound registers\n");
                        debug_out(outs);
                        sprintf(outs, "    s [n]      - step n instructions (or 1 if no parameter)\n\n");
                        debug_out(outs);
                        sprintf(outs, "    watchr n   - watch reads from address n\n");
                        debug_out(outs);
                        sprintf(outs, "    watchw n   - watch writes to address n\n");
                        debug_out(outs);
                        sprintf(outs, "    wclearr n  - clear read watchpoint n or read watchpoint at n\n");
                        debug_out(outs);
                        sprintf(outs, "    wclearw n  - clear write watchpoint n or write watchpoint at n\n");
                        debug_out(outs);
                        sprintf(outs, "    writem a v - write to memory, a = address, v = value\n");
                        debug_out(outs);
                        break;
                }
Esempio n. 15
0
errno_t __cdecl _cgetws_s (
        wchar_t *string,
        size_t sizeInWords,
        size_t * pSizeRead
        )
{
        ULONG oldstate;
        ULONG num_read;
        errno_t err = 0;

        _VALIDATE_CLEAR_OSSERR_RETURN_ERRCODE((string != NULL), EINVAL);
        _VALIDATE_CLEAR_OSSERR_RETURN_ERRCODE((sizeInWords > 0), EINVAL);
        _RESET_STRING(string, sizeInWords);

        _VALIDATE_CLEAR_OSSERR_RETURN_ERRCODE((pSizeRead != NULL), EINVAL);

        _mlock(_CONIO_LOCK);            /* lock the console */
        __TRY

            /*
             * We need to decrement sizeInWords because ReadConsole reads as
             * many characters as the parameter passed, doesn't null terminate
             */

            --sizeInWords;
            *pSizeRead = 0;

            /*
             * If the __console_whcar_buffer_used is set, then first fill the
             * buffered character and then proceed.
             */
            if (__console_wchar_buffer_used != 0 && sizeInWords > 0)
            {
                *string++ = __console_wchar_buffer;
                __console_wchar_buffer = 0;
                --sizeInWords;
                (*pSizeRead)++;
                if (__console_wchar_buffer == L'\0')
                    sizeInWords = 0;
            }

                        /* if the user only asked for one character, we have now filled their request
                        */
            if (sizeInWords != 0)
                        {
                                /*
                                * _coninpfh, the handle to the console input, is created the first
                                * time that either _getch() or _cgets() or _kbhit() is called.
                                */

                                if ( _coninpfh == -2 )
                                        __initconin();

                                if ( _coninpfh != -1 ) {

                                        GetConsoleMode( (HANDLE)_coninpfh, &oldstate );
                                        SetConsoleMode( (HANDLE)_coninpfh, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
                                        // First try usual way just as _cgets
                                        if ( bUseW)
                                        {
                                                if ( !ReadConsoleW( (HANDLE)_coninpfh,
                                                                                        (LPVOID)string,
                                                                                        (DWORD)sizeInWords,
                                                                                        &num_read,
                                                                                        NULL )
                                                        )
                                                {
                                                        if ( bUseW == 2 )
                                                        {
                                                                if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
                                                                        bUseW = FALSE;
                                                                else
                                                                        bUseW = TRUE;
                                                        }
                                                }
                                                else
                                                {
                                                        bUseW = TRUE;

                                                        /* set length of string and null terminate it */

                                                        if (string[num_read - 2] == L'\r') {
                                                                (*pSizeRead) += num_read - 2;
                                                                string[num_read - 2] = L'\0';
                                                        } else if ( (num_read == sizeInWords) &&
                                                                                (string[num_read - 1] == L'\r') ) {
                                                        /* special case 1 - \r\n straddles the boundary */
                                                                (*pSizeRead) += num_read -1;
                                                                string[num_read - 1] = L'\0';
                                                        } else if ( (num_read == 1) && (string[0] == L'\n') ) {
                                                                /* special case 2 - read a single '\n'*/
                                                                string[0] = L'\0';
                                                                (*pSizeRead) += 0;
                                                        } else {
                                                                (*pSizeRead) += num_read;
                                                                string[num_read] = L'\0';
                                                        }
                                                }
                                        }
                                        // If ReadConsoleW is not present, use ReadConsoleA and then convert
                                        // to Wide Char.
                                        if ( !bUseW)
                                        {
                                                static char AStr[BUF_MAX_LEN +1];
                                                static int in_buff = 0, was_buff_full = 0;
                                                unsigned int Copy, Sz, consoleCP;
                                                unsigned int last_read = 0, i;
                                                consoleCP = GetConsoleCP();
                                                do {
                                                        if (!in_buff)
                                                        {
                                                                if ( ReadConsoleA( (HANDLE)_coninpfh,
                                                                                                        (LPVOID)AStr,
                                                                                                        BUF_MAX_LEN,
                                                                                                        &num_read,
                                                                                   NULL) &&
                                                                     num_read <= BUF_MAX_LEN
                                                                        ) {
                                                                        if (num_read >= 2 && AStr[num_read -2] == '\r')
                                                                        {
                                                                                AStr[num_read -2] = '\0';
                                                                        }
                                                                        else if (num_read == BUF_MAX_LEN &&
                                                                                        AStr[num_read -1] == '\r')
                                                                                AStr[num_read -1] = '\0';
                                                                        else if (num_read == 1 && AStr[0] == '\n')
                                                                                AStr[0] = '\0';
                                                                        else
                                                                                AStr[num_read] = '\0';
                                                                } else {
                                                                        _dosmaperr(GetLastError());
                                                                        err = errno;
                                                                }
                                                        }
                                                        for ( i = 0; AStr[i] != '\0' &&
                                                                                i < (BUF_MAX_LEN) &&
                                                                                last_read < sizeInWords; i += Sz)
                                                        {
                                                                // Check if this character is lead byte. If yes, the size
                                                                // of this character is 2. Else 1.
                                                                if ( IsDBCSLeadByteEx( GetConsoleCP(), AStr[i]))
                                                                        Sz = 2;
                                                                else
                                                                        Sz = 1;
                                                                if ( (Copy = MultiByteToWideChar( consoleCP,
                                                                                                                                MB_PRECOMPOSED | MB_ERR_INVALID_CHARS,
                                                                                                                                &AStr[i],
                                                                                                                                Sz,
                                                                                                                                &string[last_read],
                                                                                                                                (int)sizeInWords - last_read)))
                                                                {
                                                                        last_read += Copy;
                                                                }
                                                        }
                                                        // Check if this conversion was from buffer. If yes, was
                                                        // buffer fully filled when it was first read using
                                                        // ReadConsoleA. If the buffer not fully filled, we don't need
                                                        // to read more from buffer. This is necessary to make it
                                                        // behave same as if we are reading using ReadConsoleW.
                                                        if ( in_buff && i == strlen(AStr))
                                                        {
                                                                in_buff = 0;
                                                                if ( was_buff_full)
                                                                {
                                                                        was_buff_full = 0;
                                                                        continue;
                                                                }
                                                                else
                                                                {
                                                                        break;
                                                                }
                                                        }
                                                        else if ( i < (BUF_MAX_LEN))
                                                                break;
                                                } while (last_read < sizeInWords);
                                                // We save the buffer to be used again.
                                                if ( i < strlen(AStr))
                                                {
                                                        in_buff = 1;
                                                        if ( strlen(AStr) == (BUF_MAX_LEN))
                                                                was_buff_full = 1;
                                                        memmove(AStr, &AStr[i], BUF_MAX_LEN +1 - i);
                                                }
                                                string[last_read] = '\0';
                                                (*pSizeRead) += last_read;
                                        }

                                        SetConsoleMode( (HANDLE)_coninpfh, oldstate );
                                } else {
                                        _dosmaperr(GetLastError());
                                        err = errno;
                                }
                        }

        __FINALLY
            _munlock(_CONIO_LOCK);          /* unlock the console */
        __END_TRY_FINALLY

        if (err != 0)
        {
            errno = err;
        }
        return err;
}
Esempio n. 16
0
/*
 * @implemented
 */
BOOL WINAPI
ReadFile(IN HANDLE hFile,
         IN LPVOID lpBuffer,
         IN DWORD nNumberOfBytesToRead,
         OUT LPDWORD lpNumberOfBytesRead OPTIONAL,
         IN LPOVERLAPPED lpOverlapped OPTIONAL)
{
    NTSTATUS Status;

    TRACE("ReadFile(hFile %p)\n", hFile);

    if (lpNumberOfBytesRead != NULL) *lpNumberOfBytesRead = 0;
    if (!nNumberOfBytesToRead) return TRUE;

    hFile = TranslateStdHandle(hFile);

    if (IsConsoleHandle(hFile))
    {
        if (ReadConsoleA(hFile,
                         lpBuffer,
                         nNumberOfBytesToRead,
                         lpNumberOfBytesRead,
                         NULL))
        {
            DWORD dwMode;
            GetConsoleMode(hFile, &dwMode);
            if ((dwMode & ENABLE_PROCESSED_INPUT) && *(PCHAR)lpBuffer == 0x1a)
            {
                /* EOF character entered; simulate end-of-file */
                *lpNumberOfBytesRead = 0;
            }
            return TRUE;
        }
        return FALSE;
    }

    if (lpOverlapped != NULL)
    {
        LARGE_INTEGER Offset;
        PVOID ApcContext;

        Offset.u.LowPart = lpOverlapped->Offset;
        Offset.u.HighPart = lpOverlapped->OffsetHigh;
        lpOverlapped->Internal = STATUS_PENDING;
        ApcContext = (((ULONG_PTR)lpOverlapped->hEvent & 0x1) ? NULL : lpOverlapped);

        Status = NtReadFile(hFile,
                            lpOverlapped->hEvent,
                            NULL,
                            ApcContext,
                            (PIO_STATUS_BLOCK)lpOverlapped,
                            lpBuffer,
                            nNumberOfBytesToRead,
                            &Offset,
                            NULL);

        /* return FALSE in case of failure and pending operations! */
        if (!NT_SUCCESS(Status) || Status == STATUS_PENDING)
        {
            if (Status == STATUS_END_OF_FILE && lpNumberOfBytesRead != NULL)
                *lpNumberOfBytesRead = 0;

            BaseSetLastNTError(Status);
            return FALSE;
        }

        if (lpNumberOfBytesRead != NULL)
            *lpNumberOfBytesRead = lpOverlapped->InternalHigh;
    }
    else
    {
        IO_STATUS_BLOCK Iosb;

        Status = NtReadFile(hFile,
                            NULL,
                            NULL,
                            NULL,
                            &Iosb,
                            lpBuffer,
                            nNumberOfBytesToRead,
                            NULL,
                            NULL);

        /* Wait in case operation is pending */
        if (Status == STATUS_PENDING)
        {
            Status = NtWaitForSingleObject(hFile, FALSE, NULL);
            if (NT_SUCCESS(Status)) Status = Iosb.Status;
        }

        if (Status == STATUS_END_OF_FILE)
        {
            /*
             * lpNumberOfBytesRead must not be NULL here, in fact Win doesn't
             * check that case either and crashes (only after the operation
             * completed).
             */
            *lpNumberOfBytesRead = 0;
            return TRUE;
        }

        if (NT_SUCCESS(Status))
        {
            /*
             * lpNumberOfBytesRead must not be NULL here, in fact Win doesn't
             * check that case either and crashes (only after the operation
             * completed).
             */
            *lpNumberOfBytesRead = Iosb.Information;
        }
        else
        {
            BaseSetLastNTError(Status);
            return FALSE;
        }
    }

    TRACE("ReadFile() succeeded\n");
    return TRUE;
}
Esempio n. 17
0
static char *
do_get( const char *prompt, int hidden )
{
    char *buf;
#ifndef __riscos__
    byte cbuf[1];
#endif
    int c, n, i;

    if( batchmode ) {
        log_error("Sorry, we are in batchmode - can't get input\n");
        exit(2);
    }

    if (no_terminal) {
        log_error("Sorry, no terminal at all requested - can't get input\n");
        exit(2);
    }

    if( !initialized )
        init_ttyfp();

    last_prompt_len = 0;
    tty_printf( "%s", prompt );
    buf = xmalloc((n=50));
    i = 0;

#ifdef USE_W32_CONSOLE
    if( hidden )
        SetConsoleMode(con.in, HID_INPMODE );

    for(;;) {
        DWORD nread;

        if( !ReadConsoleA( con.in, cbuf, 1, &nread, NULL ) )
            log_fatal("ReadConsole failed: rc=%d", (int)GetLastError() );
        if( !nread )
            continue;
        if( *cbuf == '\n' )
            break;

        if( !hidden )
            last_prompt_len++;
        c = *cbuf;
        if( c == '\t' )
            c = ' ';
        else if( c > 0xa0 )
            ; /* we don't allow 0xa0, as this is a protected blank which may
	       * confuse the user */
        else if( iscntrl(c) )
            continue;
        if( !(i < n-1) ) {
            n += 50;
            buf = xrealloc (buf, n);
        }
        buf[i++] = c;
    }

    if( hidden )
        SetConsoleMode(con.in, DEF_INPMODE );

#elif defined(__riscos__) || defined(HAVE_W32CE_SYSTEM)
    do {
#ifdef HAVE_W32CE_SYSTEM
        /* Using getchar is not a correct solution but for now it
           doesn't matter because we have no real console at all.  We
           should rework this as soon as we have switched this entire
           module to estream.  */
        c = getchar();
#else
        c = riscos_getchar();
#endif
        if (c == 0xa || c == 0xd) { /* Return || Enter */
            c = (int) '\n';
        } else if (c == 0x8 || c == 0x7f) { /* Backspace || Delete */
            if (i>0) {
                i--;
                if (!hidden) {
                    last_prompt_len--;
                    fputc(8, ttyfp);
                    fputc(32, ttyfp);
                    fputc(8, ttyfp);
                    fflush(ttyfp);
                }
            } else {
                fputc(7, ttyfp);
                fflush(ttyfp);
            }
            continue;
        } else if (c == (int) '\t') { /* Tab */
            c = ' ';
        } else if (c > 0xa0) {
            ; /* we don't allow 0xa0, as this is a protected blank which may
               * confuse the user */
        } else if (iscntrl(c)) {
            continue;
        }
        if(!(i < n-1)) {
            n += 50;
            buf = xrealloc (buf, n);
        }
        buf[i++] = c;
        if (!hidden) {
            last_prompt_len++;
            fputc(c, ttyfp);
            fflush(ttyfp);
        }
    } while (c != '\n');
    i = (i>0) ? i-1 : 0;
#else /* Other systems. */
    if( hidden ) {
#ifdef HAVE_TCGETATTR
        struct termios term;

        if( tcgetattr(fileno(ttyfp), &termsave) )
            log_fatal("tcgetattr() failed: %s\n", strerror(errno) );
        restore_termios = 1;
        term = termsave;
        term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
        if( tcsetattr( fileno(ttyfp), TCSAFLUSH, &term ) )
            log_fatal("tcsetattr() failed: %s\n", strerror(errno) );
#endif
    }

    /* fixme: How can we avoid that the \n is echoed w/o disabling
     * canonical mode - w/o this kill_prompt can't work */
    while( read(fileno(ttyfp), cbuf, 1) == 1 && *cbuf != '\n' ) {
        if( !hidden )
            last_prompt_len++;
        c = *cbuf;
        if( c == CONTROL_D )
            log_info("control d found\n");
        if( c == '\t' )
            c = ' ';
        else if( c > 0xa0 )
            ; /* we don't allow 0xa0, as this is a protected blank which may
	       * confuse the user */
        else if( iscntrl(c) )
            continue;
        if( !(i < n-1) ) {
            n += 50;
            buf = xrealloc (buf, n );
        }
        buf[i++] = c;
    }
    if( *cbuf != '\n' ) {
        buf[0] = CONTROL_D;
        i = 1;
    }

    if( hidden ) {
#ifdef HAVE_TCGETATTR
        if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
            log_error("tcsetattr() failed: %s\n", strerror(errno) );
        restore_termios = 0;
#endif
    }
#endif /* end unix version */
    buf[i] = 0;
    return buf;
}
Esempio n. 18
0
static DWORD WINAPI
ConsoleReaderThread(LPVOID arg)
{
    ConsoleInfo *infoPtr = (ConsoleInfo *)arg;
    HANDLE *handle = infoPtr->handle;
    DWORD count, waitResult;
    HANDLE wEvents[2];

    /* The first event takes precedence. */
    wEvents[0] = infoPtr->stopReader;
    wEvents[1] = infoPtr->startReader;

    for (;;) {
	/*
	 * Wait for the main thread to signal before attempting to wait.
	 */

	waitResult = WaitForMultipleObjects(2, wEvents, FALSE, INFINITE);

	if (waitResult != (WAIT_OBJECT_0 + 1)) {
	    /*
	     * The start event was not signaled.  It must be the stop event
	     * or an error, so exit this thread.
	     */

	    break;
	}

	count = 0;

	/* 
	 * Look for data on the console, but first ignore any events
	 * that are not KEY_EVENTs 
	 */
	if (ReadConsoleA(handle, infoPtr->buffer, CONSOLE_BUFFER_SIZE,
		(LPDWORD) &infoPtr->bytesRead, NULL) != FALSE) {
	    /*
	     * Data was stored in the buffer.
	     */
	    
	    infoPtr->readFlags |= CONSOLE_BUFFERED;
	} else {
	    DWORD err;
	    err = GetLastError();
	    
	    if (err == EOF) {
		infoPtr->readFlags = CONSOLE_EOF;
	    }
	}

	/*
	 * Signal the main thread by signalling the readable event and
	 * then waking up the notifier thread.
	 */

	SetEvent(infoPtr->readable);

	/*
	 * Alert the foreground thread.  Note that we need to treat this like
	 * a critical section so the foreground thread does not terminate
	 * this thread while we are holding a mutex in the notifier code.
	 */

	Tcl_MutexLock(&consoleMutex);
	Tcl_ThreadAlert(infoPtr->threadId);
	Tcl_MutexUnlock(&consoleMutex);
    }

    return 0;
}