From nobody Fri Nov 7 00:45:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544780609080101.82700870093151; Fri, 14 Dec 2018 01:43:29 -0800 (PST) Received: from localhost ([::1]:60494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXk0E-0004ks-UT for importer@patchew.org; Fri, 14 Dec 2018 04:43:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXjyv-0003Yr-Jb for qemu-devel@nongnu.org; Fri, 14 Dec 2018 04:42:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXjyq-0002mn-Di for qemu-devel@nongnu.org; Fri, 14 Dec 2018 04:42:05 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:33402) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXjyq-0002js-5k for qemu-devel@nongnu.org; Fri, 14 Dec 2018 04:42:00 -0500 Received: by mail-wm1-x341.google.com with SMTP id r24so15806188wmh.0 for ; Fri, 14 Dec 2018 01:41:54 -0800 (PST) Received: from donizetti.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id t76sm6259760wme.33.2018.12.14.01.41.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Dec 2018 01:41:52 -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=aZZPgX33Xv8XVnNcJEZPEVUpOmBJx1iRPjznlp9hLEo=; b=vMbSxZt15bfbZVrLhDWaCxSoPnGKajcg6ibct4rALVIOEyVnMu9LUrD4jD/C+2yymB QRm7dD/j5CBpQLzRPoF9ZjXdhQklwVccRGJhbcthv+IyH+d+O2fjXCj4/IAWG6qhCeqP sRiSSfdIODk9+bQfEe9yiv3Mb/75mj9JTAXq5vhA9Uj0lz8q9n+cBovFphFiqFVMdGNI 8Fiu/AJeFthdwfs7/zN9ggNsfeVmR9dJzBfm0XSKMsHtp0WuqongXbP0V2i1bzNB9QUg LdqzhInnwFDV9ZPUGZS52vFckxytG285Gk5x/sjOcbaFm0JDVPmdRmUzICUpYIyRKhN2 dpVw== 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=aZZPgX33Xv8XVnNcJEZPEVUpOmBJx1iRPjznlp9hLEo=; b=LhvhC7BYWIMPXNR5r8MOtUEfiwki7/nK0I+VLyyTbF1uFIcq/5zw3k920to04oWiZ4 vEAKa+tvgrPGoZeNL1hkQSQApgfKwQGCeGY0IQg5BelwCn873rXrbyfKNvPwBBRj89rs JFk5XEfFVJv9dXH3/VYGe6FOBtDUusgSDGnGAGDyeFBRGNaWEiT41SkHRHheQeHsDKOO x/c/k/BogJq5Kbpg8kQiNi6f6+kCOw25yWplk4xgKM8ATGLJVvt3Uimsaxg6LQ1t+yG2 +qcajDt13jmHtxdu2FyApLypt8lXVaeHyCXnph5Q2J7Nf8a1ivza1cVBiOd3gZ0sIK7i yO8A== X-Gm-Message-State: AA+aEWZcBGQBQNQFAZ5M5GIINNLmTx4Mr91orDMc28FmFzCl9h5NV/YQ dEJIapfp3ZB8Yxpgan2Qdkky/qgv X-Google-Smtp-Source: AFSGD/Wd+UUQ6PD8y+obzaOek+O4Enf6nYeYwikONOfBvbx8noro4KBocK93YLlMaXB3lgYI3cOfbQ== X-Received: by 2002:a1c:9cce:: with SMTP id f197mr2551333wme.135.1544780513049; Fri, 14 Dec 2018 01:41:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 14 Dec 2018 10:41:51 +0100 Message-Id: <20181214094151.16996-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH] 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, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- scripts/fix-multiline-comments.sh | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 scripts/fix-multiline-comments.sh diff --git a/scripts/fix-multiline-comments.sh b/scripts/fix-multiline-comm= ents.sh new file mode 100755 index 0000000000..09ac6803c2 --- /dev/null +++ b/scripts/fix-multiline-comments.sh @@ -0,0 +1,60 @@ +#! /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" =3D -i; then + # gawk extension + inplace=3D"-i inplace" + shift +fi +${AWK-awk} $inplace 'BEGIN { indent =3D -1 } +{ + line =3D $0 + # apply a star to the indent on lines after the first + if (indent !=3D -1) { + if (line =3D=3D "") { + line =3D sp " *" + } else if (substr(line, 1, indent + 2) =3D=3D sp " ") { + line =3D sp " *" substr(line, indent + 3) + } + } + + is_lead =3D (line ~ /^[ \t]*\/\*/) + is_trail =3D (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 =3D RLENGTH - 2 + sp =3D substr(line, 1, indent) + } + + # the regular expression filters out lone /*, /**, or */ + if (indent !=3D -1 && !(line ~ /^[ \t]*(\/\*+|\*\/)[ \t]*$/)) { + if (is_lead) { + # split the leading /* on a separate line + match(line, /^[ \t]*\/\*+[ \t]*/) + line =3D sp "/*\n" sp " *" substr(line, RLENGTH) + } + if (is_trail) { + # split the trailing */ on a separate line + match(line, /[ \t]*\*\//) + line =3D substr(line, 1, RSTART - 1) "\n" sp " */" + } + } + if (is_trail) { + indent =3D -1 + } + print line +}' "$@" --=20 2.19.2