From db7390b8eee1d2e3e10b6200acdc96b5d734993c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 18 Dec 2019 16:23:57 +0100
Subject: [PATCH] Improve indentation scripts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

— now accept several input arguments
— the script themselves can now be called with an absolute pathname
— clearer output
---
 scripts/indent-c++    | 26 ++++++++++++++++----------
 scripts/indent-matlab | 24 +++++++++++++++---------
 2 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/scripts/indent-c++ b/scripts/indent-c++
index db299d518d..5da21f39a4 100755
--- a/scripts/indent-c++
+++ b/scripts/indent-c++
@@ -1,15 +1,21 @@
-#!/bin/sh
+#!/bin/bash
 
-# Reindents the C++ source code file given in argument.
+# Reindents the C++ source code files given in argument
 
-if [ -z "$1" ]; then
-    echo "Give a filename in argument"
-    exit 1
-fi
+[[ -n $1 ]] || { echo "Give filename(s) in argument" 2>&1; exit 1; }
 
-SCRIPTS_DIR=$(pwd)/$(dirname $0)
+pushd "$(dirname "$0")" > /dev/null
+SCRIPTS_DIR=$(pwd)
+popd > /dev/null
 
-uncrustify -l CPP --replace -c ${SCRIPTS_DIR}/uncrustify.cfg $1
+for f in "$@"; do
+    echo "*** Indenting $f…"
 
-cd $(dirname $1)
-emacs -batch $(basename $1) -l ${SCRIPTS_DIR}/indent-c++.el
+    uncrustify -l CPP --replace -c "${SCRIPTS_DIR}"/uncrustify.cfg "$f"
+
+    pushd "$(dirname "$f")" > /dev/null
+    emacs -batch "$(basename "$f")" -l "${SCRIPTS_DIR}"/indent-c++.el
+    popd > /dev/null
+
+    echo
+done
diff --git a/scripts/indent-matlab b/scripts/indent-matlab
index 77772bd9a4..908e0f075e 100755
--- a/scripts/indent-matlab
+++ b/scripts/indent-matlab
@@ -1,13 +1,19 @@
-#!/bin/sh
+#!/bin/bash
 
-# Reindents the MATLAB source code file given in argument.
+# Reindents the MATLAB source code files given in argument
 
-if [ -z "$1" ]; then
-    echo "Give a filename in argument"
-    exit 1
-fi
+[[ -n $1 ]] || { echo "Give filename(s) in argument" 2>&1; exit 1; }
 
-SCRIPTS_DIR=$(pwd)/$(dirname $0)
+pushd "$(dirname "$0")" > /dev/null
+SCRIPTS_DIR=$(pwd)
+popd > /dev/null
 
-cd $(dirname $1)
-emacs -batch $(basename $1) -l ${SCRIPTS_DIR}/indent-matlab.el
+for f in "$@"; do
+    echo "*** Indenting $f…"
+
+    pushd "$(dirname "$f")" > /dev/null
+    emacs -batch "$(basename "$f")" -l "${SCRIPTS_DIR}"/indent-matlab.el
+    popd > /dev/null
+
+    echo
+done
-- 
GitLab