diff --git a/tools/README.txt b/tools/README.txt index 7662f9adab..7a9d013caa 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -541,6 +541,24 @@ indent.sh to my coding NuttX coding style. It doesn't do a really good job, however (see the comments at the top of the indent.sh file). + USAGE: + ./indent.sh [-d] -o + ./indent.sh [-d] + ./indent.sh [-d] -h + + Where: + - + A single, unformatted input file + - + A list of unformatted input files that will be reformatted in place. + -o + Write the single, reformatted to . + will not be modified. + -d + Enable script debug + -h + Show this help message and exit + refresh.sh ---------- diff --git a/tools/indent.sh b/tools/indent.sh index 866430e7e2..10bffdd60f 100755 --- a/tools/indent.sh +++ b/tools/indent.sh @@ -2,7 +2,7 @@ ############################################################################ # tools/indent.sh # -# Copyright (C) 2008, 2010 Gregory Nutt. All rights reserved. +# Copyright (C) 2008, 2010, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -48,39 +48,86 @@ options="-nbad -bap -bbb -nbbo -nbc -bl -bl2 -bls -nbs -cbi2 -ncdw -nce -ci2 -cli0 -cp40 -ncs -nbfda -nbfde -di1 -nfc1 -fca -i2 -l80 -lp -ppi2 -lps -npcs -pmt -nprs -npsl -saf -sai -sbi2 -saw -sc -sob -nss -nut" -usage="USAGE: $0 " +advice="Try '$0 -h' for more information" -# Inputs +# Parse inputs -infile=$1 -outfile=$2 +unset filelist +unset outfile +files=none +mode=inplace -# Verify inputs +while [ ! -z "${1}" ]; do + case ${1} in + -d ) + set -x + ;; + -o ) + shift + outfile=${1} + mode=copy + ;; + -h ) + echo "$0 is a tool for generation of proper version files for the NuttX build" + echo "" + echo "USAGE:" + echo " $0 [-d] -o " + echo " $0 [-d] " + echo " $0 [-d] -h" + echo "" + echo "Where:" + echo " -" + echo " A single, unformatted input file" + echo " -" + echo " A list of unformatted input files that will be reformatted in place." + echo " -o " + echo " Write the single, reformatted to . " + echo " will not be modified." + echo " -d" + echo " Enable script debug" + echo " -h" + echo " Show this help message and exit" + exit 0 + ;; + * ) + if [ ! -r ${1} ]; then + echo "Readable ${1} does not exist" + echo ${advice} + exit 1 + fi + if [ -z "${filelist}" ]; then + filelist="${1}" + files=single + else + filelist="${filelist} ${1}" + files=multiple + fi + ;; + esac + shift +done -if [ -z "$infile" ]; then - echo "Missing " - echo $usage - exit 1 -fi +# Verify that at least one input file was provided -if [ ! -r $infile ]; then - echo "Readable $infile does not exist" - exit 1 -fi - -if [ -z "$outfile" ]; then - echo "Missing " - echo $usage - exit 1 -fi - -if [ -f $outfile ]; then - echo "Removing old $outfile" - rm $outfile || { echo "Failed to remove $outfile" ; exit 1 ; } +if [ "X${files}" == "Xnone" ]; then + echo "ERROR: Neither nor provided" + echo ${advice} + exit 1 fi # Perform the indentation -indent $options $infile -o $outfile - - +if [ "X${mode}" == "Xcopy" ]; then + if [ "X${files}" == "Xmultiple" ]; then + echo "ERROR: Only a single can be used with the -o option" + echo ${advice} + exit 1 + fi + if [ -f $outfile ]; then + echo "Removing old $outfile" + rm $outfile || { echo "Failed to remove $outfile" ; exit 1 ; } + fi + indent $options $filelist -o $outfile +else + indent $options $filelist +fi