added "pidl.pl --template" to dump a rough template to save typing
authorAndrew Tridgell <tridge@samba.org>
Mon, 15 Dec 2003 10:55:10 +0000 (10:55 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 15 Dec 2003 10:55:10 +0000 (10:55 +0000)
when starting a pipe. Thanks to metze for a script that gave the idea.

do something like this to use it:

  pidl.pl --parse --template librpc/idl/XXX.idl > rpc_server/XXX/rpc_XXX.c

then fill in the functions in rpc_XXX.c
(This used to be commit 68e71d7497ddc7b8239fc4bd7cb3e780a1f53a39)

source4/build/pidl/pidl.pl
source4/build/pidl/server.pm
source4/build/pidl/template.pm [new file with mode: 0644]

index ce8250826a81c99a4705e00adb7197e81bd1c728..9b870d7263f07de6b120310cfe8a764851e1fa0a 100755 (executable)
@@ -21,12 +21,14 @@ use parser;
 use eparser;
 use validator;
 use util;
+use template;
 
 my($opt_help) = 0;
 my($opt_parse) = 0;
 my($opt_dump) = 0;
 my($opt_diff) = 0;
 my($opt_header) = 0;
+my($opt_template) = 0;
 my($opt_server) = 0;
 my($opt_parser) = 0;
 my($opt_eparser) = 0;
@@ -64,6 +66,7 @@ sub ShowHelp()
              --header              create a C header file
              --parser              create a C parser
              --server              create server boilterplate
+             --template            print a template for a pipe
              --eparser             create an ethereal parser
              --diff                run diff on the idl and dumped output
              --keep                keep the .pidl file
@@ -79,6 +82,7 @@ GetOptions (
            'dump' => \$opt_dump,
            'header' => \$opt_header,
            'server' => \$opt_server,
+           'template' => \$opt_template,
            'parser' => \$opt_parser,
            'eparser' => \$opt_eparser,
            'diff' => \$opt_diff,
@@ -149,6 +153,10 @@ sub process_file($)
                system("diff -wu $idl_file $tempfile");
                unlink($tempfile);
        }
+
+       if ($opt_template) {
+               print IdlTemplate::Parse($pidl);
+       }
 }
 
 
index e87a6a00bea4dd80280cfe5e728d775ba82468ff..f5256d18a678786569c9b13aacd7991713e38514 100644 (file)
@@ -1,5 +1,3 @@
-
-
 ###################################################
 # server boilerplate generator
 # Copyright tridge@samba.org 2003
diff --git a/source4/build/pidl/template.pm b/source4/build/pidl/template.pm
new file mode 100644 (file)
index 0000000..f9f9897
--- /dev/null
@@ -0,0 +1,88 @@
+###################################################
+# server template function generator
+# Copyright tridge@samba.org 2003
+# released under the GNU GPL
+
+package IdlTemplate;
+
+use strict;
+
+my($res);
+
+#####################################################################
+# produce boilerplate code for a interface
+sub Template($)
+{
+       my($interface) = shift;
+       my($data) = $interface->{DATA};
+       my $name = $interface->{NAME};
+
+       $res .= 
+"
+/* 
+   Unix SMB/CIFS implementation.
+
+   endpoint server for the $name pipe
+
+   Copyright (C) YOUR NAME HERE XXXX
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include \"includes.h\"
+
+";
+
+       foreach my $d (@{$data}) {
+               if ($d->{TYPE} eq "FUNCTION") {
+                       my $fname = $d->{NAME};
+                       $res .=
+"
+/* 
+  $fname 
+*/
+static NTSTATUS $fname(struct dcesrv_state *dce, TALLOC_CTX *mem_ctx, 
+                      struct $fname *r)
+{
+       return NT_STATUS_NOT_IMPLEMENTED;
+}
+
+";
+               }
+       }
+
+       $res .= 
+"
+/* include the generated boilerplate */
+#include \"librpc/gen_ndr/ndr_$name\_s.c\"
+"
+}
+
+
+#####################################################################
+# parse a parsed IDL structure back into an IDL file
+sub Parse($)
+{
+       my($idl) = shift;
+       $res = "";
+       foreach my $x (@{$idl}) {
+               ($x->{TYPE} eq "INTERFACE") && 
+                   Template($x);
+       }
+       return $res;
+}
+
+1;
+