Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@cygnus.com>
To: gdb-patches@sourceware.cygnus.com
Subject: Re: [PATCH RFC] PARAMS elimination: pointer variables
Date: Wed, 31 May 2000 13:10:00 -0000	[thread overview]
Message-ID: <1000531201029.ZM11319@ocotillo.lan> (raw)
In-Reply-To: <1000531200148.ZM11276@ocotillo.lan>

On May 31,  1:01pm, Kevin Buettner wrote:

> ... with a new script which I'll post as a reply to this message.

The script is below along with a sample invocation of it.  When I run it,
it produces one warning (shown below), but it is nothing to worry about.

--- nuke-params-indent-2 ---
#!/usr/bin/perl -w

# Remove occurrences of PARAMS from pointer variable declarations in
# gdb sources.  (It may work for other code too, but I wrote it
# after examining the gdb sources.)
#
# Pointer variable declarations frequently occur either within
# function bodies or within struct declarations, so it's important to
# preserve the leading indentation whilst at the same time reindenting
# the declaration according to GNU coding standards.  This script attempts
# to do all of this.
#
# To invoke the script, merely provide the name of the directory to
# be searched/fixed as the first and only argument to the script.

use File::Find;
use FileHandle;
use IPC::Open3;
use English;

my ($root) = @ARGV;

if (!defined($root)) {
    die "Usage: $0 root\n";
}

@ARGV = ();

find(
    sub { 
	if ($_ eq 'testsuite') {
	    $File::Find::prune = 1;
	} elsif (-f && -T && /\.[chy]$/) {
	    push @ARGV, $File::Find::name;
	}
    },
    $root
);

#$INPLACE_EDIT = '.bak';
$INPLACE_EDIT = '';
undef $/;			# slurp entire files

while (<>) {
    s{^				# line start
      ([^\n]*\w+\W+		# type name, qualifiers, etc.
      \(\*(?:const\s+)?\w+\)\s+) # left paren, star, optional const,
                                # identifier, right paren, spaces
      PARAMS			# what it says
      \s* 			# optional spaces
      \(\(			# double left parens
      ([^;]*)			# parameter list
      \)\)			# double right parens
      ( [;,] 			# semicolon or comma ...
       |			#   or
	(?:[\s\n]*=[^;]+;)	# an assignment
      )
      (?=\s*$)			# look ahead and make sure there's
      				# nothing but spaces and an eventual
				# newline after the semicolon
    }{
	reindent_preserving_leading_indent("$1 ($2)$3");
    }smgex;
    print;
}

sub reindent_preserving_leading_indent {
    my ($decl) = @_;
    my ($tabs, $spaces) = $decl =~ /^(\t*)( *)/;
    my $leading_indent = 8 * length($tabs) + length($spaces);

    my $ret = reindent($decl, 80 - $leading_indent);

    $ret =~ s/^(\t*)/' ' x (length($1) * 8 + $leading_indent)/meg;
    $ret =~ s#^((:? {8})*)#"\t" x (length($1) / 8)#meg;

    $ret;
}

sub reindent {
    my ($decl, $line_length) = @_;
    $line_length = 80		unless defined $line_length;
    my ($rfh, $wfh, $efh) = (FileHandle->new, FileHandle->new,
					      FileHandle->new);
    my $pid = open3($wfh, $rfh, $efh, "indent -l$line_length");
    $rfh->input_record_separator(undef);
    $efh->input_record_separator(undef);
    $wfh->print($decl);
    $wfh->close();
    my $replacement = <$rfh>;
    $rfh->close();
    my $errstr = <$efh>;
    $efh->close();
    waitpid $pid, 0;
    $replacement =~ s#\n$##;
    if ($errstr ne "") {
	print STDERR "Check $ARGV...\n$errstr\nInput:$decl\nOutput:$replacement\n\n"
    }
    $replacement;
}
--- end nuke-params-indent-2 ---

Here's a sample invocation:

ocotillo:gdb-sourceware$ /home/kev/ptests/nuke-params-indent-2 .
Check ./stabsread.h...
indent: Standard input:1: Warning:Extra )

Input:   int (*f)  (struct objfile *, struct symbol *, char *));
Output:int (*f) (struct objfile *, struct symbol *, char *));



       reply	other threads:[~2000-05-31 13:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1000531200148.ZM11276@ocotillo.lan>
2000-05-31 13:10 ` Kevin Buettner [this message]
2000-05-31 13:14 ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1000531201029.ZM11319@ocotillo.lan \
    --to=kevinb@cygnus.com \
    --cc=gdb-patches@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox