This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH RFC] Protoize tui/*.c


On Nov 15,  6:07pm, Kevin Buettner wrote:

> The patches below were generated automatically and "protoize" the C
> source files in tui.  If you glance at the patches, you'll notice that
> these sources were already protoized and that only the old K&R style
> declarations were removed along with the corresponding __STDC__
> ifdefs.  (The remaining, already protized, function declarators are
> reformatted too where appropriate.)  I will post the script used to do
> the conversion as a reply to this message.

Here's the script...

--- fix-ifdef-decls ---
#!/usr/bin/perl -w

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' || (-d && /-share$/)) {
	    $File::Find::prune = 1;
	} elsif (-f && -T && /\.c$/ && $_ ne "gnu-regex.c") {
	    push @ARGV, $File::Find::name;
	}
    },
    $root
);

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

while (<>) {
    s/
	^
	\#ifdef\ __STDC__
	\s+
	( 
	  ^
	  \w+			# function name
	  [^#]+
	)
	^
	\#else
	[^#]+
	^
	\#endif\n
    /
	fix_decl($1)
    /smgex;

    print;
}

sub fix_decl {
    my ($decl) = @_;

    my $newdecl = reindent($decl . "{\n}\n");
    $newdecl =~ s/{\n}//;
    return $newdecl;
}


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 $indentoptions");
    $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;
}

BEGIN {
    @typelist = qw(ADDR32 B_TYPE COMMON_ENTRY_PTR CORE_ADDR CPUSpace
	DCACHE DIE_REF DOUBLEST EXTR EventRecord FDR FILE HWND
	INSN_WORD INT32 LONG LONGEST LPARAM LRESULT PDR PTR
	PTRACE_ARG3_TYPE PXDB_header_ptr Point Ptrace_return RDB_EVENT
	REGISTER_TYPE RgnHandle Rptrace SAVED_BF_PTR
	SAVED_F77_COMMON_PTR SAVED_FUNCTION SYMR TTRACE_ARG_TYPE UINT
	ULONGEST WAITTYPE WPARAM WindowPtr XDR YYSTYPE
	alpha_extra_func_info_t arg_array arg_one arg_type arg_value
	argsin asection attach_continue_t bfd bfd_arch_info_type
	bfd_byte bfd_signed_vma bfd_vma bool_t boolean boolean_t
	bpstat branch_type catch_errors_ftype catch_fork_kind
	cma__t_int_tcb disassemble_info dld_cache_t dnttpointer
	dst_rec_ptr_t dst_sec dst_sect_ref_t dst_type_t file_ptr
	fltset_t fpregset_t func_call gdb_client_data gdb_fpregset_t
	gdb_gregset_t gdb_thread_t gdb_threadref gregset_t
	host_callback insertion_state_t insn_type kern_return_t
	lwpid_t mach_msg_header_t mach_msg_id_t mach_msg_type_name_t
	mach_port_mscount_t mach_port_t memory_page_t memxferfunc
	mips_extra_func_info_t namespace_enum off_t pid_t port_chain_t
	process_state_t procinfo quick_file_entry quick_module_entry
	quick_procedure_entry return_mask rmt_thread_action sec_ptr
	serial_t serial_ttystate sigset_t size_t sltpointer
	stepping_mode_t sysset_t t_inst task_t td_err_e td_thr_state_e
	td_thr_type_e td_thragent_t td_thrhandle_t thread_array_t
	thread_info thread_t threadinfo threadref time_t tree
	ttevents_t ttreq_t ttstate_t ttwopt_t u_long
	ui_file_delete_ftype ui_file_flush_ftype ui_file_fputs_ftype
	ui_file_isatty_ftype ui_file_put_ftype ui_file_rewind_ftype
	va_list value_ptr xdrproc_t);
    $indentoptions = '-T ' . join(' -T ', @typelist);
}
--- end fix-ifdef-decls ---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]