1 | /* $Id: scm.cpp 63559 2016-08-16 14:00:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase / Tool - Source Code Massager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2016 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 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include <iprt/assert.h>
|
---|
23 | #include <iprt/ctype.h>
|
---|
24 | #include <iprt/dir.h>
|
---|
25 | #include <iprt/env.h>
|
---|
26 | #include <iprt/file.h>
|
---|
27 | #include <iprt/err.h>
|
---|
28 | #include <iprt/getopt.h>
|
---|
29 | #include <iprt/initterm.h>
|
---|
30 | #include <iprt/mem.h>
|
---|
31 | #include <iprt/message.h>
|
---|
32 | #include <iprt/param.h>
|
---|
33 | #include <iprt/path.h>
|
---|
34 | #include <iprt/process.h>
|
---|
35 | #include <iprt/stream.h>
|
---|
36 | #include <iprt/string.h>
|
---|
37 |
|
---|
38 | #include "scm.h"
|
---|
39 | #include "scmdiff.h"
|
---|
40 |
|
---|
41 |
|
---|
42 | /*********************************************************************************************************************************
|
---|
43 | * Defined Constants And Macros *
|
---|
44 | *********************************************************************************************************************************/
|
---|
45 | /** The name of the settings files. */
|
---|
46 | #define SCM_SETTINGS_FILENAME ".scm-settings"
|
---|
47 |
|
---|
48 |
|
---|
49 | /*********************************************************************************************************************************
|
---|
50 | * Structures and Typedefs *
|
---|
51 | *********************************************************************************************************************************/
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Option identifiers.
|
---|
55 | *
|
---|
56 | * @note The first chunk, down to SCMOPT_TAB_SIZE, are alternately set &
|
---|
57 | * clear. So, the option setting a flag (boolean) will have an even
|
---|
58 | * number and the one clearing it will have an odd number.
|
---|
59 | * @note Down to SCMOPT_LAST_SETTINGS corresponds exactly to SCMSETTINGSBASE.
|
---|
60 | */
|
---|
61 | typedef enum SCMOPT
|
---|
62 | {
|
---|
63 | SCMOPT_CONVERT_EOL = 10000,
|
---|
64 | SCMOPT_NO_CONVERT_EOL,
|
---|
65 | SCMOPT_CONVERT_TABS,
|
---|
66 | SCMOPT_NO_CONVERT_TABS,
|
---|
67 | SCMOPT_FORCE_FINAL_EOL,
|
---|
68 | SCMOPT_NO_FORCE_FINAL_EOL,
|
---|
69 | SCMOPT_FORCE_TRAILING_LINE,
|
---|
70 | SCMOPT_NO_FORCE_TRAILING_LINE,
|
---|
71 | SCMOPT_STRIP_TRAILING_BLANKS,
|
---|
72 | SCMOPT_NO_STRIP_TRAILING_BLANKS,
|
---|
73 | SCMOPT_STRIP_TRAILING_LINES,
|
---|
74 | SCMOPT_NO_STRIP_TRAILING_LINES,
|
---|
75 | SCMOPT_FIX_FLOWER_BOX_MARKERS,
|
---|
76 | SCMOPT_NO_FIX_FLOWER_BOX_MARKERS,
|
---|
77 | SCMOPT_FIX_TODOS,
|
---|
78 | SCMOPT_NO_FIX_TODOS,
|
---|
79 | SCMOPT_MIN_BLANK_LINES_BEFORE_FLOWER_BOX_MARKERS,
|
---|
80 | SCMOPT_ONLY_SVN_DIRS,
|
---|
81 | SCMOPT_NOT_ONLY_SVN_DIRS,
|
---|
82 | SCMOPT_ONLY_SVN_FILES,
|
---|
83 | SCMOPT_NOT_ONLY_SVN_FILES,
|
---|
84 | SCMOPT_SET_SVN_EOL,
|
---|
85 | SCMOPT_DONT_SET_SVN_EOL,
|
---|
86 | SCMOPT_SET_SVN_EXECUTABLE,
|
---|
87 | SCMOPT_DONT_SET_SVN_EXECUTABLE,
|
---|
88 | SCMOPT_SET_SVN_KEYWORDS,
|
---|
89 | SCMOPT_DONT_SET_SVN_KEYWORDS,
|
---|
90 | SCMOPT_TAB_SIZE,
|
---|
91 | SCMOPT_WIDTH,
|
---|
92 | SCMOPT_FILTER_OUT_DIRS,
|
---|
93 | SCMOPT_FILTER_FILES,
|
---|
94 | SCMOPT_FILTER_OUT_FILES,
|
---|
95 | SCMOPT_LAST_SETTINGS = SCMOPT_FILTER_OUT_FILES,
|
---|
96 | //
|
---|
97 | SCMOPT_DIFF_IGNORE_EOL,
|
---|
98 | SCMOPT_DIFF_NO_IGNORE_EOL,
|
---|
99 | SCMOPT_DIFF_IGNORE_SPACE,
|
---|
100 | SCMOPT_DIFF_NO_IGNORE_SPACE,
|
---|
101 | SCMOPT_DIFF_IGNORE_LEADING_SPACE,
|
---|
102 | SCMOPT_DIFF_NO_IGNORE_LEADING_SPACE,
|
---|
103 | SCMOPT_DIFF_IGNORE_TRAILING_SPACE,
|
---|
104 | SCMOPT_DIFF_NO_IGNORE_TRAILING_SPACE,
|
---|
105 | SCMOPT_DIFF_SPECIAL_CHARS,
|
---|
106 | SCMOPT_DIFF_NO_SPECIAL_CHARS,
|
---|
107 | SCMOPT_END
|
---|
108 | } SCMOPT;
|
---|
109 |
|
---|
110 |
|
---|
111 | /*********************************************************************************************************************************
|
---|
112 | * Global Variables *
|
---|
113 | *********************************************************************************************************************************/
|
---|
114 | const char g_szTabSpaces[16+1] = " ";
|
---|
115 | const char g_szAsterisks[255+1] =
|
---|
116 | "****************************************************************************************************"
|
---|
117 | "****************************************************************************************************"
|
---|
118 | "*******************************************************";
|
---|
119 | const char g_szSpaces[255+1] =
|
---|
120 | " "
|
---|
121 | " "
|
---|
122 | " ";
|
---|
123 | static const char g_szProgName[] = "scm";
|
---|
124 | static const char *g_pszChangedSuff = "";
|
---|
125 | static bool g_fDryRun = true;
|
---|
126 | static bool g_fDiffSpecialChars = true;
|
---|
127 | static bool g_fDiffIgnoreEol = false;
|
---|
128 | static bool g_fDiffIgnoreLeadingWS = false;
|
---|
129 | static bool g_fDiffIgnoreTrailingWS = false;
|
---|
130 | static int g_iVerbosity = 2;//99; //0;
|
---|
131 |
|
---|
132 | /** The global settings. */
|
---|
133 | static SCMSETTINGSBASE const g_Defaults =
|
---|
134 | {
|
---|
135 | /* .fConvertEol = */ true,
|
---|
136 | /* .fConvertTabs = */ true,
|
---|
137 | /* .fForceFinalEol = */ true,
|
---|
138 | /* .fForceTrailingLine = */ false,
|
---|
139 | /* .fStripTrailingBlanks = */ true,
|
---|
140 | /* .fStripTrailingLines = */ true,
|
---|
141 | /* .fFixFlowerBoxMarkers = */ true,
|
---|
142 | /* .cMinBlankLinesBeforeFlowerBoxMakers = */ 2,
|
---|
143 | /* .fFixTodos = */ true,
|
---|
144 | /* .fOnlySvnFiles = */ false,
|
---|
145 | /* .fOnlySvnDirs = */ false,
|
---|
146 | /* .fSetSvnEol = */ false,
|
---|
147 | /* .fSetSvnExecutable = */ false,
|
---|
148 | /* .fSetSvnKeywords = */ false,
|
---|
149 | /* .cchTab = */ 8,
|
---|
150 | /* .cchWidth = */ 130,
|
---|
151 | /* .pszFilterFiles = */ (char *)"",
|
---|
152 | /* .pszFilterOutFiles = */ (char *)"*.exe|*.com|20*-*-*.log",
|
---|
153 | /* .pszFilterOutDirs = */ (char *)".svn|.hg|.git|CVS",
|
---|
154 | };
|
---|
155 |
|
---|
156 | /** Option definitions for the base settings. */
|
---|
157 | static RTGETOPTDEF g_aScmOpts[] =
|
---|
158 | {
|
---|
159 | { "--convert-eol", SCMOPT_CONVERT_EOL, RTGETOPT_REQ_NOTHING },
|
---|
160 | { "--no-convert-eol", SCMOPT_NO_CONVERT_EOL, RTGETOPT_REQ_NOTHING },
|
---|
161 | { "--convert-tabs", SCMOPT_CONVERT_TABS, RTGETOPT_REQ_NOTHING },
|
---|
162 | { "--no-convert-tabs", SCMOPT_NO_CONVERT_TABS, RTGETOPT_REQ_NOTHING },
|
---|
163 | { "--force-final-eol", SCMOPT_FORCE_FINAL_EOL, RTGETOPT_REQ_NOTHING },
|
---|
164 | { "--no-force-final-eol", SCMOPT_NO_FORCE_FINAL_EOL, RTGETOPT_REQ_NOTHING },
|
---|
165 | { "--force-trailing-line", SCMOPT_FORCE_TRAILING_LINE, RTGETOPT_REQ_NOTHING },
|
---|
166 | { "--no-force-trailing-line", SCMOPT_NO_FORCE_TRAILING_LINE, RTGETOPT_REQ_NOTHING },
|
---|
167 | { "--strip-trailing-blanks", SCMOPT_STRIP_TRAILING_BLANKS, RTGETOPT_REQ_NOTHING },
|
---|
168 | { "--no-strip-trailing-blanks", SCMOPT_NO_STRIP_TRAILING_BLANKS, RTGETOPT_REQ_NOTHING },
|
---|
169 | { "--strip-trailing-lines", SCMOPT_STRIP_TRAILING_LINES, RTGETOPT_REQ_NOTHING },
|
---|
170 | { "--strip-no-trailing-lines", SCMOPT_NO_STRIP_TRAILING_LINES, RTGETOPT_REQ_NOTHING },
|
---|
171 | { "--min-blank-lines-before-flower-box-makers", SCMOPT_FIX_FLOWER_BOX_MARKERS, RTGETOPT_REQ_UINT8 },
|
---|
172 | { "--fix-flower-box-markers", SCMOPT_FIX_FLOWER_BOX_MARKERS, RTGETOPT_REQ_NOTHING },
|
---|
173 | { "--no-fix-flower-box-markers", SCMOPT_NO_FIX_FLOWER_BOX_MARKERS, RTGETOPT_REQ_NOTHING },
|
---|
174 | { "--fix-todos", SCMOPT_FIX_TODOS, RTGETOPT_REQ_NOTHING },
|
---|
175 | { "--no-fix-todos", SCMOPT_NO_FIX_TODOS, RTGETOPT_REQ_NOTHING },
|
---|
176 | { "--only-svn-dirs", SCMOPT_ONLY_SVN_DIRS, RTGETOPT_REQ_NOTHING },
|
---|
177 | { "--not-only-svn-dirs", SCMOPT_NOT_ONLY_SVN_DIRS, RTGETOPT_REQ_NOTHING },
|
---|
178 | { "--only-svn-files", SCMOPT_ONLY_SVN_FILES, RTGETOPT_REQ_NOTHING },
|
---|
179 | { "--not-only-svn-files", SCMOPT_NOT_ONLY_SVN_FILES, RTGETOPT_REQ_NOTHING },
|
---|
180 | { "--set-svn-eol", SCMOPT_SET_SVN_EOL, RTGETOPT_REQ_NOTHING },
|
---|
181 | { "--dont-set-svn-eol", SCMOPT_DONT_SET_SVN_EOL, RTGETOPT_REQ_NOTHING },
|
---|
182 | { "--set-svn-executable", SCMOPT_SET_SVN_EXECUTABLE, RTGETOPT_REQ_NOTHING },
|
---|
183 | { "--dont-set-svn-executable", SCMOPT_DONT_SET_SVN_EXECUTABLE, RTGETOPT_REQ_NOTHING },
|
---|
184 | { "--set-svn-keywords", SCMOPT_SET_SVN_KEYWORDS, RTGETOPT_REQ_NOTHING },
|
---|
185 | { "--dont-set-svn-keywords", SCMOPT_DONT_SET_SVN_KEYWORDS, RTGETOPT_REQ_NOTHING },
|
---|
186 | { "--tab-size", SCMOPT_TAB_SIZE, RTGETOPT_REQ_UINT8 },
|
---|
187 | { "--width", SCMOPT_WIDTH, RTGETOPT_REQ_UINT8 },
|
---|
188 | { "--filter-out-dirs", SCMOPT_FILTER_OUT_DIRS, RTGETOPT_REQ_STRING },
|
---|
189 | { "--filter-files", SCMOPT_FILTER_FILES, RTGETOPT_REQ_STRING },
|
---|
190 | { "--filter-out-files", SCMOPT_FILTER_OUT_FILES, RTGETOPT_REQ_STRING },
|
---|
191 | };
|
---|
192 |
|
---|
193 | /** Consider files matching the following patterns (base names only). */
|
---|
194 | static const char *g_pszFileFilter = NULL;
|
---|
195 |
|
---|
196 | static PFNSCMREWRITER const g_aRewritersFor_Makefile_kup[] =
|
---|
197 | {
|
---|
198 | rewrite_SvnNoExecutable,
|
---|
199 | rewrite_Makefile_kup
|
---|
200 | };
|
---|
201 |
|
---|
202 | static PFNSCMREWRITER const g_aRewritersFor_Makefile_kmk[] =
|
---|
203 | {
|
---|
204 | rewrite_ForceNativeEol,
|
---|
205 | rewrite_StripTrailingBlanks,
|
---|
206 | rewrite_AdjustTrailingLines,
|
---|
207 | rewrite_SvnNoExecutable,
|
---|
208 | rewrite_SvnKeywords,
|
---|
209 | rewrite_Makefile_kmk
|
---|
210 | };
|
---|
211 |
|
---|
212 | static PFNSCMREWRITER const g_aRewritersFor_C_and_CPP[] =
|
---|
213 | {
|
---|
214 | rewrite_ForceNativeEol,
|
---|
215 | rewrite_ExpandTabs,
|
---|
216 | rewrite_StripTrailingBlanks,
|
---|
217 | rewrite_AdjustTrailingLines,
|
---|
218 | rewrite_SvnNoExecutable,
|
---|
219 | rewrite_SvnKeywords,
|
---|
220 | rewrite_FixFlowerBoxMarkers,
|
---|
221 | rewrite_Fix_C_and_CPP_Todos,
|
---|
222 | rewrite_C_and_CPP
|
---|
223 | };
|
---|
224 |
|
---|
225 | static PFNSCMREWRITER const g_aRewritersFor_H_and_HPP[] =
|
---|
226 | {
|
---|
227 | rewrite_ForceNativeEol,
|
---|
228 | rewrite_ExpandTabs,
|
---|
229 | rewrite_StripTrailingBlanks,
|
---|
230 | rewrite_AdjustTrailingLines,
|
---|
231 | rewrite_SvnNoExecutable,
|
---|
232 | rewrite_C_and_CPP
|
---|
233 | };
|
---|
234 |
|
---|
235 | static PFNSCMREWRITER const g_aRewritersFor_RC[] =
|
---|
236 | {
|
---|
237 | rewrite_ForceNativeEol,
|
---|
238 | rewrite_ExpandTabs,
|
---|
239 | rewrite_StripTrailingBlanks,
|
---|
240 | rewrite_AdjustTrailingLines,
|
---|
241 | rewrite_SvnNoExecutable,
|
---|
242 | rewrite_SvnKeywords
|
---|
243 | };
|
---|
244 |
|
---|
245 | static PFNSCMREWRITER const g_aRewritersFor_DEF[] =
|
---|
246 | {
|
---|
247 | rewrite_ForceNativeEol,
|
---|
248 | rewrite_ExpandTabs,
|
---|
249 | rewrite_StripTrailingBlanks,
|
---|
250 | rewrite_AdjustTrailingLines,
|
---|
251 | rewrite_SvnNoExecutable,
|
---|
252 | rewrite_SvnKeywords
|
---|
253 | };
|
---|
254 |
|
---|
255 | static PFNSCMREWRITER const g_aRewritersFor_ShellScripts[] =
|
---|
256 | {
|
---|
257 | rewrite_ForceLF,
|
---|
258 | rewrite_ExpandTabs,
|
---|
259 | rewrite_StripTrailingBlanks
|
---|
260 | };
|
---|
261 |
|
---|
262 | static PFNSCMREWRITER const g_aRewritersFor_BatchFiles[] =
|
---|
263 | {
|
---|
264 | rewrite_ForceCRLF,
|
---|
265 | rewrite_ExpandTabs,
|
---|
266 | rewrite_StripTrailingBlanks
|
---|
267 | };
|
---|
268 |
|
---|
269 | static PFNSCMREWRITER const g_aRewritersFor_SedScripts[] =
|
---|
270 | {
|
---|
271 | rewrite_ForceLF,
|
---|
272 | rewrite_ExpandTabs,
|
---|
273 | rewrite_StripTrailingBlanks
|
---|
274 | };
|
---|
275 |
|
---|
276 | static PFNSCMREWRITER const g_aRewritersFor_Python[] =
|
---|
277 | {
|
---|
278 | /** @todo rewrite_ForceLFIfExecutable */
|
---|
279 | rewrite_ExpandTabs,
|
---|
280 | rewrite_StripTrailingBlanks,
|
---|
281 | rewrite_AdjustTrailingLines,
|
---|
282 | rewrite_SvnKeywords
|
---|
283 | };
|
---|
284 |
|
---|
285 |
|
---|
286 | static SCMCFGENTRY const g_aConfigs[] =
|
---|
287 | {
|
---|
288 | { RT_ELEMENTS(g_aRewritersFor_Makefile_kup), &g_aRewritersFor_Makefile_kup[0], "Makefile.kup" },
|
---|
289 | { RT_ELEMENTS(g_aRewritersFor_Makefile_kmk), &g_aRewritersFor_Makefile_kmk[0], "Makefile.kmk|Config.kmk" },
|
---|
290 | { RT_ELEMENTS(g_aRewritersFor_C_and_CPP), &g_aRewritersFor_C_and_CPP[0], "*.c|*.cpp|*.C|*.CPP|*.cxx|*.cc|*.m|*.mm" },
|
---|
291 | { RT_ELEMENTS(g_aRewritersFor_H_and_HPP), &g_aRewritersFor_H_and_HPP[0], "*.h|*.hpp" },
|
---|
292 | { RT_ELEMENTS(g_aRewritersFor_RC), &g_aRewritersFor_RC[0], "*.rc" },
|
---|
293 | { RT_ELEMENTS(g_aRewritersFor_DEF), &g_aRewritersFor_DEF[0], "*.def" },
|
---|
294 | { RT_ELEMENTS(g_aRewritersFor_ShellScripts), &g_aRewritersFor_ShellScripts[0], "*.sh|configure" },
|
---|
295 | { RT_ELEMENTS(g_aRewritersFor_BatchFiles), &g_aRewritersFor_BatchFiles[0], "*.bat|*.cmd|*.btm|*.vbs|*.ps1" },
|
---|
296 | { RT_ELEMENTS(g_aRewritersFor_SedScripts), &g_aRewritersFor_SedScripts[0], "*.sed" },
|
---|
297 | { RT_ELEMENTS(g_aRewritersFor_Python), &g_aRewritersFor_Python[0], "*.py" },
|
---|
298 | };
|
---|
299 |
|
---|
300 |
|
---|
301 |
|
---|
302 | /* -=-=-=-=-=- settings -=-=-=-=-=- */
|
---|
303 |
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Init a settings structure with settings from @a pSrc.
|
---|
307 | *
|
---|
308 | * @returns IPRT status code
|
---|
309 | * @param pSettings The settings.
|
---|
310 | * @param pSrc The source settings.
|
---|
311 | */
|
---|
312 | static int scmSettingsBaseInitAndCopy(PSCMSETTINGSBASE pSettings, PCSCMSETTINGSBASE pSrc)
|
---|
313 | {
|
---|
314 | *pSettings = *pSrc;
|
---|
315 |
|
---|
316 | int rc = RTStrDupEx(&pSettings->pszFilterFiles, pSrc->pszFilterFiles);
|
---|
317 | if (RT_SUCCESS(rc))
|
---|
318 | {
|
---|
319 | rc = RTStrDupEx(&pSettings->pszFilterOutFiles, pSrc->pszFilterOutFiles);
|
---|
320 | if (RT_SUCCESS(rc))
|
---|
321 | {
|
---|
322 | rc = RTStrDupEx(&pSettings->pszFilterOutDirs, pSrc->pszFilterOutDirs);
|
---|
323 | if (RT_SUCCESS(rc))
|
---|
324 | return VINF_SUCCESS;
|
---|
325 |
|
---|
326 | RTStrFree(pSettings->pszFilterOutFiles);
|
---|
327 | }
|
---|
328 | RTStrFree(pSettings->pszFilterFiles);
|
---|
329 | }
|
---|
330 |
|
---|
331 | pSettings->pszFilterFiles = NULL;
|
---|
332 | pSettings->pszFilterOutFiles = NULL;
|
---|
333 | pSettings->pszFilterOutDirs = NULL;
|
---|
334 | return rc;
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Init a settings structure.
|
---|
339 | *
|
---|
340 | * @returns IPRT status code
|
---|
341 | * @param pSettings The settings.
|
---|
342 | */
|
---|
343 | static int scmSettingsBaseInit(PSCMSETTINGSBASE pSettings)
|
---|
344 | {
|
---|
345 | return scmSettingsBaseInitAndCopy(pSettings, &g_Defaults);
|
---|
346 | }
|
---|
347 |
|
---|
348 | /**
|
---|
349 | * Deletes the settings, i.e. free any dynamically allocated content.
|
---|
350 | *
|
---|
351 | * @param pSettings The settings.
|
---|
352 | */
|
---|
353 | static void scmSettingsBaseDelete(PSCMSETTINGSBASE pSettings)
|
---|
354 | {
|
---|
355 | if (pSettings)
|
---|
356 | {
|
---|
357 | Assert(pSettings->cchTab != UINT8_MAX);
|
---|
358 | pSettings->cchTab = UINT8_MAX;
|
---|
359 |
|
---|
360 | RTStrFree(pSettings->pszFilterFiles);
|
---|
361 | pSettings->pszFilterFiles = NULL;
|
---|
362 |
|
---|
363 | RTStrFree(pSettings->pszFilterOutFiles);
|
---|
364 | pSettings->pszFilterOutFiles = NULL;
|
---|
365 |
|
---|
366 | RTStrFree(pSettings->pszFilterOutDirs);
|
---|
367 | pSettings->pszFilterOutDirs = NULL;
|
---|
368 | }
|
---|
369 | }
|
---|
370 |
|
---|
371 |
|
---|
372 | /**
|
---|
373 | * Processes a RTGetOpt result.
|
---|
374 | *
|
---|
375 | * @retval VINF_SUCCESS if handled.
|
---|
376 | * @retval VERR_OUT_OF_RANGE if the option value was out of range.
|
---|
377 | * @retval VERR_GETOPT_UNKNOWN_OPTION if the option was not recognized.
|
---|
378 | *
|
---|
379 | * @param pSettings The settings to change.
|
---|
380 | * @param rc The RTGetOpt return value.
|
---|
381 | * @param pValueUnion The RTGetOpt value union.
|
---|
382 | */
|
---|
383 | static int scmSettingsBaseHandleOpt(PSCMSETTINGSBASE pSettings, int rc, PRTGETOPTUNION pValueUnion)
|
---|
384 | {
|
---|
385 | switch (rc)
|
---|
386 | {
|
---|
387 | case SCMOPT_CONVERT_EOL:
|
---|
388 | pSettings->fConvertEol = true;
|
---|
389 | return VINF_SUCCESS;
|
---|
390 | case SCMOPT_NO_CONVERT_EOL:
|
---|
391 | pSettings->fConvertEol = false;
|
---|
392 | return VINF_SUCCESS;
|
---|
393 |
|
---|
394 | case SCMOPT_CONVERT_TABS:
|
---|
395 | pSettings->fConvertTabs = true;
|
---|
396 | return VINF_SUCCESS;
|
---|
397 | case SCMOPT_NO_CONVERT_TABS:
|
---|
398 | pSettings->fConvertTabs = false;
|
---|
399 | return VINF_SUCCESS;
|
---|
400 |
|
---|
401 | case SCMOPT_FORCE_FINAL_EOL:
|
---|
402 | pSettings->fForceFinalEol = true;
|
---|
403 | return VINF_SUCCESS;
|
---|
404 | case SCMOPT_NO_FORCE_FINAL_EOL:
|
---|
405 | pSettings->fForceFinalEol = false;
|
---|
406 | return VINF_SUCCESS;
|
---|
407 |
|
---|
408 | case SCMOPT_FORCE_TRAILING_LINE:
|
---|
409 | pSettings->fForceTrailingLine = true;
|
---|
410 | return VINF_SUCCESS;
|
---|
411 | case SCMOPT_NO_FORCE_TRAILING_LINE:
|
---|
412 | pSettings->fForceTrailingLine = false;
|
---|
413 | return VINF_SUCCESS;
|
---|
414 |
|
---|
415 |
|
---|
416 | case SCMOPT_STRIP_TRAILING_BLANKS:
|
---|
417 | pSettings->fStripTrailingBlanks = true;
|
---|
418 | return VINF_SUCCESS;
|
---|
419 | case SCMOPT_NO_STRIP_TRAILING_BLANKS:
|
---|
420 | pSettings->fStripTrailingBlanks = false;
|
---|
421 | return VINF_SUCCESS;
|
---|
422 |
|
---|
423 | case SCMOPT_MIN_BLANK_LINES_BEFORE_FLOWER_BOX_MARKERS:
|
---|
424 | pSettings->cMinBlankLinesBeforeFlowerBoxMakers = pValueUnion->u8;
|
---|
425 | return VINF_SUCCESS;
|
---|
426 |
|
---|
427 |
|
---|
428 | case SCMOPT_STRIP_TRAILING_LINES:
|
---|
429 | pSettings->fStripTrailingLines = true;
|
---|
430 | return VINF_SUCCESS;
|
---|
431 | case SCMOPT_NO_STRIP_TRAILING_LINES:
|
---|
432 | pSettings->fStripTrailingLines = false;
|
---|
433 | return VINF_SUCCESS;
|
---|
434 |
|
---|
435 | case SCMOPT_FIX_FLOWER_BOX_MARKERS:
|
---|
436 | pSettings->fFixFlowerBoxMarkers = true;
|
---|
437 | return VINF_SUCCESS;
|
---|
438 | case SCMOPT_NO_FIX_FLOWER_BOX_MARKERS:
|
---|
439 | pSettings->fFixFlowerBoxMarkers = false;
|
---|
440 | return VINF_SUCCESS;
|
---|
441 |
|
---|
442 | case SCMOPT_ONLY_SVN_DIRS:
|
---|
443 | pSettings->fOnlySvnDirs = true;
|
---|
444 | return VINF_SUCCESS;
|
---|
445 | case SCMOPT_NOT_ONLY_SVN_DIRS:
|
---|
446 | pSettings->fOnlySvnDirs = false;
|
---|
447 | return VINF_SUCCESS;
|
---|
448 |
|
---|
449 | case SCMOPT_ONLY_SVN_FILES:
|
---|
450 | pSettings->fOnlySvnFiles = true;
|
---|
451 | return VINF_SUCCESS;
|
---|
452 | case SCMOPT_NOT_ONLY_SVN_FILES:
|
---|
453 | pSettings->fOnlySvnFiles = false;
|
---|
454 | return VINF_SUCCESS;
|
---|
455 |
|
---|
456 | case SCMOPT_SET_SVN_EOL:
|
---|
457 | pSettings->fSetSvnEol = true;
|
---|
458 | return VINF_SUCCESS;
|
---|
459 | case SCMOPT_DONT_SET_SVN_EOL:
|
---|
460 | pSettings->fSetSvnEol = false;
|
---|
461 | return VINF_SUCCESS;
|
---|
462 |
|
---|
463 | case SCMOPT_SET_SVN_EXECUTABLE:
|
---|
464 | pSettings->fSetSvnExecutable = true;
|
---|
465 | return VINF_SUCCESS;
|
---|
466 | case SCMOPT_DONT_SET_SVN_EXECUTABLE:
|
---|
467 | pSettings->fSetSvnExecutable = false;
|
---|
468 | return VINF_SUCCESS;
|
---|
469 |
|
---|
470 | case SCMOPT_SET_SVN_KEYWORDS:
|
---|
471 | pSettings->fSetSvnKeywords = true;
|
---|
472 | return VINF_SUCCESS;
|
---|
473 | case SCMOPT_DONT_SET_SVN_KEYWORDS:
|
---|
474 | pSettings->fSetSvnKeywords = false;
|
---|
475 | return VINF_SUCCESS;
|
---|
476 |
|
---|
477 | case SCMOPT_TAB_SIZE:
|
---|
478 | if ( pValueUnion->u8 < 1
|
---|
479 | || pValueUnion->u8 >= RT_ELEMENTS(g_szTabSpaces))
|
---|
480 | {
|
---|
481 | RTMsgError("Invalid tab size: %u - must be in {1..%u}\n",
|
---|
482 | pValueUnion->u8, RT_ELEMENTS(g_szTabSpaces) - 1);
|
---|
483 | return VERR_OUT_OF_RANGE;
|
---|
484 | }
|
---|
485 | pSettings->cchTab = pValueUnion->u8;
|
---|
486 | return VINF_SUCCESS;
|
---|
487 |
|
---|
488 | case SCMOPT_WIDTH:
|
---|
489 | if (pValueUnion->u8 < 20 || pValueUnion->u8 > 200)
|
---|
490 | {
|
---|
491 | RTMsgError("Invalid width size: %u - must be in {20..200} range\n", pValueUnion->u8);
|
---|
492 | return VERR_OUT_OF_RANGE;
|
---|
493 | }
|
---|
494 | pSettings->cchWidth = pValueUnion->u8;
|
---|
495 | return VINF_SUCCESS;
|
---|
496 |
|
---|
497 | case SCMOPT_FILTER_OUT_DIRS:
|
---|
498 | case SCMOPT_FILTER_FILES:
|
---|
499 | case SCMOPT_FILTER_OUT_FILES:
|
---|
500 | {
|
---|
501 | char **ppsz = NULL;
|
---|
502 | switch (rc)
|
---|
503 | {
|
---|
504 | case SCMOPT_FILTER_OUT_DIRS: ppsz = &pSettings->pszFilterOutDirs; break;
|
---|
505 | case SCMOPT_FILTER_FILES: ppsz = &pSettings->pszFilterFiles; break;
|
---|
506 | case SCMOPT_FILTER_OUT_FILES: ppsz = &pSettings->pszFilterOutFiles; break;
|
---|
507 | }
|
---|
508 |
|
---|
509 | /*
|
---|
510 | * An empty string zaps the current list.
|
---|
511 | */
|
---|
512 | if (!*pValueUnion->psz)
|
---|
513 | return RTStrATruncate(ppsz, 0);
|
---|
514 |
|
---|
515 | /*
|
---|
516 | * Non-empty strings are appended to the pattern list.
|
---|
517 | *
|
---|
518 | * Strip leading and trailing pattern separators before attempting
|
---|
519 | * to append it. If it's just separators, don't do anything.
|
---|
520 | */
|
---|
521 | const char *pszSrc = pValueUnion->psz;
|
---|
522 | while (*pszSrc == '|')
|
---|
523 | pszSrc++;
|
---|
524 | size_t cchSrc = strlen(pszSrc);
|
---|
525 | while (cchSrc > 0 && pszSrc[cchSrc - 1] == '|')
|
---|
526 | cchSrc--;
|
---|
527 | if (!cchSrc)
|
---|
528 | return VINF_SUCCESS;
|
---|
529 |
|
---|
530 | return RTStrAAppendExN(ppsz, 2,
|
---|
531 | "|", *ppsz && **ppsz ? (size_t)1 : (size_t)0,
|
---|
532 | pszSrc, cchSrc);
|
---|
533 | }
|
---|
534 |
|
---|
535 | default:
|
---|
536 | return VERR_GETOPT_UNKNOWN_OPTION;
|
---|
537 | }
|
---|
538 | }
|
---|
539 |
|
---|
540 | /**
|
---|
541 | * Parses an option string.
|
---|
542 | *
|
---|
543 | * @returns IPRT status code.
|
---|
544 | * @param pBase The base settings structure to apply the options
|
---|
545 | * to.
|
---|
546 | * @param pszOptions The options to parse.
|
---|
547 | */
|
---|
548 | static int scmSettingsBaseParseString(PSCMSETTINGSBASE pBase, const char *pszLine)
|
---|
549 | {
|
---|
550 | int cArgs;
|
---|
551 | char **papszArgs;
|
---|
552 | int rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszLine, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
|
---|
553 | if (RT_SUCCESS(rc))
|
---|
554 | {
|
---|
555 | RTGETOPTUNION ValueUnion;
|
---|
556 | RTGETOPTSTATE GetOptState;
|
---|
557 | rc = RTGetOptInit(&GetOptState, cArgs, papszArgs, &g_aScmOpts[0], RT_ELEMENTS(g_aScmOpts), 0, 0 /*fFlags*/);
|
---|
558 | if (RT_SUCCESS(rc))
|
---|
559 | {
|
---|
560 | while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
|
---|
561 | {
|
---|
562 | rc = scmSettingsBaseHandleOpt(pBase, rc, &ValueUnion);
|
---|
563 | if (RT_FAILURE(rc))
|
---|
564 | break;
|
---|
565 | }
|
---|
566 | }
|
---|
567 | RTGetOptArgvFree(papszArgs);
|
---|
568 | }
|
---|
569 |
|
---|
570 | return rc;
|
---|
571 | }
|
---|
572 |
|
---|
573 | /**
|
---|
574 | * Parses an unterminated option string.
|
---|
575 | *
|
---|
576 | * @returns IPRT status code.
|
---|
577 | * @param pBase The base settings structure to apply the options
|
---|
578 | * to.
|
---|
579 | * @param pchLine The line.
|
---|
580 | * @param cchLine The line length.
|
---|
581 | */
|
---|
582 | static int scmSettingsBaseParseStringN(PSCMSETTINGSBASE pBase, const char *pchLine, size_t cchLine)
|
---|
583 | {
|
---|
584 | char *pszLine = RTStrDupN(pchLine, cchLine);
|
---|
585 | if (!pszLine)
|
---|
586 | return VERR_NO_MEMORY;
|
---|
587 | int rc = scmSettingsBaseParseString(pBase, pszLine);
|
---|
588 | RTStrFree(pszLine);
|
---|
589 | return rc;
|
---|
590 | }
|
---|
591 |
|
---|
592 | /**
|
---|
593 | * Verifies the options string.
|
---|
594 | *
|
---|
595 | * @returns IPRT status code.
|
---|
596 | * @param pszOptions The options to verify .
|
---|
597 | */
|
---|
598 | static int scmSettingsBaseVerifyString(const char *pszOptions)
|
---|
599 | {
|
---|
600 | SCMSETTINGSBASE Base;
|
---|
601 | int rc = scmSettingsBaseInit(&Base);
|
---|
602 | if (RT_SUCCESS(rc))
|
---|
603 | {
|
---|
604 | rc = scmSettingsBaseParseString(&Base, pszOptions);
|
---|
605 | scmSettingsBaseDelete(&Base);
|
---|
606 | }
|
---|
607 | return rc;
|
---|
608 | }
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Loads settings found in editor and SCM settings directives within the
|
---|
612 | * document (@a pStream).
|
---|
613 | *
|
---|
614 | * @returns IPRT status code.
|
---|
615 | * @param pBase The settings base to load settings into.
|
---|
616 | * @param pStream The stream to scan for settings directives.
|
---|
617 | */
|
---|
618 | static int scmSettingsBaseLoadFromDocument(PSCMSETTINGSBASE pBase, PSCMSTREAM pStream)
|
---|
619 | {
|
---|
620 | /** @todo Editor and SCM settings directives in documents. */
|
---|
621 | RT_NOREF2(pBase, pStream);
|
---|
622 | return VINF_SUCCESS;
|
---|
623 | }
|
---|
624 |
|
---|
625 | /**
|
---|
626 | * Creates a new settings file struct, cloning @a pSettings.
|
---|
627 | *
|
---|
628 | * @returns IPRT status code.
|
---|
629 | * @param ppSettings Where to return the new struct.
|
---|
630 | * @param pSettingsBase The settings to inherit from.
|
---|
631 | */
|
---|
632 | static int scmSettingsCreate(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pSettingsBase)
|
---|
633 | {
|
---|
634 | PSCMSETTINGS pSettings = (PSCMSETTINGS)RTMemAlloc(sizeof(*pSettings));
|
---|
635 | if (!pSettings)
|
---|
636 | return VERR_NO_MEMORY;
|
---|
637 | int rc = scmSettingsBaseInitAndCopy(&pSettings->Base, pSettingsBase);
|
---|
638 | if (RT_SUCCESS(rc))
|
---|
639 | {
|
---|
640 | pSettings->pDown = NULL;
|
---|
641 | pSettings->pUp = NULL;
|
---|
642 | pSettings->paPairs = NULL;
|
---|
643 | pSettings->cPairs = 0;
|
---|
644 | *ppSettings = pSettings;
|
---|
645 | return VINF_SUCCESS;
|
---|
646 | }
|
---|
647 | RTMemFree(pSettings);
|
---|
648 | return rc;
|
---|
649 | }
|
---|
650 |
|
---|
651 | /**
|
---|
652 | * Destroys a settings structure.
|
---|
653 | *
|
---|
654 | * @param pSettings The settings structure to destroy. NULL is OK.
|
---|
655 | */
|
---|
656 | static void scmSettingsDestroy(PSCMSETTINGS pSettings)
|
---|
657 | {
|
---|
658 | if (pSettings)
|
---|
659 | {
|
---|
660 | scmSettingsBaseDelete(&pSettings->Base);
|
---|
661 | for (size_t i = 0; i < pSettings->cPairs; i++)
|
---|
662 | {
|
---|
663 | RTStrFree(pSettings->paPairs[i].pszPattern);
|
---|
664 | RTStrFree(pSettings->paPairs[i].pszOptions);
|
---|
665 | pSettings->paPairs[i].pszPattern = NULL;
|
---|
666 | pSettings->paPairs[i].pszOptions = NULL;
|
---|
667 | }
|
---|
668 | RTMemFree(pSettings->paPairs);
|
---|
669 | pSettings->paPairs = NULL;
|
---|
670 | RTMemFree(pSettings);
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | /**
|
---|
675 | * Adds a pattern/options pair to the settings structure.
|
---|
676 | *
|
---|
677 | * @returns IPRT status code.
|
---|
678 | * @param pSettings The settings.
|
---|
679 | * @param pchLine The line containing the unparsed pair.
|
---|
680 | * @param cchLine The length of the line.
|
---|
681 | */
|
---|
682 | static int scmSettingsAddPair(PSCMSETTINGS pSettings, const char *pchLine, size_t cchLine)
|
---|
683 | {
|
---|
684 | /*
|
---|
685 | * Split the string.
|
---|
686 | */
|
---|
687 | const char *pchOptions = (const char *)memchr(pchLine, ':', cchLine);
|
---|
688 | if (!pchOptions)
|
---|
689 | return VERR_INVALID_PARAMETER;
|
---|
690 | size_t cchPattern = pchOptions - pchLine;
|
---|
691 | size_t cchOptions = cchLine - cchPattern - 1;
|
---|
692 | pchOptions++;
|
---|
693 |
|
---|
694 | /* strip spaces everywhere */
|
---|
695 | while (cchPattern > 0 && RT_C_IS_SPACE(pchLine[cchPattern - 1]))
|
---|
696 | cchPattern--;
|
---|
697 | while (cchPattern > 0 && RT_C_IS_SPACE(*pchLine))
|
---|
698 | cchPattern--, pchLine++;
|
---|
699 |
|
---|
700 | while (cchOptions > 0 && RT_C_IS_SPACE(pchOptions[cchOptions - 1]))
|
---|
701 | cchOptions--;
|
---|
702 | while (cchOptions > 0 && RT_C_IS_SPACE(*pchOptions))
|
---|
703 | cchOptions--, pchOptions++;
|
---|
704 |
|
---|
705 | /* Quietly ignore empty patterns and empty options. */
|
---|
706 | if (!cchOptions || !cchPattern)
|
---|
707 | return VINF_SUCCESS;
|
---|
708 |
|
---|
709 | /*
|
---|
710 | * Add the pair and verify the option string.
|
---|
711 | */
|
---|
712 | uint32_t iPair = pSettings->cPairs;
|
---|
713 | if ((iPair % 32) == 0)
|
---|
714 | {
|
---|
715 | void *pvNew = RTMemRealloc(pSettings->paPairs, (iPair + 32) * sizeof(pSettings->paPairs[0]));
|
---|
716 | if (!pvNew)
|
---|
717 | return VERR_NO_MEMORY;
|
---|
718 | pSettings->paPairs = (PSCMPATRNOPTPAIR)pvNew;
|
---|
719 | }
|
---|
720 |
|
---|
721 | pSettings->paPairs[iPair].pszPattern = RTStrDupN(pchLine, cchPattern);
|
---|
722 | pSettings->paPairs[iPair].pszOptions = RTStrDupN(pchOptions, cchOptions);
|
---|
723 | int rc;
|
---|
724 | if ( pSettings->paPairs[iPair].pszPattern
|
---|
725 | && pSettings->paPairs[iPair].pszOptions)
|
---|
726 | rc = scmSettingsBaseVerifyString(pSettings->paPairs[iPair].pszOptions);
|
---|
727 | else
|
---|
728 | rc = VERR_NO_MEMORY;
|
---|
729 | if (RT_SUCCESS(rc))
|
---|
730 | pSettings->cPairs = iPair + 1;
|
---|
731 | else
|
---|
732 | {
|
---|
733 | RTStrFree(pSettings->paPairs[iPair].pszPattern);
|
---|
734 | RTStrFree(pSettings->paPairs[iPair].pszOptions);
|
---|
735 | }
|
---|
736 | return rc;
|
---|
737 | }
|
---|
738 |
|
---|
739 | /**
|
---|
740 | * Loads in the settings from @a pszFilename.
|
---|
741 | *
|
---|
742 | * @returns IPRT status code.
|
---|
743 | * @param pSettings Where to load the settings file.
|
---|
744 | * @param pszFilename The file to load.
|
---|
745 | */
|
---|
746 | static int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename)
|
---|
747 | {
|
---|
748 | ScmVerbose(NULL, 3, "Loading settings file '%s'...\n", pszFilename);
|
---|
749 |
|
---|
750 | SCMSTREAM Stream;
|
---|
751 | int rc = ScmStreamInitForReading(&Stream, pszFilename);
|
---|
752 | if (RT_FAILURE(rc))
|
---|
753 | {
|
---|
754 | RTMsgError("%s: ScmStreamInitForReading -> %Rrc\n", pszFilename, rc);
|
---|
755 | return rc;
|
---|
756 | }
|
---|
757 |
|
---|
758 | SCMEOL enmEol;
|
---|
759 | const char *pchLine;
|
---|
760 | size_t cchLine;
|
---|
761 | while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
|
---|
762 | {
|
---|
763 | /* Ignore leading spaces. */
|
---|
764 | while (cchLine > 0 && RT_C_IS_SPACE(*pchLine))
|
---|
765 | pchLine++, cchLine--;
|
---|
766 |
|
---|
767 | /* Ignore empty lines and comment lines. */
|
---|
768 | if (cchLine < 1 || *pchLine == '#')
|
---|
769 | continue;
|
---|
770 |
|
---|
771 | /* What kind of line is it? */
|
---|
772 | const char *pchColon = (const char *)memchr(pchLine, ':', cchLine);
|
---|
773 | if (pchColon)
|
---|
774 | rc = scmSettingsAddPair(pSettings, pchLine, cchLine);
|
---|
775 | else
|
---|
776 | rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine);
|
---|
777 | if (RT_FAILURE(rc))
|
---|
778 | {
|
---|
779 | RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc);
|
---|
780 | break;
|
---|
781 | }
|
---|
782 | }
|
---|
783 |
|
---|
784 | if (RT_SUCCESS(rc))
|
---|
785 | {
|
---|
786 | rc = ScmStreamGetStatus(&Stream);
|
---|
787 | if (RT_FAILURE(rc))
|
---|
788 | RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc);
|
---|
789 | }
|
---|
790 |
|
---|
791 | ScmStreamDelete(&Stream);
|
---|
792 | return rc;
|
---|
793 | }
|
---|
794 |
|
---|
795 | #if 0 /* unused */
|
---|
796 | /**
|
---|
797 | * Parse the specified settings file creating a new settings struct from it.
|
---|
798 | *
|
---|
799 | * @returns IPRT status code
|
---|
800 | * @param ppSettings Where to return the new settings.
|
---|
801 | * @param pszFilename The file to parse.
|
---|
802 | * @param pSettingsBase The base settings we inherit from.
|
---|
803 | */
|
---|
804 | static int scmSettingsCreateFromFile(PSCMSETTINGS *ppSettings, const char *pszFilename, PCSCMSETTINGSBASE pSettingsBase)
|
---|
805 | {
|
---|
806 | PSCMSETTINGS pSettings;
|
---|
807 | int rc = scmSettingsCreate(&pSettings, pSettingsBase);
|
---|
808 | if (RT_SUCCESS(rc))
|
---|
809 | {
|
---|
810 | rc = scmSettingsLoadFile(pSettings, pszFilename);
|
---|
811 | if (RT_SUCCESS(rc))
|
---|
812 | {
|
---|
813 | *ppSettings = pSettings;
|
---|
814 | return VINF_SUCCESS;
|
---|
815 | }
|
---|
816 |
|
---|
817 | scmSettingsDestroy(pSettings);
|
---|
818 | }
|
---|
819 | *ppSettings = NULL;
|
---|
820 | return rc;
|
---|
821 | }
|
---|
822 | #endif
|
---|
823 |
|
---|
824 |
|
---|
825 | /**
|
---|
826 | * Create an initial settings structure when starting processing a new file or
|
---|
827 | * directory.
|
---|
828 | *
|
---|
829 | * This will look for .scm-settings files from the root and down to the
|
---|
830 | * specified directory, combining them into the returned settings structure.
|
---|
831 | *
|
---|
832 | * @returns IPRT status code.
|
---|
833 | * @param ppSettings Where to return the pointer to the top stack
|
---|
834 | * object.
|
---|
835 | * @param pBaseSettings The base settings we inherit from (globals
|
---|
836 | * typically).
|
---|
837 | * @param pszPath The absolute path to the new directory or file.
|
---|
838 | */
|
---|
839 | static int scmSettingsCreateForPath(PSCMSETTINGS *ppSettings, PCSCMSETTINGSBASE pBaseSettings, const char *pszPath)
|
---|
840 | {
|
---|
841 | *ppSettings = NULL; /* try shut up gcc. */
|
---|
842 |
|
---|
843 | /*
|
---|
844 | * We'll be working with a stack copy of the path.
|
---|
845 | */
|
---|
846 | char szFile[RTPATH_MAX];
|
---|
847 | size_t cchDir = strlen(pszPath);
|
---|
848 | if (cchDir >= sizeof(szFile) - sizeof(SCM_SETTINGS_FILENAME))
|
---|
849 | return VERR_FILENAME_TOO_LONG;
|
---|
850 |
|
---|
851 | /*
|
---|
852 | * Create the bottom-most settings.
|
---|
853 | */
|
---|
854 | PSCMSETTINGS pSettings;
|
---|
855 | int rc = scmSettingsCreate(&pSettings, pBaseSettings);
|
---|
856 | if (RT_FAILURE(rc))
|
---|
857 | return rc;
|
---|
858 |
|
---|
859 | /*
|
---|
860 | * Enumerate the path components from the root and down. Load any setting
|
---|
861 | * files we find.
|
---|
862 | */
|
---|
863 | size_t cComponents = RTPathCountComponents(pszPath);
|
---|
864 | for (size_t i = 1; i <= cComponents; i++)
|
---|
865 | {
|
---|
866 | rc = RTPathCopyComponents(szFile, sizeof(szFile), pszPath, i);
|
---|
867 | if (RT_SUCCESS(rc))
|
---|
868 | rc = RTPathAppend(szFile, sizeof(szFile), SCM_SETTINGS_FILENAME);
|
---|
869 | if (RT_FAILURE(rc))
|
---|
870 | break;
|
---|
871 | if (RTFileExists(szFile))
|
---|
872 | {
|
---|
873 | rc = scmSettingsLoadFile(pSettings, szFile);
|
---|
874 | if (RT_FAILURE(rc))
|
---|
875 | break;
|
---|
876 | }
|
---|
877 | }
|
---|
878 |
|
---|
879 | if (RT_SUCCESS(rc))
|
---|
880 | *ppSettings = pSettings;
|
---|
881 | else
|
---|
882 | scmSettingsDestroy(pSettings);
|
---|
883 | return rc;
|
---|
884 | }
|
---|
885 |
|
---|
886 | /**
|
---|
887 | * Pushes a new settings set onto the stack.
|
---|
888 | *
|
---|
889 | * @param ppSettingsStack The pointer to the pointer to the top stack
|
---|
890 | * element. This will be used as input and output.
|
---|
891 | * @param pSettings The settings to push onto the stack.
|
---|
892 | */
|
---|
893 | static void scmSettingsStackPush(PSCMSETTINGS *ppSettingsStack, PSCMSETTINGS pSettings)
|
---|
894 | {
|
---|
895 | PSCMSETTINGS pOld = *ppSettingsStack;
|
---|
896 | pSettings->pDown = pOld;
|
---|
897 | pSettings->pUp = NULL;
|
---|
898 | if (pOld)
|
---|
899 | pOld->pUp = pSettings;
|
---|
900 | *ppSettingsStack = pSettings;
|
---|
901 | }
|
---|
902 |
|
---|
903 | /**
|
---|
904 | * Pushes the settings of the specified directory onto the stack.
|
---|
905 | *
|
---|
906 | * We will load any .scm-settings in the directory. A stack entry is added even
|
---|
907 | * if no settings file was found.
|
---|
908 | *
|
---|
909 | * @returns IPRT status code.
|
---|
910 | * @param ppSettingsStack The pointer to the pointer to the top stack
|
---|
911 | * element. This will be used as input and output.
|
---|
912 | * @param pszDir The directory to do this for.
|
---|
913 | */
|
---|
914 | static int scmSettingsStackPushDir(PSCMSETTINGS *ppSettingsStack, const char *pszDir)
|
---|
915 | {
|
---|
916 | char szFile[RTPATH_MAX];
|
---|
917 | int rc = RTPathJoin(szFile, sizeof(szFile), pszDir, SCM_SETTINGS_FILENAME);
|
---|
918 | if (RT_SUCCESS(rc))
|
---|
919 | {
|
---|
920 | PSCMSETTINGS pSettings;
|
---|
921 | rc = scmSettingsCreate(&pSettings, &(*ppSettingsStack)->Base);
|
---|
922 | if (RT_SUCCESS(rc))
|
---|
923 | {
|
---|
924 | if (RTFileExists(szFile))
|
---|
925 | rc = scmSettingsLoadFile(pSettings, szFile);
|
---|
926 | if (RT_SUCCESS(rc))
|
---|
927 | {
|
---|
928 | scmSettingsStackPush(ppSettingsStack, pSettings);
|
---|
929 | return VINF_SUCCESS;
|
---|
930 | }
|
---|
931 |
|
---|
932 | scmSettingsDestroy(pSettings);
|
---|
933 | }
|
---|
934 | }
|
---|
935 | return rc;
|
---|
936 | }
|
---|
937 |
|
---|
938 |
|
---|
939 | /**
|
---|
940 | * Pops a settings set off the stack.
|
---|
941 | *
|
---|
942 | * @returns The popped setttings.
|
---|
943 | * @param ppSettingsStack The pointer to the pointer to the top stack
|
---|
944 | * element. This will be used as input and output.
|
---|
945 | */
|
---|
946 | static PSCMSETTINGS scmSettingsStackPop(PSCMSETTINGS *ppSettingsStack)
|
---|
947 | {
|
---|
948 | PSCMSETTINGS pRet = *ppSettingsStack;
|
---|
949 | PSCMSETTINGS pNew = pRet ? pRet->pDown : NULL;
|
---|
950 | *ppSettingsStack = pNew;
|
---|
951 | if (pNew)
|
---|
952 | pNew->pUp = NULL;
|
---|
953 | if (pRet)
|
---|
954 | {
|
---|
955 | pRet->pUp = NULL;
|
---|
956 | pRet->pDown = NULL;
|
---|
957 | }
|
---|
958 | return pRet;
|
---|
959 | }
|
---|
960 |
|
---|
961 | /**
|
---|
962 | * Pops and destroys the top entry of the stack.
|
---|
963 | *
|
---|
964 | * @param ppSettingsStack The pointer to the pointer to the top stack
|
---|
965 | * element. This will be used as input and output.
|
---|
966 | */
|
---|
967 | static void scmSettingsStackPopAndDestroy(PSCMSETTINGS *ppSettingsStack)
|
---|
968 | {
|
---|
969 | scmSettingsDestroy(scmSettingsStackPop(ppSettingsStack));
|
---|
970 | }
|
---|
971 |
|
---|
972 | /**
|
---|
973 | * Constructs the base settings for the specified file name.
|
---|
974 | *
|
---|
975 | * @returns IPRT status code.
|
---|
976 | * @param pSettingsStack The top element on the settings stack.
|
---|
977 | * @param pszFilename The file name.
|
---|
978 | * @param pszBasename The base name (pointer within @a pszFilename).
|
---|
979 | * @param cchBasename The length of the base name. (For passing to
|
---|
980 | * RTStrSimplePatternMultiMatch.)
|
---|
981 | * @param pBase Base settings to initialize.
|
---|
982 | */
|
---|
983 | static int scmSettingsStackMakeFileBase(PCSCMSETTINGS pSettingsStack, const char *pszFilename,
|
---|
984 | const char *pszBasename, size_t cchBasename, PSCMSETTINGSBASE pBase)
|
---|
985 | {
|
---|
986 | int rc = scmSettingsBaseInitAndCopy(pBase, &pSettingsStack->Base);
|
---|
987 | if (RT_SUCCESS(rc))
|
---|
988 | {
|
---|
989 | /* find the bottom entry in the stack. */
|
---|
990 | PCSCMSETTINGS pCur = pSettingsStack;
|
---|
991 | while (pCur->pDown)
|
---|
992 | pCur = pCur->pDown;
|
---|
993 |
|
---|
994 | /* Work our way up thru the stack and look for matching pairs. */
|
---|
995 | while (pCur)
|
---|
996 | {
|
---|
997 | size_t const cPairs = pCur->cPairs;
|
---|
998 | if (cPairs)
|
---|
999 | {
|
---|
1000 | for (size_t i = 0; i < cPairs; i++)
|
---|
1001 | if ( RTStrSimplePatternMultiMatch(pCur->paPairs[i].pszPattern, RTSTR_MAX,
|
---|
1002 | pszBasename, cchBasename, NULL)
|
---|
1003 | || RTStrSimplePatternMultiMatch(pCur->paPairs[i].pszPattern, RTSTR_MAX,
|
---|
1004 | pszFilename, RTSTR_MAX, NULL))
|
---|
1005 | {
|
---|
1006 | rc = scmSettingsBaseParseString(pBase, pCur->paPairs[i].pszOptions);
|
---|
1007 | if (RT_FAILURE(rc))
|
---|
1008 | break;
|
---|
1009 | }
|
---|
1010 | if (RT_FAILURE(rc))
|
---|
1011 | break;
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | /* advance */
|
---|
1015 | pCur = pCur->pUp;
|
---|
1016 | }
|
---|
1017 | }
|
---|
1018 | if (RT_FAILURE(rc))
|
---|
1019 | scmSettingsBaseDelete(pBase);
|
---|
1020 | return rc;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 |
|
---|
1024 | /* -=-=-=-=-=- misc -=-=-=-=-=- */
|
---|
1025 |
|
---|
1026 |
|
---|
1027 | /**
|
---|
1028 | * Prints a verbose message if the level is high enough.
|
---|
1029 | *
|
---|
1030 | * @param pState The rewrite state. Optional.
|
---|
1031 | * @param iLevel The required verbosity level.
|
---|
1032 | * @param pszFormat The message format string. Can be NULL if we
|
---|
1033 | * only want to trigger the per file message.
|
---|
1034 | * @param ... Format arguments.
|
---|
1035 | */
|
---|
1036 | void ScmVerbose(PSCMRWSTATE pState, int iLevel, const char *pszFormat, ...)
|
---|
1037 | {
|
---|
1038 | if (iLevel <= g_iVerbosity)
|
---|
1039 | {
|
---|
1040 | if (pState && !pState->fFirst)
|
---|
1041 | {
|
---|
1042 | RTPrintf("%s: info: --= Rewriting '%s' =--\n", g_szProgName, pState->pszFilename);
|
---|
1043 | pState->fFirst = true;
|
---|
1044 | }
|
---|
1045 | if (pszFormat)
|
---|
1046 | {
|
---|
1047 | RTPrintf(pState
|
---|
1048 | ? "%s: info: "
|
---|
1049 | : "%s: info: ",
|
---|
1050 | g_szProgName);
|
---|
1051 | va_list va;
|
---|
1052 | va_start(va, pszFormat);
|
---|
1053 | RTPrintfV(pszFormat, va);
|
---|
1054 | va_end(va);
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 |
|
---|
1060 | /* -=-=-=-=-=- file and directory processing -=-=-=-=-=- */
|
---|
1061 |
|
---|
1062 |
|
---|
1063 | /**
|
---|
1064 | * Processes a file.
|
---|
1065 | *
|
---|
1066 | * @returns IPRT status code.
|
---|
1067 | * @param pState The rewriter state.
|
---|
1068 | * @param pszFilename The file name.
|
---|
1069 | * @param pszBasename The base name (pointer within @a pszFilename).
|
---|
1070 | * @param cchBasename The length of the base name. (For passing to
|
---|
1071 | * RTStrSimplePatternMultiMatch.)
|
---|
1072 | * @param pBaseSettings The base settings to use. It's OK to modify
|
---|
1073 | * these.
|
---|
1074 | */
|
---|
1075 | static int scmProcessFileInner(PSCMRWSTATE pState, const char *pszFilename, const char *pszBasename, size_t cchBasename,
|
---|
1076 | PSCMSETTINGSBASE pBaseSettings)
|
---|
1077 | {
|
---|
1078 | /*
|
---|
1079 | * Do the file level filtering.
|
---|
1080 | */
|
---|
1081 | if ( pBaseSettings->pszFilterFiles
|
---|
1082 | && *pBaseSettings->pszFilterFiles
|
---|
1083 | && !RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterFiles, RTSTR_MAX, pszBasename, cchBasename, NULL))
|
---|
1084 | {
|
---|
1085 | ScmVerbose(NULL, 5, "skipping '%s': file filter mismatch\n", pszFilename);
|
---|
1086 | return VINF_SUCCESS;
|
---|
1087 | }
|
---|
1088 | if ( pBaseSettings->pszFilterOutFiles
|
---|
1089 | && *pBaseSettings->pszFilterOutFiles
|
---|
1090 | && ( RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszBasename, cchBasename, NULL)
|
---|
1091 | || RTStrSimplePatternMultiMatch(pBaseSettings->pszFilterOutFiles, RTSTR_MAX, pszFilename, RTSTR_MAX, NULL)) )
|
---|
1092 | {
|
---|
1093 | ScmVerbose(NULL, 5, "skipping '%s': filterd out\n", pszFilename);
|
---|
1094 | return VINF_SUCCESS;
|
---|
1095 | }
|
---|
1096 | if ( pBaseSettings->fOnlySvnFiles
|
---|
1097 | && !ScmSvnIsInWorkingCopy(pState))
|
---|
1098 | {
|
---|
1099 | ScmVerbose(NULL, 5, "skipping '%s': not in SVN WC\n", pszFilename);
|
---|
1100 | return VINF_SUCCESS;
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | /*
|
---|
1104 | * Try find a matching rewrite config for this filename.
|
---|
1105 | */
|
---|
1106 | PCSCMCFGENTRY pCfg = NULL;
|
---|
1107 | for (size_t iCfg = 0; iCfg < RT_ELEMENTS(g_aConfigs); iCfg++)
|
---|
1108 | if (RTStrSimplePatternMultiMatch(g_aConfigs[iCfg].pszFilePattern, RTSTR_MAX, pszBasename, cchBasename, NULL))
|
---|
1109 | {
|
---|
1110 | pCfg = &g_aConfigs[iCfg];
|
---|
1111 | break;
|
---|
1112 | }
|
---|
1113 | if (!pCfg)
|
---|
1114 | {
|
---|
1115 | ScmVerbose(NULL, 4, "skipping '%s': no rewriters configured\n", pszFilename);
|
---|
1116 | return VINF_SUCCESS;
|
---|
1117 | }
|
---|
1118 | ScmVerbose(pState, 4, "matched \"%s\"\n", pCfg->pszFilePattern);
|
---|
1119 |
|
---|
1120 | /*
|
---|
1121 | * Create an input stream from the file and check that it's text.
|
---|
1122 | */
|
---|
1123 | SCMSTREAM Stream1;
|
---|
1124 | int rc = ScmStreamInitForReading(&Stream1, pszFilename);
|
---|
1125 | if (RT_FAILURE(rc))
|
---|
1126 | {
|
---|
1127 | RTMsgError("Failed to read '%s': %Rrc\n", pszFilename, rc);
|
---|
1128 | return rc;
|
---|
1129 | }
|
---|
1130 | if (ScmStreamIsText(&Stream1))
|
---|
1131 | {
|
---|
1132 | ScmVerbose(pState, 3, NULL);
|
---|
1133 |
|
---|
1134 | /*
|
---|
1135 | * Gather SCM and editor settings from the stream.
|
---|
1136 | */
|
---|
1137 | rc = scmSettingsBaseLoadFromDocument(pBaseSettings, &Stream1);
|
---|
1138 | if (RT_SUCCESS(rc))
|
---|
1139 | {
|
---|
1140 | ScmStreamRewindForReading(&Stream1);
|
---|
1141 |
|
---|
1142 | /*
|
---|
1143 | * Create two more streams for output and push the text thru all the
|
---|
1144 | * rewriters, switching the two streams around when something is
|
---|
1145 | * actually rewritten. Stream1 remains unchanged.
|
---|
1146 | */
|
---|
1147 | SCMSTREAM Stream2;
|
---|
1148 | rc = ScmStreamInitForWriting(&Stream2, &Stream1);
|
---|
1149 | if (RT_SUCCESS(rc))
|
---|
1150 | {
|
---|
1151 | SCMSTREAM Stream3;
|
---|
1152 | rc = ScmStreamInitForWriting(&Stream3, &Stream1);
|
---|
1153 | if (RT_SUCCESS(rc))
|
---|
1154 | {
|
---|
1155 | bool fModified = false;
|
---|
1156 | PSCMSTREAM pIn = &Stream1;
|
---|
1157 | PSCMSTREAM pOut = &Stream2;
|
---|
1158 | for (size_t iRw = 0; iRw < pCfg->cRewriters; iRw++)
|
---|
1159 | {
|
---|
1160 | bool fRc = pCfg->papfnRewriter[iRw](pState, pIn, pOut, pBaseSettings);
|
---|
1161 | if (fRc)
|
---|
1162 | {
|
---|
1163 | PSCMSTREAM pTmp = pOut;
|
---|
1164 | pOut = pIn == &Stream1 ? &Stream3 : pIn;
|
---|
1165 | pIn = pTmp;
|
---|
1166 | fModified = true;
|
---|
1167 | }
|
---|
1168 | ScmStreamRewindForReading(pIn);
|
---|
1169 | ScmStreamRewindForWriting(pOut);
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | rc = ScmStreamGetStatus(&Stream1);
|
---|
1173 | if (RT_SUCCESS(rc))
|
---|
1174 | rc = ScmStreamGetStatus(&Stream2);
|
---|
1175 | if (RT_SUCCESS(rc))
|
---|
1176 | rc = ScmStreamGetStatus(&Stream3);
|
---|
1177 | if (RT_SUCCESS(rc))
|
---|
1178 | {
|
---|
1179 | /*
|
---|
1180 | * If rewritten, write it back to disk.
|
---|
1181 | */
|
---|
1182 | if (fModified)
|
---|
1183 | {
|
---|
1184 | if (!g_fDryRun)
|
---|
1185 | {
|
---|
1186 | ScmVerbose(pState, 1, "writing modified file to \"%s%s\"\n", pszFilename, g_pszChangedSuff);
|
---|
1187 | rc = ScmStreamWriteToFile(pIn, "%s%s", pszFilename, g_pszChangedSuff);
|
---|
1188 | if (RT_FAILURE(rc))
|
---|
1189 | RTMsgError("Error writing '%s%s': %Rrc\n", pszFilename, g_pszChangedSuff, rc);
|
---|
1190 | }
|
---|
1191 | else
|
---|
1192 | {
|
---|
1193 | ScmVerbose(pState, 1, NULL);
|
---|
1194 | ScmDiffStreams(pszFilename, &Stream1, pIn, g_fDiffIgnoreEol, g_fDiffIgnoreLeadingWS,
|
---|
1195 | g_fDiffIgnoreTrailingWS, g_fDiffSpecialChars, pBaseSettings->cchTab, g_pStdOut);
|
---|
1196 | ScmVerbose(pState, 2, "would have modified the file \"%s%s\"\n", pszFilename, g_pszChangedSuff);
|
---|
1197 | }
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | /*
|
---|
1201 | * If pending SVN property changes, apply them.
|
---|
1202 | */
|
---|
1203 | if (pState->cSvnPropChanges && RT_SUCCESS(rc))
|
---|
1204 | {
|
---|
1205 | if (!g_fDryRun)
|
---|
1206 | {
|
---|
1207 | rc = ScmSvnApplyChanges(pState);
|
---|
1208 | if (RT_FAILURE(rc))
|
---|
1209 | RTMsgError("%s: failed to apply SVN property changes (%Rrc)\n", pszFilename, rc);
|
---|
1210 | }
|
---|
1211 | else
|
---|
1212 | ScmSvnDisplayChanges(pState);
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | if (!fModified && !pState->cSvnPropChanges)
|
---|
1216 | ScmVerbose(pState, 3, "no change\n", pszFilename);
|
---|
1217 | }
|
---|
1218 | else
|
---|
1219 | RTMsgError("%s: stream error %Rrc\n", pszFilename, rc);
|
---|
1220 | ScmStreamDelete(&Stream3);
|
---|
1221 | }
|
---|
1222 | else
|
---|
1223 | RTMsgError("Failed to init stream for writing: %Rrc\n", rc);
|
---|
1224 | ScmStreamDelete(&Stream2);
|
---|
1225 | }
|
---|
1226 | else
|
---|
1227 | RTMsgError("Failed to init stream for writing: %Rrc\n", rc);
|
---|
1228 | }
|
---|
1229 | else
|
---|
1230 | RTMsgError("scmSettingsBaseLoadFromDocument: %Rrc\n", rc);
|
---|
1231 | }
|
---|
1232 | else
|
---|
1233 | ScmVerbose(pState, 4, "not text file: \"%s\"\n", pszFilename);
|
---|
1234 | ScmStreamDelete(&Stream1);
|
---|
1235 |
|
---|
1236 | return rc;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | /**
|
---|
1240 | * Processes a file.
|
---|
1241 | *
|
---|
1242 | * This is just a wrapper for scmProcessFileInner for avoid wasting stack in the
|
---|
1243 | * directory recursion method.
|
---|
1244 | *
|
---|
1245 | * @returns IPRT status code.
|
---|
1246 | * @param pszFilename The file name.
|
---|
1247 | * @param pszBasename The base name (pointer within @a pszFilename).
|
---|
1248 | * @param cchBasename The length of the base name. (For passing to
|
---|
1249 | * RTStrSimplePatternMultiMatch.)
|
---|
1250 | * @param pSettingsStack The settings stack (pointer to the top element).
|
---|
1251 | */
|
---|
1252 | static int scmProcessFile(const char *pszFilename, const char *pszBasename, size_t cchBasename,
|
---|
1253 | PSCMSETTINGS pSettingsStack)
|
---|
1254 | {
|
---|
1255 | SCMSETTINGSBASE Base;
|
---|
1256 | int rc = scmSettingsStackMakeFileBase(pSettingsStack, pszFilename, pszBasename, cchBasename, &Base);
|
---|
1257 | if (RT_SUCCESS(rc))
|
---|
1258 | {
|
---|
1259 | SCMRWSTATE State;
|
---|
1260 | State.fFirst = false;
|
---|
1261 | State.pszFilename = pszFilename;
|
---|
1262 | State.cSvnPropChanges = 0;
|
---|
1263 | State.paSvnPropChanges = NULL;
|
---|
1264 |
|
---|
1265 | rc = scmProcessFileInner(&State, pszFilename, pszBasename, cchBasename, &Base);
|
---|
1266 |
|
---|
1267 | size_t i = State.cSvnPropChanges;
|
---|
1268 | while (i-- > 0)
|
---|
1269 | {
|
---|
1270 | RTStrFree(State.paSvnPropChanges[i].pszName);
|
---|
1271 | RTStrFree(State.paSvnPropChanges[i].pszValue);
|
---|
1272 | }
|
---|
1273 | RTMemFree(State.paSvnPropChanges);
|
---|
1274 |
|
---|
1275 | scmSettingsBaseDelete(&Base);
|
---|
1276 | }
|
---|
1277 | return rc;
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 |
|
---|
1281 | /**
|
---|
1282 | * Tries to correct RTDIRENTRY_UNKNOWN.
|
---|
1283 | *
|
---|
1284 | * @returns Corrected type.
|
---|
1285 | * @param pszPath The path to the object in question.
|
---|
1286 | */
|
---|
1287 | static RTDIRENTRYTYPE scmFigureUnknownType(const char *pszPath)
|
---|
1288 | {
|
---|
1289 | RTFSOBJINFO Info;
|
---|
1290 | int rc = RTPathQueryInfo(pszPath, &Info, RTFSOBJATTRADD_NOTHING);
|
---|
1291 | if (RT_FAILURE(rc))
|
---|
1292 | return RTDIRENTRYTYPE_UNKNOWN;
|
---|
1293 | if (RTFS_IS_DIRECTORY(Info.Attr.fMode))
|
---|
1294 | return RTDIRENTRYTYPE_DIRECTORY;
|
---|
1295 | if (RTFS_IS_FILE(Info.Attr.fMode))
|
---|
1296 | return RTDIRENTRYTYPE_FILE;
|
---|
1297 | return RTDIRENTRYTYPE_UNKNOWN;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /**
|
---|
1301 | * Recurse into a sub-directory and process all the files and directories.
|
---|
1302 | *
|
---|
1303 | * @returns IPRT status code.
|
---|
1304 | * @param pszBuf Path buffer containing the directory path on
|
---|
1305 | * entry. This ends with a dot. This is passed
|
---|
1306 | * along when recursing in order to save stack space
|
---|
1307 | * and avoid needless copying.
|
---|
1308 | * @param cchDir Length of our path in pszbuf.
|
---|
1309 | * @param pEntry Directory entry buffer. This is also passed
|
---|
1310 | * along when recursing to save stack space.
|
---|
1311 | * @param pSettingsStack The settings stack (pointer to the top element).
|
---|
1312 | * @param iRecursion The recursion depth. This is used to restrict
|
---|
1313 | * the recursions.
|
---|
1314 | */
|
---|
1315 | static int scmProcessDirTreeRecursion(char *pszBuf, size_t cchDir, PRTDIRENTRY pEntry,
|
---|
1316 | PSCMSETTINGS pSettingsStack, unsigned iRecursion)
|
---|
1317 | {
|
---|
1318 | int rc;
|
---|
1319 | Assert(cchDir > 1 && pszBuf[cchDir - 1] == '.');
|
---|
1320 |
|
---|
1321 | /*
|
---|
1322 | * Make sure we stop somewhere.
|
---|
1323 | */
|
---|
1324 | if (iRecursion > 128)
|
---|
1325 | {
|
---|
1326 | RTMsgError("recursion too deep: %d\n", iRecursion);
|
---|
1327 | return VINF_SUCCESS; /* ignore */
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | /*
|
---|
1331 | * Check if it's excluded by --only-svn-dir.
|
---|
1332 | */
|
---|
1333 | if (pSettingsStack->Base.fOnlySvnDirs)
|
---|
1334 | {
|
---|
1335 | if (!ScmSvnIsDirInWorkingCopy(pszBuf))
|
---|
1336 | return VINF_SUCCESS;
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | /*
|
---|
1340 | * Try open and read the directory.
|
---|
1341 | */
|
---|
1342 | PRTDIR pDir;
|
---|
1343 | rc = RTDirOpenFiltered(&pDir, pszBuf, RTDIRFILTER_NONE, 0);
|
---|
1344 | if (RT_FAILURE(rc))
|
---|
1345 | {
|
---|
1346 | RTMsgError("Failed to enumerate directory '%s': %Rrc", pszBuf, rc);
|
---|
1347 | return rc;
|
---|
1348 | }
|
---|
1349 | for (;;)
|
---|
1350 | {
|
---|
1351 | /* Read the next entry. */
|
---|
1352 | rc = RTDirRead(pDir, pEntry, NULL);
|
---|
1353 | if (RT_FAILURE(rc))
|
---|
1354 | {
|
---|
1355 | if (rc == VERR_NO_MORE_FILES)
|
---|
1356 | rc = VINF_SUCCESS;
|
---|
1357 | else
|
---|
1358 | RTMsgError("RTDirRead -> %Rrc\n", rc);
|
---|
1359 | break;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | /* Skip '.' and '..'. */
|
---|
1363 | if ( pEntry->szName[0] == '.'
|
---|
1364 | && ( pEntry->cbName == 1
|
---|
1365 | || ( pEntry->cbName == 2
|
---|
1366 | && pEntry->szName[1] == '.')))
|
---|
1367 | continue;
|
---|
1368 |
|
---|
1369 | /* Enter it into the buffer so we've got a full name to work
|
---|
1370 | with when needed. */
|
---|
1371 | if (pEntry->cbName + cchDir >= RTPATH_MAX)
|
---|
1372 | {
|
---|
1373 | RTMsgError("Skipping too long entry: %s", pEntry->szName);
|
---|
1374 | continue;
|
---|
1375 | }
|
---|
1376 | memcpy(&pszBuf[cchDir - 1], pEntry->szName, pEntry->cbName + 1);
|
---|
1377 |
|
---|
1378 | /* Figure the type. */
|
---|
1379 | RTDIRENTRYTYPE enmType = pEntry->enmType;
|
---|
1380 | if (enmType == RTDIRENTRYTYPE_UNKNOWN)
|
---|
1381 | enmType = scmFigureUnknownType(pszBuf);
|
---|
1382 |
|
---|
1383 | /* Process the file or directory, skip the rest. */
|
---|
1384 | if (enmType == RTDIRENTRYTYPE_FILE)
|
---|
1385 | rc = scmProcessFile(pszBuf, pEntry->szName, pEntry->cbName, pSettingsStack);
|
---|
1386 | else if (enmType == RTDIRENTRYTYPE_DIRECTORY)
|
---|
1387 | {
|
---|
1388 | /* Append the dot for the benefit of the pattern matching. */
|
---|
1389 | if (pEntry->cbName + cchDir + 5 >= RTPATH_MAX)
|
---|
1390 | {
|
---|
1391 | RTMsgError("Skipping too deep dir entry: %s", pEntry->szName);
|
---|
1392 | continue;
|
---|
1393 | }
|
---|
1394 | memcpy(&pszBuf[cchDir - 1 + pEntry->cbName], "/.", sizeof("/."));
|
---|
1395 | size_t cchSubDir = cchDir - 1 + pEntry->cbName + sizeof("/.") - 1;
|
---|
1396 |
|
---|
1397 | if ( !pSettingsStack->Base.pszFilterOutDirs
|
---|
1398 | || !*pSettingsStack->Base.pszFilterOutDirs
|
---|
1399 | || ( !RTStrSimplePatternMultiMatch(pSettingsStack->Base.pszFilterOutDirs, RTSTR_MAX,
|
---|
1400 | pEntry->szName, pEntry->cbName, NULL)
|
---|
1401 | && !RTStrSimplePatternMultiMatch(pSettingsStack->Base.pszFilterOutDirs, RTSTR_MAX,
|
---|
1402 | pszBuf, cchSubDir, NULL)
|
---|
1403 | )
|
---|
1404 | )
|
---|
1405 | {
|
---|
1406 | rc = scmSettingsStackPushDir(&pSettingsStack, pszBuf);
|
---|
1407 | if (RT_SUCCESS(rc))
|
---|
1408 | {
|
---|
1409 | rc = scmProcessDirTreeRecursion(pszBuf, cchSubDir, pEntry, pSettingsStack, iRecursion + 1);
|
---|
1410 | scmSettingsStackPopAndDestroy(&pSettingsStack);
|
---|
1411 | }
|
---|
1412 | }
|
---|
1413 | }
|
---|
1414 | if (RT_FAILURE(rc))
|
---|
1415 | break;
|
---|
1416 | }
|
---|
1417 | RTDirClose(pDir);
|
---|
1418 | return rc;
|
---|
1419 |
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | /**
|
---|
1423 | * Process a directory tree.
|
---|
1424 | *
|
---|
1425 | * @returns IPRT status code.
|
---|
1426 | * @param pszDir The directory to start with. This is pointer to
|
---|
1427 | * a RTPATH_MAX sized buffer.
|
---|
1428 | */
|
---|
1429 | static int scmProcessDirTree(char *pszDir, PSCMSETTINGS pSettingsStack)
|
---|
1430 | {
|
---|
1431 | /*
|
---|
1432 | * Setup the recursion.
|
---|
1433 | */
|
---|
1434 | int rc = RTPathAppend(pszDir, RTPATH_MAX, ".");
|
---|
1435 | if (RT_SUCCESS(rc))
|
---|
1436 | {
|
---|
1437 | RTDIRENTRY Entry;
|
---|
1438 | rc = scmProcessDirTreeRecursion(pszDir, strlen(pszDir), &Entry, pSettingsStack, 0);
|
---|
1439 | }
|
---|
1440 | else
|
---|
1441 | RTMsgError("RTPathAppend: %Rrc\n", rc);
|
---|
1442 | return rc;
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 |
|
---|
1446 | /**
|
---|
1447 | * Processes a file or directory specified as an command line argument.
|
---|
1448 | *
|
---|
1449 | * @returns IPRT status code
|
---|
1450 | * @param pszSomething What we found in the command line arguments.
|
---|
1451 | * @param pSettingsStack The settings stack (pointer to the top element).
|
---|
1452 | */
|
---|
1453 | static int scmProcessSomething(const char *pszSomething, PSCMSETTINGS pSettingsStack)
|
---|
1454 | {
|
---|
1455 | char szBuf[RTPATH_MAX];
|
---|
1456 | int rc = RTPathAbs(pszSomething, szBuf, sizeof(szBuf));
|
---|
1457 | if (RT_SUCCESS(rc))
|
---|
1458 | {
|
---|
1459 | RTPathChangeToUnixSlashes(szBuf, false /*fForce*/);
|
---|
1460 |
|
---|
1461 | PSCMSETTINGS pSettings;
|
---|
1462 | rc = scmSettingsCreateForPath(&pSettings, &pSettingsStack->Base, szBuf);
|
---|
1463 | if (RT_SUCCESS(rc))
|
---|
1464 | {
|
---|
1465 | scmSettingsStackPush(&pSettingsStack, pSettings);
|
---|
1466 |
|
---|
1467 | if (RTFileExists(szBuf))
|
---|
1468 | {
|
---|
1469 | const char *pszBasename = RTPathFilename(szBuf);
|
---|
1470 | if (pszBasename)
|
---|
1471 | {
|
---|
1472 | size_t cchBasename = strlen(pszBasename);
|
---|
1473 | rc = scmProcessFile(szBuf, pszBasename, cchBasename, pSettingsStack);
|
---|
1474 | }
|
---|
1475 | else
|
---|
1476 | {
|
---|
1477 | RTMsgError("RTPathFilename: NULL\n");
|
---|
1478 | rc = VERR_IS_A_DIRECTORY;
|
---|
1479 | }
|
---|
1480 | }
|
---|
1481 | else
|
---|
1482 | rc = scmProcessDirTree(szBuf, pSettingsStack);
|
---|
1483 |
|
---|
1484 | PSCMSETTINGS pPopped = scmSettingsStackPop(&pSettingsStack);
|
---|
1485 | Assert(pPopped == pSettings); RT_NOREF_PV(pPopped);
|
---|
1486 | scmSettingsDestroy(pSettings);
|
---|
1487 | }
|
---|
1488 | else
|
---|
1489 | RTMsgError("scmSettingsInitStack: %Rrc\n", rc);
|
---|
1490 | }
|
---|
1491 | else
|
---|
1492 | RTMsgError("RTPathAbs: %Rrc\n", rc);
|
---|
1493 | return rc;
|
---|
1494 | }
|
---|
1495 |
|
---|
1496 | static void usage(PCRTGETOPTDEF paOpts, size_t cOpts)
|
---|
1497 | {
|
---|
1498 | RTPrintf("VirtualBox Source Code Massager\n"
|
---|
1499 | "\n"
|
---|
1500 | "Usage: %s [options] <files & dirs>\n"
|
---|
1501 | "\n"
|
---|
1502 | "Options:\n", g_szProgName);
|
---|
1503 | for (size_t i = 0; i < cOpts; i++)
|
---|
1504 | {
|
---|
1505 | bool fAdvanceTwo = false;
|
---|
1506 | if ((paOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_NOTHING)
|
---|
1507 | {
|
---|
1508 | fAdvanceTwo = i + 1 < cOpts
|
---|
1509 | && ( strstr(paOpts[i+1].pszLong, "-no-") != NULL
|
---|
1510 | || strstr(paOpts[i+1].pszLong, "-not-") != NULL
|
---|
1511 | || strstr(paOpts[i+1].pszLong, "-dont-") != NULL
|
---|
1512 | || (paOpts[i].iShort == 'q' && paOpts[i+1].iShort == 'v')
|
---|
1513 | || (paOpts[i].iShort == 'd' && paOpts[i+1].iShort == 'D')
|
---|
1514 | );
|
---|
1515 | if (fAdvanceTwo)
|
---|
1516 | RTPrintf(" %s, %s\n", paOpts[i].pszLong, paOpts[i + 1].pszLong);
|
---|
1517 | else
|
---|
1518 | RTPrintf(" %s\n", paOpts[i].pszLong);
|
---|
1519 | }
|
---|
1520 | else if ((paOpts[i].fFlags & RTGETOPT_REQ_MASK) == RTGETOPT_REQ_STRING)
|
---|
1521 | RTPrintf(" %s string\n", paOpts[i].pszLong);
|
---|
1522 | else
|
---|
1523 | RTPrintf(" %s value\n", paOpts[i].pszLong);
|
---|
1524 | switch (paOpts[i].iShort)
|
---|
1525 | {
|
---|
1526 | case 'd':
|
---|
1527 | case 'D': RTPrintf(" Default: --dry-run\n"); break;
|
---|
1528 | case 'f': RTPrintf(" Default: none\n"); break;
|
---|
1529 | case 'q':
|
---|
1530 | case 'v': RTPrintf(" Default: -vv\n"); break;
|
---|
1531 |
|
---|
1532 | case SCMOPT_DIFF_IGNORE_EOL: RTPrintf(" Default: false\n"); break;
|
---|
1533 | case SCMOPT_DIFF_IGNORE_SPACE: RTPrintf(" Default: false\n"); break;
|
---|
1534 | case SCMOPT_DIFF_IGNORE_LEADING_SPACE: RTPrintf(" Default: false\n"); break;
|
---|
1535 | case SCMOPT_DIFF_IGNORE_TRAILING_SPACE: RTPrintf(" Default: false\n"); break;
|
---|
1536 | case SCMOPT_DIFF_SPECIAL_CHARS: RTPrintf(" Default: true\n"); break;
|
---|
1537 |
|
---|
1538 | case SCMOPT_CONVERT_EOL: RTPrintf(" Default: %RTbool\n", g_Defaults.fConvertEol); break;
|
---|
1539 | case SCMOPT_CONVERT_TABS: RTPrintf(" Default: %RTbool\n", g_Defaults.fConvertTabs); break;
|
---|
1540 | case SCMOPT_FORCE_FINAL_EOL: RTPrintf(" Default: %RTbool\n", g_Defaults.fForceFinalEol); break;
|
---|
1541 | case SCMOPT_FORCE_TRAILING_LINE: RTPrintf(" Default: %RTbool\n", g_Defaults.fForceTrailingLine); break;
|
---|
1542 | case SCMOPT_STRIP_TRAILING_BLANKS: RTPrintf(" Default: %RTbool\n", g_Defaults.fStripTrailingBlanks); break;
|
---|
1543 | case SCMOPT_STRIP_TRAILING_LINES: RTPrintf(" Default: %RTbool\n", g_Defaults.fStripTrailingLines); break;
|
---|
1544 | case SCMOPT_FIX_FLOWER_BOX_MARKERS: RTPrintf(" Default: %RTbool\n", g_Defaults.fFixFlowerBoxMarkers); break;
|
---|
1545 | case SCMOPT_MIN_BLANK_LINES_BEFORE_FLOWER_BOX_MARKERS: RTPrintf(" Default: %u\n", g_Defaults.cMinBlankLinesBeforeFlowerBoxMakers); break;
|
---|
1546 | case SCMOPT_ONLY_SVN_DIRS: RTPrintf(" Default: %RTbool\n", g_Defaults.fOnlySvnDirs); break;
|
---|
1547 | case SCMOPT_ONLY_SVN_FILES: RTPrintf(" Default: %RTbool\n", g_Defaults.fOnlySvnFiles); break;
|
---|
1548 | case SCMOPT_SET_SVN_EOL: RTPrintf(" Default: %RTbool\n", g_Defaults.fSetSvnEol); break;
|
---|
1549 | case SCMOPT_SET_SVN_EXECUTABLE: RTPrintf(" Default: %RTbool\n", g_Defaults.fSetSvnExecutable); break;
|
---|
1550 | case SCMOPT_SET_SVN_KEYWORDS: RTPrintf(" Default: %RTbool\n", g_Defaults.fSetSvnKeywords); break;
|
---|
1551 | case SCMOPT_TAB_SIZE: RTPrintf(" Default: %u\n", g_Defaults.cchTab); break;
|
---|
1552 | case SCMOPT_WIDTH: RTPrintf(" Default: %u\n", g_Defaults.cchWidth); break;
|
---|
1553 | case SCMOPT_FILTER_OUT_DIRS: RTPrintf(" Default: %s\n", g_Defaults.pszFilterOutDirs); break;
|
---|
1554 | case SCMOPT_FILTER_FILES: RTPrintf(" Default: %s\n", g_Defaults.pszFilterFiles); break;
|
---|
1555 | case SCMOPT_FILTER_OUT_FILES: RTPrintf(" Default: %s\n", g_Defaults.pszFilterOutFiles); break;
|
---|
1556 | default: AssertMsgFailed(("i=%d %d %s\n", i, paOpts[i].iShort, paOpts[i].pszLong));
|
---|
1557 | }
|
---|
1558 | i += fAdvanceTwo;
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | int main(int argc, char **argv)
|
---|
1564 | {
|
---|
1565 | int rc = RTR3InitExe(argc, &argv, 0);
|
---|
1566 | if (RT_FAILURE(rc))
|
---|
1567 | return 1;
|
---|
1568 |
|
---|
1569 | /*
|
---|
1570 | * Init the settings.
|
---|
1571 | */
|
---|
1572 | PSCMSETTINGS pSettings;
|
---|
1573 | rc = scmSettingsCreate(&pSettings, &g_Defaults);
|
---|
1574 | if (RT_FAILURE(rc))
|
---|
1575 | {
|
---|
1576 | RTMsgError("scmSettingsCreate: %Rrc\n", rc);
|
---|
1577 | return 1;
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | /*
|
---|
1581 | * Parse arguments and process input in order (because this is the only
|
---|
1582 | * thing that works at the moment).
|
---|
1583 | */
|
---|
1584 | static RTGETOPTDEF s_aOpts[14 + RT_ELEMENTS(g_aScmOpts)] =
|
---|
1585 | {
|
---|
1586 | { "--dry-run", 'd', RTGETOPT_REQ_NOTHING },
|
---|
1587 | { "--real-run", 'D', RTGETOPT_REQ_NOTHING },
|
---|
1588 | { "--file-filter", 'f', RTGETOPT_REQ_STRING },
|
---|
1589 | { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
|
---|
1590 | { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
|
---|
1591 | { "--diff-ignore-eol", SCMOPT_DIFF_IGNORE_EOL, RTGETOPT_REQ_NOTHING },
|
---|
1592 | { "--diff-no-ignore-eol", SCMOPT_DIFF_NO_IGNORE_EOL, RTGETOPT_REQ_NOTHING },
|
---|
1593 | { "--diff-ignore-space", SCMOPT_DIFF_IGNORE_SPACE, RTGETOPT_REQ_NOTHING },
|
---|
1594 | { "--diff-no-ignore-space", SCMOPT_DIFF_NO_IGNORE_SPACE, RTGETOPT_REQ_NOTHING },
|
---|
1595 | { "--diff-ignore-leading-space", SCMOPT_DIFF_IGNORE_LEADING_SPACE, RTGETOPT_REQ_NOTHING },
|
---|
1596 | { "--diff-no-ignore-leading-space", SCMOPT_DIFF_NO_IGNORE_LEADING_SPACE, RTGETOPT_REQ_NOTHING },
|
---|
1597 | { "--diff-ignore-trailing-space", SCMOPT_DIFF_IGNORE_TRAILING_SPACE, RTGETOPT_REQ_NOTHING },
|
---|
1598 | { "--diff-no-ignore-trailing-space", SCMOPT_DIFF_NO_IGNORE_TRAILING_SPACE, RTGETOPT_REQ_NOTHING },
|
---|
1599 | { "--diff-special-chars", SCMOPT_DIFF_SPECIAL_CHARS, RTGETOPT_REQ_NOTHING },
|
---|
1600 | { "--diff-no-special-chars", SCMOPT_DIFF_NO_SPECIAL_CHARS, RTGETOPT_REQ_NOTHING },
|
---|
1601 | };
|
---|
1602 | memcpy(&s_aOpts[RT_ELEMENTS(s_aOpts) - RT_ELEMENTS(g_aScmOpts)], &g_aScmOpts[0], sizeof(g_aScmOpts));
|
---|
1603 |
|
---|
1604 | RTGETOPTUNION ValueUnion;
|
---|
1605 | RTGETOPTSTATE GetOptState;
|
---|
1606 | rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
|
---|
1607 | AssertReleaseRCReturn(rc, 1);
|
---|
1608 | size_t cProcessed = 0;
|
---|
1609 |
|
---|
1610 | while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
|
---|
1611 | {
|
---|
1612 | switch (rc)
|
---|
1613 | {
|
---|
1614 | case 'd':
|
---|
1615 | g_fDryRun = true;
|
---|
1616 | break;
|
---|
1617 | case 'D':
|
---|
1618 | g_fDryRun = false;
|
---|
1619 | break;
|
---|
1620 |
|
---|
1621 | case 'f':
|
---|
1622 | g_pszFileFilter = ValueUnion.psz;
|
---|
1623 | break;
|
---|
1624 |
|
---|
1625 | case 'h':
|
---|
1626 | usage(s_aOpts, RT_ELEMENTS(s_aOpts));
|
---|
1627 | return 1;
|
---|
1628 |
|
---|
1629 | case 'q':
|
---|
1630 | g_iVerbosity = 0;
|
---|
1631 | break;
|
---|
1632 |
|
---|
1633 | case 'v':
|
---|
1634 | g_iVerbosity++;
|
---|
1635 | break;
|
---|
1636 |
|
---|
1637 | case 'V':
|
---|
1638 | {
|
---|
1639 | /* The following is assuming that svn does it's job here. */
|
---|
1640 | static const char s_szRev[] = "$Revision: 63559 $";
|
---|
1641 | const char *psz = RTStrStripL(strchr(s_szRev, ' '));
|
---|
1642 | RTPrintf("r%.*s\n", strchr(psz, ' ') - psz, psz);
|
---|
1643 | return 0;
|
---|
1644 | }
|
---|
1645 |
|
---|
1646 | case SCMOPT_DIFF_IGNORE_EOL:
|
---|
1647 | g_fDiffIgnoreEol = true;
|
---|
1648 | break;
|
---|
1649 | case SCMOPT_DIFF_NO_IGNORE_EOL:
|
---|
1650 | g_fDiffIgnoreEol = false;
|
---|
1651 | break;
|
---|
1652 |
|
---|
1653 | case SCMOPT_DIFF_IGNORE_SPACE:
|
---|
1654 | g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = true;
|
---|
1655 | break;
|
---|
1656 | case SCMOPT_DIFF_NO_IGNORE_SPACE:
|
---|
1657 | g_fDiffIgnoreTrailingWS = g_fDiffIgnoreLeadingWS = false;
|
---|
1658 | break;
|
---|
1659 |
|
---|
1660 | case SCMOPT_DIFF_IGNORE_LEADING_SPACE:
|
---|
1661 | g_fDiffIgnoreLeadingWS = true;
|
---|
1662 | break;
|
---|
1663 | case SCMOPT_DIFF_NO_IGNORE_LEADING_SPACE:
|
---|
1664 | g_fDiffIgnoreLeadingWS = false;
|
---|
1665 | break;
|
---|
1666 |
|
---|
1667 | case SCMOPT_DIFF_IGNORE_TRAILING_SPACE:
|
---|
1668 | g_fDiffIgnoreTrailingWS = true;
|
---|
1669 | break;
|
---|
1670 | case SCMOPT_DIFF_NO_IGNORE_TRAILING_SPACE:
|
---|
1671 | g_fDiffIgnoreTrailingWS = false;
|
---|
1672 | break;
|
---|
1673 |
|
---|
1674 | case SCMOPT_DIFF_SPECIAL_CHARS:
|
---|
1675 | g_fDiffSpecialChars = true;
|
---|
1676 | break;
|
---|
1677 | case SCMOPT_DIFF_NO_SPECIAL_CHARS:
|
---|
1678 | g_fDiffSpecialChars = false;
|
---|
1679 | break;
|
---|
1680 |
|
---|
1681 | case VINF_GETOPT_NOT_OPTION:
|
---|
1682 | {
|
---|
1683 | if (!g_fDryRun)
|
---|
1684 | {
|
---|
1685 | if (!cProcessed)
|
---|
1686 | {
|
---|
1687 | RTPrintf("%s: Warning! This program will make changes to your source files and\n"
|
---|
1688 | "%s: there is a slight risk that bugs or a full disk may cause\n"
|
---|
1689 | "%s: LOSS OF DATA. So, please make sure you have checked in\n"
|
---|
1690 | "%s: all your changes already. If you didn't, then don't blame\n"
|
---|
1691 | "%s: anyone for not warning you!\n"
|
---|
1692 | "%s:\n"
|
---|
1693 | "%s: Press any key to continue...\n",
|
---|
1694 | g_szProgName, g_szProgName, g_szProgName, g_szProgName, g_szProgName,
|
---|
1695 | g_szProgName, g_szProgName);
|
---|
1696 | RTStrmGetCh(g_pStdIn);
|
---|
1697 | }
|
---|
1698 | cProcessed++;
|
---|
1699 | }
|
---|
1700 | rc = scmProcessSomething(ValueUnion.psz, pSettings);
|
---|
1701 | if (RT_FAILURE(rc))
|
---|
1702 | return rc;
|
---|
1703 | break;
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | default:
|
---|
1707 | {
|
---|
1708 | int rc2 = scmSettingsBaseHandleOpt(&pSettings->Base, rc, &ValueUnion);
|
---|
1709 | if (RT_SUCCESS(rc2))
|
---|
1710 | break;
|
---|
1711 | if (rc2 != VERR_GETOPT_UNKNOWN_OPTION)
|
---|
1712 | return 2;
|
---|
1713 | return RTGetOptPrintError(rc, &ValueUnion);
|
---|
1714 | }
|
---|
1715 | }
|
---|
1716 | }
|
---|
1717 |
|
---|
1718 | scmSettingsDestroy(pSettings);
|
---|
1719 | return 0;
|
---|
1720 | }
|
---|
1721 |
|
---|