VirtualBox

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

Last change on this file since 69222 was 69215, checked in by vboxsync, 7 years ago

scm: Check for 'Contributed by' preceeding the copyright statement.

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