From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- src/bldprogs/scmstream.h | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/bldprogs/scmstream.h (limited to 'src/bldprogs/scmstream.h') diff --git a/src/bldprogs/scmstream.h b/src/bldprogs/scmstream.h new file mode 100644 index 00000000..e66311ca --- /dev/null +++ b/src/bldprogs/scmstream.h @@ -0,0 +1,152 @@ +/* $Id: scmstream.h $ */ +/** @file + * IPRT Testcase / Tool - Source Code Massager Stream Code. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#ifndef VBOX_INCLUDED_SRC_bldprogs_scmstream_h +#define VBOX_INCLUDED_SRC_bldprogs_scmstream_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include + +RT_C_DECLS_BEGIN + +/** End of line marker type. */ +typedef enum SCMEOL +{ + SCMEOL_NONE = 0, + SCMEOL_LF = 1, + SCMEOL_CRLF = 2 +} SCMEOL; +/** Pointer to an end of line marker type. */ +typedef SCMEOL *PSCMEOL; + +/** + * Line record. + */ +typedef struct SCMSTREAMLINE +{ + /** The offset of the line. */ + size_t off; + /** The line length, excluding the LF character. + * @todo This could be derived from the offset of the next line if that wasn't + * so tedious. */ + size_t cch; + /** The end of line marker type. */ + SCMEOL enmEol; +} SCMSTREAMLINE; +/** Pointer to a line record. */ +typedef SCMSTREAMLINE *PSCMSTREAMLINE; + +/** + * Source code massager stream. + */ +typedef struct SCMSTREAM +{ + /** Pointer to the file memory. */ + char *pch; + /** The current stream position. */ + size_t off; + /** The current stream size. */ + size_t cb; + /** The size of the memory pb points to. */ + size_t cbAllocated; + + /** Line records. */ + PSCMSTREAMLINE paLines; + /** The current line. */ + size_t iLine; + /** The current stream size given in lines. */ + size_t cLines; + /** The sizeof the memory backing paLines. */ + size_t cLinesAllocated; + + /** Set if write-only, clear if read-only. */ + bool fWriteOrRead; + /** Set if the memory pb points to is from RTFileReadAll. */ + bool fFileMemory; + /** Set if fully broken into lines. */ + bool fFullyLineated; + + /** Stream status code (IPRT). */ + int rc; +} SCMSTREAM; +/** Pointer to a SCM stream. */ +typedef SCMSTREAM *PSCMSTREAM; +/** Pointer to a const SCM stream. */ +typedef SCMSTREAM const *PCSCMSTREAM; + + +int ScmStreamInitForReading(PSCMSTREAM pStream, const char *pszFilename); +int ScmStreamInitForWriting(PSCMSTREAM pStream, PCSCMSTREAM pRelatedStream); +void ScmStreamDelete(PSCMSTREAM pStream); +int ScmStreamGetStatus(PCSCMSTREAM pStream); +void ScmStreamRewindForReading(PSCMSTREAM pStream); +void ScmStreamRewindForWriting(PSCMSTREAM pStream); +bool ScmStreamIsText(PSCMSTREAM pStream); +int ScmStreamCheckItegrity(PSCMSTREAM pStream); +int ScmStreamWriteToFile(PSCMSTREAM pStream, const char *pszFilenameFmt, ...); +int ScmStreamWriteToStdOut(PSCMSTREAM pStream); + +size_t ScmStreamTell(PSCMSTREAM pStream); +size_t ScmStreamTellLine(PSCMSTREAM pStream); +size_t ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine); +size_t ScmStreamSize(PSCMSTREAM pStream); +size_t ScmStreamCountLines(PSCMSTREAM pStream); +int ScmStreamSeekAbsolute(PSCMSTREAM pStream, size_t offAbsolute); +int ScmStreamSeekRelative(PSCMSTREAM pStream, ssize_t offRelative); +int ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine); +bool ScmStreamIsAtStartOfLine(PSCMSTREAM pStream); +bool ScmStreamAreIdentical(PCSCMSTREAM pStream1, PCSCMSTREAM pStream2); + +const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol); +const char *ScmStreamGetLine(PSCMSTREAM pStream, size_t *pcchLine, PSCMEOL penmEol); +unsigned ScmStreamGetCh(PSCMSTREAM pStream); +const char *ScmStreamGetCur(PSCMSTREAM pStream); +unsigned ScmStreamPeekCh(PSCMSTREAM pStream); +int ScmStreamRead(PSCMSTREAM pStream, void *pvBuf, size_t cbToRead); +bool ScmStreamIsEndOfStream(PSCMSTREAM pStream); +bool ScmStreamIsWhiteLine(PSCMSTREAM pStream, size_t iLine); +SCMEOL ScmStreamGetEol(PSCMSTREAM pStream); +SCMEOL ScmStreamGetEolByLine(PSCMSTREAM pStream, size_t iLine); + +int ScmStreamPutLine(PSCMSTREAM pStream, const char *pchLine, size_t cchLine, SCMEOL enmEol); +int ScmStreamWrite(PSCMSTREAM pStream, const char *pchBuf, size_t cchBuf); +int ScmStreamPutCh(PSCMSTREAM pStream, char ch); +int ScmStreamPutEol(PSCMSTREAM pStream, SCMEOL enmEol); +ssize_t ScmStreamPrintf(PSCMSTREAM pStream, const char *pszFormat, ...); +ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va); +int ScmStreamCopyLines(PSCMSTREAM pDst, PSCMSTREAM pSrc, size_t cLines); + +bool ScmStreamCMatchingWordM1(PSCMSTREAM pStream, const char *pszWord, size_t cchWord); +const char *ScmStreamCGetWord(PSCMSTREAM pStream, size_t *pcchWord); +const char *ScmStreamCGetWordM1(PSCMSTREAM pStream, size_t *pcchWord); + +RT_C_DECLS_END + +#endif /* !VBOX_INCLUDED_SRC_bldprogs_scmstream_h */ + -- cgit v1.2.3