From: Eugene Syromyatnikov Date: Mon, 1 May 2017 17:10:15 +0000 (+0200) Subject: Add scripts for automating copyright notices update X-Git-Tag: v4.17~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2930b90aefefbe2890283e14056329637ace1c7;p=strace Add scripts for automating copyright notices update * maint/update_copyright_years.awk: New file. * maint/update_copyright_years.sh: Likewise. Co-authored-by: Elvira Khabirova --- diff --git a/maint/update_copyright_years.awk b/maint/update_copyright_years.awk new file mode 100644 index 00000000..ee356c31 --- /dev/null +++ b/maint/update_copyright_years.awk @@ -0,0 +1,45 @@ +# External variables: +# COMMENT_MARKER - marks beginning of the comment on the line +# COMMENT_MARKER_RE - the same as previous, but in form usable +# as a part of a regular expression +# COPYRIGHT_MARKER - text inside comment +# COPYRIGHT_NOTICE - copyright notice text to insert + +BEGIN { + # States: + # 0 - before finding copyright notice + # 1 - in copyright notice or its continuation + # 2 - right after the end of copyright notice + # 3 - copyright notice added + state = 0 + prefix = " " + + comment_re = "^" COMMENT_MARKER_RE + copyright_re = comment_re "([[:space:]]*)" COPYRIGHT_MARKER + copyright_cont_re = copyright_re +} + +state <= 1 && match($0, copyright_re, a) { + state = 1 + prefix = a[1] + # set copyright notice continuation + copyright_cont_re = comment_re a[1] "[[:space:]]" +} + +# this is neither copyright notice nor its continuation +state == 1 && ($0 !~ copyright_re) && ($0 !~ copyright_cont_re) { + state = 2 +} + +state == 2 { + print COMMENT_MARKER prefix COPYRIGHT_NOTICE + state = 3 +} + +{ + print +} + +END { + exit 3 - state +} diff --git a/maint/update_copyright_years.sh b/maint/update_copyright_years.sh new file mode 100755 index 00000000..74442455 --- /dev/null +++ b/maint/update_copyright_years.sh @@ -0,0 +1,202 @@ +#!/bin/sh +# +# Update copyright notices for source files. +# +# Copyright (c) 2017 The strace developers. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +: ${COPYRIGHT_NOTICE='The strace developers.'} +: ${COPYRIGHT_MARKER='Copyright'} +: ${COPYRIGHT_PREFIX="${COPYRIGHT_MARKER} (c)"} +: ${VERBOSE=1} +: ${CALL_GIT_ADD=0} + +# These files are only imported into strace and not changed. +# Remove them from the list once they have been changed. +IGNORED_FILES="git-set-file-times +gitlog-to-changelog +${ADDITIONAL_IGNORED_FILES}" + +log() { [ "$VERBOSE" -ge 1 ] && printf '%s\n' "$*"; } +debug() { [ "$VERBOSE" -ge 2 ] && printf '%s\n' "$*"; } + +print_help() +{ + cat < "$f.out" && { + cat "$f.out" > "$f" + log "Added copyright notice to $f (start year $start_note)" + } || debug "No changes performed (exit code $?), skipping: $f" + + rm -f "$f.out" + fi + + [ "$CALL_GIT_ADD" = 0 ] || git add "$f" +} + +while [ -n "$1" ]; do + case "$1" in + "-v") + VERBOSE=$(($VERBOSE + 1)) + ;; + "-q") + VERBOSE=$(($VERBOSE - 1)) + ;; + "-h") + print_help + exit 1 + ;; + "-a") + CALL_GIT_ADD=1 + ;; + *) + break + ;; + esac + + shift +done + +git ls-files -- "$@" | grep -vFx "$IGNORED_FILES" | while read f; do + process_file "$f" +done