]> git.ipfire.org Git - thirdparty/cups.git/blame - cgi-bin/testhi.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cgi-bin / testhi.c
CommitLineData
ef416fc2 1/*
503b54c9 2 * Help index test program for CUPS.
ef416fc2 3 *
503b54c9
MS
4 * Copyright 2007-2011 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
ef416fc2 6 *
e3101897 7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
ef416fc2 8 */
9
10/*
11 * Include necessary headers...
12 */
13
14#include "cgi.h"
15
16
17/*
18 * Local functions...
19 */
20
ecdc0628 21static void list_nodes(const char *title, cups_array_t *nodes);
ef416fc2 22
23
24/*
25 * 'main()' - Test the help index code.
26 */
27
28int /* O - Exit status */
29main(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
ecdc0628 42 list_nodes("nodes", hi->nodes);
43 list_nodes("sorted", hi->sorted);
ef416fc2 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 {
ecdc0628 55 list_nodes(argv[1], search->sorted);
ef416fc2 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
76static void
ecdc0628 77list_nodes(const char *title, /* I - Title string */
78 cups_array_t *nodes) /* I - Nodes */
ef416fc2 79{
ecdc0628 80 int i; /* Looping var */
81 help_node_t *node; /* Current node */
ef416fc2 82
83
ecdc0628 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))
f7deaa1a 88 {
ecdc0628 89 if (node->anchor)
f7deaa1a 90 printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor,
ecdc0628 91 node->text);
ef416fc2 92 else
f7deaa1a 93 printf(" %d: %s \"%s\"", i, node->filename, node->text);
94
95 printf(" (%d words)\n", cupsArrayCount(node->words));
96 }
ef416fc2 97}