diff --git a/bin/check_copy.sh b/bin/check_copy.sh index 2a5f28bf2..515ba558c 100755 --- a/bin/check_copy.sh +++ b/bin/check_copy.sh @@ -4,6 +4,23 @@ set -e -u # SPDX-FileCopyrightText: Bradley M. Bell # SPDX-FileContributor: 2023-24 Bradley M. Bell # ---------------------------------------------------------------------------- +if [ "$0" != "bin/check_copy.sh" ] +then + echo "bin/check_copy.sh: must be executed from its parent directory" + exit 1 +fi +if [ "$#" != 0 ] +then + echo 'check_copy does not expect any arguments' + exit 1 +fi +# +# grep, sed +source bin/grep_and_sed.sh +# +# spdx_license_id, no_copyright_list +source bin/dev_settings.sh +# ---------------------------------------------------------------------------- if [ $# != 0 ] then echo 'bin/check_copy.sh does not expect any arguments' @@ -20,43 +37,60 @@ then exit 1 fi # --------------------------------------------------------------------------- -license='SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later' +username='bradbell' +fullname='Bradley M. Bell' +# --------------------------------------------------------------------------- +if [ -e temp.sed ] +then + rm temp.sed +fi +for name in $no_copyright_list +do + if [ -f $name ] + then + echo "^$name\$" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> temp.sed + elif [ -d $name ] + then + echo "^$name/" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> temp.sed + else + echo "$name in no_copyright_list is not a file or directory" + exit 1 + fi +done missing='no' changed='no' -for file_name in $(git ls-files | sed \ - -e '/\.yml$/d' \ - -e '/\.png$/d' \ - -e '/\.html$/d' \ - -e '/\.toml$/d' \ - -e '/\.xml$/d' \ - -e '/^.gitignore$/d' \ - -e '/^.readthedocs.yaml$/d' \ - -e '/^epl-2.0.txt$/d' \ - -e '/^COPYING$/d' \ - -e '/^authors$/d' \ - -e '/^batch_edit.sed$/d' \ - -e '/^build.bat$/d' \ - -e '/^bin[/]build.bat$/d' \ - -e '/^cmake[/]cppad_uninstall.cmake$/d' \ -) +for file_name in $(git ls-files | $sed -f temp.sed) do - if ! grep "$license\$" $file_name > /dev/null + if ! $grep "$spdx_license_id\$" $file_name > /dev/null then if [ "$missing" == 'no' ] then echo "Cannot find line that ends with:" - echo " $license" + echo " $spdx_license_id" echo "In the following files:" fi echo "$file_name" missing='yes' fi done -for file_name in $(git status --porcelain | sed -e 's|^...||' ) +# --------------------------------------------------------------------------- +cat << EOF > temp.sed +s|\\(SPDX-FileContributor: *[0-9]\\{4\\}\\)[-0-9]* $fullname|\\1-24 $fullname| +s|\\(SPDX-FileContributor\\): 2024-24 |\\1: 2024 | +EOF +list='' +if [ "${USER+x}" != '' ] +then + if [ "$USER" == 'bradbell' ] + then + list=$(git status --porcelain | $sed -e 's|^...||' ) + fi +fi +for file_name in $list do if [ -e $file_name ] then - sed \ + $sed \ -e 's|\(SPDX-FileContributor\): *\([0-9]\{4\}\)[-0-9]* |\1: \2-24 |' \ -e 's|\(SPDX-FileContributor\): 2024-24 |\1: 2024 |' \ $file_name > temp.$$ @@ -69,6 +103,11 @@ do echo 'The following file contributor dates have been updated' fi echo $file_name + if diff $file_name temp.$$ + then + echo 'check_version.sh: program error' + exit 1 + fi changed='yes' if [ -x $file_name ] then @@ -81,9 +120,10 @@ do fi done # -if [ "$missing" = 'yes' ] +if [ "$missing" = 'yes' ] || [ "$changed" == 'yes' ] then echo 'bin/check_copy.sh: See copyright errors above' + echo 'Re-execute bin/check_copy.sh ?' exit 1 fi echo 'bin/check_copy.sh: OK' diff --git a/bin/check_invisible.sh b/bin/check_invisible.sh index 07b526686..89a0d3ebf 100755 --- a/bin/check_invisible.sh +++ b/bin/check_invisible.sh @@ -19,18 +19,40 @@ else echo 'usage: bin/check_invisible [all]' exit 1 fi +# +# sed +source bin/grep_and_sed.sh +# +# invisible_and_tab_ok +source bin/dev_settings.sh # ---------------------------------------------------------------------------- +# +# sed.$$ +echo '#' > sed.$$ +for name in $no_copyright_list +do + if [ -f $name ] + then + echo "^$name\$" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> sed.$$ + elif [ -d $name ] + then + echo "^$name/" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> sed.$$ + else + echo "$name in no_copyright_list is not a file or directory" + exit 1 + fi +done +# # file_list if [ "$all" == 'true' ] then - file_list=$(git ls-files | sed \ - -e '/^uw_copy_040507.html$/d' \ - ) + file_list=$(git ls-files | $sed -f sed.$$) else - file_list=$(git status --porcelain | sed -e 's|^...||' \ - -e '/^uw_copy_040507.html$/d' \ + file_list=$(git status --porcelain | \ + $sed -e '/^D/d' -e 's|^...||' | $sed -f sed.$$ ) fi +# ---------------------------------------------------------------------------- # # sed.$$ cat << EOF > sed.$$ @@ -45,7 +67,7 @@ for file in $file_list do if [ -f "$file" ] then - sed -f sed.$$ $file > copy.$$ + $sed -f sed.$$ $file > copy.$$ if ! diff $file copy.$$ > diff.$$ then echo "original (<) invisible white space removed (>)" diff --git a/bin/check_sort.sh b/bin/check_sort.sh new file mode 100755 index 000000000..8f4e894b7 --- /dev/null +++ b/bin/check_sort.sh @@ -0,0 +1,75 @@ +#! /usr/bin/env bash +set -e -u +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later +# SPDX-FileCopyrightText: Bradley M. Bell +# SPDX-FileContributor: 2020-24 Bradley M. Bell +# ----------------------------------------------------------------------------- +if [ "$0" != "bin/check_sort.sh" ] +then + echo "bin/check_sort.sh: must be executed from its parent directory" + exit 1 +fi +if [ "$#" == 0 ] +then + all='false' +elif [ "$#" == 1 ] && [ "$1" == 'all' ] +then + all='true' +else + echo 'usage: bin/check_sort [all]' + echo 'see usage message forbin/sort.sh' + exit 1 +fi +# +# grep, sed +source bin/grep_and_sed.sh +# ---------------------------------------------------------------------------- +# file_list +if [ "$all" == 'true' ] +then + file_list=$(git grep -l 'BEGIN_SORT_THIS_LINE_PLUS_') +else + file_list=$(git status --porcelain | $sed -e '/^D/d' -e 's|^...||') +fi +# +# ok +ok='yes' +for file_name in $file_list +do + check='yes' + if [ "$file_name" == 'bin/sort.sh' ] + then + check='no' + fi + if [ "$file_name" == 'bin/check_sort.sh' ] + then + check='no' + fi + if ! $grep BEGIN_SORT_THIS_LINE $file_name > /dev/null + then + check='no' + fi + if [ "$check" == 'yes' ] + then + if ! bin/sort.sh $file_name >& temp.$$ + then + cat temp.$$ + echo 'check_sort.sh: Error' + exit 1 + fi + last_line=$(tail -1 temp.$$) + if [ "$last_line" == 'sort.sh: Done' ] + then + cat temp.$$ + ok='no' + fi + fi +done +# +if [ "$ok" == 'no' ] +then + echo 'check_sort.sh: Some files have been sorted (run again to get OK).' + exit 1 +fi +echo 'check_sort.sh: OK' +exit 0 diff --git a/bin/check_tab.sh b/bin/check_tab.sh index 39f49704b..cbc9096c7 100755 --- a/bin/check_tab.sh +++ b/bin/check_tab.sh @@ -1,43 +1,74 @@ -#! /bin/bash -e +#! /usr/bin/env bash +set -e -u # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later # SPDX-FileCopyrightText: Bradley M. Bell -# SPDX-FileContributor: 2003-22 Bradley M. Bell -# ---------------------------------------------------------------------------- -if [ "$0" != 'bin/check_tab.sh' ] +# SPDX-FileContributor: 2020-24 Bradley M. Bell +# ----------------------------------------------------------------------------- +if [ "$0" != "bin/check_tab.sh" ] then echo "bin/check_tab.sh: must be executed from its parent directory" exit 1 fi -echo "-------------------------------------------------------" +if [ "$#" == 0 ] +then + all='false' +elif [ "$#" == 1 ] && [ "$1" == 'all' ] +then + all='true' +else + echo 'usage: bin/check_tab [all]' + exit 1 +fi +# +# sed +source bin/grep_and_sed.sh +# +# invisible_and_tab_ok +source bin/dev_settings.sh +# ---------------------------------------------------------------------------- +# +# sed.$$ +echo '#' > sed.$$ +for name in $invisible_and_tab_ok +do + if [ -f $name ] + then + echo "^$name\$" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> sed.$$ + elif [ -d $name ] + then + echo "^$name/" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> sed.$$ + else + echo "$name in no_copyright_list is not a file or directory" + exit 1 + fi +done +# +# file_list +if [ "$all" == 'true' ] +then + file_list=$(git ls-files | $sed -f sed.$$) +else + file_list=$(git status --porcelain | \ + $sed -e '/^D/d' -e 's|^...||' | $sed -f sed.$$) +fi +# +# ok ok='yes' -file_list=`git ls-files | sed \ - -e '/makefile[.]am$/d' \ - -e '/makefile[.]in$/d' \ - -e '/^batch_edit.sed$/d' \ - -e '/^coin.png$/d' \ - -e '/^ar-lib$/d' \ - -e '/^configure$/d' \ - -e '/^compile$/d' \ - -e '/^config.guess$/d' \ - -e '/^config.sub$/d' \ - -e '/^depcomp$/d' \ - -e '/^install-sh$/d' \ - -e '/^uw_copy_040507.html/d' \ -` -tab=$'\t' for file in $file_list do - if grep $'\t' $file > /dev/null + if $grep -P '\t' $file > /dev/null then - echo $file + echo "$file has a tab" ok='no' fi done -echo "-------------------------------------------------------" -if [ "$ok" = 'no' ] +if [ "$ok" != 'yes' ] then - echo 'bin/check_tab.sh: The files above contain tabs' + echo 'check_tab: Error' + rm sed.$$ exit 1 fi -echo 'bin/check_if.sh: OK' +# ----------------------------------------------------------------------------- +rm sed.$$ +echo 'check_tab.sh: OK' exit 0 diff --git a/bin/dev_settings.sh b/bin/dev_settings.sh new file mode 100644 index 000000000..3d959d3fb --- /dev/null +++ b/bin/dev_settings.sh @@ -0,0 +1,46 @@ +# --------------------------------------------------------------------------- +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later +# SPDX-FileCopyrightText: Bradley M. Bell +# SPDX-FileContributor: 2003-24 Bradley M. Bell +# --------------------------------------------------------------------------- +# +# source bin/dev_settings.sh +# Sets the development tool variables listed below to settings for this system. +# +# spdx_license_id +# Each file, except those specified by no_copyright_list, should have a line +# that ends with the following text: +spdx_license_id='EPL-2.0 OR GPL-2.0-or-later' +# +# no_copyright_list +# These files do not have the spdx license id in them. +# If an entry below is a directory it specifies all the files in the directory. +# BEGIN_SORT_THIS_LINE_PLUS_2 +no_copyright_list=' + .circleci/config.yml + .coin-or/projDesc.xml + .github/workflows + .gitignore + .readthedocs.yaml + .travis.yml + COPYING + appveyor.yml + authors + batch_edit.sed + bin/build.bat + cmake/cppad_uninstall.cmake + coin.png + epl-2.0.txt + uw_copy_040507.html + xrst.toml +' +# END_SORT_THIS_LINE_MINUS_2 +# +# invisible_and_tab_ok +# These files are not checked for invisible white space or tabs. +# If an entry below is a directory it specifies all the files in the directory. +invisible_and_tab_ok=' + batch_edit.sed + coin.png + uw_copy_040507.html +' diff --git a/bin/git_commit.sh b/bin/git_commit.sh index b1b6777cd..ca0e3ab0c 100755 --- a/bin/git_commit.sh +++ b/bin/git_commit.sh @@ -26,6 +26,9 @@ then echo 'bin/git_commit.sh: cannot find ./.git' exit 1 fi +# +# grep, sed +source bin/grep_and_sed.sh # ----------------------------------------------------------------------------- # EDITOR set +u @@ -39,13 +42,13 @@ set -u # new files # convert spaces in file names to @@ list=$( - git status --porcelain | sed -n -e '/^?? /p' | \ - sed -e 's|^?? ||' -e 's|"||g' -e 's| |@@|g' + git status --porcelain | $sed -n -e '/^?? /p' | \ + $sed -e 's|^?? ||' -e 's|"||g' -e 's| |@@|g' ) for file in $list do # convert @@ in file names back to spaces - file=$(echo $file | sed -e 's|@@| |g') + file=$(echo $file | $sed -e 's|@@| |g') res='' while [ "$res" != 'delete' ] && [ "$res" != 'add' ] && [ "$res" != 'abort' ] do @@ -76,16 +79,16 @@ $branch: # 4. Lines starting with '#' are not included in the message. # 5. Below is a list of the files for this commit: EOF -git status --porcelain | sed -e 's|^|# |' >> temp.log +git status --porcelain | $sed -e 's|^|# |' >> temp.log $EDITOR temp.log -sed -i temp.log -e '/^#/d' -if ! head -1 temp.log | grep "^$branch:" > /dev/null +$sed -i -e '/^#/d' temp.log +if ! head -1 temp.log | $grep "^$branch:" > /dev/null then echo "Aborting because first line does not begin with $branch:" echo 'See ./temp.log' exit 1 fi -if ! head -1 temp.log | grep "^$branch:.*[^ \t]" > /dev/null +if ! head -1 temp.log | $grep "^$branch:.*[^ \t]" > /dev/null then echo "Aborting because only white space follow $branch: in first line" echo 'See ./temp.log' diff --git a/bin/grep_and_sed.sh b/bin/grep_and_sed.sh new file mode 100644 index 000000000..8c9a9121b --- /dev/null +++ b/bin/grep_and_sed.sh @@ -0,0 +1,27 @@ +# --------------------------------------------------------------------------- +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later +# SPDX-FileCopyrightText: Bradley M. Bell +# SPDX-FileContributor: 2003-24 Bradley M. Bell +# --------------------------------------------------------------------------- +# +# source bin/grep_and_sed +# Sets the shell variables grep and sed to the gnu version for this system +# +# sed, grep +sed=sed +grep=grep +if [ "$(uname)" == 'Darwin' ] +then +if which gsed > /dev/null + then + sed=gsed + else + echo 'darwin_names.sh: cannot find gsed (gnu sed) on MacOS system' + fi + if which ggrep > /dev/null + then + grep=ggrep + else + echo 'darwin_names.sh: cannot find ggrep (gnu grep) on MacOS system' + fi +fi diff --git a/bin/sort.sh b/bin/sort.sh new file mode 100755 index 000000000..0ab1bf719 --- /dev/null +++ b/bin/sort.sh @@ -0,0 +1,166 @@ +#! /usr/bin/env bash +set -e -u +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later +# SPDX-FileCopyrightText: Bradley M. Bell +# SPDX-FileContributor: 2023-24 Bradley M. Bell +# ---------------------------------------------------------------------------- +# fix sort order; see +# unix.stackexchange.com/questions/87745/what-does-lc-all-c-do/87763#87763 +export LC_ALL='C' +# +if [ "$#" == 0 ] +then +cat<< EOF +usage: sort.sh file_name +BEGIN_SORT_THIS_LINE_PLUS_nb: defines beginning line for sort. +END_SORT_THIS_LINE_MINUS_ne: defines ending line for sort. +The tokens nb and ne are both a single non-zero decimal digit. + +If the exit status is 0, the last line on standard out is one of the following: +'sort.sh: OK' The file was already sorted +'sort.sh: Done' The file was sorted +EOF + exit 1 +fi +file_name="$1" +# +# grep, sed +source bin/grep_and_sed.sh +# +if $grep 'BEGIN_SORT_THIS_LINE_PLUS_[1-9][0-9]' "$file_name" +then + echo "in BEGIN_SORT_THIS_LINE_PLUS_nb in file $file_name" + echo 'nb has more that one decial digit.' + exit 1 +fi +if $grep 'END_SORT_THIS_LINE_MINUS_[1-9][0-9]' "$file_name" +then + echo "in END_SORT_THIS_LINE_PLUS_ne in file $file_name" + echo 'ne has more that one decial digit.' + exit 1 +fi +# -------------------------------------------------------------------------- +# +# is_file_executable +if [ -x $file_name ] +then + is_file_executable='yes' +else + is_file_executable='no' +fi +# +# begin_sum +# is th sum for the beginning line number +set +e +begin_sum=`$grep --line-number 'BEGIN_SORT_THIS_LINE_PLUS_[1-9]' $file_name | \ + $sed -e 's|\([0-9]*\):.*BEGIN_SORT_THIS_LINE_PLUS_\([1-9]\).*|\1+\2|'` +set -e +if [ "$begin_sum" == '' ] +then + echo "sort.sh $file_name" + echo "Cannot find BEGIN_SORT_THIS_LINE_PLUS_nb in $file_name" + exit 1 +fi +# +# begin_line +begin_count=0 +for sum in $begin_sum +do + # This does the summation + let begin_line[$begin_count]="$sum" + let begin_count="$begin_count + 1" +done +# +# end_diff +# ios the difference for the ending line number +set +e +end_diff=`$grep --line-number 'END_SORT_THIS_LINE_MINUS_[1-9]' $file_name | \ + $sed -e 's|\([0-9]*\):.*END_SORT_THIS_LINE_MINUS_\([1-9]\).*|\1-\2|'` +set -e +if [ "$end_diff" == '' ] +then + echo "sort.sh $file_name" + echo "Cannot find END_SORT_THIS_LINE_MINUS_nb in $file_name" + exit 1 +fi +# +# end_line +end_count=0 +for diff in $end_diff +do + # This does the difference + let end_line[$end_count]="$diff" + let end_count="$end_count + 1" +done +if [ $begin_count != $end_count ] +then + echo "sort.sh $file_name" + echo 'number of BEGIN_SORT_THIS_LINE_PLUS_nb is not equal to' + echo 'number of END_SORT_THIS_LINE_MINUS_ne.' + exit 1 +fi +# +# first_line +first_line='1' +# +# last_line +last_line=`wc -l $file_name | $sed -e 's|^ *\([0-9]*\) .*|\1|'` +# +# count, stop_line_previous, sorted.$$ +count=0 +stop_line_previous=0 +cp $file_name sorted.$$ +while [ $count -lt $begin_count ] +do + # + # start_line, stop_line, count + start_line=${begin_line[$count]} + stop_line=${end_line[$count]} + let count="$count + 1" + echo "sort.sh: sorting lines $start_line to $stop_line in $file_name" + # + if [ $start_line -ge $stop_line ] + then + echo "start_line = $start_line >= stop_line = $stop_line " + exit 1 + fi + # + # stop_line_previous + if [ $stop_line_previous -ge $start_line ] + then + echo "previous stop_line=$stop_line_previous >= start_line=$start_line" + exit 1 + fi + stop_line_previous="$stop_line" + # + # temp.$$ + if [ "$start_line" != "$first_line" ] + then + let start_m1="$start_line - 1" + $sed -n -e "1,${start_m1}p" sorted.$$ >> temp.$$ + fi + # + $sed -n -e "${start_line},${stop_line}p" sorted.$$ | sort >> temp.$$ + # + if [ "$stop_line" != "$last_line" ] + then + stop_p1=`expr $stop_line + 1` + $sed -n -e "${stop_p1},${last_line}p" sorted.$$ >> temp.$$ + fi + # + # sorted.$$ + mv temp.$$ sorted.$$ +done +if diff sorted.$$ $file_name > /dev/null +then + rm sorted.$$ + echo 'sort.sh: OK' +else + mv sorted.$$ $file_name + if [ "$is_file_executable" == 'yes' ] + then + chmod +x $file_name + fi + echo 'sort.sh: Done' +fi +exit 0 diff --git a/bin/sort_all.sh b/bin/sort_all.sh deleted file mode 100755 index 1b5d2adc4..000000000 --- a/bin/sort_all.sh +++ /dev/null @@ -1,23 +0,0 @@ -#! /bin/bash -e -# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later -# SPDX-FileCopyrightText: Bradley M. Bell -# SPDX-FileContributor: 2003-22 Bradley M. Bell -# ---------------------------------------------------------------------------- -if [ $0 != "bin/sort_all.sh" ] -then - echo "bin/sort_all.sh: must be executed from its parent directory" - exit 1 -fi -list=`git grep -l 'BEGIN_SORT_THIS_LINE_PLUS_' | sed \ - -e '/\/makefile.in$/d' \ - -e '\/^makefile.in$/d' \ - -e '/\/sort_all.sh$/d' ` -# -for file in $list -do - sort.sh $file -done -# -# ---------------------------------------------------------------------------- -echo "$0: OK" -exit 0