VirtualBox

source: vbox/trunk/src/bldprogs/scmstream.h@ 82968

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette