Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [PATCH RFC] PARAMS elimination: pointer variables
       [not found] <1000531200148.ZM11276@ocotillo.lan>
@ 2000-05-31 13:10 ` Kevin Buettner
  2000-05-31 13:14 ` Kevin Buettner
  1 sibling, 0 replies; 2+ messages in thread
From: Kevin Buettner @ 2000-05-31 13:10 UTC (permalink / raw)
  To: gdb-patches

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 *));



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH RFC] PARAMS elimination: pointer variables
       [not found] <1000531200148.ZM11276@ocotillo.lan>
  2000-05-31 13:10 ` [PATCH RFC] PARAMS elimination: pointer variables Kevin Buettner
@ 2000-05-31 13:14 ` Kevin Buettner
  1 sibling, 0 replies; 2+ messages in thread
From: Kevin Buettner @ 2000-05-31 13:14 UTC (permalink / raw)
  To: gdb-patches

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

> After these changes, there remain about 30 occurrences of PARAMS in
> the source code that need to be eliminated by hand.

FYI, here is a list:

./command.h[118]: #define NO_FUNCTION ((void (*) PARAMS((char *args, int from_tty))) 0)
./monitor.h[99]:     void (*load_routine) PARAMS ((serial_t desc, char *file,
./monitor.h[101]:     int (*dumpregs) PARAMS ((void));	/* routine to dump all registers */
./monitor.h[102]:     int (*continue_hook) PARAMS ((void));	/* Emit the continue command */
./procfs.c[101]: static void procfs_open              PARAMS((char *, int));
./procfs.c[757]: 			       int (*func) PARAMS ((procinfo *,
./remote.c[5166]: PARAMS ((void))
./ser-ocd.c[52]:       dll_do_command = ((int (*)PARAMS ((const char *, char *)))
./symtab.c[80]: static struct partial_symbol *lookup_partial_symbol PARAMS
./v850ice.c[124]: static void do_gdb (char *, char *, void (*func) PARAMS ((char *, int)), int);
./v850ice.c[130]: long (__stdcall * ExeAppReq) PARAMS ((char *, long, char *, struct MessageIO *));
./v850ice.c[132]: long (__stdcall * RegisterClient) PARAMS ((HWND));
./v850ice.c[134]: long (__stdcall * UnregisterClient) PARAMS ((void));
./v850ice.c[349]:       ExeAppReq = (long (*)PARAMS ((char *, long, char *, struct MessageIO *)))
./v850ice.c[351]:       RegisterClient = (long (*)PARAMS ((HWND)))
./v850ice.c[353]:       UnregisterClient = (long (*)PARAMS ((void)))
./tui/tuiIO.c[605]:       tputs (term_memory_unlock, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiIO.c[621]:       tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiIO.c[711]:       tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiIO.c[712]:       tputs (term_memory_lock, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiIO.c[720]:       tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiIO.c[726]:     tputs (term_se, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiIO.c[730]:   tputs (buffer, 1, (int (*)PARAMS ((int))) putchar);
./tui/tuiLayout.c[23]: static void _initGenWinInfo PARAMS
./tui/tuiLayout.c[25]: static void _initAndMakeWin PARAMS
./tui/tuiLayout.c[27]: static void _showSourceOrDisassemAndCommand PARAMS
./tui/tuiLayout.c[29]: static void _makeSourceOrDisassemWindow PARAMS
./tui/tuiLayout.c[33]: static void _makeDisassemWindow PARAMS
./tui/tuiSourceWin.h[9]: extern void tuiUpdateSourceWindow PARAMS
./tui/tuiSourceWin.h[11]: extern void tuiUpdateSourceWindowAsIs PARAMS


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-05-31 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1000531200148.ZM11276@ocotillo.lan>
2000-05-31 13:10 ` [PATCH RFC] PARAMS elimination: pointer variables Kevin Buettner
2000-05-31 13:14 ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox