|
|
@@ -370,7 +370,13 @@ namespace |
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
static bool cleanWhitespace (const File& file, bool replaceTabs)
|
|
|
|
struct CleanupOptions
|
|
|
|
{
|
|
|
|
bool removeTabs;
|
|
|
|
bool fixDividerComments;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool cleanWhitespace (const File& file, CleanupOptions options)
|
|
|
|
{
|
|
|
|
const String content (file.loadFileAsString());
|
|
|
|
|
|
|
@@ -385,7 +391,7 @@ namespace |
|
|
|
{
|
|
|
|
String& line = lines.getReference(i);
|
|
|
|
|
|
|
|
if (replaceTabs && line.containsChar ('\t'))
|
|
|
|
if (options.removeTabs && line.containsChar ('\t'))
|
|
|
|
{
|
|
|
|
anyTabsRemoved = true;
|
|
|
|
|
|
|
@@ -401,10 +407,28 @@ namespace |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.fixDividerComments)
|
|
|
|
{
|
|
|
|
String afterIndent (line.trim());
|
|
|
|
|
|
|
|
if (afterIndent.startsWith ("//") && afterIndent.length() > 20)
|
|
|
|
{
|
|
|
|
afterIndent = afterIndent.substring (2);
|
|
|
|
|
|
|
|
if (afterIndent.containsOnly ("=")
|
|
|
|
|| afterIndent.containsOnly ("/")
|
|
|
|
|| afterIndent.containsOnly ("-"))
|
|
|
|
{
|
|
|
|
line = line.substring (0, line.indexOfChar ('/'))
|
|
|
|
+ "//" + String::repeatedString ("=", 78);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
line = line.trimEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (replaceTabs && ! anyTabsRemoved)
|
|
|
|
if (options.removeTabs && ! anyTabsRemoved)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
while (lines.size() > 10 && lines [lines.size() - 1].isEmpty())
|
|
|
@@ -416,8 +440,8 @@ namespace |
|
|
|
if (newText == content || newText == content + lineEnding)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
std::cout << (replaceTabs ? "Removing tabs in: "
|
|
|
|
: "Cleaning file: ") << file.getFullPathName() << std::endl;
|
|
|
|
std::cout << (options.removeTabs ? "Removing tabs in: "
|
|
|
|
: "Cleaning file: ") << file.getFullPathName() << std::endl;
|
|
|
|
|
|
|
|
TemporaryFile temp (file);
|
|
|
|
|
|
|
@@ -436,7 +460,7 @@ namespace |
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cleanWhitespace (const StringArray& args, bool replaceTabs)
|
|
|
|
static int scanFilesForCleanup (const StringArray& args, CleanupOptions options)
|
|
|
|
{
|
|
|
|
if (! checkArgumentCount (args, 2))
|
|
|
|
return 1;
|
|
|
@@ -452,18 +476,30 @@ namespace |
|
|
|
if (targetFolder.isDirectory())
|
|
|
|
{
|
|
|
|
for (DirectoryIterator di (targetFolder, true, "*.cpp;*.h;*.hpp;*.c;*.cc;*.mm;*.m", File::findFiles); di.next();)
|
|
|
|
if (! cleanWhitespace (di.getFile(), replaceTabs))
|
|
|
|
if (! cleanWhitespace (di.getFile(), options))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (! cleanWhitespace (targetFolder, replaceTabs))
|
|
|
|
if (! cleanWhitespace (targetFolder, options))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cleanWhitespace (const StringArray& args, bool replaceTabs)
|
|
|
|
{
|
|
|
|
CleanupOptions options = { replaceTabs, false };
|
|
|
|
return scanFilesForCleanup (args, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tidyDividerComments (const StringArray& args)
|
|
|
|
{
|
|
|
|
CleanupOptions options = { false, true };
|
|
|
|
return scanFilesForCleanup (args, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
static int showHelp()
|
|
|
|
{
|
|
|
@@ -502,6 +538,9 @@ namespace |
|
|
|
<< std::endl
|
|
|
|
<< " introjucer --remove-tabs target_folder" << std::endl
|
|
|
|
<< " Scans the given folder for C/C++ source files, and replaces any tab characters with 4 spaces." << std::endl
|
|
|
|
<< std::endl
|
|
|
|
<< " introjucer --tidy-divider-comments target_folder" << std::endl
|
|
|
|
<< " Scans the given folder for C/C++ source files, and normalises any juce-style comment division lines (i.e. any lines that look like //===== or //------- or /////////// will be replaced)." << std::endl
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
@@ -517,18 +556,19 @@ int performCommandLine (const String& commandLine) |
|
|
|
|
|
|
|
String command (args[0]);
|
|
|
|
|
|
|
|
if (matchArgument (command, "help")) return showHelp();
|
|
|
|
if (matchArgument (command, "h")) return showHelp();
|
|
|
|
if (matchArgument (command, "resave")) return resaveProject (args, false);
|
|
|
|
if (matchArgument (command, "resave-resources")) return resaveProject (args, true);
|
|
|
|
if (matchArgument (command, "set-version")) return setVersion (args);
|
|
|
|
if (matchArgument (command, "bump-version")) return bumpVersion (args);
|
|
|
|
if (matchArgument (command, "git-tag-version")) return gitTag (args);
|
|
|
|
if (matchArgument (command, "buildmodule")) return buildModules (args, false);
|
|
|
|
if (matchArgument (command, "buildallmodules")) return buildModules (args, true);
|
|
|
|
if (matchArgument (command, "status")) return showStatus (args);
|
|
|
|
if (matchArgument (command, "trim-whitespace")) return cleanWhitespace (args, false);
|
|
|
|
if (matchArgument (command, "remove-tabs")) return cleanWhitespace (args, true);
|
|
|
|
if (matchArgument (command, "help")) return showHelp();
|
|
|
|
if (matchArgument (command, "h")) return showHelp();
|
|
|
|
if (matchArgument (command, "resave")) return resaveProject (args, false);
|
|
|
|
if (matchArgument (command, "resave-resources")) return resaveProject (args, true);
|
|
|
|
if (matchArgument (command, "set-version")) return setVersion (args);
|
|
|
|
if (matchArgument (command, "bump-version")) return bumpVersion (args);
|
|
|
|
if (matchArgument (command, "git-tag-version")) return gitTag (args);
|
|
|
|
if (matchArgument (command, "buildmodule")) return buildModules (args, false);
|
|
|
|
if (matchArgument (command, "buildallmodules")) return buildModules (args, true);
|
|
|
|
if (matchArgument (command, "status")) return showStatus (args);
|
|
|
|
if (matchArgument (command, "trim-whitespace")) return cleanWhitespace (args, false);
|
|
|
|
if (matchArgument (command, "remove-tabs")) return cleanWhitespace (args, true);
|
|
|
|
if (matchArgument (command, "tidy-divider-comments")) return tidyDividerComments (args);
|
|
|
|
|
|
|
|
return commandLineNotPerformed;
|
|
|
|
}
|