summaryrefslogtreecommitdiff
path: root/source4/script/mkproto.pl
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-23 01:29:42 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-23 01:29:42 +0000
commitfec4b5b0cc8160d93dfbb91643a9783a08ed12a5 (patch)
treea4ff47039d224e0c253e1557298578c3dafab1b6 /source4/script/mkproto.pl
parent868555bca5fdc87d4e46df6e853c19e5d5f5f796 (diff)
downloadsamba-fec4b5b0cc8160d93dfbb91643a9783a08ed12a5.tar.gz
samba-fec4b5b0cc8160d93dfbb91643a9783a08ed12a5.tar.bz2
samba-fec4b5b0cc8160d93dfbb91643a9783a08ed12a5.zip
changed to perl for mkproto, patch from vance
(This used to be commit 9386326868f43dab95b5508ce0ca5a9c1160a2eb)
Diffstat (limited to 'source4/script/mkproto.pl')
-rw-r--r--source4/script/mkproto.pl140
1 files changed, 140 insertions, 0 deletions
diff --git a/source4/script/mkproto.pl b/source4/script/mkproto.pl
new file mode 100644
index 0000000000..93a908165c
--- /dev/null
+++ b/source4/script/mkproto.pl
@@ -0,0 +1,140 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $header_name = '_PROTO_H_';
+
+if ($ARGV[0] eq '-h') {
+ shift @ARGV;
+ $header_name = shift @ARGV;
+}
+
+
+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";
+}
+
+sub print_footer {
+ printf "\n#endif /* %s */\n", $header_name;
+}
+
+sub process_files {
+ my $line;
+ my $inheader;
+ my $gotstart;
+
+ FILE: foreach my $filename (@ARGV) {
+ next FILE unless (open(FH, "< $filename")); # skip over file unless it can be opened
+ print "\n/* The following definitions come from $filename */\n\n";
+
+ $inheader = 0;
+ $gotstart = 0;
+ LINE: while (defined($line = <FH>)) {
+
+ if ($inheader) {
+ # this chomp is somewhat expensive, so don't do it unless we know
+ # that we probably want to use it
+ chomp $line;
+ if ($line =~ /\)\s*$/o) {
+ $inheader = 0;
+ print "$line;\n";
+ } else {
+ print "$line\n";
+ }
+ next LINE;
+ }
+
+ $gotstart = 0;
+
+ # ignore static and extern declarations
+ if ($line =~ /^static|^extern/o ||
+ $line !~ /^[a-zA-Z]/o ||
+ $line =~ /[;]/o) {
+ next LINE;
+ }
+
+
+ if ($line =~ /^FN_GLOBAL_STRING/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "char *$fnName(void);\n";
+ }
+ elsif ($line =~ /^FN_LOCAL_STRING/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "char *$fnName(int );\n";
+ }
+ elsif ($line =~ /^FN_GLOBAL_BOOL/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "BOOL $fnName(void);\n";
+ }
+ elsif ($line =~ /^FN_LOCAL_BOOL/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "BOOL $fnName(int );\n";
+ }
+ elsif ($line =~ /^FN_GLOBAL_INTEGER/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "int $fnName(void);\n";
+ }
+ elsif ($line =~ /^FN_LOCAL_INTEGER/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "int $fnName(int );\n";
+ }
+ elsif ($line =~ /^FN_GLOBAL_LIST/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "const char **$fnName(void);\n";
+ }
+ elsif ($line =~ /^FN_LOCAL_LIST/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "const char **$fnName(int );\n";
+ }
+ elsif ($line =~ /^FN_GLOBAL_CONST_STRING/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "const char *$fnName(void);\n";
+ }
+ elsif ($line =~ /^FN_LOCAL_CONST_STRING/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "const char *$fnName(int );\n";
+ }
+ elsif ($line =~ /^FN_LOCAL_CHAR/o) {
+ my $fnName = (split(/[\(,]/, $line))[1];
+ print "char $fnName(int );\n";
+ }
+
+
+ # I'm going to leave these as is for now - perl can probably handle larger regex, though -- vance
+ # I've also sort of put these in approximate order of most commonly called
+
+ elsif ( $line =~ /^NTSTATUS|^void|^BOOL|^int|^struct|^char|^const|^PyObject|^ssize_t|^size_t|^uint|^ADS_STATUS|^ADS_STRUCT|^enum.*\(|^SMB_ACL_T|^time|^smb_ucs2_t|^DATA_BLOB|^WERROR/o ) {
+ $gotstart = 1;
+ } elsif ( $line =~ /^smb_iconv_t|^long|^CLI_POLICY_HND|^FILE|^XFILE|^SMB_OFF_T|^pipes_struct|^smb_np_struct|^file_fd_struct|^files_struct|^connection_struct|^uid_t|^gid_t|^unsigned|^DIR|^user/o) {
+ $gotstart = 1;
+ } elsif ( $line =~ /^pid_t|^ino_t|^off_t|^double|^TDB_CONTEXT|^TDB_DATA|^TALLOC_CTX|^NT_DEVICEMODE|^NT_USER_TOKEN|^ADS_MODLIST|^SORTED_TREE|^REGISTRY_HOOK|^REGISTRY_VALUE|^NTTIME|^UNISTR2|^SMB_STRUCT_DIRENT|^SEC_DESC|^DOM_SID/o ) {
+ $gotstart = 1;
+ }
+
+
+ # goto next line if we don't have a start
+ next LINE unless $gotstart;
+
+ if ( $line =~ /\(.*\)\s*$/o ) {
+ # now that we're here, we know we
+ chomp $line;
+ print "$line;\n";
+ next LINE;
+ }
+ elsif ( $line =~ /\(/o ) {
+
+ $inheader = 1;
+ # line hasn't been chomped, so we can assume it already has the \n
+ print $line;
+ next LINE;
+ }
+ }
+ }
+}
+
+print_header();
+process_files();
+print_footer();