3 # Fix multiline comments to match CODING_STYLE
5 # Copyright (C) 2018 Red Hat, Inc.
7 # Author: Paolo Bonzini
9 # Usage: scripts/fix-multiline-comments.sh [-i] FILE...
11 # -i edits the file in place (requires gawk 4.1.0).
13 # Set the AWK environment variable to choose the awk interpreter to use
16 if test "$1" = -i; then
21 ${AWK-awk} $inplace 'BEGIN { indent = -1 }
24 # apply a star to the indent on lines after the first
28 } else if (substr(line, 1, indent + 2) == sp " ") {
29 line = sp " *" substr(line, indent + 3)
33 is_lead = (line ~ /^[ \t]*\/\*/)
34 is_trail = (line ~ /\*\//)
35 if (is_lead && !is_trail) {
36 # grab the indent at the start of a comment, but not for
37 # single-line comments
38 match(line, /^[ \t]*\/\*/)
40 sp = substr(line, 1, indent)
43 # the regular expression filters out lone /*, /**, or */
44 if (indent != -1 && !(line ~ /^[ \t]*(\/\*+|\*\/)[ \t]*$/)) {
46 # split the leading /* or /** on a separate line
47 match(line, /^[ \t]*\/\*+/)
48 lead = substr(line, 1, RLENGTH)
49 match(line, /^[ \t]*\/\*+[ \t]*/)
50 line = lead "\n" sp " *" substr(line, RLENGTH)
53 # split the trailing */ on a separate line
54 match(line, /[ \t]*\*\//)
55 line = substr(line, 1, RSTART - 1) "\n" sp " */"