VirtualBox

Changeset 41179 in vbox for trunk/src/bldprogs/scmstream.cpp


Ignore:
Timestamp:
May 6, 2012 8:31:02 PM (13 years ago)
Author:
vboxsync
Message:

More CPP core.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/scmstream.cpp

    r40558 r41179  
    2121#include <iprt/assert.h>
    2222#include <iprt/ctype.h>
     23#include <iprt/err.h>
    2324#include <iprt/file.h>
    24 #include <iprt/err.h>
     25#include <iprt/handle.h>
    2526#include <iprt/mem.h>
     27#include <iprt/pipe.h>
    2628#include <iprt/string.h>
    2729
     
    328330
    329331/**
     332 * Writes the stream to standard output.
     333 *
     334 * @returns IPRT status code
     335 * @param   pStream             The stream.
     336 */
     337int ScmStreamWriteToStdOut(PSCMSTREAM pStream)
     338{
     339    int rc;
     340
     341#ifdef RT_STRICT
     342    /*
     343     * Check that what we're going to write makes sense first.
     344     */
     345    rc = ScmStreamCheckItegrity(pStream);
     346    if (RT_FAILURE(rc))
     347        return rc;
     348#endif
     349
     350    /*
     351     * Do the actual writing.
     352     */
     353    RTHANDLE h;
     354    rc = RTHandleGetStandard(RTHANDLESTD_OUTPUT, &h);
     355    if (RT_SUCCESS(rc))
     356    {
     357        switch (h.enmType)
     358        {
     359            case RTHANDLETYPE_FILE:
     360                rc = RTFileWrite(h.u.hFile, pStream->pch, pStream->cb, NULL);
     361                break;
     362            case RTHANDLETYPE_PIPE:
     363                rc = RTPipeWriteBlocking(h.u.hPipe, pStream->pch, pStream->cb, NULL);
     364                break;
     365            default:
     366                rc = VERR_INVALID_HANDLE;
     367                break;
     368        }
     369    }
     370    return rc;
     371}
     372
     373/**
    330374 * Worker for ScmStreamGetLine that builds the line number index while parsing
    331375 * the stream.
     
    642686const char *ScmStreamGetLine(PSCMSTREAM pStream, size_t *pcchLine, PSCMEOL penmEol)
    643687{
    644     /** @todo this doesn't work when pStream->off !=
    645      *        pStream->paLines[pStream->iLine-1].off. */
    646688    if (!pStream->fFullyLineated)
    647689        return scmStreamGetLineInternal(pStream, pcchLine, penmEol);
    648     return ScmStreamGetLineByNo(pStream, pStream->iLine, pcchLine, penmEol);
     690
     691    size_t      offCur   = pStream->off;
     692    size_t      iCurLine = pStream->iLine;
     693    const char *pszLine  = ScmStreamGetLineByNo(pStream, iCurLine, pcchLine, penmEol);
     694    if (   pszLine
     695        && pStream->paLines[iCurLine].off < offCur)
     696    {
     697        offCur -= pStream->paLines[iCurLine].off;
     698        Assert(offCur <= pStream->paLines[iCurLine].off);
     699        *pcchLine -= offCur;
     700        pszLine   += offCur;
     701    }
     702    return pszLine;
    649703}
    650704
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette