VirtualBox

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

Last change on this file since 90692 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

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