changeset 442:7f49f0e68bca

Extended the created batch/shell script so it is able to indent only one file given as parameter or a whole directory recursively with a defined file suffix. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@677 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 15 May 2008 20:21:42 +0000
parents 5afe7540135e
children 2f7c7f3e4342
files src/indenthandler.cpp src/templateBatchScript.h
diffstat 2 files changed, 21 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/indenthandler.cpp	Thu May 15 19:35:55 2008 +0000
+++ b/src/indenthandler.cpp	Thu May 15 20:21:42 2008 +0000
@@ -125,11 +125,11 @@
 	QString parameterParameterFile;
     QString replaceInputFileCommand;
 
-    // Define the placeholder for variable either in batch or bash programming.
+    // Define the placeholder for parameter variable either in batch or bash programming.
 #if defined(Q_OS_WIN32)
-    QString shellPlaceholder = "%1";
+    QString shellParameterPlaceholder = "%1";
 #else
-    QString shellPlaceholder = "$1";
+    QString shellParameterPlaceholder = "$1";
 #endif
 
     // Generate the parameter string that will be saved to the indenters config file.
@@ -144,11 +144,11 @@
         inputFileExtension = "." + inputFileExtension;
     }
 
-    parameterInputFile = " " + inputFileParameter + "\"" + shellPlaceholder + "\"";
+    parameterInputFile = " " + inputFileParameter + "\"" + shellParameterPlaceholder + "\"";
 
     if ( outputFileParameter != "none" && outputFileParameter != "stdout" ) {
         if ( outputFileName == inputFileName ) {
-            parameterOuputFile = " " + outputFileParameter + "\"" + shellPlaceholder + "\"";
+            parameterOuputFile = " " + outputFileParameter + "\"" + shellParameterPlaceholder + "\"";
         }
         else {
             parameterOuputFile = " " + outputFileParameter + outputFileName + inputFileExtension;
@@ -193,13 +193,21 @@
     // If the output filename is not the same as the input filename copy the output over the input.
     if ( outputFileName != inputFileName ) {
 #if defined(Q_OS_WIN32)
-        replaceInputFileCommand = "move /Y " + outputFileName + inputFileExtension + " \"" + shellPlaceholder + "\"\n";
+        replaceInputFileCommand = "move /Y " + outputFileName + inputFileExtension + " \"" + shellParameterPlaceholder + "\"\n";
 #else
-        replaceInputFileCommand = "mv " + outputFileName + inputFileExtension + " \"" + shellPlaceholder + "\"\n";
+        replaceInputFileCommand = "mv " + outputFileName + inputFileExtension + " \"" + shellParameterPlaceholder + "\"\n";
 #endif
     }
 
-    return indenterCompleteCallString + "\n" + replaceInputFileCommand;
+    QString shellScript(templateBatchScript);
+    shellScript = shellScript.replace("__INDENTERCALLSTRING2__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
+#if defined(Q_OS_WIN32)
+    indenterCompleteCallString = indenterCompleteCallString.replace("%1", "%%G");
+#else
+#endif
+    shellScript = shellScript.replace("__INDENTERCALLSTRING1__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
+
+    return shellScript;
 }
 
 
--- a/src/templateBatchScript.h	Thu May 15 19:35:55 2008 +0000
+++ b/src/templateBatchScript.h	Thu May 15 20:21:42 2008 +0000
@@ -24,12 +24,7 @@
 "@echo off\n"
 "\n"
 "IF (%1)==() GOTO error\n"
-"IF EXIST %1\\. GOTO indentDir\n"
-":: if the directory parameter contains quotes, remove them and try again if the dir exists\n"
-"set newpath=%1%\n"
-"set newpath=\"%newpath:~1,-1%\\.\"\n"
-"::echo newpath=%newpath%\n"
-"IF EXIST %newpath% GOTO indentDir\n"
+"dir /b /ad %1 >nul 2>nul && GOTO indentDir\n"
 "IF NOT EXIST %1 GOTO error\n"
 "goto indentFile\n"
 "\n"
@@ -55,16 +50,13 @@
 ":run\n"
 "FOR /F \"tokens=*\" %%G IN ('DIR /B /S %searchdir%\\*.%filesuffix%') DO (\n"
     "echo Indenting file \"%%G\"\n"
-    "::call call_CSSTidy.bat \"%%G\"\n"
-	"\"C:/Dokumente und Einstellungen/ts/Eigene Dateien/Visual Studio 2005/Projects/UiGuixy/indenters/csstidy.exe\" \"%%G\" --timestamp=true --allow_html_in_templates=false --compress_colors=true --compress_font=true --lowercase_s=false --preserve_css=false --remove_last_;=false --remove_bslash=true --sort_properties=false --sort_selectors=false  indentoutput.css\n"
-    "move /Y indentoutput.css \"%%G\"\n"
+    "__INDENTERCALLSTRING1__\n"
 ")\n"
 "GOTO ende\n"
 "\n"
 ":indentFile\n"
 "echo Indenting one file %1\n"
-"\"C:/Dokumente und Einstellungen/ts/Eigene Dateien/Visual Studio 2005/Projects/UiGuixy/indenters/csstidy.exe\" %1 --timestamp=true --allow_html_in_templates=false --compress_colors=true --compress_font=true --lowercase_s=false --preserve_css=false --remove_last_;=false --remove_bslash=true --sort_properties=false --sort_selectors=false  indentoutput.css\n"
-"move /Y indentoutput.css %1\n"
+"__INDENTERCALLSTRING2__\n"
 "\n"
 "GOTO ende\n"
 "\n"
@@ -84,12 +76,7 @@
 @echo off
 
 IF (%1)==() GOTO error
-IF EXIST %1\. GOTO indentDir
-:: if the directory parameter contains quotes, remove them and try again if the dir exists
-set newpath=%1%
-set newpath="%newpath:~1,-1%\."
-::echo newpath=%newpath%
-IF EXIST %newpath% GOTO indentDir
+dir /b /ad %1 >nul 2>nul && GOTO indentDir
 IF NOT EXIST %1 GOTO error
 goto indentFile
 
@@ -131,7 +118,7 @@
 :error
 echo .
 echo ERROR: As parameter given directory or file does not exist!
-echo Syntax is: recurse.bat dirname filesuffix
+echo Syntax is: recurse.bat dirname file suffix
 echo Syntax is: recurse.bat filename
 echo Example: recurse.bat temp cpp
 echo .