summaryrefslogtreecommitdiffstats
path: root/src/bldprogs/scmstream.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 03:01:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 03:01:46 +0000
commitf8fe689a81f906d1b91bb3220acde2a4ecb14c5b (patch)
tree26484e9d7e2c67806c2d1760196ff01aaa858e8c /src/bldprogs/scmstream.h
parentInitial commit. (diff)
downloadvirtualbox-upstream.tar.xz
virtualbox-upstream.zip
Adding upstream version 6.0.4-dfsg.upstream/6.0.4-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bldprogs/scmstream.h')
-rw-r--r--src/bldprogs/scmstream.h140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/bldprogs/scmstream.h b/src/bldprogs/scmstream.h
new file mode 100644
index 00000000..1807d154
--- /dev/null
+++ b/src/bldprogs/scmstream.h
@@ -0,0 +1,140 @@
+/* $Id: scmstream.h $ */
+/** @file
+ * IPRT Testcase / Tool - Source Code Massager Stream Code.
+ */
+
+/*
+ * Copyright (C) 2012-2019 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef VBOX_INCLUDED_SRC_bldprogs_scmstream_h
+#define VBOX_INCLUDED_SRC_bldprogs_scmstream_h
+#ifndef RT_WITHOUT_PRAGMA_ONCE
+# pragma once
+#endif
+
+#include <iprt/types.h>
+
+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);
+
+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 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 */
+