From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C62AFC4363C for ; Fri, 2 Oct 2020 15:30:55 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FC89206DC for ; Fri, 2 Oct 2020 15:30:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DJVCRzdq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FC89206DC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1kON16-0001M9-KW; Fri, 02 Oct 2020 11:30:40 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kOMNc-0007mk-4s for kernelnewbies@kernelnewbies.org; Fri, 02 Oct 2020 10:49:52 -0400 Received: by mail-pj1-x102e.google.com with SMTP id p21so976232pju.0 for ; Fri, 02 Oct 2020 07:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=Khn8CfhobmHbzhXXTDMSt4Dh601ttzUMdRYWXwdYRPo=; b=DJVCRzdqpxICqnwpdEMu4UOgh8muUdxeYvAVfpAOME/Py3vcwz4BdGQvhysx3sFU5K ClVes1oURmnz88HUcBumi4d8BRhUwlKGdr0ysmvUMNdIkBXRUBCevHT/W9lm4z8C0nCm yCEK+RCjzMOER5R6r8qy+1lMKE1wJYRQ41NqFMAnmwooDIdDyjlbV+N/ydWo3M9lElcq ihBGTM3yXXWNktTz1UL/6HIFHunHziDgityBGyiEiydATqvfVA0zW9/IIiDalAy8XqPu yOX8otRKWm0NkJj24ogiGE3CtQ9DS56Jeatu9vlLDoKhJe+2ohnw+B0u9rw0HosMpVDp C6gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=Khn8CfhobmHbzhXXTDMSt4Dh601ttzUMdRYWXwdYRPo=; b=qSQa6mQUyHBYUCiEwhS969slymC1tsnU/teRrFeb4PLqbOE73kNtn2VJfCSkZyqQwL TmB8f2aqhbd9Ko5QURaDZ1rdT9IG2ZaLogAFJUzYLBtSGWiEdCCXoDo4lNfV9PjWcYh9 ZkStkfYV/Xv007PkiNFXsyEw2D6BAfXtogdk2nplgRpE6uq/Kg4JNLZjcHRjzj8FeUtR IpKYO0arIIVlZ8u0Cy1cD+0ku5YGyxyZqjO1gw5Ec4YkyCKm10Kz3XxquygwHFZ3QRjU +U/6NnDJovU6X7ADi48giP3ZxHcCm2qewjEH3ExWhaOXyMvFHzWfGoSW/MK7BNvEozl1 wWSg== X-Gm-Message-State: AOAM5325H7c7ewP+iLW7KGgWr4jZtntQR9BPXCFP+xgA9U1HdkKO2idp vxNao650DL/M+Ji7mUEtxTg= X-Google-Smtp-Source: ABdhPJxwW3dtMkRmIG5bjtfHXLP/iJtqLM2Vvz1Qub+OGsJcG5JmRFgbh6HpS0hiEJPKxStWbCVnOg== X-Received: by 2002:a17:90b:241:: with SMTP id fz1mr1137101pjb.17.1601650190202; Fri, 02 Oct 2020 07:49:50 -0700 (PDT) Received: from Gentoo (sau-465d4-or.servercontrol.com.au. [43.250.207.1]) by smtp.gmail.com with ESMTPSA id h9sm1720278pfh.213.2020.10.02.07.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 07:49:49 -0700 (PDT) Date: Fri, 2 Oct 2020 20:19:36 +0530 From: Bhaskar Chowdhury To: Joe Perches Subject: Re: external tool to remove embedded filenames Message-ID: <20201002144936.GA17987@Gentoo> Mail-Followup-To: Bhaskar Chowdhury , Joe Perches , Andrew Morton , Andy Whitcroft , LKML , "kernel-mentors@selenic.com" , kernelnewbies References: <1fd5f9188a14acdca703ca00301ee323de672a8d.camel@perches.com> MIME-Version: 1.0 In-Reply-To: X-Mailman-Approved-At: Fri, 02 Oct 2020 11:30:39 -0400 Cc: Andy Whitcroft , "kernel-mentors@selenic.com" , Andrew Morton , LKML , kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============3851277863338278629==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============3851277863338278629== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PEIAKu/WMn1b1Hv9" Content-Disposition: inline --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 11:47 Thu 01 Oct 2020, Joe Perches wrote: >It's rather unnecessary for files to contain their >path/filename in source code comments. > >Here's a trivial little script that can remove >embedded filenames in c90 style comments from files. > >This requires git. > >It does the following types of removals: > >remove individual lines like /* filename */ completely >remove filename from /* filename -- comment */, leave /* comment */ >remove filename and any trailing ' *\n' from /* filename, leave /* >remove filename from /* filename, leave /* >remove filename from continuation ' * filename -- comment' leave ' * comment' >remove filename and any trailing ' *\n' from continuation ' * filename\n *\n' > >It seems to work well enough. > >It does not handle c99 comments. >No // filename variants are removed. > >Running it on today's -next gives: > >$ perl remove_embedded_filenames.pl >$ git diff --shortstat > 2310 files changed, 354 insertions(+), 4239 deletions(-) > >It's also possible to give any filename or path >as an argument to the script > >For instance: > >$ perl remove_embedded_filenames.pl drivers/net > >#!/usr/bin/perl -w > ># script to remove * comments; ># use: perl remove_embedded_filenames.pl ># e.g.: perl remove_embedded_filenames.pl drivers/net/ethernet/intel > >use strict; > >my $P = $0; >my $modified = 0; >my $quiet = 0; > >sub expand_tabs { > my ($str) = @_; > > my $res = ''; > my $n = 0; > for my $c (split(//, $str)) { > if ($c eq "\t") { > $res .= ' '; > $n++; > for (; ($n % 8) != 0; $n++) { > $res .= ' '; > } > next; > } > $res .= $c; > $n++; > } > > return $res; >} > >my $args = join(" ", @ARGV); >my $output = `git ls-files -- $args`; >my @files = split("\n", $output); > >foreach my $file (@files) { > my $f; > my $cvt = 0; > my $text; > ># read the file > > next if ((-d $file)); > > open($f, '<', $file) > or die "$P: Can't open $file for read\n"; > $text = do { local($/) ; <$f> }; > close($f); > > next if ($text eq ""); > ># Remove the embedded filenames > > # remove individual lines like /* filename */ completely > $cvt += $text =~ s@/\*[ \t]+(?:linux\/)?\Q$file\E[ \t]*\*/[ \t]*\n@@g; > pos($text) = 0; > # remove filenamee from /* filename -- comment */, leave /* comment */ > $cvt += $text =~ s@/\*([ \t]+)(?:linux\/)?\Q$file\E[ \t]*[:-]+[ \t]*@/*$1@g; > pos($text) = 0; > # remove filename and any trailing ' *\n' from /* filename, leave /* > $cvt += $text =~ s@/\*([ \t]+)(?:linux\/)?\Q$file\E[ \t]*\n([ \t]*\*[ \t]*\n)*(?:[ \t]*\*)?@/*@g; > pos($text) = 0; > # remove filename from /* filename, leave /* > $cvt += $text =~ s@/\*([ \t]+)(?:linux\/)?\Q$file\E[ \t]*\n@/*@g; > pos($text) = 0; > # remove filename from continuation ' * filename -- comment' > # leave ' * comment' > $cvt += $text =~ s/([ \t]+)\*([ \t]*)(?:linux\/)?\Q$file\E[ \t]*[:-]+[ \t]*/$1*$2/g; > pos($text) = 0; > # remove filename and any trailing ' *\n' from > # continuation ' * filename\n *\n' > $cvt += $text =~ s/([ \t]*)\*([ \t]*)(?:linux\/)?\Q$file\E[ \t]*\n([ \t]*\*[ \t]*\n)*//g; > pos($text) = 0; > ># write the file if something was changed > > if ($cvt > 0) { > $modified = 1; > print("$file\n"); > open($f, '>', $file) > or die "$P: Can't open $file for write\n"; > print $f $text; > close($f); > } >} > >if ($modified && !$quiet) { > print < >Warning: these changes may not be correct. > >These changes should be carefully reviewed manually and not combined with >any functional changes. > >Compile, build and test your changes. > >You should understand and be responsible for all object changes. > >Make sure you read Documentation/SubmittingPatches before sending >any changes to reviewers, maintainers or mailing lists. >EOT >} Joe, Suggestion.... please take those damn EOT lines out of it ..absolutely not required...or did you put for your own purpose?? As I believe it not the final product. Anyway, it would be good if those not there. Yup, I do like the "individual option" stuff ...so, you can only mess around single thing than the whole lot. ~Bhaskar --PEIAKu/WMn1b1Hv9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEnwF+nWawchZUPOuwsjqdtxFLKRUFAl93PfwACgkQsjqdtxFL KRV9CQgAhFY2kGXd+1qEwoZeNs7nVKb4v62+/RE8wWKm5Ys1RpiRjIRbRT3TJzxO EM+KzisFPmI6hHW51UJcve4QJn06DlddjdRe/VE2ioHPjz/UEScaBQ2K3qzT+7QE ARKMRRNCwPZIoUM/hZBXUhAmDoPzn0XPr2+/uLdA+6sqUo2BwTY/Y/AP/mEWmXyv 1MYxxsKmI+cQeRgXOde/Z17Rc7udjUbSk9jFUrtJyH6Fle1DuZAkYaEL5H9plua5 TePwFi9u+OmtptxTlTGLIi8wIBMOIDjS+xSDbodL0shR74eDYRLOUOcDd0FlmoFm eNaL2ptBn+bFXIUsQ/mj1RGTrtjNVQ== =D+Sc -----END PGP SIGNATURE----- --PEIAKu/WMn1b1Hv9-- --===============3851277863338278629== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============3851277863338278629==--