diff options
author | Zoltan Fridrich <zfridric@redhat.com> | 2023-01-27 13:38:45 +0100 |
---|---|---|
committer | Zoltan Fridrich <zfridric@redhat.com> | 2023-01-27 14:48:43 +0100 |
commit | 8ae1242930bd863d1cac3ed21afae4bea233a778 (patch) | |
tree | 302d39a06a5dda40ea89260b0c231c3d777c205c | |
parent | b665409cbc1a54e0f64b0672d4a7ac43b3f6c9c1 (diff) | |
download | gnutls-8ae1242930bd863d1cac3ed21afae4bea233a778.tar.gz |
Add code indentation scripts
Co-authored-by: Simon Josefsson <simon@josefsson.org>
Signed-off-by: Zoltan Fridrich <zfridric@redhat.com>
-rwxr-xr-x | devel/indent-gnutls | 15 | ||||
-rwxr-xr-x | devel/indent-maybe | 52 |
2 files changed, 67 insertions, 0 deletions
diff --git a/devel/indent-gnutls b/devel/indent-gnutls new file mode 100755 index 0000000000..b3eb630b82 --- /dev/null +++ b/devel/indent-gnutls @@ -0,0 +1,15 @@ +#!/bin/sh + +# Copyright (c) 2022 Simon Josefsson +# License: GPLv3+ <http://gnu.org/licenses/gpl.html> + +if ! indent --version 2> /dev/null | grep 'GNU indent' > /dev/null; then + echo 1>&2 "$0: GNU indent is missing" + exit 77 +fi + +INDENT="indent -ppi1 -linux"; export INDENT + +git ls-files -z | grep -z '\.[ch]\(.in\)\?$' | grep -z -v '^./devel/' | xargs -0 -n1 `dirname "$0"`/indent-maybe + +exit $? diff --git a/devel/indent-maybe b/devel/indent-maybe new file mode 100755 index 0000000000..cdaa58b7e1 --- /dev/null +++ b/devel/indent-maybe @@ -0,0 +1,52 @@ +#!/bin/sh + +# NAME +# indent-maybe(3) +# +# SYNOPSIS +# indent-maybe [options] [single-input-file] +# +# DESCRIPTION +# Run 'indent' on a file in an idempotent fashion, showing any +# modifications performed using diff(3). +# +# There are two concerns with using 'indent' directly that this +# script solves: +# +# 1) 'indent' modifies files even when no modifications are +# necessary, which causes churn to rebuild dependent files, and +# it is thus not safe to run 'indent' frequently even for a +# file that needs no re-indentation. +# +# 2) Running 'indent' on a file once is not guaranteed to return +# output that will look the same as running 'indent' on the file +# again. However, running 'indent' twice has this property. +# +# Only GNU indent is supported. +# +# ENVIRONMENT +# The behaviour of 'indent-maybe' is affected by the INDENT variable which +# can be used to override the 'indent' tool that is used. It may also +# include command line parameters, since it is expanded before use. +# +# EXAMPLES +# indent-maybe lib/kx.h +# INDENT="indent -ppi1 -linux" indent-maybe lib/kx.h +# +# COPYRIGHT +# Copyright (c) 2022 Simon Josefsson +# License: GPLv3+ <http://gnu.org/licenses/gpl.html> + +: ${INDENT=indent} +ME="$0" + +if ! $INDENT --version 2> /dev/null | grep 'GNU indent' > /dev/null; then + echo 1>&2 "$ME: GNU indent is missing, consider INDENT=..." + exit 77 +fi + +for f in "$@"; do + $INDENT -st "$f" | $INDENT -st - | diff -u "$f" - || ($INDENT "$f" && $INDENT "$f") +done + +exit $? |