From 52728b7d416f7837fc3460a9e131355094649b15 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 Dec 2005 12:29:13 +0000 Subject: r12446: Merge mkproto.sh's functionality into mkproto.pl Allow specifying the _PUBLIC_ keyword on functions to indicate a function is public. Public prototypes can now be written to a seperate header, although this functionality is not used yet. (This used to be commit e3466df6dfb62bbf8bee3acfa92996945054c2dd) --- source4/include/includes.h | 2 + source4/include/structs.h | 2 + source4/main.mk | 8 ++-- source4/script/mkproto.pl | 112 +++++++++++++++++++++++++++++++++------------ source4/script/mkproto.sh | 48 ------------------- 5 files changed, 90 insertions(+), 82 deletions(-) delete mode 100644 source4/script/mkproto.sh (limited to 'source4') diff --git a/source4/include/includes.h b/source4/include/includes.h index 18fc38031c..9f5679fa80 100644 --- a/source4/include/includes.h +++ b/source4/include/includes.h @@ -160,4 +160,6 @@ extern int DEBUGLEVEL; #define discard_const(ptr) ((void *)((intptr_t)(ptr))) #define discard_const_p(type, ptr) ((type *)discard_const(ptr)) +#define _PUBLIC_ + #endif /* _INCLUDES_H */ diff --git a/source4/include/structs.h b/source4/include/structs.h index b652579edd..a7dd758b5c 100644 --- a/source4/include/structs.h +++ b/source4/include/structs.h @@ -370,3 +370,5 @@ struct smb2_handle; struct com_context; struct IUnknown; struct IUnknown_vtable; + +struct MprVar; diff --git a/source4/main.mk b/source4/main.mk index 61ea36eaa3..118d544665 100644 --- a/source4/main.mk +++ b/source4/main.mk @@ -197,10 +197,10 @@ include/config.h: include/proto.h: $(PROTO_PROTO_OBJ_LIST:.o=.c) @-rm -f include/includes.h.gch - @$(SHELL) script/mkproto.sh "$(PERL)" \ - -h _PROTO_H_ include/proto.h \ - $(PROTO_PROTO_OBJ_LIST) - @touch include/proto.h + @echo "Creating include/proto.h" + @$(PERL) script/mkproto.pl --public-define=_PROTO_H_ \ + --public=include/proto.h --private=include/proto.h \ + $(PROTO_PROTO_OBJ_LIST) proto: include/proto.h pch: include/config.h \ diff --git a/source4/script/mkproto.pl b/source4/script/mkproto.pl index 227c7c0dce..5db9424cd8 100755 --- a/source4/script/mkproto.pl +++ b/source4/script/mkproto.pl @@ -5,26 +5,71 @@ use strict; # don't use warnings module as it is not portable enough # use warnings; -my $header_name = '_PROTO_H_'; -if ($ARGV[0] eq '-h') { - shift @ARGV; - $header_name = shift @ARGV; +use Getopt::Long; + +my $public_file = undef; +my $private_file = undef; +my $public_define = undef; +my $private_define = undef; +my $public_fd = \*STDOUT; +my $private_fd = \*STDOUT; + +GetOptions( + 'public=s' => sub { my ($f,$v) = @_; $public_file = $v; }, + 'private=s' => sub { my ($f,$v) = @_; $private_file = $v; }, + 'define=s' => sub { + my ($f,$v) = @_; + $public_define = $v; + $private_define = "$v\_PRIVATE"; + }, + 'public-define=s' => \$public_define, + 'private-define=s' => \$private_define +); + +if ($public_define eq undef and $public_file ne undef) { + $public_define = $public_file; + $public_define =~ tr{./}{__}; +} elsif ($public_define eq undef) { + $public_define = '_PROTO_H_'; } -sub print_header { - print "#ifndef $header_name\n"; - print "#define $header_name\n\n"; - print "/* This file is automatically generated with \"make proto\". DO NOT EDIT */\n\n"; +if ($private_define eq undef and $private_file ne undef) { + $private_define = $private_file; + $private_define =~ tr{./}{__}; +} elsif ($public_define eq undef) { + $public_define = '_PROTO_H_'; } -sub print_footer { - printf "\n#endif /* %s */\n", $header_name; +if ($public_file ne undef) { + open PUBLIC, ">$public_file"; + $public_fd = \*PUBLIC; } +if ($private_file eq $public_file) { + $private_fd = $public_fd; +} elsif ($private_file ne undef) { + open PRIVATE, ">$private_file"; + $private_fd = \*PRIVATE; +} + +sub print_header($$) +{ + my ($file, $header_name) = @_; + print $file "#ifndef $header_name\n"; + print $file "#define $header_name\n\n"; + print $file "/* This file is automatically generated with \"make proto\". DO NOT EDIT */\n\n"; +} -sub handle_loadparm { - my $line = shift; +sub print_footer($$) +{ + my ($file, $header_name) = @_; + printf $file "\n#endif /* %s */\n", $header_name; +} + +sub handle_loadparm($$) +{ + my ($file,$line) = @_; if ($line =~ /^FN_(GLOBAL|LOCAL)_(CONST_STRING|STRING|BOOL|CHAR|INTEGER|LIST)\((\w+),.*\)/o) { my $scope = $1; @@ -45,20 +90,23 @@ sub handle_loadparm { "LOCAL" => "int " ); - print "$tmap{$type}$name($smap{$scope});\n"; + print $file "$tmap{$type}$name($smap{$scope});\n"; } } - -sub process_file($) +sub process_file($$$) { - my $filename = shift; + my ($public_file, $private_file, $filename) = @_; + + $filename =~ s/\.o$/\.c/g; open(FH, "< $filename") || die "Failed to open $filename"; - print "\n/* The following definitions come from $filename */\n\n"; + print $private_file "\n/* The following definitions come from $filename */\n\n"; while (my $line = ) { + my $target = $private_file; + # these are ordered for maximum speed next if ($line =~ /^\s/); @@ -76,37 +124,41 @@ sub process_file($) next if ($line =~ /^int\s*main/); if ($line =~ /^FN_/) { - handle_loadparm($line); + handle_loadparm($public_file, $line); next; } + if ($line =~ s/_PUBLIC_//xo) { + $target = $public_file; + } + if ( $line =~ /\(.*\)\s*$/o ) { chomp $line; - print "$line;\n"; + print $target "$line;\n"; next; } - print $line; + print $target $line; while ($line = ) { if ($line =~ /\)\s*$/o) { chomp $line; - print "$line;\n"; + print $target "$line;\n"; last; } - print $line; + print $target $line; } } close(FH); } -sub process_files { - foreach my $filename (@ARGV) { - process_file($filename); - } +if ($public_file != $private_file) { + print_header($private_fd, $private_define); +} +print_header($public_fd, $public_define); +process_file($public_fd, $private_fd, $_) foreach (@ARGV); +print_footer($public_fd, $public_define); +if ($public_file != $private_file) { + print_footer($private_fd, $private_define); } - -print_header(); -process_files(); -print_footer(); diff --git a/source4/script/mkproto.sh b/source4/script/mkproto.sh deleted file mode 100644 index c6da261b65..0000000000 --- a/source4/script/mkproto.sh +++ /dev/null @@ -1,48 +0,0 @@ -#! /bin/sh - -LANG=C; export LANG -LC_ALL=C; export LC_ALL -LC_COLLATE=C; export LC_COLLATE - -if [ $# -lt 3 ] -then - echo "Usage: $0 perl [-h headerdefine] outputheader proto_obj" - exit 1 -fi - -perl="$1" -shift - -if [ x"$1" = x-h ] -then - headeropt="-h $2" - shift; shift; -else - headeropt="-h _`echo $1 | tr ./ __`_" -fi - -header="$1" -shift -headertmp="$header.$$.tmp~" - -proto_src="`echo $@ | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort | uniq | egrep -v 'ubiqx/|wrapped'`" - -echo creating $header - -mkdir -p `dirname $header` - -${perl} script/mkproto.pl $headeropt $proto_src > $headertmp - -RET=$? - -if test x"$RET" != x"0";then - exit $RET -fi - -if cmp -s $header $headertmp 2>/dev/null -then - echo "$header unchanged" - rm $headertmp -else - mv $headertmp $header -fi -- cgit