1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * Copyright (C) 2006 Shaun McCance
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
19 * Author: Shaun McCance <shaunm@gnome.org>
24 #include <libxml/parser.h>
25 #include <libxml/xinclude.h>
27 #include "yelp-error.h"
28 #include "yelp-docbook.h"
32 static gchar
*mode
= NULL
;
33 static gchar
**files
= NULL
;
34 static const GOptionEntry options
[] = {
36 0, G_OPTION_ARG_STRING
,
38 "One of man, docbook or toc", "MODE" },
40 0, 0, G_OPTION_ARG_FILENAME_ARRAY
,
45 static void document_func (YelpDocument
*document
,
46 YelpDocumentSignal signal
,
54 document_func (YelpDocument
*document
,
55 YelpDocumentSignal signal
,
66 case YELP_DOCUMENT_SIGNAL_PAGE
:
67 page
= (YelpPage
*) func_data
;
68 printf ("PAGE: %s (%i)\n", page
->id
, req_id
);
69 printf (" PREV: %s\n", page
->prev_id
);
70 printf (" NEXT: %s\n", page
->next_id
);
71 printf (" UP: %s\n", page
->up_id
);
72 printf (" ROOT: %s\n", page
->root_id
);
73 printf (" SECTIONS: %s\n", yelp_document_get_sections (document
) ? "yep": "nah");
74 yelp_page_read (page
, contents
, 60, &read
, NULL
);
75 /* contents isn't \0-terminated */
76 contents_
= g_strndup (contents
, read
);
77 printf (" DATA: %s\n", contents_
);
79 yelp_page_free (page
);
81 case YELP_DOCUMENT_SIGNAL_TITLE
:
82 printf ("TITLE: %s (%i)\n", (gchar
*) func_data
, req_id
);
85 case YELP_DOCUMENT_SIGNAL_ERROR
:
86 error
= (YelpError
*) func_data
;
87 printf ("ERROR: %s\n", yelp_error_get_title (error
));
88 printf (" %s\n", yelp_error_get_message (error
));
89 yelp_error_free (error
);
95 main (gint argc
, gchar
**argv
)
97 GOptionContext
*context
;
98 YelpDocument
*document
;
101 g_thread_init (NULL
);
103 gdk_threads_leave ();
105 gtk_init (&argc
, &argv
);
107 context
= g_option_context_new ("FILE PAGE_IDS...");
108 g_option_context_add_main_entries (context
, options
, NULL
);
109 g_option_context_parse (context
, &argc
, &argv
, NULL
);
112 mode
= g_strdup ("docbook");
114 if ((files
== NULL
|| files
[0] == NULL
) && !g_str_equal (mode
, "toc")) {
115 g_printerr ("Usage: test-docbook FILE PAGE_IDS...\n");
119 if (g_str_equal (mode
, "man"))
120 document
= yelp_man_new (files
[0]);
121 else if (g_str_equal (mode
, "toc"))
122 document
= yelp_toc_new ();
123 else if (g_str_equal (mode
, "docbook"))
124 document
= yelp_docbook_new (files
[0]);
126 g_error ("Unknown test. Please try again later\n");
130 if ((files
== NULL
|| files
[1] == NULL
) && (!g_str_equal (mode
, "toc")))
131 yelp_document_get_page (document
, "x-yelp-index", (YelpDocumentFunc
) document_func
, NULL
);
132 else if (!g_str_equal (mode
, "toc")) {
133 for (i
= 1; files
[i
]; i
++)
134 yelp_document_get_page (document
, files
[i
], (YelpDocumentFunc
) document_func
, NULL
);
137 for (i
= 0; files
[i
]; i
++)
138 yelp_document_get_page (document
, files
[i
], (YelpDocumentFunc
) document_func
, NULL
);
140 yelp_document_get_page (document
, "index", (YelpDocumentFunc
) document_func
, NULL
);
143 loop
= g_main_loop_new (NULL
, FALSE
);
144 g_main_loop_run (loop
);
146 gdk_threads_leave ();