VirtualBox

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

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

scm: check svn:sync-process on files and parent dir.

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