|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# enforce use of GNU version of coreutils |
| 5 | +. ./tidy/util/enforce_gnu_utils.sh |
| 6 | + |
| 7 | +# license notice boilerplate for source files that aren't in include/ |
| 8 | + |
| 9 | +for filename in $(find . -name '*.cpp' -type f ! -path "./third-party/*") $(find . -name '*.hpp' -type f ! -path "./third-party/*" ! -path "./include/*"); do |
| 10 | + |
| 11 | + # grow file up to at least 8 lines |
| 12 | + FILE_NUM_LINES="$(cat "${filename}" | wc -l)" |
| 13 | + for __ in $(seq "${FILE_NUM_LINES}" 1 6); do |
| 14 | + echo >> "${filename}" |
| 15 | + done |
| 16 | + |
| 17 | + # stamp in expected boilerplate line-by-line |
| 18 | + # just like file docstrings, but don't require a brief |
| 19 | + # stamp in expected boilerplate line-by-line |
| 20 | + sed -i '1s|^.*$|/**|' "${filename}" |
| 21 | + sed -i '2s|^.*$| * @note This file is part of Empirical, https://github.com/devosoft/Empirical|' "${filename}" |
| 22 | + sed -i '3s|^.*$| * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md|' "${filename}" |
| 23 | + # only match if a @date isn't currently in place |
| 24 | + # if we see @date, "break" (b) sed script for that line |
| 25 | + # adapted from https://stackoverflow.com/a/5334825 |
| 26 | + # and https://stackoverflow.com/a/12178023 |
| 27 | + # and https://stackoverflow.com/a/9053163 |
| 28 | + sed -i "/^ \* @date /b; 4s/^.*\$/ * @date $(date +'%Y')/" "${filename}" |
| 29 | + sed -i '5s/^.*$/ */' "${filename}" |
| 30 | + sed -i "6s/^.*\$/ * @file $(basename "${filename}")/" "${filename}" |
| 31 | + # only match empty lines |
| 32 | + # add extra * to replace later with */ when constructing fresh |
| 33 | + sed -i '7s/^$/ */' "${filename}" |
| 34 | + |
| 35 | + # close boilerplate file docstring |
| 36 | + # must accomodate possible additional content in docstring |
| 37 | + # so, search backwards from first blank line to place close */ |
| 38 | + FILE_NUM_LINES="$(cat "${filename}" | wc -l)" |
| 39 | + ONE_PAST_LAST_LINE_NO="$((${FILE_NUM_LINES}+1))" |
| 40 | + # adapted from https://stackoverflow.com/a/66474842 |
| 41 | + FIRST_BLANK_LINE_NO="$(awk '! NF { print NR; exit }' "${filename}")" |
| 42 | + # two cases: file does or does not have a blank line |
| 43 | + FIRST_EMPTY_LINE_NO="$(grep -q '^$' "${filename}" && echo "${FIRST_BLANK_LINE_NO}" || echo "${ONE_PAST_LAST_LINE_NO}")" |
| 44 | + DOCSTRING_CLOSE_LINE_NO="$((${FIRST_EMPTY_LINE_NO}-1))" |
| 45 | + # stamp */ into line preceding first empty line |
| 46 | + sed -i "${DOCSTRING_CLOSE_LINE_NO}s|^.*\$| */|" "${filename}" |
| 47 | + |
| 48 | + |
| 49 | +done |
0 commit comments