widl [6/6]: Print pointers using better style

Dan Hipschman dsh at linux.ucla.edu
Mon Aug 28 20:34:01 CDT 2006


One of the earlier patches to write_type in this series changed the way
pointers were output from "foo_t *f" to "foo_t* f".  I personally like
the first style better, and it was the original style after all, so this
changes it back.

This series of patches, especially the third one, was written in order
to make certain problems in generating code for oaidl.idl easier to fix.
I have some works in progress that depend on these patches, and they fix
quite a few subtle bugs.

ChangeLog:
* Print pointers more aesthetically in generated header.
---
 tools/widl/header.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tools/widl/header.c b/tools/widl/header.c
index 5de43c0..168f4c6 100644
--- a/tools/widl/header.c
+++ b/tools/widl/header.c
@@ -199,6 +199,11 @@ static void write_enums(FILE *h, var_t *
   fprintf(h, "\n");
 }
 
+int needs_space_after(type_t *t)
+{
+  return t->kind == TKIND_ALIAS || ! is_ptr(t);
+}
+
 void write_type(FILE *h, type_t *t, const var_t *v, const char *n)
 {
   int c;
@@ -259,7 +264,7 @@ void write_type(FILE *h, type_t *t, cons
       case RPC_FC_FP:
       case RPC_FC_OP:
         if (t->ref) write_type(h, t->ref, NULL, t->name);
-        fprintf(h, "*");
+        fprintf(h, "%s*", needs_space_after(t->ref) ? " " : "");
         break;
       default:
         fprintf(h, "%s", t->name);
@@ -338,7 +343,7 @@ void write_typedef(type_t *type)
 {
   fprintf(header, "typedef ");
   write_type(header, type->orig, NULL, NULL);
-  fprintf(header, " %s;\n", type->name);
+  fprintf(header, "%s%s;\n", needs_space_after(type->orig) ? " " : "", type->name);
 }
 
 void write_expr(FILE *h, const expr_t *e, int brackets)
@@ -585,7 +590,8 @@ void write_args(FILE *h, var_t *arg, con
     }
     else
     {
-      fprintf(h, " ");
+      if (needs_space_after(arg->type))
+        fprintf(h, " ");
       write_name(h, arg);
     }
     write_array(h, arg->array, 0);



More information about the wine-patches mailing list