From e714c89d2fe27137ec014a66e0d0c9e0013c4709 Mon Sep 17 00:00:00 2001 From: Dan Hipschman Date: Wed, 25 Apr 2007 18:17:31 -0700 Subject: [PATCH] widl: Add --prefix-* options (take 3). --- tools/widl/client.c | 6 ++--- tools/widl/header.c | 53 +++++++++++++++++++++++++++++++-------------- tools/widl/header.h | 1 + tools/widl/server.c | 6 ++--- tools/widl/widl.c | 30 +++++++++++++++++++++++-- tools/widl/widl.h | 2 ++ 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/tools/widl/client.c b/tools/widl/client.c index 3322a07e21d..ba4962495de 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -115,7 +115,7 @@ static void write_function_stubs(type_t *iface, unsigned int *proc_offset, unsig write_type(client, def->type, def, def->tname); fprintf(client, " "); - write_name(client, def); + write_prefix_name(client, prefix_client, def); fprintf(client, "(\n"); indent++; if (func->args) @@ -363,8 +363,8 @@ static void write_clientinterfacedecl(type_t *iface) print_client("RPC_IF_HANDLE %s_ClientIfHandle = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n", iface->name, iface->name); else - print_client("RPC_IF_HANDLE %s_v%d_%d_c_ifspec = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n", - iface->name, LOWORD(ver), HIWORD(ver), iface->name); + print_client("RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec = (RPC_IF_HANDLE)& %s___RpcClientInterface;\n", + prefix_client, iface->name, LOWORD(ver), HIWORD(ver), iface->name); fprintf(client, "\n"); } diff --git a/tools/widl/header.c b/tools/widl/header.c index 372b0b14db5..b7fd9835482 100644 --- a/tools/widl/header.c +++ b/tools/widl/header.c @@ -125,6 +125,12 @@ void write_name(FILE *h, const var_t *v) fprintf(h, "%s", v->name); } +void write_prefix_name(FILE *h, const char *prefix, const var_t *v) +{ + fprintf(h, "%s", prefix); + write_name(h, v); +} + const char* get_name(const var_t *v) { return v->name; @@ -709,12 +715,29 @@ 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); const var_t* explicit_handle_var; const func_t *cur; + int prefixes_differ = strcmp(prefix_client, prefix_server); if (!iface->funcs) return; LIST_FOR_EACH_ENTRY( cur, iface->funcs, const func_t, entry ) @@ -735,16 +758,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 (prefixes_differ) { + fprintf(header, "/* client prototype */\n"); + write_function_proto(iface, cur, prefix_client); + fprintf(header, "/* server prototype */\n"); + } + write_function_proto(iface, cur, prefix_server); } } @@ -868,15 +887,17 @@ static void write_rpc_interface(const type_t *iface) if (var) fprintf(header, "extern handle_t %s;\n", var); if (old_names) { - fprintf(header, "extern RPC_IF_HANDLE %s_ClientIfHandle;\n", iface->name); - fprintf(header, "extern RPC_IF_HANDLE %s_ServerIfHandle;\n", iface->name); + fprintf(header, "extern RPC_IF_HANDLE %s%s_ClientIfHandle;\n", prefix_client, iface->name); + fprintf(header, "extern RPC_IF_HANDLE %s%s_ServerIfHandle;\n", prefix_server, iface->name); } else { - 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)); + fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_c_ifspec;\n", + prefix_client, iface->name, LOWORD(ver), HIWORD(ver)); + fprintf(header, "extern RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec;\n", + prefix_server, 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 1383fdae3d8..ebf79175d01 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 831d7acf52d..6f95b09d072 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, prefix_server, def); if (func->args) { @@ -393,8 +393,8 @@ static void write_serverinterfacedecl(type_t *iface) print_server("RPC_IF_HANDLE %s_ServerIfHandle = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n", iface->name, iface->name); else - print_server("RPC_IF_HANDLE %s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n", - iface->name, LOWORD(ver), HIWORD(ver), iface->name); + print_server("RPC_IF_HANDLE %s%s_v%d_%d_s_ifspec = (RPC_IF_HANDLE)& %s___RpcServerInterface;\n", + prefix_server, iface->name, LOWORD(ver), HIWORD(ver), iface->name); fprintf(server, "\n"); } diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 8cb84dc76e8..ed09b32089a 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -22,6 +22,7 @@ #include "config.h" #include "wine/port.h" +#include #include #include #ifdef HAVE_UNISTD_H @@ -62,6 +63,9 @@ static char usage[] = " --oldnames Use old naming conventions\n" " -p Generate proxy\n" " -P file Name of proxy file (default is infile_p.c)\n" +" --prefix-all=p Prefix names of client stubs / server functions with 'p'\n" +" --prefix-client=p Prefix names of client stubs with 'p'\n" +" --prefix-server=p Prefix names of server functions with 'p'\n" " -s Generate server stub\n" " -S file Name of server stub file (default is infile_s.c)\n" " -t Generate typelib\n" @@ -111,6 +115,8 @@ char *server_token; char *idfile_name; char *idfile_token; char *temp_name; +const char *prefix_client = ""; +const char *prefix_server = ""; int line_number = 1; @@ -120,10 +126,20 @@ FILE *idfile; time_t now; +enum { + OLDNAMES_OPTION = CHAR_MAX + 1, + PREFIX_ALL_OPTION, + PREFIX_CLIENT_OPTION, + PREFIX_SERVER_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 }, + { "prefix-all", required_argument, 0, PREFIX_ALL_OPTION }, + { "prefix-client", required_argument, 0, PREFIX_CLIENT_OPTION }, + { "prefix-server", required_argument, 0, PREFIX_SERVER_OPTION }, { 0, 0, 0, 0 } }; @@ -181,9 +197,19 @@ 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 PREFIX_ALL_OPTION: + prefix_client = xstrdup(optarg); + prefix_server = xstrdup(optarg); + break; + case PREFIX_CLIENT_OPTION: + prefix_client = xstrdup(optarg); + break; + case PREFIX_SERVER_OPTION: + prefix_server = xstrdup(optarg); + break; case 'c': do_everything = 0; do_client = 1; diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 92a9faff2a3..a2b905c2225 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -54,6 +54,8 @@ extern char *client_name; extern char *client_token; extern char *server_name; extern char *server_token; +extern const char *prefix_client; +extern const char *prefix_server; extern time_t now; extern int line_number;