scanner: add --no-documentation flag

Submitted by Felipe Ferreira da Silva on Dec. 4, 2017, 11:08 p.m.

Details

Message ID 20171204230853.3756-1-ferreiradaselva@protonmail.com
State New
Headers show
Series "scanner: add --no-documentation flag" ( rev: 1 ) in Wayland

Not browsing as part of any series.

Commit Message

Felipe Ferreira da Silva Dec. 4, 2017, 11:08 p.m.
The --no-documentation flag sets a static global variable print_doc to
`false`. When activated, the flag prevents wayland-scanner to print the
documentation comments. The copyright notice is not affected by this
flag.

Signed-off-by: Felipe Ferreira da Silva <ferreiradaselva@protonmail.com>
---
 src/scanner.c | 218 +++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 123 insertions(+), 95 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/scanner.c b/src/scanner.c
index c345ed6..a23e371 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -52,6 +52,8 @@  extern int DTD_DATA_len;
 
 #define PROGRAM_NAME "wayland-scanner"
 
+static bool print_doc = true;
+
 enum side {
 	CLIENT,
 	SERVER,
@@ -72,7 +74,8 @@  usage(int ret)
 			"                                 the scanner was built against.\n"
 			"    -c,  --include-core-only     include the core version of the headers,\n"
 			"                                 that is e.g. wayland-client-core.h instead\n"
-			"                                 of wayland-client.h.\n");
+			"                                 of wayland-client.h.\n"
+			"    --no-documentation           don't include the documentation.\n");
 	exit(ret);
 }
 
@@ -1004,7 +1007,8 @@  emit_opcode_versions(struct wl_list *message_list, struct interface *interface)
 	struct message *m;
 
 	wl_list_for_each(m, message_list, link) {
-		printf("/**\n * @ingroup iface_%s\n */\n", interface->name);
+		if (print_doc)
+			printf("/**\n * @ingroup iface_%s\n */\n", interface->name);
 		printf("#define %s_%s_SINCE_VERSION %d\n",
 		       interface->uppercase_name, m->uppercase_name, m->since);
 	}
@@ -1047,7 +1051,8 @@  emit_stubs(struct wl_list *message_list, struct interface *interface)
 	struct arg *a, *ret;
 	int has_destructor, has_destroy;
 
-	printf("/** @ingroup iface_%s */\n", interface->name);
+	if (print_doc)
+		printf("/** @ingroup iface_%s */\n", interface->name);
 	printf("static inline void\n"
 	       "%s_set_user_data(struct %s *%s, void *user_data)\n"
 	       "{\n"
@@ -1056,7 +1061,8 @@  emit_stubs(struct wl_list *message_list, struct interface *interface)
 	       interface->name, interface->name, interface->name,
 	       interface->name);
 
