summaryrefslogtreecommitdiffstats
path: root/extract-copyright-comments
diff options
context:
space:
mode:
Diffstat (limited to 'extract-copyright-comments')
-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