VirtualBox

source: vbox/trunk/src/bldprogs/scm.h@ 69434

Last change on this file since 69434 was 69433, checked in by vboxsync, 7 years ago

scm: Reuse the subversion client context and pool, the former is very expensive to create.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1/* $Id: scm.h 69433 2017-10-27 14:49:11Z 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
24RT_C_DECLS_BEGIN
25
26/** Pointer to the rewriter state. */
27typedef struct SCMRWSTATE *PSCMRWSTATE;
28/** Pointer to const massager settings. */
29typedef struct SCMSETTINGSBASE const *PCSCMSETTINGSBASE;
30
31
32/** @name Subversion Access
33 * @{ */
34
35/**
36 * SVN property.
37 */
38typedef 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. */
48typedef SCMSVNPROP *PSCMSVNPROP;
49/** Pointer to a const SVN property. */
50typedef SCMSVNPROP const *PCSCMSVNPROP;
51
52
53void ScmSvnInit(void);
54void ScmSvnTerm(void);
55bool ScmSvnIsDirInWorkingCopy(const char *pszDir);
56bool ScmSvnIsInWorkingCopy(PSCMRWSTATE pState);
57int ScmSvnQueryProperty(PSCMRWSTATE pState, const char *pszName, char **ppszValue);
58int ScmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue);
59int ScmSvnDelProperty(PSCMRWSTATE pState, const char *pszName);
60int ScmSvnDisplayChanges(PSCMRWSTATE pState);
61int ScmSvnApplyChanges(PSCMRWSTATE pState);
62
63/** @} */
64
65
66/** @name Code Parsing
67 * @{ */
68
69/**
70 * Comment style.
71 */
72typedef enum SCMCOMMENTSTYLE
73{
74 kScmCommentStyle_Invalid = 0,
75 kScmCommentStyle_C,
76 kScmCommentStyle_Hash,
77 kScmCommentStyle_Python, /**< Same as hash, except for copyright/license. */
78 kScmCommentStyle_Semicolon,
79 kScmCommentStyle_Rem_Upper,
80 kScmCommentStyle_Rem_Lower,
81 kScmCommentStyle_Rem_Camel,
82 kScmCommentStyle_Tick,
83 kScmCommentStyle_End
84} SCMCOMMENTSTYLE;
85
86/**
87 * Comment types.
88 */
89typedef enum SCMCOMMENTTYPE
90{
91 kScmCommentType_Invalid = 0, /**< Customary invalid zero value. */
92 kScmCommentType_Line, /**< Line comment. */
93 kScmCommentType_Line_JavaDoc, /**< Line comment, JavaDoc style. */
94 kScmCommentType_Line_JavaDoc_After, /**< Line comment, JavaDoc after-member style. */
95 kScmCommentType_Line_Qt, /**< Line comment, JavaDoc style. */
96 kScmCommentType_Line_Qt_After, /**< Line comment, JavaDoc after-member style. */
97 kScmCommentType_MultiLine, /**< Multi-line comment (e.g. ansi C). */
98 kScmCommentType_MultiLine_JavaDoc, /**< Multi-line comment, JavaDoc style. */
99 kScmCommentType_MultiLine_JavaDoc_After, /**< Multi-line comment, JavaDoc after-member style. */
100 kScmCommentType_MultiLine_Qt, /**< Multi-line comment, Qt style. */
101 kScmCommentType_MultiLine_Qt_After, /**< Multi-line comment, Qt after-member style. */
102 kScmCommentType_DocString, /**< Triple quoted python doc string. */
103 kScmCommentType_End /**< Customary exclusive end value. */
104} SCMCOMMENTTYPE;
105
106
107/**
108 * Comment information.
109 */
110typedef struct SCMCOMMENTINFO
111{
112 /** Comment type. */
113 SCMCOMMENTTYPE enmType;
114 /** Start line number (0-based). */
115 uint32_t iLineStart;
116 /** Start line offset (0-based). */
117 uint32_t offStart;
118 /** End line number (0-based). */
119 uint32_t iLineEnd;
120 /** End line offset (0-based). */
121 uint32_t offEnd;
122 /** Number of blank lines before the body (@a pszBody). */
123 uint32_t cBlankLinesBefore;
124 /** Number of blank lines after the body (@a pszBody + @a cchBody). */
125 uint32_t cBlankLinesAfter;
126 /** @todo add min/max indent. Raw length. Etc. */
127} SCMCOMMENTINFO;
128/** Pointer to comment info. */
129typedef SCMCOMMENTINFO *PSCMCOMMENTINFO;
130/** Pointer to const comment info. */
131typedef SCMCOMMENTINFO const *PCSCMCOMMENTINFO;
132
133
134/**
135 * Comment enumeration callback function.
136 *
137 * @returns IPRT style status code. Failures causes immediate return. While an
138 * informational status code is saved (first one) and returned later.
139 * @param pInfo Additional comment info.
140 * @param pszBody The comment body. This is somewhat stripped.
141 * @param cchBody The comment body length.
142 * @param pvUser User callback argument.
143 */
144typedef DECLCALLBACK(int) FNSCMCOMMENTENUMERATOR(PCSCMCOMMENTINFO pInfo, const char *pszBody, size_t cchBody, void *pvUser);
145/** Poiter to a omment enumeration callback function. */
146typedef FNSCMCOMMENTENUMERATOR *PFNSCMCOMMENTENUMERATOR;
147
148int ScmEnumerateComments(PSCMSTREAM pIn, SCMCOMMENTSTYLE enmCommentStyle, PFNSCMCOMMENTENUMERATOR pfnCallback, void *pvUser);
149
150/** @} */
151
152
153/** @name Rewriters
154 * @{ */
155
156/**
157 * Rewriter state.
158 */
159typedef struct SCMRWSTATE
160{
161 /** The filename. */
162 const char *pszFilename;
163 /** Set after the printing the first verbose message about a file under
164 * rewrite. */
165 bool fFirst;
166 /** The number of SVN property changes. */
167 size_t cSvnPropChanges;
168 /** Pointer to an array of SVN property changes. */
169 struct SCMSVNPROP *paSvnPropChanges;
170 /** For error propagation. */
171 int32_t rc;
172} SCMRWSTATE;
173
174/**
175 * A rewriter.
176 *
177 * This works like a stream editor, reading @a pIn, modifying it and writing it
178 * to @a pOut.
179 *
180 * @returns true if any changes were made, false if not.
181 * @param pIn The input stream.
182 * @param pOut The output stream.
183 * @param pSettings The settings.
184 */
185typedef bool FNSCMREWRITER(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
186/** Pointer to a rewriter method. */
187typedef FNSCMREWRITER *PFNSCMREWRITER;
188
189FNSCMREWRITER rewrite_StripTrailingBlanks;
190FNSCMREWRITER rewrite_ExpandTabs;
191FNSCMREWRITER rewrite_ForceNativeEol;
192FNSCMREWRITER rewrite_ForceLF;
193FNSCMREWRITER rewrite_ForceCRLF;
194FNSCMREWRITER rewrite_AdjustTrailingLines;
195FNSCMREWRITER rewrite_SvnNoExecutable;
196FNSCMREWRITER rewrite_SvnNoKeyword;
197FNSCMREWRITER rewrite_SvnNoEolStyle;
198FNSCMREWRITER rewrite_SvnBinary;
199FNSCMREWRITER rewrite_SvnKeywords;
200FNSCMREWRITER rewrite_Copyright_CstyleComment;
201FNSCMREWRITER rewrite_Copyright_HashComment;
202FNSCMREWRITER rewrite_Copyright_PythonComment;
203FNSCMREWRITER rewrite_Copyright_RemComment;
204FNSCMREWRITER rewrite_Copyright_SemicolonComment;
205FNSCMREWRITER rewrite_Copyright_TickComment;
206FNSCMREWRITER rewrite_Makefile_kup;
207FNSCMREWRITER rewrite_Makefile_kmk;
208FNSCMREWRITER rewrite_FixFlowerBoxMarkers;
209FNSCMREWRITER rewrite_Fix_C_and_CPP_Todos;
210FNSCMREWRITER rewrite_C_and_CPP;
211
212/** @} */
213
214
215/** @name Settings
216 * @{ */
217
218/**
219 * Configuration entry.
220 */
221typedef struct SCMCFGENTRY
222{
223 /** Number of rewriters. */
224 size_t cRewriters;
225 /** Pointer to an array of rewriters. */
226 PFNSCMREWRITER const *papfnRewriter;
227 /** Set if the entry handles binaries. */
228 bool fBinary;
229 /** File pattern (simple). */
230 const char *pszFilePattern;
231} SCMCFGENTRY;
232typedef SCMCFGENTRY *PSCMCFGENTRY;
233typedef SCMCFGENTRY const *PCSCMCFGENTRY;
234
235
236/** License update options. */
237typedef enum SCMLICENSE
238{
239 kScmLicense_LeaveAlone = 0, /**< Leave it alone. */
240 kScmLicense_OseGpl, /**< VBox OSE GPL if public. */
241 kScmLicense_OseDualGplCddl, /**< VBox OSE dual GPL & CDDL if public. */
242 kScmLicense_OseCddl, /**< VBox OSE CDDL if public. */
243 kScmLicense_Lgpl, /**< LGPL if public. */
244 kScmLicense_Mit, /**< MIT if public. */
245 kScmLicense_BasedOnMit, /**< Copyright us but based on someone else's MIT . */
246 kScmLicense_End
247} SCMLICENSE;
248
249/**
250 * Source Code Massager Settings.
251 */
252typedef struct SCMSETTINGSBASE
253{
254 bool fConvertEol;
255 bool fConvertTabs;
256 bool fForceFinalEol;
257 bool fForceTrailingLine;
258 bool fStripTrailingBlanks;
259 bool fStripTrailingLines;
260
261 /** Whether to fix C/C++ flower box section markers. */
262 bool fFixFlowerBoxMarkers;
263 /** The minimum number of blank lines we want before flowerbox markers. */
264 uint8_t cMinBlankLinesBeforeFlowerBoxMakers;
265
266 /** Whether to fix C/C++ todos. */
267 bool fFixTodos;
268
269 /** Update the copyright year. */
270 bool fUpdateCopyrightYear;
271 /** Only external copyright holders. */
272 bool fExternalCopyright;
273 /** Whether there should be a LGPL disclaimer. */
274 bool fLgplDisclaimer;
275 /** How to update the license. */
276 SCMLICENSE enmUpdateLicense;
277
278 /** Only process files that are part of a SVN working copy. */
279 bool fOnlySvnFiles;
280 /** Only recurse into directories containing an .svn dir. */
281 bool fOnlySvnDirs;
282 /** Set svn:eol-style if missing or incorrect. */
283 bool fSetSvnEol;
284 /** Set svn:executable according to type (unusually this means deleting it). */
285 bool fSetSvnExecutable;
286 /** Set svn:keyword if completely or partially missing. */
287 bool fSetSvnKeywords;
288 /** Tab size. */
289 uint8_t cchTab;
290 /** Optimal source code width. */
291 uint8_t cchWidth;
292 /** Treat the file as if it had the given name (for finding SCMCFGENTRY). */
293 char *pszTreatAsName;
294 /** Only consider files matching these patterns. This is only applied to the
295 * base names. */
296 char *pszFilterFiles;
297 /** Filter out files matching the following patterns. This is applied to base
298 * names as well as the absolute paths. */
299 char *pszFilterOutFiles;
300 /** Filter out directories matching the following patterns. This is applied
301 * to base names as well as the absolute paths. All absolute paths ends with a
302 * slash and dot ("/."). */
303 char *pszFilterOutDirs;
304} SCMSETTINGSBASE;
305/** Pointer to massager settings. */
306typedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
307
308/**
309 * File/dir pattern + options.
310 */
311typedef struct SCMPATRNOPTPAIR
312{
313 char *pszPattern;
314 char *pszOptions;
315 char *pszRelativeTo;
316} SCMPATRNOPTPAIR;
317/** Pointer to a pattern + option pair. */
318typedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
319
320
321/** Pointer to a settings set. */
322typedef struct SCMSETTINGS *PSCMSETTINGS;
323/**
324 * Settings set.
325 *
326 * This structure is constructed from the command line arguments or any
327 * .scm-settings file found in a directory we recurse into. When recursing in
328 * and out of a directory, we push and pop a settings set for it.
329 *
330 * The .scm-settings file has two kinds of setttings, first there are the
331 * unqualified base settings and then there are the settings which applies to a
332 * set of files or directories. The former are lines with command line options.
333 * For the latter, the options are preceded by a string pattern and a colon.
334 * The pattern specifies which files (and/or directories) the options applies
335 * to.
336 *
337 * We parse the base options into the Base member and put the others into the
338 * paPairs array.
339 */
340typedef struct SCMSETTINGS
341{
342 /** Pointer to the setting file below us in the stack. */
343 PSCMSETTINGS pDown;
344 /** Pointer to the setting file above us in the stack. */
345 PSCMSETTINGS pUp;
346 /** File/dir patterns and their options. */
347 PSCMPATRNOPTPAIR paPairs;
348 /** The number of entires in paPairs. */
349 uint32_t cPairs;
350 /** The base settings that was read out of the file. */
351 SCMSETTINGSBASE Base;
352} SCMSETTINGS;
353/** Pointer to a const settings set. */
354typedef SCMSETTINGS const *PCSCMSETTINGS;
355
356/** @} */
357
358
359void ScmVerboseBanner(PSCMRWSTATE pState, int iLevel);
360void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
361bool ScmError(PSCMRWSTATE pState, int rc, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
362
363extern const char g_szTabSpaces[16+1];
364extern const char g_szAsterisks[255+1];
365extern const char g_szSpaces[255+1];
366extern uint32_t g_uYear;
367
368RT_C_DECLS_END
369
370#endif
371
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