scmstream.cpp revision 0c69348b58bb8eabb1bea8867ee932b667bd0d34
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * IPRT Testcase / Tool - Source Code Massager Stream Code.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Copyright (C) 2010-2012 Oracle Corporation
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * available from http://www.virtualbox.org. This file is free software;
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * you can redistribute it and/or modify it under the terms of the GNU
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * General Public License (GPL) as published by the Free Software
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync/*******************************************************************************
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync* Header Files *
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync*******************************************************************************/
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Initializes the stream structure.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param pStream The stream structure.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param fWriteOrRead The value of the fWriteOrRead stream member.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncstatic void scmStreamInitInternal(PSCMSTREAM pStream, bool fWriteOrRead)
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Initialize an input stream.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @returns IPRT status code.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param pStream The stream to initialize.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param pszFilename The file to take the stream content from.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncint ScmStreamInitForReading(PSCMSTREAM pStream, const char *pszFilename)
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync scmStreamInitInternal(pStream, false /*fWriteOrRead*/);
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync int rc = pStream->rc = RTFileReadAll(pszFilename, &pvFile, &cbFile);
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Initialize an output stream.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @returns IPRT status code
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param pStream The stream to initialize.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param pRelatedStream Pointer to a related stream. NULL is fine.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsyncint ScmStreamInitForWriting(PSCMSTREAM pStream, PCSCMSTREAM pRelatedStream)
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync scmStreamInitInternal(pStream, true /*fWriteOrRead*/);
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync /* allocate stuff */
152b12e401b58b34fbdbf2a4510152b67884ee89vboxsync size_t cLinesEstimate = pRelatedStream && pRelatedStream->fFullyLineated
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync ? pRelatedStream->cLines + pRelatedStream->cLines / 10
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync pStream->paLines = (PSCMSTREAMLINE)RTMemAlloc(cLinesEstimate * sizeof(SCMSTREAMLINE));
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Frees the resources associated with the stream.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * Nothing is happens to whatever the stream was initialized from or dumped to.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync * @param pStream The stream to delete.
75fb03f8c1ac60d0449d333b78ec1ef08fcc9868vboxsync RTFileReadAllFree(pStream->pch, pStream->cbAllocated);
void *pvNew;
if (!pvNew)
if (!pvNew)
return VINF_SUCCESS;
if (!pvNew)
return VINF_SUCCESS;
case SCMEOL_LF:
case SCMEOL_CRLF:
case SCMEOL_NONE:
return VINF_SUCCESS;
int rc;
#ifdef RT_STRICT
return rc;
rc = RTFileOpenV(&hFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE, pszFilenameFmt, va);
return rc;
return NULL;
return NULL;
return NULL;
cb--;
return pchRet;
return rc;
return VINF_SUCCESS;
if (offRelative >= 0)
offAbsolute = 0;
return rc;
return VINF_SUCCESS;
const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol)
return NULL;
return NULL;
return NULL;
pStream->off = pStream->paLines[iLine].off + pStream->paLines[iLine].cch + pStream->paLines[iLine].enmEol;
return pchRet;
if (pStream->off >= pStream->paLines[iLine].off + pStream->paLines[iLine].cch + pStream->paLines[iLine].enmEol)
return (unsigned)ch;
return (unsigned)ch;
return VERR_EOF;
if (!pchLine)
return cchLine == 0;
return enmEol;
return enmEol;
return rc;
return rc;
return rc;
iLine++;
return VINF_SUCCESS;
return rc;
iLine--;
if (!pchLF)
return rc;
if ( cchLine
cchLine--;
iLine++;
if (!pchLF)
return VINF_SUCCESS;
return VINF_SUCCESS;
while (cLines-- > 0)
if (!pchLine)
return rc;
return VINF_SUCCESS;