[1/2] widl: Add a --server-prefix option

Dan Hipschman dsh at linux.ucla.edu
Mon Apr 23 20:07:29 CDT 2007


This patch adds a --server-prefix option to widl, like Rob suggested, so
that the next patch can add tests for widl.

---
 tools/widl/header.c |   44 +++++++++++++++++++++++++++++++-------------
 tools/widl/header.h |    1 +
 tools/widl/server.c |    2 +-
 tools/widl/widl.c   |   15 +++++++++++++--
 tools/widl/widl.h   |    1 +
 5 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index 372b0b1..e6c513e 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -114,8 +114,9 @@ static void write_pident(FILE *h, const var_t *v)
   if (v->name) fprintf(h, "%s", v->name);
 }
 
-void write_name(FILE *h, const var_t *v)
+void write_prefix_name(FILE *h, const char *prefix, const var_t *v)
 {
+  fprintf(h, "%s", prefix);
   if (is_attr( v->attrs, ATTR_PROPGET ))
     fprintf(h, "get_" );
   else if (is_attr( v->attrs, ATTR_PROPPUT ))
@@ -125,6 +126,11 @@ void write_name(FILE *h, const var_t *v)
   fprintf(h, "%s", v->name);
 }
 
+void write_name(FILE *h, const var_t *v)
+{
+  write_prefix_name(h, "", v);
+}
+
 const char* get_name(const var_t *v)
 {
   return v->name;
@@ -709,7 +715,23 @@ static void write_method_proto(const type_t *iface)
   }
 }
 
-static void write_function_proto(const type_t *iface)
+static void write_function_proto(const type_t *iface, const func_t *fun, const char *prefix)
+{
+  var_t *def = fun->def;
+
+  /* FIXME: do we need to handle call_as? */
+  write_type(header, def->type, def, def->tname);
+  fprintf(header, " ");
+  write_prefix_name(header, prefix, def);
+  fprintf(header, "(\n");
+  if (fun->args)
+    write_args(header, fun->args, iface->name, 0, TRUE);
+  else
+    fprintf(header, "    void");
+  fprintf(header, ");\n");
+}
+
+static void write_function_protos(const type_t *iface)
 {
   const char *implicit_handle = get_attrp(iface->attrs, ATTR_IMPLICIT_HANDLE);
   int explicit_handle = is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE);
@@ -735,16 +757,12 @@ static void write_function_proto(const type_t *iface)
       }
     }
 
-    /* FIXME: do we need to handle call_as? */
-    write_type(header, def->type, def, def->tname);
-    fprintf(header, " ");
-    write_name(header, def);
-    fprintf(header, "(\n");
-    if (cur->args)
-      write_args(header, cur->args, iface->name, 0, TRUE);
-    else
-      fprintf(header, "    void");
-    fprintf(header, ");\n");
+    if (server_prefix[0]) {
+      fprintf(header, "/* server prototype */\n");
+      write_function_proto(iface, cur, server_prefix);
+      fprintf(header, "/* client prototype */\n");
+    }
+    write_function_proto(iface, cur, "");
   }
 }
 
@@ -876,7 +894,7 @@ static void write_rpc_interface(const type_t *iface)
         fprintf(header, "extern RPC_IF_HANDLE %s_v%d_%d_c_ifspec;\n", iface->name, LOWORD(ver), HIWORD(ver));
         fprintf(header, "extern RPC_IF_HANDLE %s_v%d_%d_s_ifspec;\n", iface->name, LOWORD(ver), HIWORD(ver));
     }
-    write_function_proto(iface);
+    write_function_protos(iface);
   }
   fprintf(header,"\n#endif  /* __%s_INTERFACE_DEFINED__ */\n\n", iface->name);
 
diff --git a/tools/widl/header.h b/tools/widl/header.h
index 1383fda..ebf7917 100644
--- a/tools/widl/header.h
+++ b/tools/widl/header.h
@@ -28,6 +28,7 @@ extern int is_void(const type_t *t, const var_t *v);
 extern int is_conformant_array( const array_dims_t *array );
 extern int is_non_void(const expr_list_t *list);
 extern void write_name(FILE *h, const var_t *v);
+extern void write_prefix_name(FILE *h, const char *prefix, const var_t *v);
 extern const char* get_name(const var_t *v);
 extern void write_type(FILE *h, type_t *t, const var_t *v, const char *n);
 extern int is_object(const attr_list_t *list);
diff --git a/tools/widl/server.c b/tools/widl/server.c
index 831d7ac..7d447b5 100644
--- a/tools/widl/server.c
+++ b/tools/widl/server.c
@@ -196,7 +196,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsig
             print_server("_RetVal = ");
         else
             print_server("");
-        write_name(server, def);
+        write_prefix_name(server, server_prefix, def);
 
         if (func->args)
         {
diff --git a/tools/widl/widl.c b/tools/widl/widl.c
index 8cb84dc..8dfeeba 100644
--- a/tools/widl/widl.c
+++ b/tools/widl/widl.c
@@ -64,6 +64,7 @@ static char usage[] =
 "   -P file     Name of proxy file (default is infile_p.c)\n"
 "   -s          Generate server stub\n"
 "   -S file     Name of server stub file (default is infile_s.c)\n"
+"   --server-prefix=val  Add the prefix val to names in the server stub\n"
 "   -t          Generate typelib\n"
 "   -T file     Name of typelib file (default is infile.tlb)\n"
 "   -u          Generate interface identifiers file\n"
@@ -111,6 +112,7 @@ char *server_token;
 char *idfile_name;
 char *idfile_token;
 char *temp_name;
+const char *server_prefix = "";
 
 int line_number = 1;
 
@@ -120,10 +122,16 @@ FILE *idfile;
 
 time_t now;
 
+enum {
+    OLDNAMES_OPTION = 256,
+    SERVER_PREFIX_OPTION,
+};
+
 static const char *short_options =
     "cC:d:D:EhH:I:NpP:sS:tT:uU:VW";
 static struct option long_options[] = {
-    { "oldnames", 0, 0, 1 },
+    { "oldnames", no_argument, 0, OLDNAMES_OPTION },
+    { "server-prefix", required_argument, 0, SERVER_PREFIX_OPTION },
     { 0, 0, 0, 0 }
 };
 
@@ -181,9 +189,12 @@ int main(int argc,char *argv[])
 
   while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF) {
     switch(optc) {
-    case 1:
+    case OLDNAMES_OPTION:
       old_names = 1;
       break;
+    case SERVER_PREFIX_OPTION:
+      server_prefix = optarg;
+      break;
     case 'c':
       do_everything = 0;
       do_client = 1;
diff --git a/tools/widl/widl.h b/tools/widl/widl.h
index 92a9faf..bfd3313 100644
--- a/tools/widl/widl.h
+++ b/tools/widl/widl.h
@@ -54,6 +54,7 @@ extern char *client_name;
 extern char *client_token;
 extern char *server_name;
 extern char *server_token;
+extern const char *server_prefix;
 extern time_t now;
 
 extern int line_number;



More information about the wine-patches mailing list