[cogl/wip/sparse: 4/5] sparse: Adds tool to dump gtk-doc comments



commit c5b8027bf7444f2f56634259c78bd339076b3de5
Author: Robert Bragg <robert linux intel com>
Date:   Mon Apr 9 19:58:47 2012 +0100

    sparse: Adds tool to dump gtk-doc comments
    
    This adds a minimal tool that performs preprocessing on input files and
    then dump all comments that start with "/**\n" with NULL separators to
    stdout for easy processing by some other tool.

 deps/sparse/dump-gtk-doc.c |   45 ++++++++++++++++++++++++++++++++++++++++++++
 deps/sparse/lib.c          |   17 +++++++++++++++-
 deps/sparse/lib.h          |    1 +
 3 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/deps/sparse/dump-gtk-doc.c b/deps/sparse/dump-gtk-doc.c
new file mode 100644
index 0000000..99e38ac
--- /dev/null
+++ b/deps/sparse/dump-gtk-doc.c
@@ -0,0 +1,45 @@
+/*
+ * Example test program that just uses the tokenization and
+ * preprocessing phases, and prints out the results.
+ *
+ * Copyright (C) 2003 Transmeta Corp.
+ *               2003 Linus Torvalds
+ *
+ *  Licensed under the Open Software License version 1.1
+ */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "lib.h"
+#include "token.h"
+#include "allocate.h"
+
+int main(int argc, char **argv)
+{
+	struct string_list *filelist = NULL;
+	char *file;
+
+	keep_comment_tokens = 1;
+	sparse_initialize(argc, argv, &filelist);
+	FOR_EACH_PTR_NOTAG(filelist, file) {
+		struct token *token = tokenize_keep_tokens(file);
+		for (token = preprocess(token);
+		     !eof_token(token);
+		     token = token->next)
+		{
+			if (token_type(token) == TOKEN_COMMENT) {
+				const char *comment = token->comment->data;
+				if (strncmp (comment, "/**\n", 4) == 0)
+					printf("%s\n%c", token->comment->data, '\0');
+
+			}
+		}
+		clear_token_alloc();
+	} END_FOR_EACH_PTR_NOTAG(file);
+	return 0;
+}
diff --git a/deps/sparse/lib.c b/deps/sparse/lib.c
index fdf1a3c..5acdeab 100644
--- a/deps/sparse/lib.c
+++ b/deps/sparse/lib.c
@@ -862,7 +862,7 @@ static struct symbol_list *sparse_tokenstream(struct token *token)
 	return translation_unit_used_list;
 }
 
-static struct symbol_list *sparse_file(const char *filename)
+static struct token *tokenize_file(const char *filename)
 {
 	int fd;
 	struct token *token;
@@ -879,6 +879,13 @@ static struct symbol_list *sparse_file(const char *filename)
 	token = tokenize(filename, fd, NULL, includepath);
 	close(fd);
 
+	return token;
+}
+
+static struct symbol_list *sparse_file(const char *filename)
+{
+	struct token *token;
+	token = tokenize_file(filename);
 	return sparse_tokenstream(token);
 }
 
@@ -967,6 +974,14 @@ struct symbol_list * sparse_keep_tokens(char *filename)
 	return res;
 }
 
+struct token * tokenize_keep_tokens(char *filename)
+{
+	/* Clear previous symbol list */
+	translation_unit_used_list = NULL;
+
+	new_file_scope();
+	return tokenize_file(filename);
+}
 
 struct symbol_list * __sparse(char *filename)
 {
diff --git a/deps/sparse/lib.h b/deps/sparse/lib.h
index 1e48574..fb5863a 100644
--- a/deps/sparse/lib.h
+++ b/deps/sparse/lib.h
@@ -127,6 +127,7 @@ extern struct symbol_list *sparse_initialize(int argc, char **argv, struct strin
 extern struct symbol_list *__sparse(char *filename);
 extern struct symbol_list *sparse_keep_tokens(char *filename);
 extern struct symbol_list *sparse(char *filename);
+struct token * tokenize_keep_tokens(char *filename);
 
 static inline int symbol_list_size(struct symbol_list *list)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]