Ignore:
Timestamp:
Oct 27, 1999, 8:36:36 PM (26 years ago)
Author:
phaller
Message:

Fix: console (unicode) updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/conin.cpp

    r670 r1484  
    1 /* $Id: conin.cpp,v 1.5 1999-08-24 23:37:07 phaller Exp $ */
     1/* $Id: conin.cpp,v 1.6 1999-10-27 18:36:34 phaller Exp $ */
    22
    33/*
     
    1010#ifdef DEBUG
    1111#define DEBUG_LOCAL
     12#define DEBUG_LOCAL2
    1213#endif
    1314
     
    4142#include "Conin.H"
    4243#include "Console2.h"
     44#include <heapstring.h>
    4345
    4446
     
    123125  INPUT_RECORD InputRecord;               /* buffer for the event to be read */
    124126  ULONG  ulPostCounter;                            /* semaphore post counter */
     127  BOOL   fLoop = TRUE;      /* set to false if function may return to caller */
    125128
    126129#ifdef DEBUG_LOCAL
     
    138141
    139142                                  /* block if no key events are in the queue */
    140   for (;ulCounter==0;)                       /* until we got some characters */
     143  for (;fLoop;)                       /* until we got some characters */
    141144  {
    142145    if (iConsoleInputQueryEvents() == 0)      /* if queue is currently empty */
     
    153156      if (rc == NO_ERROR)         /* if we've got a valid event in the queue */
    154157      {
    155         if (InputRecord.EventType == KEY_EVENT)          /* check event type */
     158        //@@@PH other events are discarded!
     159        if ( (InputRecord.EventType == KEY_EVENT) &&     /* check event type */
     160             (InputRecord.Event.KeyEvent.bKeyDown == TRUE) )
    156161        {
     162          // console in line input mode ?
     163          if (pConsoleInput->dwConsoleMode & ENABLE_LINE_INPUT)
     164          {
     165            // continue until buffer full or CR entered
     166            if (InputRecord.Event.KeyEvent.uChar.AsciiChar == 0x0d)
     167              fLoop = FALSE;
     168          }
     169          else
     170            fLoop = FALSE; // return on any single key in buffer :)
     171
     172          // record key stroke
     173          if (pConsoleInput->dwConsoleMode & ENABLE_PROCESSED_INPUT)
     174          {
     175            // filter special characters first
     176            switch (InputRecord.Event.KeyEvent.uChar.AsciiChar)
     177            {
     178              case 0x03: // ctrl-c is filtered!
     179              case 0x0a: // LF
     180              case 0x0d: // CR
     181                // do NOT insert those keys into the resulting buffer
     182                break;
     183
     184              case 0x08: // backspace
     185                if (ulCounter > 0)
     186                {
     187                  //@@@PH erase character on screen!
     188                  ulCounter--;
     189                  pszTarget--;
    157190                                                     /* local echo enabled ? */
    158           if (pConsoleInput->dwConsoleMode & ENABLE_ECHO_INPUT)
    159             HMWriteFile(pConsoleGlobals->hConsoleBuffer,
     191                  if (pConsoleInput->dwConsoleMode & ENABLE_ECHO_INPUT)
     192                    HMWriteFile(pConsoleGlobals->hConsoleBuffer,
    160193                        &InputRecord.Event.KeyEvent.uChar.AsciiChar,
    161194                        1,
    162195                        &ulPostCounter,                      /* dummy result */
    163196                        NULL);
    164 
    165           // console in line input mode ?
    166           if ( (pConsoleInput->dwConsoleMode & ENABLE_LINE_INPUT) &&
    167                (InputRecord.Event.KeyEvent.uChar.AsciiChar == 0x0d))
    168             goto __readfile_exit;
    169 
    170           // record key stroke
    171           *pszTarget = InputRecord.Event.KeyEvent.uChar.AsciiChar;
    172           pszTarget++;
    173           ulCounter++;
     197                }
     198                break;
     199
     200              default:
     201                // OK, for the rest ...
     202                *pszTarget = InputRecord.Event.KeyEvent.uChar.AsciiChar;
     203                dprintf(("KERNEL32:CONIN$: Debug: recorded key (%c - %02xh)\n",
     204                         *pszTarget,
     205                         *pszTarget));
     206
     207                pszTarget++;
     208                ulCounter++;
     209                                                     /* local echo enabled ? */
     210                if (pConsoleInput->dwConsoleMode & ENABLE_ECHO_INPUT)
     211                  HMWriteFile(pConsoleGlobals->hConsoleBuffer,
     212                        &InputRecord.Event.KeyEvent.uChar.AsciiChar,
     213                        1,
     214                        &ulPostCounter,                      /* dummy result */
     215                        NULL);
     216
     217
     218            }
     219          }
     220          else
     221          {
     222            *pszTarget = InputRecord.Event.KeyEvent.uChar.AsciiChar;
     223            dprintf(("KERNEL32:CONIN$: Debug: recorded key (%c - %02xh)\n",
     224                     *pszTarget,
     225                     *pszTarget));
     226
     227            pszTarget++;
     228            ulCounter++;
     229
     230                                                     /* local echo enabled ? */
     231            if (pConsoleInput->dwConsoleMode & ENABLE_ECHO_INPUT)
     232              HMWriteFile(pConsoleGlobals->hConsoleBuffer,
     233                        &InputRecord.Event.KeyEvent.uChar.AsciiChar,
     234                        1,
     235                        &ulPostCounter,                      /* dummy result */
     236                        NULL);
     237          }
    174238
    175239          // buffer filled?
    176240          if (ulCounter >= nNumberOfBytesToRead)        /* at buffer's end ? */
    177             goto __readfile_exit;
     241            fLoop = FALSE;
    178242        }
    179243                                         /* Note: other events are discarded */
     
    182246    while (rc == NO_ERROR);
    183247  }
    184 
    185 __readfile_exit:
    186248
    187249  *lpNumberOfBytesRead = ulCounter;                          /* write result */
     
    642704  PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
    643705  DWORD          dwResult;
     706  LPSTR          lpstrAscii;
    644707
    645708#ifdef DEBUG_LOCAL2
     
    652715#endif
    653716
     717  // create ascii buffer
     718  lpstrAscii = (LPSTR)HEAP_malloc(cchToRead);
     719  if (lpstrAscii == NULL)
     720     return ERROR_NOT_ENOUGH_MEMORY;
     721
    654722                               /* simply forward the request to that routine */
    655723  dwResult = HMDeviceConsoleInClass::ReadFile(pHMHandleData,
    656                                               lpvBuffer,
     724                                              lpstrAscii,
    657725                                              cchToRead,
    658726                                              lpcchRead,
    659727                                              NULL);
    660   /* @@@PH AScii -> unicode translation */
     728  /* Ascii -> unicode translation */
     729  if (dwResult == TRUE)
     730    lstrcpynAtoW((LPWSTR)lpvBuffer, lpstrAscii, *lpcchRead);
     731
     732  HEAP_free(lpstrAscii);
    661733
    662734  return (dwResult);                                  /* deliver return code */
Note: See TracChangeset for help on using the changeset viewer.