[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 33/35] scripts: add script to convert multiline comme
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 33/35] scripts: add script to convert multiline comments into 4-line format |
Date: |
Tue, 18 Dec 2018 00:16:58 +0100 |
Since we're adding checkpatch rules to enforce 4-line multiline comment
format, i.e. with lone /* and */, this script can be run on existing
code so that the comment style does not become inconsistent within a
file.
The alternative to awk-in-a-shell-script could be Perl, which also
supports -i directly, but a2p seems to have bitrotten and I didn't quite
feel like writing this twice...
Signed-off-by: Paolo Bonzini <address@hidden>
---
scripts/fix-multiline-comments.sh | 62 +++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
create mode 100755 scripts/fix-multiline-comments.sh
diff --git a/scripts/fix-multiline-comments.sh
b/scripts/fix-multiline-comments.sh
new file mode 100755
index 0000000000..93f9b10669
--- /dev/null
+++ b/scripts/fix-multiline-comments.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+#
+# Fix multiline comments to match CODING_STYLE
+#
+# Copyright (C) 2018 Red Hat, Inc.
+#
+# Author: Paolo Bonzini
+#
+# Usage: scripts/fix-multiline-comments.sh [-i] FILE...
+#
+# -i edits the file in place (requires gawk 4.1.0).
+#
+# Set the AWK environment variable to choose the awk interpreter to use
+# (default 'awk')
+
+if test "$1" = -i; then
+ # gawk extension
+ inplace="-i inplace"
+ shift
+fi
+${AWK-awk} $inplace 'BEGIN { indent = -1 }
+{
+ line = $0
+ # apply a star to the indent on lines after the first
+ if (indent != -1) {
+ if (line == "") {
+ line = sp " *"
+ } else if (substr(line, 1, indent + 2) == sp " ") {
+ line = sp " *" substr(line, indent + 3)
+ }
+ }
+
+ is_lead = (line ~ /^[ \t]*\/\*/)
+ is_trail = (line ~ /\*\//)
+ if (is_lead && !is_trail) {
+ # grab the indent at the start of a comment, but not for
+ # single-line comments
+ match(line, /^[ \t]*\/\*/)
+ indent = RLENGTH - 2
+ sp = substr(line, 1, indent)
+ }
+
+ # the regular expression filters out lone /*, /**, or */
+ if (indent != -1 && !(line ~ /^[ \t]*(\/\*+|\*\/)[ \t]*$/)) {
+ if (is_lead) {
+ # split the leading /* or /** on a separate line
+ match(line, /^[ \t]*\/\*+/)
+ lead = substr(line, 1, RLENGTH)
+ match(line, /^[ \t]*\/\*+[ \t]*/)
+ line = lead "\n" sp " *" substr(line, RLENGTH)
+ }
+ if (is_trail) {
+ # split the trailing */ on a separate line
+ match(line, /[ \t]*\*\//)
+ line = substr(line, 1, RSTART - 1) "\n" sp " */"
+ }
+ }
+ if (is_trail) {
+ indent = -1
+ }
+ print line
+}' "$@"
--
2.20.1
- [Qemu-devel] [PULL 22/35] test: execute g_test_run when tests are skipped, (continued)
- [Qemu-devel] [PULL 22/35] test: execute g_test_run when tests are skipped, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 24/35] qemu/queue.h: do not access tqe_prev directly, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 23/35] test: replace gtester with a TAP driver, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 25/35] vfio: make vfio_address_spaces static, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 26/35] qemu/queue.h: leave head structs anonymous unless necessary, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 27/35] qemu/queue.h: typedef QTAILQ heads, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 31/35] checkpatch: warn about qemu/queue.h head structs that are not typedef-ed, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 28/35] qemu/queue.h: remove Q_TAILQ_{HEAD, ENTRY}, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 29/35] qemu/queue.h: reimplement QTAILQ without pointer-to-pointers, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 32/35] hw/watchdog/wdt_i6300esb: remove a unnecessary comment, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 33/35] scripts: add script to convert multiline comments into 4-line format,
Paolo Bonzini <=
- [Qemu-devel] [PULL 30/35] qemu/queue.h: simplify reverse access to QTAILQ, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 34/35] remove space-tab sequences, Paolo Bonzini, 2018/12/17
- [Qemu-devel] [PULL 35/35] avoid TABs in files that only contain a few, Paolo Bonzini, 2018/12/17
- Re: [Qemu-devel] [PULL 00/35] Misc patches for 2018-12-18, Peter Maydell, 2018/12/19