]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/testhi.c
License change: Apache License, Version 2.0.
[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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
8 */
9
10 /*
11 * Include necessary headers...
12 */
13
14 #include "cgi.h"
15
16
17 /*
18 * Local functions...
19 */
20
21 static void list_nodes(const char *title, cups_array_t *nodes);
22
23
24 /*
25 * 'main()' - Test the help index code.
26 */
27
28 int /* O - Exit status */
29 main(int argc, /* I - Number of command-line arguments */
30 char *argv[]) /* I - Command-line arguments */
31 {
32 help_index_t *hi, /* Help index */
33 *search; /* Search index */
34
35
36 /*
37 * Load the help index...
38 */
39
40 hi = helpLoadIndex("testhi.index", ".");
41
42 list_nodes("nodes", hi->nodes);
43 list_nodes("sorted", hi->sorted);
44
45 /*
46 * Do any searches...
47 */
48
49 if (argc > 1)
50 {
51 search = helpSearchIndex(hi, argv[1], NULL, argv[2]);
52
53 if (search)
54 {
55 list_nodes(argv[1], search->sorted);
56 helpDeleteIndex(search);
57 }
58 else
59 printf("%s (0 nodes)\n", argv[1]);
60 }
61
62 helpDeleteIndex(hi);
63
64 /*
65 * Return with no errors...
66 */
67
68 return (0);
69 }
70
71
72 /*
73 * 'list_nodes()' - List nodes in an array...
74 */
75
76 static void
77 list_nodes(const char *title, /* I - Title string */
78 cups_array_t *nodes) /* I - Nodes */
79 {
80 int i; /* Looping var */
81 help_node_t *node; /* Current node */
82
83
84 printf("%s (%d nodes):\n", title, cupsArrayCount(nodes));
85 for (i = 1, node = (help_node_t *)cupsArrayFirst(nodes);
86 node;
87 i ++, node = (help_node_t *)cupsArrayNext(nodes))
88 {
89 if (node->anchor)
90 printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor,
91 node->text);
92 else
93 printf(" %d: %s \"%s\"", i, node->filename, node->text);
94
95 printf(" (%d words)\n", cupsArrayCount(node->words));
96 }
97 }