VirtualBox

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

Last change on this file since 69198 was 69171, checked in by vboxsync, 7 years ago

scm: License and copyright updating. [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/* $Id: scm.h 69171 2017-10-23 16:03:51Z 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 /** How to update the license. */
261 SCMLICENSE enmUpdateLicense;
262
263 /** Only process files that are part of a SVN working copy. */
264 bool fOnlySvnFiles;
265 /** Only recurse into directories containing an .svn dir. */
266 bool fOnlySvnDirs;
267 /** Set svn:eol-style if missing or incorrect. */
268 bool fSetSvnEol;
269 /** Set svn:executable according to type (unusually this means deleting it). */
270 bool fSetSvnExecutable;
271 /** Set svn:keyword if completely or partially missing. */
272 bool fSetSvnKeywords;
273 /** Tab size. */
274 uint8_t cchTab;
275 /** Optimal source code width. */
276 uint8_t cchWidth;
277 /** Only consider files matching these patterns. This is only applied to the
278 * base names. */
279 char *pszFilterFiles;
280 /** Filter out files matching the following patterns. This is applied to base
281 * names as well as the absolute paths. */
282 char *pszFilterOutFiles;
283 /** Filter out directories matching the following patterns. This is applied
284 * to base names as well as the absolute paths. All absolute paths ends with a
285 * slash and dot ("/."). */
286 char *pszFilterOutDirs;
287} SCMSETTINGSBASE;
288/** Pointer to massager settings. */
289typedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
290
291/**
292 * File/dir pattern + options.
293 */
294typedef struct SCMPATRNOPTPAIR
295{
296 char *pszPattern;
297 char *pszOptions;
298} SCMPATRNOPTPAIR;
299/** Pointer to a pattern + option pair. */
300typedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
301
302
303/** Pointer to a settings set. */
304typedef struct SCMSETTINGS *PSCMSETTINGS;
305/**
306 * Settings set.
307 *
308 * This structure is constructed from the command line arguments or any
309 * .scm-settings file found in a directory we recurse into. When recursing in
310 * and out of a directory, we push and pop a settings set for it.
311 *
312 * The .scm-settings file has two kinds of setttings, first there are the
313 * unqualified base settings and then there are the settings which applies to a
314 * set of files or directories. The former are lines with command line options.
315 * For the latter, the options are preceded by a string pattern and a colon.
316 * The pattern specifies which files (and/or directories) the options applies
317 * to.
318 *
319 * We parse the base options into the Base member and put the others into the
320 * paPairs array.
321 */
322typedef struct SCMSETTINGS
323{
324 /** Pointer to the setting file below us in the stack. */
325 PSCMSETTINGS pDown;
326 /** Pointer to the setting file above us in the stack. */
327 PSCMSETTINGS pUp;
328 /** File/dir patterns and their options. */
329 PSCMPATRNOPTPAIR paPairs;
330 /** The number of entires in paPairs. */
331 uint32_t cPairs;
332 /** The base settings that was read out of the file. */
333 SCMSETTINGSBASE Base;
334} SCMSETTINGS;
335/** Pointer to a const settings set. */
336typedef SCMSETTINGS const *PCSCMSETTINGS;
337
338/** @} */
339
340
341void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
342void ScmVerboseBanner(PSCMRWSTATE pState, int iLevel);
343bool ScmError(PSCMRWSTATE pState, int rc, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
344
345extern const char g_szTabSpaces[16+1];
346extern const char g_szAsterisks[255+1];
347extern const char g_szSpaces[255+1];
348extern uint32_t g_uYear;
349
350RT_C_DECLS_END
351
352#endif
353
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