VirtualBox

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

Last change on this file since 76451 was 76451, checked in by vboxsync, 6 years ago

scm: Added crude pass for adjusting err.h to errcore.h when possible. Currently disabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.5 KB
Line 
1/* $Id: scm.h 76451 2018-12-25 01:40:08Z 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 * Include directive type.
155 */
156typedef enum SCMINCLUDEDIR
157{
158 kScmIncludeDir_Invalid = 0, /**< Constomary invalid enum value. */
159 kScmIncludeDir_Quoted, /**< \#include \"filename.h\" */
160 kScmIncludeDir_Bracketed, /**< \#include \<filename.h\> */
161 kScmIncludeDir_Macro, /**< \#include MACRO_H */
162 kScmIncludeDir_End /**< End of valid enum values. */
163} SCMINCLUDEDIR;
164
165SCMINCLUDEDIR ScmMaybeParseCIncludeLine(PSCMRWSTATE pState, const char *pchLine, size_t cchLine,
166 const char **ppchFilename, size_t *pcchFilename);
167
168/**
169 * Checks if the given character is a valid C identifier lead character.
170 *
171 * @returns true / false.
172 * @param ch The character to inspect.
173 * @sa vbcppIsCIdentifierLeadChar
174 */
175DECLINLINE(bool) ScmIsCIdentifierLeadChar(char ch)
176{
177 return RT_C_IS_ALPHA(ch)
178 || ch == '_';
179}
180
181
182/**
183 * Checks if the given character is a valid C identifier character.
184 *
185 * @returns true / false.
186 * @param ch The character to inspect.
187 * @sa vbcppIsCIdentifierChar
188 */
189DECLINLINE(bool) scmIsCIdentifierChar(char ch)
190{
191 return RT_C_IS_ALNUM(ch)
192 || ch == '_';
193}
194
195
196/** @} */
197
198
199/** @name Rewriters
200 * @{ */
201
202/**
203 * Rewriter state.
204 */
205typedef struct SCMRWSTATE
206{
207 /** The filename. */
208 const char *pszFilename;
209 /** Set after the printing the first verbose message about a file under
210 * rewrite. */
211 bool fFirst;
212 /** Cached ScmSvnIsInWorkingCopy response. 0 indicates not known, 1 means it
213 * is in WC, -1 means it doesn't. */
214 int8_t fIsInSvnWorkingCopy;
215 /** The number of SVN property changes. */
216 size_t cSvnPropChanges;
217 /** Pointer to an array of SVN property changes. */
218 struct SCMSVNPROP *paSvnPropChanges;
219 /** For error propagation. */
220 int32_t rc;
221} SCMRWSTATE;
222
223/**
224 * A rewriter.
225 *
226 * This works like a stream editor, reading @a pIn, modifying it and writing it
227 * to @a pOut.
228 *
229 * @returns true if any changes were made, false if not.
230 * @param pIn The input stream.
231 * @param pOut The output stream.
232 * @param pSettings The settings.
233 */
234typedef bool FNSCMREWRITER(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings);
235/** Pointer to a rewriter method. */
236typedef FNSCMREWRITER *PFNSCMREWRITER;
237
238FNSCMREWRITER rewrite_StripTrailingBlanks;
239FNSCMREWRITER rewrite_ExpandTabs;
240FNSCMREWRITER rewrite_ForceNativeEol;
241FNSCMREWRITER rewrite_ForceLF;
242FNSCMREWRITER rewrite_ForceCRLF;
243FNSCMREWRITER rewrite_AdjustTrailingLines;
244FNSCMREWRITER rewrite_SvnNoExecutable;
245FNSCMREWRITER rewrite_SvnNoKeywords;
246FNSCMREWRITER rewrite_SvnNoEolStyle;
247FNSCMREWRITER rewrite_SvnBinary;
248FNSCMREWRITER rewrite_SvnKeywords;
249FNSCMREWRITER rewrite_SvnSyncProcess;
250FNSCMREWRITER rewrite_Copyright_CstyleComment;
251FNSCMREWRITER rewrite_Copyright_HashComment;
252FNSCMREWRITER rewrite_Copyright_PythonComment;
253FNSCMREWRITER rewrite_Copyright_RemComment;
254FNSCMREWRITER rewrite_Copyright_SemicolonComment;
255FNSCMREWRITER rewrite_Copyright_SqlComment;
256FNSCMREWRITER rewrite_Copyright_TickComment;
257FNSCMREWRITER rewrite_Makefile_kup;
258FNSCMREWRITER rewrite_Makefile_kmk;
259FNSCMREWRITER rewrite_FixFlowerBoxMarkers;
260FNSCMREWRITER rewrite_Fix_C_and_CPP_Todos;
261FNSCMREWRITER rewrite_Fix_Err_H;
262FNSCMREWRITER rewrite_C_and_CPP;
263
264/**
265 * Rewriter configuration.
266 */
267typedef struct SCMREWRITERCFG
268{
269 /** The rewriter function. */
270 PFNSCMREWRITER pfnRewriter;
271 /** The name of the rewriter. */
272 const char *pszName;
273} SCMREWRITERCFG;
274/** Pointer to a const rewriter config. */
275typedef SCMREWRITERCFG const *PCSCMREWRITERCFG;
276
277/** @} */
278
279
280/** @name Settings
281 * @{ */
282
283/**
284 * Configuration entry.
285 */
286typedef struct SCMCFGENTRY
287{
288 /** Number of rewriters. */
289 size_t cRewriters;
290 /** Pointer to an array of rewriters. */
291 PCSCMREWRITERCFG const *paRewriters;
292 /** Set if the entry handles binaries. */
293 bool fBinary;
294 /** File pattern (simple). */
295 const char *pszFilePattern;
296 /** Name (for treat as). */
297 const char *pszName;
298} SCMCFGENTRY;
299typedef SCMCFGENTRY *PSCMCFGENTRY;
300typedef SCMCFGENTRY const *PCSCMCFGENTRY;
301
302
303/** License update options. */
304typedef enum SCMLICENSE
305{
306 kScmLicense_LeaveAlone = 0, /**< Leave it alone. */
307 kScmLicense_OseGpl, /**< VBox OSE GPL if public. */
308 kScmLicense_OseDualGplCddl, /**< VBox OSE dual GPL & CDDL if public. */
309 kScmLicense_OseCddl, /**< VBox OSE CDDL if public. */
310 kScmLicense_Lgpl, /**< LGPL if public. */
311 kScmLicense_Mit, /**< MIT if public. */
312 kScmLicense_BasedOnMit, /**< Copyright us but based on someone else's MIT. */
313 kScmLicense_End
314} SCMLICENSE;
315
316/**
317 * Source Code Massager Settings.
318 */
319typedef struct SCMSETTINGSBASE
320{
321 bool fConvertEol;
322 bool fConvertTabs;
323 bool fForceFinalEol;
324 bool fForceTrailingLine;
325 bool fStripTrailingBlanks;
326 bool fStripTrailingLines;
327
328 /** Whether to fix C/C++ flower box section markers. */
329 bool fFixFlowerBoxMarkers;
330 /** The minimum number of blank lines we want before flowerbox markers. */
331 uint8_t cMinBlankLinesBeforeFlowerBoxMakers;
332
333 /** Whether to fix C/C++ todos. */
334 bool fFixTodos;
335 /** Whether to fix C/C++ err.h/errcore.h usage. */
336 bool fFixErrH;
337
338 /** Update the copyright year. */
339 bool fUpdateCopyrightYear;
340 /** Only external copyright holders. */
341 bool fExternalCopyright;
342 /** Whether there should be a LGPL disclaimer. */
343 bool fLgplDisclaimer;
344 /** How to update the license. */
345 SCMLICENSE enmUpdateLicense;
346
347 /** Only process files that are part of a SVN working copy. */
348 bool fOnlySvnFiles;
349 /** Only recurse into directories containing an .svn dir. */
350 bool fOnlySvnDirs;
351 /** Set svn:eol-style if missing or incorrect. */
352 bool fSetSvnEol;
353 /** Set svn:executable according to type (unusually this means deleting it). */
354 bool fSetSvnExecutable;
355 /** Set svn:keyword if completely or partially missing. */
356 bool fSetSvnKeywords;
357 /** Skip checking svn:sync-process. */
358 bool fSkipSvnSyncProcess;
359 /** Tab size. */
360 uint8_t cchTab;
361 /** Optimal source code width. */
362 uint8_t cchWidth;
363 /** Free the treat as structure. */
364 bool fFreeTreatAs;
365 /** Prematched config entry. */
366 PCSCMCFGENTRY pTreatAs;
367 /** Only consider files matching these patterns. This is only applied to the
368 * base names. */
369 char *pszFilterFiles;
370 /** Filter out files matching the following patterns. This is applied to base
371 * names as well as the absolute paths. */
372 char *pszFilterOutFiles;
373 /** Filter out directories matching the following patterns. This is applied
374 * to base names as well as the absolute paths. All absolute paths ends with a
375 * slash and dot ("/."). */
376 char *pszFilterOutDirs;
377} SCMSETTINGSBASE;
378/** Pointer to massager settings. */
379typedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
380
381/**
382 * File/dir pattern + options.
383 */
384typedef struct SCMPATRNOPTPAIR
385{
386 char *pszPattern;
387 char *pszOptions;
388 char *pszRelativeTo;
389 bool fMultiPattern;
390} SCMPATRNOPTPAIR;
391/** Pointer to a pattern + option pair. */
392typedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
393
394
395/** Pointer to a settings set. */
396typedef struct SCMSETTINGS *PSCMSETTINGS;
397/**
398 * Settings set.
399 *
400 * This structure is constructed from the command line arguments or any
401 * .scm-settings file found in a directory we recurse into. When recursing in
402 * and out of a directory, we push and pop a settings set for it.
403 *
404 * The .scm-settings file has two kinds of setttings, first there are the
405 * unqualified base settings and then there are the settings which applies to a
406 * set of files or directories. The former are lines with command line options.
407 * For the latter, the options are preceded by a string pattern and a colon.
408 * The pattern specifies which files (and/or directories) the options applies
409 * to.
410 *
411 * We parse the base options into the Base member and put the others into the
412 * paPairs array.
413 */
414typedef struct SCMSETTINGS
415{
416 /** Pointer to the setting file below us in the stack. */
417 PSCMSETTINGS pDown;
418 /** Pointer to the setting file above us in the stack. */
419 PSCMSETTINGS pUp;
420 /** File/dir patterns and their options. */
421 PSCMPATRNOPTPAIR paPairs;
422 /** The number of entires in paPairs. */
423 uint32_t cPairs;
424 /** The base settings that was read out of the file. */
425 SCMSETTINGSBASE Base;
426} SCMSETTINGS;
427/** Pointer to a const settings set. */
428typedef SCMSETTINGS const *PCSCMSETTINGS;
429
430/** @} */
431
432
433void ScmVerboseBanner(PSCMRWSTATE pState, int iLevel);
434void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
435bool ScmError(PSCMRWSTATE pState, int rc, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
436
437extern const char g_szTabSpaces[16+1];
438extern const char g_szAsterisks[255+1];
439extern const char g_szSpaces[255+1];
440extern uint32_t g_uYear;
441
442RT_C_DECLS_END
443
444#endif
445
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette