]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/testhi.c
1fbe9063b779eece8b1ed3dc3e76578c31787a8e
[thirdparty/cups.git] / cgi-bin / testhi.c
1 /*
2 * Help index test program for CUPS.
3 *
4 * Copyright 2007-2011 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
6 *
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
12 */
13
14 /*
15 * Include necessary headers...
16 */
17
18 #include "cgi.h"
19
20
21 /*
22 * Local functions...
23 */
24
25 static void list_nodes(const char *title, cups_array_t *nodes);
26
27
28 /*
29 * 'main()' - Test the help index code.
30 */
31
32 int /* O - Exit status */
33 main(int argc, /* I - Number of command-line arguments */
34 char *argv[]) /* I - Command-line arguments */
35 {
36 help_index_t *hi, /* Help index */
37 *search; /* Search index */
38
39
40 /*
41 * Load the help index...
42 */
43
44 hi = helpLoadIndex("testhi.index", ".");
45
46 list_nodes("nodes", hi->nodes);
47 list_nodes("sorted", hi->sorted);
48
49 /*
50 * Do any searches...
51 */
52
53 if (argc > 1)
54 {
55 search = helpSearchIndex(hi, argv[1], NULL, argv[2]);
56
57 if (search)
58 {
59 list_nodes(argv[1], search->sorted);
60 helpDeleteIndex(search);
61 }
62 else
63 printf("%s (0 nodes)\n", argv[1]);
64 }
65
66 helpDeleteIndex(hi);
67
68 /*
69 * Return with no errors...
70 */
71
72 return (0);
73 }
74
75
76 /*
77 * 'list_nodes()' - List nodes in an array...
78 */
79
80 static void
81 list_nodes(const char *title, /* I - Title string */
82 cups_array_t *nodes) /* I - Nodes */
83 {
84 int i; /* Looping var */
85 help_node_t *node; /* Current node */
86
87
88 printf("%s (%d nodes):\n", title, cupsArrayCount(nodes));
89 for (i = 1, node = (help_node_t *)cupsArrayFirst(nodes);
90 node;
91 i ++, node = (help_node_t *)cupsArrayNext(nodes))
92 {
93 if (node->anchor)
94 printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor,
95 node->text);
96 else
97 printf(" %d: %s \"%s\"", i, node->filename, node->text);
98
99 printf(" (%d words)\n", cupsArrayCount(node->words));
100 }
101 }