-	printf("/** @ingroup iface_%s */\n", interface->name);
+	if (print_doc)
+		printf("/** @ingroup iface_%s */\n", interface->name);
 	printf("static inline void *\n"
 	       "%s_get_user_data(struct %s *%s)\n"
 	       "{\n"
@@ -1091,7 +1097,8 @@  emit_stubs(struct wl_list *message_list, struct interface *interface)
 	}
 
 	if (!has_destroy && strcmp(interface->name, "wl_display") != 0) {
-		printf("/** @ingroup iface_%s */\n", interface->name);
+		if (print_doc)
+			printf("/** @ingroup iface_%s */\n", interface->name);
 		printf("static inline void\n"
 		       "%s_destroy(struct %s *%s)\n"
 		       "{\n"
@@ -1120,11 +1127,13 @@  emit_stubs(struct wl_list *message_list, struct interface *interface)
 				ret = a;
 		}
 
-		printf("/**\n"
-		       " * @ingroup iface_%s\n", interface->name);
-		if (m->description && m->description->text)
-			format_text_to_comment(m->description->text, false);
-		printf(" */\n");
+		if (print_doc) {
+			printf("/**\n"
+			       " * @ingroup iface_%s\n", interface->name);
+			if (m->description && m->description->text)
+				format_text_to_comment(m->description->text, false);
+			printf(" */\n");
+		}
 		if (ret && ret->interface_name == NULL)
 			printf("static inline void *\n");
 		else if (ret)
@@ -1220,17 +1229,19 @@  emit_event_wrappers(struct wl_list *message_list, struct interface *interface)
 		return;
 
 	wl_list_for_each(m, message_list, link) {
-		printf("/**\n"
-		       " * @ingroup iface_%s\n"
-		       " * Sends an %s event to the client owning the resource.\n",
-		       interface->name,
-		       m->name);
-		printf(" * @param resource_ The client's resource\n");
-		wl_list_for_each(a, &m->arg_list, link) {
-			if (a->summary)
-				printf(" * @param %s %s\n", a->name, a->summary);
+		if (print_doc) {
+			printf("/**\n"
+			       " * @ingroup iface_%s\n"
+			       " * Sends an %s event to the client owning the resource.\n",
+			       interface->name,
+			       m->name);
+			printf(" * @param resource_ The client's resource\n");
+			wl_list_for_each(a, &m->arg_list, link) {
+				if (a->summary)
+					printf(" * @param %s %s\n", a->name, a->summary);
+			}
+			printf(" */\n");
 		}
-		printf(" */\n");
 		printf("static inline void\n"
 		       "%s_send_%s(struct wl_resource *resource_",
 		       interface->name, m->name);
@@ -1275,7 +1286,7 @@  emit_enumerations(struct interface *interface)
 		printf("#define %s_%s_ENUM\n",
 		       interface->uppercase_name, e->uppercase_name);
 
-		if (desc) {
+		if (desc && print_doc) {
 			printf("/**\n");
 			printf(" * @ingroup iface_%s\n", interface->name);
 			format_text_to_comment(desc->summary, false);
@@ -1285,7 +1296,7 @@  emit_enumerations(struct interface *interface)
 		}
 		printf("enum %s_%s {\n", interface->name, e->name);
 		wl_list_for_each(entry, &e->entry_list, link) {
-			if (entry->summary || entry->since > 1) {
+			if (print_doc && (entry->summary || entry->since > 1)) {
 				printf("\t/**\n");
 				if (entry->summary)
 					printf("\t * %s\n", entry->summary);
@@ -1304,7 +1315,8 @@  emit_enumerations(struct interface *interface)
 			if (entry->since == 1)
                             continue;
 
-                        printf("/**\n * @ingroup iface_%s\n */\n", interface->name);
+			if (print_doc)
+				printf("/**\n * @ingroup iface_%s\n */\n", interface->name);
                         printf("#define %s_%s_%s_SINCE_VERSION %d\n",
                                interface->uppercase_name,
                                e->uppercase_name, entry->uppercase_name,
@@ -1327,38 +1339,42 @@  emit_structs(struct wl_list *message_list, struct interface *interface, enum sid
 	if (wl_list_empty(message_list))
 		return;
 
-	printf("/**\n");
-	printf(" * @ingroup iface_%s\n", interface->name);
-	printf(" * @struct %s_%s\n", interface->name,
-	       (side == SERVER) ? "interface" : "listener");
-	printf(" */\n");
+	if (print_doc) {
+		printf("/**\n");
+		printf(" * @ingroup iface_%s\n", interface->name);
+		printf(" * @struct %s_%s\n", interface->name,
+		       (side == SERVER) ? "interface" : "listener");
+		printf(" */\n");
+	}
 	printf("struct %s_%s {\n", interface->name,
 	       (side == SERVER) ? "interface" : "listener");
 
 	wl_list_for_each(m, message_list, link) {
 		struct description *mdesc = m->description;
 
-		printf("\t/**\n");
-		if (mdesc) {
-			if (mdesc->summary)
-				printf("\t * %s\n", mdesc->summary);
-			printf("\t *\n");
-			desc_dump(mdesc->text, "\t * ");
-		}
-		wl_list_for_each(a, &m->arg_list, link) {
-			if (side == SERVER && a->type == NEW_ID &&
-			    a->interface_name == NULL)
-				printf("\t * @param interface name of the objects interface\n"
-				       "\t * @param version version of the objects interface\n");
-
-			if (a->summary)
-				printf("\t * @param %s %s\n", a->name,
-				       a->summary);
-		}
-		if (m->since > 1) {
-			printf("\t * @since %d\n", m->since);
+		if (print_doc) {
+			printf("\t/**\n");
+			if (mdesc) {
+				if (mdesc->summary)
+					printf("\t * %s\n", mdesc->summary);
+				printf("\t *\n");
+				desc_dump(mdesc->text, "\t * ");
+			}
+			wl_list_for_each(a, &m->arg_list, link) {
+				if (side == SERVER && a->type == NEW_ID &&
+				    a->interface_name == NULL)
+					printf("\t * @param interface name of the objects interface\n"
+					       "\t * @param version version of the objects interface\n");
+
+				if (a->summary)
+					printf("\t * @param %s %s\n", a->name,
+					       a->summary);
+			}
+			if (m->since > 1) {
+				printf("\t * @since %d\n", m->since);
+			}
+			printf("\t */\n");
 		}
-		printf("\t */\n");
 		printf("\tvoid (*%s)(", m->name);
 
 		n = strlen(m->name) + 17;
@@ -1396,9 +1412,11 @@  emit_structs(struct wl_list *message_list, struct interface *interface, enum sid
 	printf("};\n\n");
 
 	if (side == CLIENT) {
-	    printf("/**\n"
-		   " * @ingroup iface_%s\n"
-		   " */\n", interface->name);
+		if (print_doc) {
+			printf("/**\n"
+			       " * @ingroup iface_%s\n"
+			       " */\n", interface->name);
+		}
 	    printf("static inline int\n"
 		   "%s_add_listener(struct %s *%s,\n"
 		   "%sconst struct %s_listener *listener, void *data)\n"
@@ -1471,39 +1489,43 @@  emit_mainpage_blurb(const struct protocol *protocol, enum side side)
 {
 	struct interface *i;
 
-	printf("/**\n"
-	       " * @page page_%s The %s protocol\n",
-	       protocol->name, protocol->name);
+	if (print_doc) {
+		printf("/**\n"
+		       " * @page page_%s The %s protocol\n",
+		       protocol->name, protocol->name);
+
+		if (protocol->description) {
+			if (protocol->description->summary) {
+				printf(" * %s\n"
+				       " *\n", protocol->description->summary);
+			}
 
-	if (protocol->description) {
-		if (protocol->description->summary) {
-			printf(" * %s\n"
-			       " *\n", protocol->description->summary);
+			if (protocol->description->text) {
+				printf(" * @section page_desc_%s Description\n", protocol->name);
+				format_text_to_comment(protocol->description->text, false);
+				printf(" *\n");
+			}
 		}
 
-		if (protocol->description->text) {
-			printf(" * @section page_desc_%s Description\n", protocol->name);
-			format_text_to_comment(protocol->description->text, false);
-			printf(" *\n");
+		printf(" * @section page_ifaces_%s Interfaces\n", protocol->name);
+		wl_list_for_each(i, &protocol->interface_list, link) {
+			printf(" * - @subpage page_iface_%s - %s\n",
+			       i->name,
+			       i->description && i->description->summary ?  i->description->summary : "");
 		}
-	}
 
-	printf(" * @section page_ifaces_%s Interfaces\n", protocol->name);
-	wl_list_for_each(i, &protocol->interface_list, link) {
-		printf(" * - @subpage page_iface_%s - %s\n",
-		       i->name,
-		       i->description && i->description->summary ?  i->description->summary : "");
-	}
+		if (protocol->copyright) {
+			printf(" * @section page_copyright_%s Copyright\n",
+			       protocol->name);
+			printf(" * <pre>\n");
+			format_text_to_comment(protocol->copyright, false);
+			printf(" * </pre>\n");
+		}
 
-	if (protocol->copyright) {
-		printf(" * @section page_copyright_%s Copyright\n",
-		       protocol->name);
-		printf(" * <pre>\n");
-		format_text_to_comment(protocol->copyright, false);
-		printf(" * </pre>\n");
+		printf(" */\n");
+	} else if (protocol->copyright) {
+			format_text_to_comment(protocol->copyright, true);
 	}
-
-	printf(" */\n");
 }
 
 static void
@@ -1557,24 +1579,26 @@  emit_header(struct protocol *protocol, enum side side)
 	printf("\n");
 
 	wl_list_for_each(i, &protocol->interface_list, link) {
-		printf("/**\n"
-		       " * @page page_iface_%s %s\n",
-		       i->name, i->name);
-		if (i->description && i->description->text) {
-			printf(" * @section page_iface_%s_desc Description\n",
-			       i->name);
-			format_text_to_comment(i->description->text, false);
+		if (print_doc) {
+			printf("/**\n"
+			       " * @page page_iface_%s %s\n",
+			       i->name, i->name);
+			if (i->description && i->description->text) {
+				printf(" * @section page_iface_%s_desc Description\n",
+				       i->name);
+				format_text_to_comment(i->description->text, false);
+			}
+			printf(" * @section page_iface_%s_api API\n"
+			       " * See @ref iface_%s.\n"
+			       " */\n",
+			       i->name, i->name);
+			printf("/**\n"
+			       " * @defgroup iface_%s The %s interface\n",
+			       i->name, i->name);
+			if (i->description && i->description->text)
+				format_text_to_comment(i->description->text, false);
+			printf(" */\n");
 		}
-		printf(" * @section page_iface_%s_api API\n"
-		       " * See @ref iface_%s.\n"
-		       " */\n",
-		       i->name, i->name);
-		printf("/**\n"
-		       " * @defgroup iface_%s The %s interface\n",
-		       i->name, i->name);
-		if (i->description && i->description->text)
-			format_text_to_comment(i->description->text, false);
-		printf(" */\n");
 		printf("extern const struct wl_interface "
 		       "%s_interface;\n", i->name);
 	}
@@ -1813,11 +1837,12 @@  int main(int argc, char *argv[])
 		{ "help",              no_argument, NULL, 'h' },
 		{ "version",           no_argument, NULL, 'v' },
 		{ "include-core-only", no_argument, NULL, 'c' },
+		{ "no-documentation",  no_argument, NULL, 'n' },
 		{ 0,                   0,           NULL, 0 }
 	};
 
 	while (1) {
-		opt = getopt_long(argc, argv, "hvc", options, NULL);
+		opt = getopt_long(argc, argv, "hvcn", options, NULL);
 
 		if (opt == -1)
 			break;
@@ -1832,6 +1857,9 @@  int main(int argc, char *argv[])
 		case 'c':
 			core_headers = true;
 			break;
+		case 'n':
+			print_doc = false;
+			break;
 		default:
 			fail = true;
 			break;