VirtualBox

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

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

scm,asm*watcom*.h: Added scm option to omit the #pragma once for the multipass watcom inline assembly files. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.8 KB
Line 
1/* $Id: scm.h 76512 2018-12-30 05:14: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_FixHeaderGuards;
263FNSCMREWRITER rewrite_C_and_CPP;
264
265/**
266 * Rewriter configuration.
267 */
268typedef struct SCMREWRITERCFG
269{
270 /** The rewriter function. */
271 PFNSCMREWRITER pfnRewriter;
272 /** The name of the rewriter. */
273 const char *pszName;
274} SCMREWRITERCFG;
275/** Pointer to a const rewriter config. */
276typedef SCMREWRITERCFG const *PCSCMREWRITERCFG;
277
278/** @} */
279
280
281/** @name Settings
282 * @{ */
283
284/**
285 * Configuration entry.
286 */
287typedef struct SCMCFGENTRY
288{
289 /** Number of rewriters. */
290 size_t cRewriters;
291 /** Pointer to an array of rewriters. */
292 PCSCMREWRITERCFG const *paRewriters;
293 /** Set if the entry handles binaries. */
294 bool fBinary;
295 /** File pattern (simple). */
296 const char *pszFilePattern;
297 /** Name (for treat as). */
298 const char *pszName;
299} SCMCFGENTRY;
300typedef SCMCFGENTRY *PSCMCFGENTRY;
301typedef SCMCFGENTRY const *PCSCMCFGENTRY;
302
303
304/** License update options. */
305typedef enum SCMLICENSE
306{
307 kScmLicense_LeaveAlone = 0, /**< Leave it alone. */
308 kScmLicense_OseGpl, /**< VBox OSE GPL if public. */
309 kScmLicense_OseDualGplCddl, /**< VBox OSE dual GPL & CDDL if public. */
310 kScmLicense_OseCddl, /**< VBox OSE CDDL if public. */
311 kScmLicense_Lgpl, /**< LGPL if public. */
312 kScmLicense_Mit, /**< MIT if public. */
313 kScmLicense_BasedOnMit, /**< Copyright us but based on someone else's MIT. */
314 kScmLicense_End
315} SCMLICENSE;
316
317/**
318 * Source Code Massager Settings.
319 */
320typedef struct SCMSETTINGSBASE
321{
322 bool fConvertEol;
323 bool fConvertTabs;
324 bool fForceFinalEol;
325 bool fForceTrailingLine;
326 bool fStripTrailingBlanks;
327 bool fStripTrailingLines;
328
329 /** Whether to fix C/C++ flower box section markers. */
330 bool fFixFlowerBoxMarkers;
331 /** The minimum number of blank lines we want before flowerbox markers. */
332 uint8_t cMinBlankLinesBeforeFlowerBoxMakers;
333
334 /** Whether to fix C/C++ header guards and \#pragma once directives. */
335 bool fFixHeaderGuards;
336 /** Whether to include a pragma once statement with the header guard. */
337 bool fPragmaOnce;
338
339 /** Whether to fix C/C++ todos. */
340 bool fFixTodos;
341 /** Whether to fix C/C++ err.h/errcore.h usage. */
342 bool fFixErrH;
343
344 /** Update the copyright year. */
345 bool fUpdateCopyrightYear;
346 /** Only external copyright holders. */
347 bool fExternalCopyright;
348 /** Whether there should be a LGPL disclaimer. */
349 bool fLgplDisclaimer;
350 /** How to update the license. */
351 SCMLICENSE enmUpdateLicense;
352
353 /** Only process files that are part of a SVN working copy. */
354 bool fOnlySvnFiles;
355 /** Only recurse into directories containing an .svn dir. */
356 bool fOnlySvnDirs;
357 /** Set svn:eol-style if missing or incorrect. */
358 bool fSetSvnEol;
359 /** Set svn:executable according to type (unusually this means deleting it). */
360 bool fSetSvnExecutable;
361 /** Set svn:keyword if completely or partially missing. */
362 bool fSetSvnKeywords;
363 /** Skip checking svn:sync-process. */
364 bool fSkipSvnSyncProcess;
365 /** Tab size. */
366 uint8_t cchTab;
367 /** Optimal source code width. */
368 uint8_t cchWidth;
369 /** Free the treat as structure. */
370 bool fFreeTreatAs;
371 /** Prematched config entry. */
372 PCSCMCFGENTRY pTreatAs;
373 /** Only consider files matching these patterns. This is only applied to the
374 * base names. */
375 char *pszFilterFiles;
376 /** Filter out files matching the following patterns. This is applied to base
377 * names as well as the absolute paths. */
378 char *pszFilterOutFiles;
379 /** Filter out directories matching the following patterns. This is applied
380 * to base names as well as the absolute paths. All absolute paths ends with a
381 * slash and dot ("/."). */
382 char *pszFilterOutDirs;
383} SCMSETTINGSBASE;
384/** Pointer to massager settings. */
385typedef SCMSETTINGSBASE *PSCMSETTINGSBASE;
386
387/**
388 * File/dir pattern + options.
389 */
390typedef struct SCMPATRNOPTPAIR
391{
392 char *pszPattern;
393 char *pszOptions;
394 char *pszRelativeTo;
395 bool fMultiPattern;
396} SCMPATRNOPTPAIR;
397/** Pointer to a pattern + option pair. */
398typedef SCMPATRNOPTPAIR *PSCMPATRNOPTPAIR;
399
400
401/** Pointer to a settings set. */
402typedef struct SCMSETTINGS *PSCMSETTINGS;
403/**
404 * Settings set.
405 *
406 * This structure is constructed from the command line arguments or any
407 * .scm-settings file found in a directory we recurse into. When recursing in
408 * and out of a directory, we push and pop a settings set for it.
409 *
410 * The .scm-settings file has two kinds of setttings, first there are the
411 * unqualified base settings and then there are the settings which applies to a
412 * set of files or directories. The former are lines with command line options.
413 * For the latter, the options are preceded by a string pattern and a colon.
414 * The pattern specifies which files (and/or directories) the options applies
415 * to.
416 *
417 * We parse the base options into the Base member and put the others into the
418 * paPairs array.
419 */
420typedef struct SCMSETTINGS
421{
422 /** Pointer to the setting file below us in the stack. */
423 PSCMSETTINGS pDown;
424 /** Pointer to the setting file above us in the stack. */
425 PSCMSETTINGS pUp;
426 /** File/dir patterns and their options. */
427 PSCMPATRNOPTPAIR paPairs;
428 /** The number of entires in paPairs. */
429 uint32_t cPairs;
430 /** The base settings that was read out of the file. */
431 SCMSETTINGSBASE Base;
432} SCMSETTINGS;
433/** Pointer to a const settings set. */
434typedef SCMSETTINGS const *PCSCMSETTINGS;
435
436/** @} */
437
438
439void ScmVerboseBanner(PSCMRWSTATE pState, int iLevel);
440void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
441bool ScmError(PSCMRWSTATE pState, int rc, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
442
443extern const char g_szTabSpaces[16+1];
444extern const char g_szAsterisks[255+1];
445extern const char g_szSpaces[255+1];
446extern uint32_t g_uYear;
447
448RT_C_DECLS_END
449
450#endif
451
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