summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2020-12-01 19:24:16 (EST)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2020-12-01 19:24:16 (EST)
commit5f454f16586d637008f3e712f220f8ebf1bbb4b0 (patch)
treee4932f95d2f9b56a57e4b38f50907bd9b33f87dc
parent2e55ba1179040cfafa04ebd482876fb51a83a3bd (diff)
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.
-rwxr-xr-xextract-copyright-comments31
1 files changed, 27 insertions, 4 deletions
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