VirtualBox

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

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

scm: build fix

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