1 | /* $Id: scmstream.h 100618 2023-07-18 00:27:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase / Tool - Source Code Massager Stream Code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_bldprogs_scmstream_h
|
---|
29 | #define VBOX_INCLUDED_SRC_bldprogs_scmstream_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 | RT_C_DECLS_BEGIN
|
---|
37 |
|
---|
38 | /** End of line marker type. */
|
---|
39 | typedef enum SCMEOL
|
---|
40 | {
|
---|
41 | SCMEOL_NONE = 0,
|
---|
42 | SCMEOL_LF = 1,
|
---|
43 | SCMEOL_CRLF = 2
|
---|
44 | } SCMEOL;
|
---|
45 | /** Pointer to an end of line marker type. */
|
---|
46 | typedef SCMEOL *PSCMEOL;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Line record.
|
---|
50 | */
|
---|
51 | typedef struct SCMSTREAMLINE
|
---|
52 | {
|
---|
53 | /** The offset of the line. */
|
---|
54 | size_t off;
|
---|
55 | /** The line length, excluding the LF character.
|
---|
56 | * @todo This could be derived from the offset of the next line if that wasn't
|
---|
57 | * so tedious. */
|
---|
58 | size_t cch;
|
---|
59 | /** The end of line marker type. */
|
---|
60 | SCMEOL enmEol;
|
---|
61 | } SCMSTREAMLINE;
|
---|
62 | /** Pointer to a line record. */
|
---|
63 | typedef SCMSTREAMLINE *PSCMSTREAMLINE;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Source code massager stream.
|
---|
67 | */
|
---|
68 | typedef struct SCMSTREAM
|
---|
69 | {
|
---|
70 | /** Pointer to the file memory. */
|
---|
71 | char *pch;
|
---|
72 | /** The current stream position. */
|
---|
73 | size_t off;
|
---|
74 | /** The current stream size. */
|
---|
75 | size_t cb;
|
---|
76 | /** The size of the memory pb points to. */
|
---|
77 | size_t cbAllocated;
|
---|
78 |
|
---|
79 | /** Line records. */
|
---|
80 | PSCMSTREAMLINE paLines;
|
---|
81 | /** The current line. */
|
---|
82 | size_t iLine;
|
---|
83 | /** The current stream size given in lines. */
|
---|
84 | size_t cLines;
|
---|
85 | /** The sizeof the memory backing paLines. */
|
---|
86 | size_t cLinesAllocated;
|
---|
87 |
|
---|
88 | /** Set if write-only, clear if read-only. */
|
---|
89 | bool fWriteOrRead;
|
---|
90 | /** Set if the memory pb points to is from RTFileReadAll. */
|
---|
91 | bool fFileMemory;
|
---|
92 | /** Set if fully broken into lines. */
|
---|
93 | bool fFullyLineated;
|
---|
94 |
|
---|
95 | /** Stream status code (IPRT). */
|
---|
96 | int rc;
|
---|
97 | } SCMSTREAM;
|
---|
98 | /** Pointer to a SCM stream. */
|
---|
99 | typedef SCMSTREAM *PSCMSTREAM;
|
---|
100 | /** Pointer to a const SCM stream. */
|
---|
101 | typedef SCMSTREAM const *PCSCMSTREAM;
|
---|
102 |
|
---|
103 |
|
---|
104 | int ScmStreamInitForReading(PSCMSTREAM pStream, const char *pszFilename);
|
---|
105 | int ScmStreamInitForReadingFromStdInput(PSCMSTREAM pStream);
|
---|
106 | int ScmStreamInitForWriting(PSCMSTREAM pStream, PCSCMSTREAM pRelatedStream);
|
---|
107 | void ScmStreamDelete(PSCMSTREAM pStream);
|
---|
108 | int ScmStreamGetStatus(PCSCMSTREAM pStream);
|
---|
109 | void ScmStreamRewindForReading(PSCMSTREAM pStream);
|
---|
110 | void ScmStreamRewindForWriting(PSCMSTREAM pStream);
|
---|
111 | bool ScmStreamIsText(PSCMSTREAM pStream);
|
---|
112 | int ScmStreamCheckItegrity(PSCMSTREAM pStream);
|
---|
113 | int ScmStreamWriteToFile(PSCMSTREAM pStream, const char *pszFilenameFmt, ...);
|
---|
114 | int ScmStreamWriteToStdOut(PSCMSTREAM pStream);
|
---|
115 |
|
---|
116 | size_t ScmStreamTell(PSCMSTREAM pStream);
|
---|
117 | size_t ScmStreamTellLine(PSCMSTREAM pStream);
|
---|
118 | size_t ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine);
|
---|
119 | size_t ScmStreamSize(PSCMSTREAM pStream);
|
---|
120 | size_t ScmStreamCountLines(PSCMSTREAM pStream);
|
---|
121 | int ScmStreamSeekAbsolute(PSCMSTREAM pStream, size_t offAbsolute);
|
---|
122 | int ScmStreamSeekRelative(PSCMSTREAM pStream, ssize_t offRelative);
|
---|
123 | int ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine);
|
---|
124 | bool ScmStreamIsAtStartOfLine(PSCMSTREAM pStream);
|
---|
125 | bool ScmStreamAreIdentical(PCSCMSTREAM pStream1, PCSCMSTREAM pStream2);
|
---|
126 |
|
---|
127 | const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol);
|
---|
128 | const char *ScmStreamGetLine(PSCMSTREAM pStream, size_t *pcchLine, PSCMEOL penmEol);
|
---|
129 | unsigned ScmStreamGetCh(PSCMSTREAM pStream);
|
---|
130 | const char *ScmStreamGetCur(PSCMSTREAM pStream);
|
---|
131 | unsigned ScmStreamPeekCh(PSCMSTREAM pStream);
|
---|
132 | int ScmStreamRead(PSCMSTREAM pStream, void *pvBuf, size_t cbToRead);
|
---|
133 | bool ScmStreamIsEndOfStream(PSCMSTREAM pStream);
|
---|
134 | bool ScmStreamIsWhiteLine(PSCMSTREAM pStream, size_t iLine);
|
---|
135 | SCMEOL ScmStreamGetEol(PSCMSTREAM pStream);
|
---|
136 | SCMEOL ScmStreamGetEolByLine(PSCMSTREAM pStream, size_t iLine);
|
---|
137 |
|
---|
138 | int ScmStreamPutLine(PSCMSTREAM pStream, const char *pchLine, size_t cchLine, SCMEOL enmEol);
|
---|
139 | int ScmStreamWrite(PSCMSTREAM pStream, const char *pchBuf, size_t cchBuf);
|
---|
140 | int ScmStreamPutCh(PSCMSTREAM pStream, char ch);
|
---|
141 | int ScmStreamPutEol(PSCMSTREAM pStream, SCMEOL enmEol);
|
---|
142 | ssize_t ScmStreamPrintf(PSCMSTREAM pStream, const char *pszFormat, ...);
|
---|
143 | ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va);
|
---|
144 | int ScmStreamCopyLines(PSCMSTREAM pDst, PSCMSTREAM pSrc, size_t cLines);
|
---|
145 |
|
---|
146 | bool ScmStreamCMatchingWordM1(PSCMSTREAM pStream, const char *pszWord, size_t cchWord);
|
---|
147 | const char *ScmStreamCGetWord(PSCMSTREAM pStream, size_t *pcchWord);
|
---|
148 | const char *ScmStreamCGetWordM1(PSCMSTREAM pStream, size_t *pcchWord);
|
---|
149 |
|
---|
150 | RT_C_DECLS_END
|
---|
151 |
|
---|
152 | #endif /* !VBOX_INCLUDED_SRC_bldprogs_scmstream_h */
|
---|
153 |
|
---|