]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
503b54c9 | 2 | * Help index test program for CUPS. |
ef416fc2 | 3 | * |
cfd375ad | 4 | * Copyright 2007-2017 by Apple Inc. |
503b54c9 | 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 | 21 | static void list_nodes(const char *title, cups_array_t *nodes); |
cfd375ad | 22 | static int usage(void); |
ef416fc2 | 23 | |
24 | ||
25 | /* | |
26 | * 'main()' - Test the help index code. | |
27 | */ | |
28 | ||
29 | int /* O - Exit status */ | |
30 | main(int argc, /* I - Number of command-line arguments */ | |
31 | char *argv[]) /* I - Command-line arguments */ | |
32 | { | |
cfd375ad | 33 | int i; /* Looping var */ |
ef416fc2 | 34 | help_index_t *hi, /* Help index */ |
35 | *search; /* Search index */ | |
cfd375ad MS |
36 | const char *opt, /* Current option character */ |
37 | *dir = ".", /* Directory to index */ | |
38 | *q = NULL, /* Query string */ | |
39 | *section = NULL, /* Section string */ | |
40 | *filename = NULL; /* Filename string */ | |
41 | ||
42 | ||
43 | /* | |
44 | * Parse the command-line... | |
45 | */ | |
ef416fc2 | 46 | |
cfd375ad MS |
47 | for (i = 1; i < argc; i ++) |
48 | { | |
49 | if (argv[i][0] == '-') | |
50 | { | |
51 | if (!strcmp(argv[i], "--help")) | |
52 | { | |
53 | usage(); | |
54 | return (0); | |
55 | } | |
56 | ||
57 | for (opt = argv[i] + 1; *opt; opt ++) | |
58 | { | |
59 | switch (*opt) | |
60 | { | |
61 | case 'd' : /* -d directory */ | |
62 | i ++; | |
63 | if (i < argc) | |
64 | { | |
65 | dir = argv[i]; | |
66 | } | |
67 | else | |
68 | { | |
69 | fputs("testhi: Missing directory for \"-d\" option.\n", stderr); | |
70 | return (usage()); | |
71 | } | |
72 | break; | |
73 | ||
74 | case 's' : /* -s section */ | |
75 | i ++; | |
76 | if (i < argc) | |
77 | { | |
78 | section = argv[i]; | |
79 | } | |
80 | else | |
81 | { | |
82 | fputs("testhi: Missing section name for \"-s\" option.\n", stderr); | |
83 | return (usage()); | |
84 | } | |
85 | break; | |
86 | ||
87 | default : | |
88 | fprintf(stderr, "testhi: Unknown option \"-%c\".\n", *opt); | |
89 | return (usage()); | |
90 | } | |
91 | } | |
92 | } | |
93 | else if (!q) | |
94 | q = argv[i]; | |
95 | else if (!filename) | |
96 | filename = argv[i]; | |
97 | else | |
98 | { | |
99 | fprintf(stderr, "testhi: Unknown argument \"%s\".\n", argv[i]); | |
100 | return (usage()); | |
101 | } | |
102 | } | |
ef416fc2 | 103 | |
104 | /* | |
105 | * Load the help index... | |
106 | */ | |
107 | ||
cfd375ad | 108 | hi = helpLoadIndex("testhi.index", dir); |
ef416fc2 | 109 | |
ecdc0628 | 110 | list_nodes("nodes", hi->nodes); |
111 | list_nodes("sorted", hi->sorted); | |
ef416fc2 | 112 | |
113 | /* | |
114 | * Do any searches... | |
115 | */ | |
116 | ||
cfd375ad | 117 | if (q) |
ef416fc2 | 118 | { |
cfd375ad | 119 | search = helpSearchIndex(hi, q, section, filename); |
ef416fc2 | 120 | |
121 | if (search) | |
122 | { | |
ecdc0628 | 123 | list_nodes(argv[1], search->sorted); |
ef416fc2 | 124 | helpDeleteIndex(search); |
125 | } | |
126 | else | |
cfd375ad | 127 | printf("%s (0 nodes)\n", q); |
ef416fc2 | 128 | } |
129 | ||
130 | helpDeleteIndex(hi); | |
131 | ||
132 | /* | |
133 | * Return with no errors... | |
134 | */ | |
135 | ||
136 | return (0); | |
137 | } | |
138 | ||
139 | ||
140 | /* | |
141 | * 'list_nodes()' - List nodes in an array... | |
142 | */ | |
143 | ||
144 | static void | |
ecdc0628 | 145 | list_nodes(const char *title, /* I - Title string */ |
146 | cups_array_t *nodes) /* I - Nodes */ | |
ef416fc2 | 147 | { |
ecdc0628 | 148 | int i; /* Looping var */ |
149 | help_node_t *node; /* Current node */ | |
ef416fc2 | 150 | |
151 | ||
ecdc0628 | 152 | printf("%s (%d nodes):\n", title, cupsArrayCount(nodes)); |
153 | for (i = 1, node = (help_node_t *)cupsArrayFirst(nodes); | |
154 | node; | |
155 | i ++, node = (help_node_t *)cupsArrayNext(nodes)) | |
f7deaa1a | 156 | { |
ecdc0628 | 157 | if (node->anchor) |
f7deaa1a | 158 | printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor, |
ecdc0628 | 159 | node->text); |
ef416fc2 | 160 | else |
f7deaa1a | 161 | printf(" %d: %s \"%s\"", i, node->filename, node->text); |
162 | ||
163 | printf(" (%d words)\n", cupsArrayCount(node->words)); | |
164 | } | |
ef416fc2 | 165 | } |
cfd375ad MS |
166 | |
167 | ||
168 | /* | |
169 | * 'usage()' - Show program usage. | |
170 | */ | |
171 | ||
172 | static int /* O - Exit status */ | |
173 | usage(void) | |
174 | { | |
175 | puts("Usage: ./testhi [options] [\"query\"] [filename]"); | |
176 | puts("Options:"); | |
177 | puts("-d directory Specify index directory."); | |
178 | puts("-s section Specify search section."); | |
179 | ||
180 | return (1); | |
181 | } |