From patchwork Fri Dec 14 09:48:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 10730801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1985213BF for ; Fri, 14 Dec 2018 09:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07E362D0C7 for ; Fri, 14 Dec 2018 09:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED7DD2D143; Fri, 14 Dec 2018 09:49:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B6962D0C7 for ; Fri, 14 Dec 2018 09:49:45 +0000 (UTC) Received: from localhost ([::1]:60532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXk6K-0001AF-ML for patchwork-qemu-devel@patchwork.kernel.org; Fri, 14 Dec 2018 04:49:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXk5E-0000J4-JW for qemu-devel@nongnu.org; Fri, 14 Dec 2018 04:48:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXk59-0006mO-K3 for qemu-devel@nongnu.org; Fri, 14 Dec 2018 04:48:36 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:55681) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXk59-0006l9-DT for qemu-devel@nongnu.org; Fri, 14 Dec 2018 04:48:31 -0500 Received: by mail-wm1-x334.google.com with SMTP id y139so5000560wmc.5 for ; Fri, 14 Dec 2018 01:48:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bs4j6sYjMHuNDvsZPtbjeaG8JJdN9fkCuf0Fkjgaj+I=; b=oEZ+68BXnozBsd6MnYZ3LO25f0XuX7C1/J9/70qZCCWGHpqk2FK4nu94SiGK0iWRs5 LuBo3kaSZSk39n/+I+uKd6boGkJaas9yIC5uKEdVFoPmPwuma2J4ZicynTdQxtwH5rVr x5tYsI7mSuRO6hD2aynVEoG0cpPk4czYJHAxOATch7zk9B5vsvMvC5ArIhDlvyVtQ7Tc Mtx9FKZHuYOGEDo47EP6EPbDZoTex9+MNTw8zaQTrCbdKedpkkLafGiWxiiKY3LFNelS vTkH6LEYy22r53PDV66UMicQJ7y/yhUTky/aOdpmCPkdnQGnGXguOOqs/hawd1eLIwSl yj+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=bs4j6sYjMHuNDvsZPtbjeaG8JJdN9fkCuf0Fkjgaj+I=; b=rE5hcx+BI/MflX1cMuzZxAstDENkbt53rGlLUGzP7HiviQIq3bAFiGxBZRKPaCz/E7 Ov/ThHEoVNp7jf/FCrasg8DuC0QQf1bMiQeh2GKuE59n1PpEwM68WNnPp6hU/bAGq4Oe VnTogxp1J4PnmBK9W+vO7YYqu0xog6kNgdxl7kY3UWYvlxb1MhxBkBBMHHFeUM87izRc +Kq2W06CcxKzodA4tZSONaNjy6Fgs0s7v1k36340x/bFxL/e2js3+MeVDsz/DXY9z/et JTlhMZrz4RZEnrWqPK+j8fvd3D6ea1r8h/5bf9RDDqS9tn9/J+SPYGixCgo8S5XfDGsm fgzA== X-Gm-Message-State: AA+aEWZ2u2BALf0aGzeFaGpz48KZkolqzdcei5RLeEhddYSMuHbiq6JQ h+fDfIN5HkqPXlb3O2by20q8gjoY X-Google-Smtp-Source: AFSGD/V9/NkJZ6bSvJzI2uxVXkHMldYeB2ZuvrPc9CttNwjHzJ5m2cYfuClAD7qa6d+xhud3YBRScw== X-Received: by 2002:a1c:8089:: with SMTP id b131mr2640605wmd.141.1544780909999; Fri, 14 Dec 2018 01:48:29 -0800 (PST) Received: from donizetti.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id v132sm5177992wme.20.2018.12.14.01.48.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Dec 2018 01:48:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 14 Dec 2018 10:48:28 +0100 Message-Id: <20181214094828.18343-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::334 Subject: [Qemu-devel] [PATCH v2] scripts: add script to convert multiline comments into 4-line format X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, richard.henderson@linaro.org, armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Wainer dos Santos Moschetta --- v1->v2: fix handling of multiline doc comments without lone /** --- 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 +}' "$@"