VirtualBox

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

Last change on this file since 72687 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: scmstream.h 69500 2017-10-28 15:14:05Z vboxsync $ */
2/** @file
3 * IPRT Testcase / Tool - Source Code Massager Stream Code.
4 */
5
6/*
7 * Copyright (C) 2012-2017 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 ___scmstream_h___
19#define ___scmstream_h___
20
21#include <iprt/types.h>
22
23RT_C_DECLS_BEGIN
24
25/** End of line marker type. */
26typedef enum SCMEOL
27{
28 SCMEOL_NONE = 0,
29 SCMEOL_LF = 1,
30 SCMEOL_CRLF = 2
31} SCMEOL;
32/** Pointer to an end of line marker type. */
33typedef SCMEOL *PSCMEOL;
34
35/**
36 * Line record.
37 */
38typedef struct SCMSTREAMLINE
39{
40 /** The offset of the line. */
41 size_t off;
42 /** The line length, excluding the LF character.
43 * @todo This could be derived from the offset of the next line if that wasn't
44 * so tedious. */
45 size_t cch;
46 /** The end of line marker type. */
47 SCMEOL enmEol;
48} SCMSTREAMLINE;
49/** Pointer to a line record. */
50typedef SCMSTREAMLINE *PSCMSTREAMLINE;
51
52/**
53 * Source code massager stream.
54 */
55typedef struct SCMSTREAM
56{
57 /** Pointer to the file memory. */
58 char *pch;
59 /** The current stream position. */
60 size_t off;
61 /** The current stream size. */
62 size_t cb;
63 /** The size of the memory pb points to. */
64 size_t cbAllocated;
65
66 /** Line records. */
67 PSCMSTREAMLINE paLines;
68 /** The current line. */
69 size_t iLine;
70 /** The current stream size given in lines. */
71 size_t cLines;
72 /** The sizeof the memory backing paLines. */
73 size_t cLinesAllocated;
74
75 /** Set if write-only, clear if read-only. */
76 bool fWriteOrRead;
77 /** Set if the memory pb points to is from RTFileReadAll. */
78 bool fFileMemory;
79 /** Set if fully broken into lines. */
80 bool fFullyLineated;
81
82 /** Stream status code (IPRT). */
83 int rc;
84} SCMSTREAM;
85/** Pointer to a SCM stream. */
86typedef SCMSTREAM *PSCMSTREAM;
87/** Pointer to a const SCM stream. */
88typedef SCMSTREAM const *PCSCMSTREAM;
89
90
91int ScmStreamInitForReading(PSCMSTREAM pStream, const char *pszFilename);
92int ScmStreamInitForWriting(PSCMSTREAM pStream, PCSCMSTREAM pRelatedStream);
93void ScmStreamDelete(PSCMSTREAM pStream);
94int ScmStreamGetStatus(PCSCMSTREAM pStream);
95void ScmStreamRewindForReading(PSCMSTREAM pStream);
96void ScmStreamRewindForWriting(PSCMSTREAM pStream);
97bool ScmStreamIsText(PSCMSTREAM pStream);
98int ScmStreamCheckItegrity(PSCMSTREAM pStream);
99int ScmStreamWriteToFile(PSCMSTREAM pStream, const char *pszFilenameFmt, ...);
100int ScmStreamWriteToStdOut(PSCMSTREAM pStream);
101
102size_t ScmStreamTell(PSCMSTREAM pStream);
103size_t ScmStreamTellLine(PSCMSTREAM pStream);
104size_t ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine);
105size_t ScmStreamSize(PSCMSTREAM pStream);
106size_t ScmStreamCountLines(PSCMSTREAM pStream);
107int ScmStreamSeekAbsolute(PSCMSTREAM pStream, size_t offAbsolute);
108int ScmStreamSeekRelative(PSCMSTREAM pStream, ssize_t offRelative);
109int ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine);
110bool ScmStreamIsAtStartOfLine(PSCMSTREAM pStream);
111
112const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol);
113const char *ScmStreamGetLine(PSCMSTREAM pStream, size_t *pcchLine, PSCMEOL penmEol);
114unsigned ScmStreamGetCh(PSCMSTREAM pStream);
115const char *ScmStreamGetCur(PSCMSTREAM pStream);
116unsigned ScmStreamPeekCh(PSCMSTREAM pStream);
117int ScmStreamRead(PSCMSTREAM pStream, void *pvBuf, size_t cbToRead);
118bool ScmStreamIsWhiteLine(PSCMSTREAM pStream, size_t iLine);
119SCMEOL ScmStreamGetEol(PSCMSTREAM pStream);
120SCMEOL ScmStreamGetEolByLine(PSCMSTREAM pStream, size_t iLine);
121
122int ScmStreamPutLine(PSCMSTREAM pStream, const char *pchLine, size_t cchLine, SCMEOL enmEol);
123int ScmStreamWrite(PSCMSTREAM pStream, const char *pchBuf, size_t cchBuf);
124int ScmStreamPutCh(PSCMSTREAM pStream, char ch);
125int ScmStreamPutEol(PSCMSTREAM pStream, SCMEOL enmEol);
126ssize_t ScmStreamPrintf(PSCMSTREAM pStream, const char *pszFormat, ...);
127ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va);
128int ScmStreamCopyLines(PSCMSTREAM pDst, PSCMSTREAM pSrc, size_t cLines);
129
130bool ScmStreamCMatchingWordM1(PSCMSTREAM pStream, const char *pszWord, size_t cchWord);
131const char *ScmStreamCGetWord(PSCMSTREAM pStream, size_t *pcchWord);
132const char *ScmStreamCGetWordM1(PSCMSTREAM pStream, size_t *pcchWord);
133
134RT_C_DECLS_END
135
136#endif
137
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