[4/5] widl: Factor the output functions

Dan Hipschman dsh at linux.ucla.edu
Thu Jun 14 20:29:33 CDT 2007


Each of the client, server, and proxy output files has their own print
function, that are all exactly the same except they use different file-
scope variables.  This at least factors the code to some degree so only
one function contains the logic, and the different variables can be
passed as parameters.

---
 tools/widl/client.c  |   10 ++--------
 tools/widl/proxy.c   |   10 ++--------
 tools/widl/server.c  |   10 ++--------
 tools/widl/typegen.c |   22 +++++++++++++---------
 tools/widl/typegen.h |    2 ++
 5 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/tools/widl/client.c b/tools/widl/client.c
index 6172cfe..86ead20 100644
--- a/tools/widl/client.c
+++ b/tools/widl/client.c
@@ -44,18 +44,12 @@
 static FILE* client;
 static int indent = 0;
 
-static int print_client( const char *format, ... )
+static void print_client( const char *format, ... )
 {
     va_list va;
-    int i, r;
-
     va_start(va, format);
-    if (format[0] != '\n')
-        for (i = 0; i < indent; i++)
-            fprintf(client, "    ");
-    r = vfprintf(client, format, va);
+    print(client, indent, format, va);
     va_end(va);
-    return r;
 }
 
 
diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c
index 72f1f9d..93eddf5 100644
--- a/tools/widl/proxy.c
+++ b/tools/widl/proxy.c
@@ -51,18 +51,12 @@ static int indent = 0;
 
 /* FIXME: support generation of stubless proxies */
 
-static int print_proxy( const char *format, ... )
+static void print_proxy( const char *format, ... )
 {
   va_list va;
-  int i, r;
-
   va_start( va, format );
-  if ( format[0] != '\n' )
-    for( i=0; i<indent; i++ )
-      fprintf( proxy, "    " );
-  r = vfprintf( proxy, format, va );
+  print( proxy, indent, format, va );
   va_end( va );
-  return r;
 }
 
 static void write_stubdescproto(void)
diff --git a/tools/widl/server.c b/tools/widl/server.c
index f85a5bb..e3740ce 100644
--- a/tools/widl/server.c
+++ b/tools/widl/server.c
@@ -46,18 +46,12 @@ static FILE* server;
 static int indent = 0;
 
 
-static int print_server(const char *format, ...)
+static void print_server(const char *format, ...)
 {
     va_list va;
-    int i, r;
-
     va_start(va, format);
-    if (format[0] != '\n')
-        for (i = 0; i < indent; i++)
-            fprintf(server, "    ");
-    r = vfprintf(server, format, va);
+    print(server, indent, format, va);
     va_end(va);
-    return r;
 }
 
 
diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c
index 67872f0..6da96f5 100644
--- a/tools/widl/typegen.c
+++ b/tools/widl/typegen.c
@@ -254,19 +254,23 @@ static int compare_expr(const expr_t *a, const expr_t *b)
     } \
     while (0)
 
-static int print_file(FILE *file, int indent, const char *format, ...)
+static void print_file(FILE *file, int indent, const char *format, ...)
 {
     va_list va;
-    int i, r;
-
-    if (!file) return 0;
-
     va_start(va, format);
-    for (i = 0; i < indent; i++)
-        fprintf(file, "    ");
-    r = vfprintf(file, format, va);
+    print(file, indent, format, va);
     va_end(va);
-    return r;
+}
+
+void print(FILE *file, int indent, const char *format, va_list va)
+{
+    if (file)
+    {
+        if (format[0] != '\n')
+            while (0 < indent--)
+                fprintf(file, "    ");
+        vfprintf(file, format, va);
+    }
 }
 
 static void write_formatdesc(FILE *f, int indent, const char *str)
diff --git a/tools/widl/typegen.h b/tools/widl/typegen.h
index be97d01..77b207e 100644
--- a/tools/widl/typegen.h
+++ b/tools/widl/typegen.h
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <stdarg.h>
 
 enum pass
 {
@@ -53,3 +54,4 @@ void write_endpoints( FILE *f, const char *prefix, const str_list_t *list );
 size_t type_memsize(const type_t *t, unsigned int *align);
 int decl_indirect(const type_t *t);
 void write_parameters_init(const func_t *func);
+void print(FILE *file, int indent, const char *format, va_list ap);



More information about the wine-patches mailing list