VirtualBox

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

Last change on this file since 96751 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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