1 | /* $Id: scm.h 62537 2016-07-22 19:32:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase / Tool - Source Code Massager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2016 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 |
|
---|
19 | #ifndef ___scm_h___
|
---|
20 | #define ___scm_h___
|
---|
21 |
|
---|
22 | #include "scmstream.h"
|
---|
23 |
|
---|
24 | RT_C_DECLS_BEGIN
|
---|
25 |
|
---|
26 | /** Pointer to the rewriter state. */
|
---|
27 | typedef struct SCMRWSTATE *PSCMRWSTATE;
|
---|
28 | /** Pointer to const massager settings. */
|
---|
29 | typedef struct SCMSETTINGSBASE const *PCSCMSETTINGSBASE;
|
---|
30 |
|
---|
31 |
|
---|
32 | /** @name Subversion Access
|
---|
33 | * @{ */
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * SVN property.
|
---|
37 | */
|
---|
38 | typedef struct SCMSVNPROP
|
---|
39 | {
|
---|
40 | /** The property. */
|
---|
41 | char *pszName;
|
---|
42 | /** The value.
|
---|
43 | * When used to record updates, this can be set to NULL to trigger the
|
---|
44 | * deletion of the property. */
|
---|
45 | char *pszValue;
|
---|
46 | } SCMSVNPROP;
|
---|
47 | /** Pointer to a SVN property. */
|
---|
48 | typedef SCMSVNPROP *PSCMSVNPROP;
|
---|
49 | /** Pointer to a const SVN property. */
|
---|
50 | typedef SCMSVNPROP const *PCSCMSVNPROP;
|
---|
51 |
|
---|
52 |
|
---|
53 | bool ScmSvnIsDirInWorkingCopy(const char *pszDir);
|
---|
54 | bool ScmSvnIsInWorkingCopy(PSCMRWSTATE pState);
|
---|
55 | int ScmSvnQueryProperty(PSCMRWSTATE pState, const char *pszName, char **ppszValue);
|
---|
56 | int ScmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue);
|
---|
57 | int ScmSvnDelProperty(PSCMRWSTATE pState, const char *pszName);
|
---|
58 | int ScmSvnDisplayChanges(PSCMRWSTATE pState);
|
---|
59 | int ScmSvnApplyChanges(PSCMRWSTATE pState);
|
---|
60 |
|
---|
61 | /** @} */
|
---|
62 |
|
---|
63 |
|
---|
64 | /** @name Rewriters
|
---|
65 | * @{ */
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Rewriter state.
|
---|
69 | */
|
---|
70 | typedef struct SCMRWSTATE
|
---|
71 | {
|
---|
72 | /** The filename. */
|
---|
73 | const char *pszFilename;
|
---|
74 | /** Set after the printing the first verbose message about a file under
|
---|
75 | * rewrite. */
|
---|
76 | bool fFirst;
|
---|
77 | /** The number of SVN property changes. */
|
---|
78 | size_t cSvnPropChanges;
|
---|
79 | /** Pointer to an array of SVN property changes. */
|
---|
80 | struct SCMSVNPROP *paSvnPropChanges;
|
---|
81 | } SCMRWSTATE;
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * A rewriter.
|
---|
85 | *
|
---|
86 | * This works like a stream editor, reading @a pIn, modifying it and writing it
|
---|
87 | * to @a pOut.
|
---|
88 | *
|
---|
89 | * @returns true if any changes were made, false if not.
|
---|
90 | * @param pIn The input stream.
|
---|
91 | * @param pOut The output stream.
|
---|
92 | * @param pSettings The settings.
|
---|
93 | */
|
---|
94 | typedef bool FNSCMREWRITER(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
|
---|
95 | /** Pointer to a rewriter method. */
|
---|
96 | typedef FNSCMREWRITER *PFNSCMREWRITER;
|
---|
97 |
|
---|
98 | FNSCMREWRITER rewrite_StripTrailingBlanks;
|
---|
99 | FNSCMREWRITER rewrite_ExpandTabs;
|
---|
100 | FNSCMREWRITER rewrite_ForceNativeEol;
|
---|
101 | FNSCMREWRITER rewrite_ForceLF;
|
---|
102 | FNSCMREWRITER rewrite_ForceCRLF;
|
---|
103 | FNSCMREWRITER rewrite_AdjustTrailingLines;
|
---|
104 | FNSCMREWRITER rewrite_SvnNoExecutable;
|
---|
105 | FNSCMREWRITER rewrite_SvnKeywords;
|
---|
106 | FNSCMREWRITER rewrite_Makefile_kup;
|
---|
107 | FNSCMREWRITER rewrite_Makefile_kmk;
|
---|
108 | FNSCMREWRITER rewrite_FixFlowerBoxMarkers;
|
---|
109 | FNSCMREWRITER rewrite_C_and_CPP;
|
---|
110 |
|
---|
111 | /** @} */
|
---|
112 |
|
---|
113 |
|
---|
114 | /** @name Settings
|
---|
115 | * @{ */
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Configuration entry.
|
---|
119 | */
|
---|
120 | typedef struct SCMCFGENTRY
|
---|
121 | {
|
---|
122 | /** Number of rewriters. */
|
---|
123 | size_t cRewriters;
|
---|
124 | /** Pointer to an array of rewriters. */
|
---|
125 | PFNSCMREWRITER const *papfnRewriter;
|
---|
126 | /** File pattern (simple). */
|
---|
127 | const char *pszFilePattern;
|
---|
128 | } SCMCFGENTRY;
|
---|
129 | typedef SCMCFGENTRY *PSCMCFGENTRY;
|
---|
130 | typedef SCMCFGENTRY const *PCSCMCFGENTRY;
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Source Code Massager Settings.
|
---|
135 | */
|
---|
136 | typedef struct SCMSETTINGSBASE
|
---|
137 | {
|
---|
138 | bool fConvertEol;
|
---|
139 | bool fConvertTabs;
|
---|
140 | bool fForceFinalEol;
|
---|
141 | bool fForceTrailingLine;
|
---|
142 | bool fStripTrailingBlanks;
|
---|
143 | bool fStripTrailingLines;
|
---|
144 |
|
---|
145 | /** Whether to fix C/C++ flower box section markers. */
|
---|
146 | bool fFixFlowerBoxMarkers;
|
---|
147 | /** The minimum number of blank lines we want before flowerbox markers. */
|
---|
148 | uint8_t cMinBlankLinesBeforeFlowerBoxMakers;
|
---|
149 |
|
---|
150 | /** Only process files that are part of a SVN working copy. */
|
---|
151 | bool fOnlySvnFiles;
|
---|
152 | /** Only recurse into directories containing an .svn dir. */
|
---|
153 | bool fOnlySvnDirs;
|
---|
154 | /** Set svn:eol-style if missing or incorrect. */
|
---|
155 | bool fSetSvnEol;
|
---|
156 | /** Set svn:executable according to type (unusually this means deleting it). */
|
---|
157 | bool fSetSvnExecutable;
|
---|
158 | /** Set svn:keyword if completely or partially missing. */
|
---|
159 | bool fSetSvnKeywords;
|
---|
160 | /** Tab size. */
|
---|
161 | uint8_t cchTab;
|
---|
162 | /** Optimal source code width. */
|
---|
163 | uint8_t cchWidth;
|
---|
164 | /** Only consider files matching these patterns. This is only applied to the
|
---|
165 | * base names. */
|
---|
166 | char *pszFilterFiles;
|
---|
167 | /** Filter out files matching the following patterns. This is applied to base
|
---|
168 | * names as well as the absolute paths. */
|
---|
169 | char *pszFilterOutFiles;
|
---|
170 | /** Filter out directories matching the following patterns. This is applied
|
---|
171 | * to base names as well as the absolute paths. All absolute paths ends with a
|
---|
172 | * slash and dot ("/."). */
|
---|
173 | char *pszFilterOutDirs;
|
---|
174 | } SCMSETTINGSBASE;
|
---|
175 | /** Pointer to massager settings. */
|
---|
176 | typedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * File/dir pattern + options.
|
---|
180 | */
|
---|
181 | typedef struct SCMPATRNOPTPAIR
|
---|
182 | {
|
---|
183 | char *pszPattern;
|
---|
184 | char *pszOptions;
|
---|
185 | } SCMPATRNOPTPAIR;
|
---|
186 | /** Pointer to a pattern + option pair. */
|
---|
187 | typedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
|
---|
188 |
|
---|
189 |
|
---|
190 | /** Pointer to a settings set. */
|
---|
191 | typedef struct SCMSETTINGS *PSCMSETTINGS;
|
---|
192 | /**
|
---|
193 | * Settings set.
|
---|
194 | *
|
---|
195 | * This structure is constructed from the command line arguments or any
|
---|
196 | * .scm-settings file found in a directory we recurse into. When recursing in
|
---|
197 | * and out of a directory, we push and pop a settings set for it.
|
---|
198 | *
|
---|
199 | * The .scm-settings file has two kinds of setttings, first there are the
|
---|
200 | * unqualified base settings and then there are the settings which applies to a
|
---|
201 | * set of files or directories. The former are lines with command line options.
|
---|
202 | * For the latter, the options are preceded by a string pattern and a colon.
|
---|
203 | * The pattern specifies which files (and/or directories) the options applies
|
---|
204 | * to.
|
---|
205 | *
|
---|
206 | * We parse the base options into the Base member and put the others into the
|
---|
207 | * paPairs array.
|
---|
208 | */
|
---|
209 | typedef struct SCMSETTINGS
|
---|
210 | {
|
---|
211 | /** Pointer to the setting file below us in the stack. */
|
---|
212 | PSCMSETTINGS pDown;
|
---|
213 | /** Pointer to the setting file above us in the stack. */
|
---|
214 | PSCMSETTINGS pUp;
|
---|
215 | /** File/dir patterns and their options. */
|
---|
216 | PSCMPATRNOPTPAIR paPairs;
|
---|
217 | /** The number of entires in paPairs. */
|
---|
218 | uint32_t cPairs;
|
---|
219 | /** The base settings that was read out of the file. */
|
---|
220 | SCMSETTINGSBASE Base;
|
---|
221 | } SCMSETTINGS;
|
---|
222 | /** Pointer to a const settings set. */
|
---|
223 | typedef SCMSETTINGS const *PCSCMSETTINGS;
|
---|
224 |
|
---|
225 | /** @} */
|
---|
226 |
|
---|
227 |
|
---|
228 | void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...);
|
---|
229 |
|
---|
230 | extern const char g_szTabSpaces[16+1];
|
---|
231 | extern const char g_szAsterisks[255+1];
|
---|
232 | extern const char g_szSpaces[255+1];
|
---|
233 |
|
---|
234 | RT_C_DECLS_END
|
---|
235 |
|
---|
236 | #endif
|
---|
237 |
|
---|