Ignore:
Timestamp:
Jun 30, 2002, 11:54:51 AM (23 years ago)
Author:
sandervl
Message:

WriteFile for standard out: convert line feed without carriage return into CR+LF

File:
1 edited

Legend:

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

    r8795 r8806  
    1 /* $Id: hmstd.cpp,v 1.10 2002-06-27 12:35:56 sandervl Exp $ */
     1/* $Id: hmstd.cpp,v 1.11 2002-06-30 09:54:51 sandervl Exp $ */
    22
    33/*
     
    2323#include <os2win.h>
    2424#include <stdlib.h>
     25#include <stdio.h>
    2526#include <string.h>
    2627#include <unicode.h>
    27 #include <misc.h>
     28#include <dbglog.h>
    2829
    2930#include "HandleManager.H"
     
    7172                                 LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
    7273{
    73   BOOL         bRC;
    74   DWORD        bytesread;
    75 
    76   dprintf2(("KERNEL32: HMDeviceStandardClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED\n",
    77            lpHMDeviceName,
    78            pHMHandleData,
    79            lpBuffer,
    80            nNumberOfBytesToRead,
    81            lpNumberOfBytesRead,
    82            lpOverlapped));
    83 
    84   if(lpCompletionRoutine) {
    85       dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    86   }
    87 
    88   if(lpNumberOfBytesRead == NULL) {
    89      lpNumberOfBytesRead = &bytesread;
    90   }
    91   if(pHMHandleData->dwUserData != STD_INPUT_HANDLE) {
    92      return FALSE;
    93   }
    94   return O32_ReadFile(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToRead,
    95                       lpNumberOfBytesRead, lpOverlapped);
     74    BOOL         bRC;
     75    DWORD        bytesread;
     76
     77    dprintf2(("KERNEL32: HMDeviceStandardClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x) - NOT IMPLEMENTED\n",
     78              lpHMDeviceName, pHMHandleData, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped));
     79
     80    if(lpCompletionRoutine) {
     81        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     82    }
     83   
     84    if(lpNumberOfBytesRead == NULL) {
     85        lpNumberOfBytesRead = &bytesread;
     86    }
     87    if(pHMHandleData->dwUserData != STD_INPUT_HANDLE) {
     88        return FALSE;
     89    }
     90    return O32_ReadFile(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToRead,
     91                        lpNumberOfBytesRead, lpOverlapped);
    9692}
    9793
     
    112108 * Author    : Patrick Haller [Wed, 1998/02/11 20:44]
    113109 *****************************************************************************/
     110#define CARRIAGE_RETURN 0xD
     111#define LINE_FEED       0xA
    114112
    115113BOOL HMDeviceStandardClass::WriteFile(PHMHANDLEDATA pHMHandleData,
     
    124122
    125123    dprintf(("KERNEL32: HMDeviceStandardClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
    126              lpHMDeviceName,
    127              pHMHandleData,
    128              lpBuffer,
    129              nNumberOfBytesToWrite,
    130              lpNumberOfBytesWritten,
     124             lpHMDeviceName, pHMHandleData, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,
    131125             lpOverlapped));
    132     if (lpNumberOfBytesWritten == NULL)
     126
     127    if(lpNumberOfBytesWritten == NULL)
    133128        lpNumberOfBytesWritten = &byteswritten;
    134     if (lpCompletionRoutine)
     129
     130    if(lpCompletionRoutine)
    135131    {
    136132        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    137133    }
    138134
    139     if (pHMHandleData->dwUserData == STD_INPUT_HANDLE)
    140         return FALSE;
     135    if(pHMHandleData->dwUserData == STD_INPUT_HANDLE)
     136        return FALSE;
     137
     138    //count linefeed without carriage return occurances
     139    char *src, *dest;
     140    int  i         = 0;
     141    int  missingCR = 0;
     142    char prevchar  = 0;
     143
     144    src = (char *)lpBuffer;
     145    while(i < nNumberOfBytesToWrite) {
     146        if(src[i] == LINE_FEED && prevchar != CARRIAGE_RETURN) {
     147            missingCR++;
     148        }
     149        prevchar = src[i];
     150        i++;
     151    }
     152    nNumberOfBytesToWrite += missingCR;
     153    dprintf(("missingCR %d", missingCR));
     154
    141155    lpLowMemBuffer = alloca(nNumberOfBytesToWrite);
    142     if (lpLowMemBuffer == NULL)
     156    if(lpLowMemBuffer == NULL)
    143157    {
    144158        DebugInt3();
    145159        return FALSE;
    146160    }
    147     memcpy(lpLowMemBuffer, lpBuffer, nNumberOfBytesToWrite);
    148 
    149     if (    WinExe
    150         &&  !WinExe->isConsoleApp()
    151         &&  O32_GetFileType(pHMHandleData->hHMHandle) == FILE_TYPE_UNKNOWN) /* kso */
     161
     162    //convert linefeed without carriage return into LF+CR
     163    i         = 0;
     164    missingCR = 0;
     165    prevchar  = 0;
     166    src       = (char *)lpBuffer;
     167    dest      = (char *)lpLowMemBuffer;
     168
     169    while(i < nNumberOfBytesToWrite) {
     170        if(src[i] == LINE_FEED && prevchar != CARRIAGE_RETURN) {
     171            dest[i+missingCR] = CARRIAGE_RETURN;
     172            missingCR++;
     173            dest[i+missingCR] = LINE_FEED;
     174        }
     175        else {
     176            dest[i+missingCR] = src[i];
     177        }
     178        prevchar = src[i];
     179        i++;
     180    }
     181    //memcpy(lpLowMemBuffer, lpBuffer, nNumberOfBytesToWrite);
     182
     183    if(WinExe && !WinExe->isConsoleApp() && O32_GetFileType(pHMHandleData->hHMHandle) == FILE_TYPE_UNKNOWN) /* kso */
    152184    {
    153185        //DosWrite returns error 436 when PM apps try to write to std out
     
    162194    dprintf(("%s: %.*s", pHMHandleData->dwUserData == STD_ERROR_HANDLE ? "STDERR" : "STDOUT",
    163195             nNumberOfBytesToWrite, lpLowMemBuffer));
    164     if (!O32_WriteFile(pHMHandleData->hHMHandle, lpLowMemBuffer, nNumberOfBytesToWrite,
    165                        lpNumberOfBytesWritten, lpOverlapped))
    166     {
    167         /* Open32 wasn't made for console apps... */
     196
     197
     198    if(!O32_WriteFile(pHMHandleData->hHMHandle, lpLowMemBuffer, nNumberOfBytesToWrite,
     199                      lpNumberOfBytesWritten, lpOverlapped))
     200    {
    168201        dprintf(("STD*: failed with lasterror=%d\n", GetLastError()));
    169202        return FALSE;
Note: See TracChangeset for help on using the changeset viewer.