From 1d3bca8ad331e7e709bb5e39c23dc19014af8399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 31 Jul 2014 15:29:18 +0200 Subject: [PATCH] Push scripts for reindenting and for fixing copyright years. --- scripts/fix-copyright-years | 62 +++++++++++++++++++++++++++++++++++++ scripts/indent-c++ | 13 ++++++++ scripts/indent-c++.el | 5 +++ scripts/indent-matlab | 12 +++++++ scripts/indent-matlab.el | 7 +++++ 5 files changed, 99 insertions(+) create mode 100755 scripts/fix-copyright-years create mode 100755 scripts/indent-c++ create mode 100644 scripts/indent-c++.el create mode 100755 scripts/indent-matlab create mode 100644 scripts/indent-matlab.el diff --git a/scripts/fix-copyright-years b/scripts/fix-copyright-years new file mode 100755 index 000000000..86eceb7bd --- /dev/null +++ b/scripts/fix-copyright-years @@ -0,0 +1,62 @@ +#!/bin/sh + +# This scripts updates all the "Copyright" lines in source files with the +# correct most recent modification years. +# +# It must be given a file in argument. A typical usage can be to run it on all +# code source files: +# +# find \( -name '*.m' -or -name '*.cc' -or -name '*.hh' -or -name '*.c' -or -name '*.h' -or -name '*.f' \) -exec fix-copyright-years '{}' ';' +# +# The LAST_UPDATE_COMMIT variable must be updated to contain the number of the +# last commit in which such a copyright update has been done. +# +# Note that the script does not understand some unusual copyright notices: it +# will display a message in that case. + +LAST_UPDATE_COMMIT=61485ab809d9a33484abf6136f05abd84da2be1b + +if [ -z "$1" ]; then + echo "Give a filename in argument" + exit 1 +fi + +if [ ! -f "$1" ]; then + echo "$1: Unknown file" + exit 1 +fi + +GITYEAR=$(git log $LAST_UPDATE_COMMIT.. --date=short --pretty=format:%cd -n 1 $1 | sed "s/\([0-9]\{4\}\)-[0-9]\{2\}-[0-9]\{2\}/\1/") + +if [ -z "$GITYEAR" ]; then + # Not in git + exit 0 +fi + +COPYLINES=$(grep -c Copyright $1) + +if [ $COPYLINES -eq 0 ]; then + echo "$1: File has no copyright line" + exit 1 +fi + +if [ $COPYLINES -ge 2 ]; then + COPYLINES=$(grep Copyright $1) + echo "$1: File has too many copyright lines (Git year: $GITYEAR): $COPYLINES" + exit 1 +fi + +COPYLINE=$(grep -o -E "Copyright \(C\) ([[:digit:]]{4}-)?[[:digit:]]{4} Dynare Team" $1) + +if [ -z "$COPYLINE" ]; then + COPYLINE=$(grep Copyright $1) + echo "$1: Unsupported copyright notice (Git year: $GITYEAR): $COPYLINE" + exit 1 +fi + +ACTUALYEAR=$(echo $COPYLINE | sed "s/Copyright (C) \([0-9]\{4\}-\)\?\([0-9]\{4\}\) Dynare Team/\2/") + +if [ $GITYEAR -gt $ACTUALYEAR ]; then + sed -i "s/Copyright (C) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? Dynare Team/Copyright (C) \1-$GITYEAR Dynare Team/" $1 + echo "$1: Updating to $GITYEAR" +fi diff --git a/scripts/indent-c++ b/scripts/indent-c++ new file mode 100755 index 000000000..ee9d522e4 --- /dev/null +++ b/scripts/indent-c++ @@ -0,0 +1,13 @@ +#!/bin/sh + +# Reindents the C++ source code file given in argument. + +if [ -z "$1" ]; then + echo "Give a filename in argument" + exit 1 +fi + +SCRIPTS_DIR=$(dirname $0) + +uncrustify -l CPP --replace -c ${SCRIPTS_DIR}/uncrustify.cfg $1 +emacs -batch $1 -l ${SCRIPTS_DIR}/indent-c++.el diff --git a/scripts/indent-c++.el b/scripts/indent-c++.el new file mode 100644 index 000000000..17ab26ba5 --- /dev/null +++ b/scripts/indent-c++.el @@ -0,0 +1,5 @@ +(c++-mode) +(setq indent-tabs-mode nil) +(indent-region (point-min) (point-max)) +(set-buffer-file-coding-system 'unix) +(save-buffer) diff --git a/scripts/indent-matlab b/scripts/indent-matlab new file mode 100755 index 000000000..3a604285d --- /dev/null +++ b/scripts/indent-matlab @@ -0,0 +1,12 @@ +#!/bin/sh + +# Reindents the MATLAB source code file given in argument. + +if [ -z "$1" ]; then + echo "Give a filename in argument" + exit 1 +fi + +SCRIPTS_DIR=$(dirname $0) + +emacs -batch $1 -l ${SCRIPTS_DIR}/indent-matlab.el diff --git a/scripts/indent-matlab.el b/scripts/indent-matlab.el new file mode 100644 index 000000000..76861b258 --- /dev/null +++ b/scripts/indent-matlab.el @@ -0,0 +1,7 @@ +(matlab-mode) +(setq matlab-indent-level 4) +(setq matlab-indent-function-body nil) +(untabify (point-min) (point-max)) +(indent-region (point-min) (point-max)) +(set-buffer-file-coding-system 'unix) +(save-buffer)