VirtualBox

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

Last change on this file since 69311 was 69295, checked in by vboxsync, 7 years ago

scm: Added --lgpl-disclaimer options (checking not yet implemented).

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