summaryrefslogtreecommitdiff
path: root/src/scanner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scanner.c')
-rw-r--r--src/scanner.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/scanner.c b/src/scanner.c
index 51c01af..5a7e466 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -32,7 +32,7 @@
static int
usage(char *name, int ret)
{
- fprintf(stderr, "usage: %s [client-header|server-header|code]"
+ fprintf(stderr, "usage: %s [client-header|server-header|code|tex]"
" < xmlfile\n", name);
exit(ret);
}
@@ -975,6 +975,52 @@ emit_code(struct protocol *protocol)
}
}
+static char *
+get_latex(char *name)
+{
+ int i, j, lenght, new_lenght;
+ char *word = name;
+
+ lenght = strlen(word);
+ new_lenght = lenght;
+ for (i = 0; i < lenght; i++)
+ if (word[i] == '_')
+ new_lenght++;
+
+ if (lenght == new_lenght)
+ return word;
+
+ word = realloc(word, new_lenght + 1);
+
+ /* e.g. "wl_display" becomes "wl\_display" */
+ for (i = 0; i < new_lenght; i++) {
+ if (word[i] == '_') {
+ for (j = lenght - 1; j >= i; j--)
+ word[j + 1] = word[j];
+ word[i] = '\\';
+ i++;
+ lenght++;
+ }
+ }
+ word[new_lenght] = '\0';
+
+ return word;
+}
+
+static void
+emit_tex(struct protocol *protocol)
+{
+ struct interface *i;
+
+ printf("\\begin{itemize}\n");
+ wl_list_for_each(i, &protocol->interface_list, link) {
+ printf("\\item %s: %s.\n",
+ i->name ? get_latex(i->name) : 0,
+ i->description ? get_latex(i->description->summary) : NULL);
+ }
+ printf("\\end{itemize}\n");
+}
+
int main(int argc, char *argv[])
{
struct parse_context ctx;
@@ -1021,6 +1067,8 @@ int main(int argc, char *argv[])
emit_header(&protocol, 1);
} else if (strcmp(argv[1], "code") == 0) {
emit_code(&protocol);
+ } else if (strcmp(argv[1], "tex") == 0) {
+ emit_tex(&protocol);
}
return 0;