]>
Commit | Line | Data |
---|---|---|
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 | * |
503b54c9 MS |
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/". | |
ef416fc2 | 12 | */ |
13 | ||
14 | /* | |
15 | * Include necessary headers... | |
16 | */ | |
17 | ||
18 | #include "cgi.h" | |
19 | ||
20 | ||
21 | /* | |
22 | * Local functions... | |
23 | */ | |
24 | ||
ecdc0628 | 25 | static void list_nodes(const char *title, cups_array_t *nodes); |
ef416fc2 | 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 | ||
ecdc0628 | 46 | list_nodes("nodes", hi->nodes); |
47 | list_nodes("sorted", hi->sorted); | |
ef416fc2 | 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 | { | |
ecdc0628 | 59 | list_nodes(argv[1], search->sorted); |
ef416fc2 | 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 | |
ecdc0628 | 81 | list_nodes(const char *title, /* I - Title string */ |
82 | cups_array_t *nodes) /* I - Nodes */ | |
ef416fc2 | 83 | { |
ecdc0628 | 84 | int i; /* Looping var */ |
85 | help_node_t *node; /* Current node */ | |
ef416fc2 | 86 | |
87 | ||
ecdc0628 | 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)) | |
f7deaa1a | 92 | { |
ecdc0628 | 93 | if (node->anchor) |
f7deaa1a | 94 | printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor, |
ecdc0628 | 95 | node->text); |
ef416fc2 | 96 | else |
f7deaa1a | 97 | printf(" %d: %s \"%s\"", i, node->filename, node->text); |
98 | ||
99 | printf(" (%d words)\n", cupsArrayCount(node->words)); | |
100 | } | |
ef416fc2 | 101 | } |