From 0ede449fe1c1ee02a6a34836c672e19cde94377c Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Tue, 3 Feb 2009 16:09:57 -0500 Subject: generate docbook docs for structs --- docs/eggdbus/Makefile.am | 5 ++ docs/eggdbus/eggdbus-docs.xml | 5 ++ src/eggdbus/docbook.c | 123 +++++++++++++++++++++++++++++++++++++++ src/eggdbus/docbook.h | 4 ++ src/eggdbus/eggdbusbindingtool.c | 21 ++++++- src/tests/Makefile.am | 2 +- 6 files changed, 158 insertions(+), 2 deletions(-) diff --git a/docs/eggdbus/Makefile.am b/docs/eggdbus/Makefile.am index 940f55c..26a9331 100644 --- a/docs/eggdbus/Makefile.am +++ b/docs/eggdbus/Makefile.am @@ -73,6 +73,11 @@ content_files = \ ../../src/tests/docbook-enum-Error.xml \ ../../src/tests/docbook-enum-OtherFlags.xml \ ../../src/tests/docbook-enum-Vehicle.xml \ + ../../src/tests/docbook-struct-Pair.xml \ + ../../src/tests/docbook-struct-Point.xml \ + ../../src/tests/docbook-struct-DescribedPair.xml \ + ../../src/tests/docbook-struct-DescribedPoint.xml \ + ../../src/tests/docbook-struct-StructWithVariant.xml \ ../../src/tests/docbook-interface-com.example.Frob.xml \ ../../src/tests/docbook-interface-com.example.Tweak.xml \ ../../src/tests/docbook-interface-com.example.Twiddle.xml \ diff --git a/docs/eggdbus/eggdbus-docs.xml b/docs/eggdbus/eggdbus-docs.xml index bd4b688..3437a37 100644 --- a/docs/eggdbus/eggdbus-docs.xml +++ b/docs/eggdbus/eggdbus-docs.xml @@ -145,6 +145,11 @@ + + + + + diff --git a/src/eggdbus/docbook.c b/src/eggdbus/docbook.c index 2ae44e9..f20bd4b 100644 --- a/src/eggdbus/docbook.c +++ b/src/eggdbus/docbook.c @@ -1056,3 +1056,126 @@ enum_generate_docbook (EnumData *enum_data, return ret; } +/* ---------------------------------------------------------------------------------------------------- */ + +gboolean +struct_generate_docbook (StructData *struct_data, + GError **error) +{ + gboolean ret; + gchar *struct_summary_doc_string; + gchar *struct_doc_string; + guint n; + gboolean has_none_elem; + guint max_type_len; + + ret = FALSE; + has_none_elem = TRUE; + + struct_summary_doc_string = get_summary_doc_string (struct_data->annotations, "Structure"); + struct_doc_string = get_doc_string (struct_data->annotations, "Structure"); + + g_print ("\n" + "\n"); + + g_print ("\n", struct_data->name); + g_print (" \n"); + g_print (" %s\n", struct_data->name); + g_print (" \n"); + g_print (" \n"); + g_print (" %s\n", struct_data->name); + g_print (" %s\n", struct_summary_doc_string); + g_print (" \n"); + + g_print (" \n"); + + g_print (" \n"); + g_print (" <anchor role=\"struct\" id=\"%s\"/>The %s Structure\n", + struct_data->name, + struct_data->name); + g_print (" \n"); + g_print (" \n"); + max_type_len = 0; + for (n = 0; n < struct_data->num_elements; n++) + { + StructElemData *elem = struct_data->elements[n]; + guint type_len; + gchar *type_name; + + docbook_get_typename_for_signature (elem->signature, &type_name, NULL); + type_len = strlen (type_name); + g_free (type_name); + + if (type_len > max_type_len) + max_type_len = type_len; + } + g_print ("{\n"); + for (n = 0; n < struct_data->num_elements; n++) + { + StructElemData *elem = struct_data->elements[n]; + gchar *type_name; + gchar *type_name_link; + guint type_len; + + if (n > 0) + g_print (",\n"); + + docbook_get_typename_for_signature (elem->signature, &type_name, &type_name_link); + type_len = strlen (type_name); + + g_print (" %s%*s %s", + type_name_link, + max_type_len - type_len, "", + elem->name); + + g_free (type_name); + g_free (type_name_link); + } + g_print ("\n" + "}\n"); + g_print (" \n"); + g_print (" \n"); + g_print ("%s\n", struct_doc_string); + g_print (" \n"); + + g_print (" \n"); + + for (n = 0; n < struct_data->num_elements; n++) + { + StructElemData *elem = struct_data->elements[n]; + gchar *struct_doc_string; + gchar *type_name_link; + + struct_doc_string = get_doc_string (elem->annotations, "Member"); + docbook_get_typename_for_signature (elem->signature, NULL, &type_name_link); + + g_print (" \n"); + g_print (" %s %s\n", type_name_link, elem->name); + g_print (" \n"); + g_print (" \n"); + g_print ("%s\n", struct_doc_string); + g_print (" \n"); + g_print (" \n"); + g_print (" \n"); + + g_free (type_name_link); + g_free (struct_doc_string); + } + g_print (" \n"); + g_print (" \n"); + g_print (" \n"); + + g_print (" \n"); + + + g_print ("\n"); + + ret = TRUE; + + g_free (struct_doc_string); + g_free (struct_summary_doc_string); + + return ret; +} + diff --git a/src/eggdbus/docbook.h b/src/eggdbus/docbook.h index 3e141cb..6e84f85 100644 --- a/src/eggdbus/docbook.h +++ b/src/eggdbus/docbook.h @@ -24,6 +24,7 @@ #include "eggdbusinterface.h" #include "enum.h" +#include "struct.h" G_BEGIN_DECLS @@ -33,6 +34,9 @@ gboolean interface_generate_docbook (const EggDBusInterfaceInfo *interface, gboolean enum_generate_docbook (EnumData *enum_data, GError **error); +gboolean struct_generate_docbook (StructData *struct_data, + GError **error); + G_END_DECLS #endif /* __DOCBOOK_H */ diff --git a/src/eggdbus/eggdbusbindingtool.c b/src/eggdbus/eggdbusbindingtool.c index b29f924..6b60691 100644 --- a/src/eggdbus/eggdbusbindingtool.c +++ b/src/eggdbus/eggdbusbindingtool.c @@ -1273,12 +1273,31 @@ generate_struct_interfaces (GSList *nodes, StructData *struct_data = l->data; gchar *h_file_name; gchar *c_file_name; + gchar *docbook_file_name; - /* now generate C and H files for struct_interface unless they are user supplied */ + /* now generate Docbook, H and C files for struct_interface unless they are user supplied */ if (struct_data->user_supplied) continue; + /* generate docbook file */ + docbook_file_name = g_strdup_printf ("docbook-struct-%s.xml", struct_data->name); + file_print_func_begin (docbook_file_name); + if (!struct_generate_docbook (struct_data, error)) + { + g_free (docbook_file_name); + file_print_func_end (FALSE, NULL); + goto out; + } + if (!file_print_func_end (TRUE, error)) + { + g_free (docbook_file_name); + goto out; + } + g_printerr ("Wrote %s\n", docbook_file_name); + generated_files = g_slist_prepend (generated_files, g_strdup (docbook_file_name)); + g_free (docbook_file_name); + /* generate header file */ h_file_name = compute_file_name (name_space, struct_data->name, ".h"); file_print_func_begin (h_file_name); diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index bea8866..7bc1b24 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -37,7 +37,7 @@ test-built-sources.stamp : Makefile.am $(top_builddir)/src/eggdbus/eggdbus-bindi # keep in sync with contents of test-built-sources.stamp (Thanks autotools) # -test_built_sources = testbindingsmarshal.c testbindingsmarshal.h testbindingsmarshal.list testbindings.c testbindings.h testbindingstypes.h testtwiddle.c testtwiddle.h docbook-interface-com.example.Twiddle.xml testtweak.c testtweak.h docbook-interface-com.example.Tweak.xml testfrob.c testfrob.h docbook-interface-com.example.Frob.xml testvehicle.c testvehicle.h docbook-enum-Vehicle.xml testotherflags.c testotherflags.h docbook-enum-OtherFlags.xml testdeleteflags.c testdeleteflags.h docbook-enum-DeleteFlags.xml testcreateflags.c testcreateflags.h docbook-enum-CreateFlags.xml testdetailederror.c testdetailederror.h docbook-enum-DetailedError.xml testerror.c testerror.h docbook-enum-Error.xml teststructwithvariant.c teststructwithvariant.h testextendeddescribedpoint.c testextendeddescribedpoint.h testdescribedpair.c testdescribedpair.h testdescribedpoint.c testdescribedpoint.h testpair.c testpair.h testpoint.c testpoint.h +test_built_sources = testbindingsmarshal.c testbindingsmarshal.h testbindingsmarshal.list testbindings.c testbindings.h testbindingstypes.h testtwiddle.c testtwiddle.h docbook-interface-com.example.Twiddle.xml testtweak.c testtweak.h docbook-interface-com.example.Tweak.xml testfrob.c testfrob.h docbook-interface-com.example.Frob.xml testvehicle.c testvehicle.h docbook-enum-Vehicle.xml testotherflags.c testotherflags.h docbook-enum-OtherFlags.xml testdeleteflags.c testdeleteflags.h docbook-enum-DeleteFlags.xml testcreateflags.c testcreateflags.h docbook-enum-CreateFlags.xml testdetailederror.c testdetailederror.h docbook-enum-DetailedError.xml testerror.c testerror.h docbook-enum-Error.xml teststructwithvariant.c teststructwithvariant.h docbook-struct-StructWithVariant.xml testextendeddescribedpoint.c testextendeddescribedpoint.h docbook-struct-ExtendedDescribedPoint.xml testdescribedpair.c testdescribedpair.h docbook-struct-DescribedPair.xml testdescribedpoint.c testdescribedpoint.h docbook-struct-DescribedPoint.xml testpair.c testpair.h docbook-struct-Pair.xml testpoint.c testpoint.h docbook-struct-Point.xml libeggdbustests_la_SOURCES = \ test-built-sources.stamp \ -- cgit v1.2.3