Changeset 1484 for trunk/src/kernel32


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

Fix: console (unicode) updates

Location:
trunk/src/kernel32
Files:
5 edited

Legend:

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

    r297 r1484  
    1 /* $Id: conbuffer.cpp,v 1.4 1999-07-12 17:45:50 phaller Exp $ */
     1/* $Id: conbuffer.cpp,v 1.5 1999-10-27 18:36:33 phaller Exp $ */
    22
    33/*
     
    1818#endif
    1919
    20 #undef DEBUG_LOCAL
    21 #undef DEBUG_LOCAL2
     20//#undef DEBUG_LOCAL
     21//#undef DEBUG_LOCAL2
    2222
    2323
     
    7373#include "ConBuffer.H"
    7474#include "Console2.h"
     75#include <heapstring.h>
    7576
    7677
     
    289290
    290291        case 8: /* Backspace */
     292          // not correct if deleting expanded tab character
    291293          if (pConsoleBuffer->coordCursorPosition.X > 0)
    292294            pConsoleBuffer->coordCursorPosition.X--;
     295
     296          //@@@PH overwrite old character
     297          *(pConsoleBuffer->ppszLine[pConsoleBuffer->coordCursorPosition.Y] +
     298            pConsoleBuffer->coordCursorPosition.X * 2) = 0x20;
    293299          break;
    294300
     
    319325          break;
    320326
     327        case 13: /* CARRIAGE RETURN */
     328          pConsoleBuffer->coordCursorPosition.X = 0;
     329          //@@@PH test break;
     330
    321331        case 10: /* LINEFEED */
    322332          pConsoleBuffer->coordCursorPosition.Y++;
     
    329339            pConsoleBuffer->coordCursorPosition.Y--;
    330340          }
    331           break;
    332 
    333         case 13: /* CARRIAGE RETURN */
    334           pConsoleBuffer->coordCursorPosition.X = 0;
    335341          break;
    336342
     
    25212527{
    25222528  PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
     2529  DWORD          rc;
     2530  LPSTR          pszAscii;
    25232531
    25242532#ifdef DEBUG_LOCAL2
     
    25312539#endif
    25322540
    2533   /* @@@PH AScii -> unicode translation */
     2541  /* Ascii -> unicode translation */
     2542  pszAscii = (LPSTR)HEAP_malloc(cchToWrite);
     2543  if (pszAscii == NULL)
     2544     return ERROR_NOT_ENOUGH_MEMORY;
     2545
     2546  lstrcpynWtoA(pszAscii, (LPWSTR)lpvBuffer, cchToWrite);
    25342547
    25352548  /* simply forward the request to that routine */
    2536   return (HMDeviceConsoleBufferClass::WriteFile(pHMHandleData,
    2537                                                 lpvBuffer,
    2538                                                 cchToWrite,
    2539                                                 lpcchWritten,
    2540                                                 NULL));
     2549  rc = HMDeviceConsoleBufferClass::WriteFile(pHMHandleData,
     2550                                             pszAscii,
     2551                                             cchToWrite,
     2552                                             lpcchWritten,
     2553                                             NULL);
     2554  // free memory again
     2555  HEAP_free(pszAscii);
     2556  return (rc);
    25412557}
    25422558
  • 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 */
  • trunk/src/kernel32/conout.cpp

    r149 r1484  
    1 /* $Id: conout.cpp,v 1.3 1999-06-21 18:53:51 phaller Exp $ */
     1/* $Id: conout.cpp,v 1.4 1999-10-27 18:36:35 phaller Exp $ */
    22
    33/*
     
    1313#endif
    1414
    15 #undef DEBUG_LOCAL
    16 #undef DEBUG_LOCAL2
     15//#undef DEBUG_LOCAL
     16//#undef DEBUG_LOCAL2
    1717
    1818
     
    8383{
    8484  void   _System _O32_SetLastError(DWORD  dwError);
     85  int    _System _O32_GetLastError(void);
    8586}
    8687
     
    9394}
    9495
     96inline int GetLastError(void)
     97{
     98  USHORT sel = GetFS();
     99  int    rc;
     100
     101  rc = _O32_GetLastError();
     102  SetFS(sel);
     103  return rc;
     104}
    95105
    96106
  • trunk/src/kernel32/console.cpp

    r1476 r1484  
    1 /* $Id: console.cpp,v 1.15 1999-10-27 12:38:47 phaller Exp $ */
     1/* $Id: console.cpp,v 1.16 1999-10-27 18:36:35 phaller Exp $ */
    22
    33/*
     
    1818#endif
    1919
    20 #undef DEBUG_LOCAL
    21 #undef DEBUG_LOCAL2
     20//#undef DEBUG_LOCAL
     21//#undef DEBUG_LOCAL2
    2222
    2323
  • trunk/src/kernel32/heapstring.cpp

    r1292 r1484  
    1 /* $Id: heapstring.cpp,v 1.15 1999-10-14 17:15:26 phaller Exp $ */
     1/* $Id: heapstring.cpp,v 1.16 1999-10-27 18:36:36 phaller Exp $ */
    22
    33/*
     
    570570
    571571// asciilen: max length of unicode buffer (including end 0)
    572 
     572// @@@PH 0 termination is NOT necessarily included !
    573573int WIN32API lstrcpynAtoW(LPWSTR unicode,
    574574                          LPSTR  ascii,
     
    583583  char*    in_buf;
    584584
    585   dprintf(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh)\n",
     585  dprintf(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh,%d)\n",
    586586           ascii,
    587            unicode));
     587           unicode,
     588           asciilen));
    588589
    589590  //CB: no input, set at least terminator
     
    599600  if (getUconvObject())
    600601  {
    601     if (asciilen == 1)
     602    //@@@PH what's this?
     603    if ((asciilen == 1) && (*ascii == '\0') )
    602604    {
    603605       unicode[0] = 0;
     
    606608
    607609    in_buf        = ascii;
    608     in_bytes_left = asciilen-1; //buffer size in bytes
     610
     611    //@@@PH what's this?
     612    //in_bytes_left = asciilen-1; //buffer size in bytes
     613
     614    in_bytes_left = asciilen; //buffer size in bytes
    609615    out_buf = (UniChar*)unicode;
    610616
     
    616622                        &num_subs );
    617623
    618     unicode[asciilen-1-in_bytes_left] = 0;
     624    //@@@PH what's this?
     625    //unicode[asciilen-1-in_bytes_left] = 0;
    619626
    620627    //if (rc != ULS_SUCCESS && in_bytes_left > 0) //CB: never the case during my tests
    621628    //   dprintf(("KERNEL32: AsciiToUnicode failed, %d bytes left!\n",in_bytes_left));
    622     return asciilen - 1;
     629
     630    //@@@PH what's this?
     631    //return asciilen - 1;
     632    return asciilen;
    623633  }
    624634  else
    625635  { //poor man's conversion
    626636
    627     for(i = 0;i < asciilen-1;i++)
     637//    for(i = 0;i < asciilen-1;i++)
     638    for(i = 0;i < asciilen;i++)
    628639    {
    629640      unicode[i] = ascii[i];
    630641      if (ascii[i] == 0)
    631         return i-1; //work done
     642        //return i-1; //work done
     643        return i; //work done
    632644    }
    633645
    634     unicode[asciilen-1] = 0;
    635     return asciilen-1;
     646//    unicode[asciilen-1] = 0;
     647//    return asciilen-1;
     648    return asciilen;
    636649  }
    637650}
     
    652665LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPWSTR unicode)
    653666{
     667  //@@@PH huh? wuz dat?
    654668  if (unicode == NULL)
    655669  {
Note: See TracChangeset for help on using the changeset viewer.