1 | /* $Id: scmstream.h 56310 2015-06-09 22:36:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase / Tool - Source Code Massager Stream Code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2015 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 |
|
---|
23 | RT_C_DECLS_BEGIN
|
---|
24 |
|
---|
25 | /** End of line marker type. */
|
---|
26 | typedef 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. */
|
---|
33 | typedef SCMEOL *PSCMEOL;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Line record.
|
---|
37 | */
|
---|
38 | typedef 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. */
|
---|
50 | typedef SCMSTREAMLINE *PSCMSTREAMLINE;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Source code massager stream.
|
---|
54 | */
|
---|
55 | typedef 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 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. */
|
---|
86 | typedef SCMSTREAM *PSCMSTREAM;
|
---|
87 | /** Pointer to a const SCM stream. */
|
---|
88 | typedef SCMSTREAM const *PCSCMSTREAM;
|
---|
89 |
|
---|
90 |
|
---|
91 | int ScmStreamInitForReading(PSCMSTREAM pStream, const char *pszFilename);
|
---|
92 | int ScmStreamInitForWriting(PSCMSTREAM pStream, PCSCMSTREAM pRelatedStream);
|
---|
93 | void ScmStreamDelete(PSCMSTREAM pStream);
|
---|
94 | int ScmStreamGetStatus(PCSCMSTREAM pStream);
|
---|
95 | void ScmStreamRewindForReading(PSCMSTREAM pStream);
|
---|
96 | void ScmStreamRewindForWriting(PSCMSTREAM pStream);
|
---|
97 | bool ScmStreamIsText(PSCMSTREAM pStream);
|
---|
98 | int ScmStreamCheckItegrity(PSCMSTREAM pStream);
|
---|
99 | int ScmStreamWriteToFile(PSCMSTREAM pStream, const char *pszFilenameFmt, ...);
|
---|
100 | int ScmStreamWriteToStdOut(PSCMSTREAM pStream);
|
---|
101 |
|
---|
102 | size_t ScmStreamTell(PSCMSTREAM pStream);
|
---|
103 | size_t ScmStreamTellLine(PSCMSTREAM pStream);
|
---|
104 | size_t ScmStreamTellOffsetOfLine(PSCMSTREAM pStream, size_t iLine);
|
---|
105 | size_t ScmStreamSize(PSCMSTREAM pStream);
|
---|
106 | size_t ScmStreamCountLines(PSCMSTREAM pStream);
|
---|
107 | int ScmStreamSeekAbsolute(PSCMSTREAM pStream, size_t offAbsolute);
|
---|
108 | int ScmStreamSeekRelative(PSCMSTREAM pStream, ssize_t offRelative);
|
---|
109 | int ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine);
|
---|
110 | bool ScmStreamIsAtStartOfLine(PSCMSTREAM pStream);
|
---|
111 |
|
---|
112 | const char *ScmStreamGetLineByNo(PSCMSTREAM pStream, size_t iLine, size_t *pcchLine, PSCMEOL penmEol);
|
---|
113 | const char *ScmStreamGetLine(PSCMSTREAM pStream, size_t *pcchLine, PSCMEOL penmEol);
|
---|
114 | unsigned ScmStreamGetCh(PSCMSTREAM pStream);
|
---|
115 | const char *ScmStreamGetCur(PSCMSTREAM pStream);
|
---|
116 | unsigned ScmStreamPeekCh(PSCMSTREAM pStream);
|
---|
117 | int ScmStreamRead(PSCMSTREAM pStream, void *pvBuf, size_t cbToRead);
|
---|
118 | bool ScmStreamIsWhiteLine(PSCMSTREAM pStream, size_t iLine);
|
---|
119 | SCMEOL ScmStreamGetEol(PSCMSTREAM pStream);
|
---|
120 | SCMEOL ScmStreamGetEolByLine(PSCMSTREAM pStream, size_t iLine);
|
---|
121 |
|
---|
122 | int ScmStreamPutLine(PSCMSTREAM pStream, const char *pchLine, size_t cchLine, SCMEOL enmEol);
|
---|
123 | int ScmStreamWrite(PSCMSTREAM pStream, const char *pchBuf, size_t cchBuf);
|
---|
124 | int ScmStreamPutCh(PSCMSTREAM pStream, char ch);
|
---|
125 | ssize_t ScmStreamPrintf(PSCMSTREAM pStream, const char *pszFormat, ...);
|
---|
126 | ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va);
|
---|
127 | int ScmStreamCopyLines(PSCMSTREAM pDst, PSCMSTREAM pSrc, size_t cLines);
|
---|
128 |
|
---|
129 | bool ScmStreamCMatchingWordM1(PSCMSTREAM pStream, const char *pszWord, size_t cchWord);
|
---|
130 | const char *ScmStreamCGetWord(PSCMSTREAM pStream, size_t *pcchWord);
|
---|
131 | const char *ScmStreamCGetWordM1(PSCMSTREAM pStream, size_t *pcchWord);
|
---|
132 |
|
---|
133 | RT_C_DECLS_END
|
---|
134 |
|
---|
135 | #endif
|
---|
136 |
|
---|