1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/* $Id: scmstream.h $ */
/** @file
* IPRT Testcase / Tool - Source Code Massager Stream Code.
*/
/*
* Copyright (C) 2012-2022 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 <https://www.gnu.org/licenses>.
*
* 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 <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 */
|