changeset 443:2f7c7f3e4342

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. Now also for Unix systems. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@678 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 15 May 2008 21:07:47 +0000
parents 7f49f0e68bca
children d1fbad5db5ce
files src/indenthandler.cpp src/templateBatchScript.h
diffstat 2 files changed, 49 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/indenthandler.cpp	Thu May 15 20:21:42 2008 +0000
+++ b/src/indenthandler.cpp	Thu May 15 21:07:47 2008 +0000
@@ -199,13 +199,17 @@
 #endif
     }
 
+#if defined(Q_OS_WIN32)
     QString shellScript(templateBatchScript);
     shellScript = shellScript.replace("__INDENTERCALLSTRING2__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
-#if defined(Q_OS_WIN32)
     indenterCompleteCallString = indenterCompleteCallString.replace("%1", "%%G");
+    shellScript = shellScript.replace("__INDENTERCALLSTRING1__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
 #else
+    QString shellScript(templateShellScript);
+    shellScript = shellScript.replace("__INDENTERCALLSTRING2__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
+    indenterCompleteCallString = indenterCompleteCallString.replace("$1", "$file2indent");
+    shellScript = shellScript.replace("__INDENTERCALLSTRING1__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
 #endif
-    shellScript = shellScript.replace("__INDENTERCALLSTRING1__", indenterCompleteCallString + "\n" + replaceInputFileCommand);
 
     return shellScript;
 }
--- a/src/templateBatchScript.h	Thu May 15 20:21:42 2008 +0000
+++ b/src/templateBatchScript.h	Thu May 15 21:07:47 2008 +0000
@@ -21,6 +21,7 @@
 #define TEMPLATEBATCHSCRIPT_H
 
 static const char* templateBatchScript =
+#if defined(Q_OS_WIN32)
 "@echo off\n"
 "\n"
 "IF (%1)==() GOTO error\n"
@@ -70,6 +71,47 @@
 "\n"
 ":ende\n";
 
+#else
+
+"#!/bin/sh \n"
+"\n"
+"if [ ! -n \"$1\" ]; then\n"
+    "echo \"Syntax is: recurse.sh dirname filesuffix\"\n"
+    "echo \"Syntax is: recurse.sh filename\"\n"
+    "echo \"Example: recurse.sh temp cpp\"\n"
+    "exit 1\n"
+"fi\n"
+"\n"
+"if [ -d \"$1\" ]; then\n"
+    "#echo \"Dir ${1} exists\"\n"
+    "if [ -n \"$2\" ]; then\n"
+        "filesuffix=$2\n"
+    "else\n"
+        "filesuffix=\"*\"\n"
+    "fi\n"
+    "\n"
+    "#echo \"Filtering files using suffix ${filesuffix}\"\n"
+    "\n"
+    "file_list=`find temp -name \"*.${filesuffix}\" -type f`\n"
+    "for file2indent in $file_list\n"
+    "do \n"
+        "echo \"Indenting file $file2indent\"\n"
+        "__INDENTERCALLSTRING1__\n"
+    "done\n"
+"else\n"
+    "if [ -f \"$1\" ]; then\n"
+        "echo \"Indenting one file $1\"\n"
+        "__INDENTERCALLSTRING2__\n"
+    "else\n"
+        "echo \"ERROR: As parameter given directory or file does not exist!\"\n"
+        "echo \"Syntax is: recurse.sh dirname filesuffix\"\n"
+        "echo \"Syntax is: recurse.sh filename\"\n"
+        "echo \"Example: recurse.sh temp cpp\"\n"
+        "exit 1\n"
+    "fi\n"
+"fi\n";
+#endif // #if defined(Q_OS_WIN32)
+
 #endif // TEMPLATEBATCHSCRIPT_H
 
 /* Here comes the original batch script without the c++ markup
@@ -118,7 +160,7 @@
 :error
 echo .
 echo ERROR: As parameter given directory or file does not exist!
-echo Syntax is: recurse.bat dirname file suffix
+echo Syntax is: recurse.bat dirname filesuffix
 echo Syntax is: recurse.bat filename
 echo Example: recurse.bat temp cpp
 echo .