From 5f454f16586d637008f3e712f220f8ebf1bbb4b0 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 01 Dec 2020 19:24:16 -0500 Subject: extract-copyright-comments: Preserve indentation For example, shell/shell_common.c has a comment with a "(c)" (which is not actually a copyright notice) that is indented. Without this change, the first line of the comment is not indented in the output, but subsequent lines are. Now all lines are indented. --- diff --git a/extract-copyright-comments b/extract-copyright-comments index 87d0d3b..b65f91f 100755 --- a/extract-copyright-comments +++ b/extract-copyright-comments @@ -21,6 +21,7 @@ set -eu LF=' ' +HT=' ' bufc= bufi= @@ -38,6 +39,8 @@ getc() extract_cxx_comment() { + local indent="${1}" + shift 1 local comment='//' while :; do @@ -58,7 +61,7 @@ extract_cxx_comment() done if printf '%s' "${comment}" | grep -Eqi 'copyright|\(c\)'; then - printf '\t%s\n' "${comment}" + printf '\t%s\n' "${indent}${comment}" fi return 0 @@ -66,6 +69,8 @@ extract_cxx_comment() extract_c_comment() { + local indent="${1}" + shift 1 local comment='/*' local asterisk=false @@ -94,7 +99,7 @@ extract_c_comment() done if printf '%s' "${comment}" | grep -Eqi 'copyright|\(c\)'; then - printf '%s\n' "${comment}" | sed 's/^/\t/' + printf '%s\n' "${indent}${comment}" | sed 's/^/\t/' fi return 0 @@ -104,6 +109,8 @@ extract() { local fn="${1}" shift 1 + local newline=true + local indent='' local quote= printf '%s\n' "${fn}" @@ -128,17 +135,30 @@ extract() getc case "${c}" in '/') + newline=false getc case "${c}" in '/') - extract_cxx_comment || return 1 + extract_cxx_comment "${indent}"\ + || return 1 ;; '*') - extract_c_comment || return 1 + extract_c_comment "${indent}" \ + || return 1 ;; esac ;; + "${LF}") + newline=true + indent='' + ;; + "${HT}" | ' ') + if ${newline}; then + indent="${indent}${c}" + fi + ;; "'" | '"') + newline=false quote="${c}" while :; do getc @@ -161,6 +181,9 @@ extract() '') break ;; + *) + newline=false + ;; esac done -- cgit v0.9.1