]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/testhi.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / cgi-bin / testhi.c
1 /*
2 * Help index test program for CUPS.
3 *
4 * Copyright 2007-2017 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 static int usage(void);
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 {
33 int i; /* Looping var */
34 help_index_t *hi, /* Help index */
35 *search; /* Search index */
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 */
46
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 }
103
104 /*
105 * Load the help index...
106 */
107
108 hi = helpLoadIndex("testhi.index", dir);
109
110 list_nodes("nodes", hi->nodes);
111 list_nodes("sorted", hi->sorted);
112
113 /*
114 * Do any searches...
115 */
116
117 if (q)
118 {
119 search = helpSearchIndex(hi, q, section, filename);
120
121 if (search)
122 {
123 list_nodes(argv[1], search->sorted);
124 helpDeleteIndex(search);
125 }
126 else
127 printf("%s (0 nodes)\n", q);
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
145 list_nodes(const char *title, /* I - Title string */
146 cups_array_t *nodes) /* I - Nodes */
147 {
148 int i; /* Looping var */
149 help_node_t *node; /* Current node */
150
151
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))
156 {
157 if (node->anchor)
158 printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor,
159 node->text);
160 else
161 printf(" %d: %s \"%s\"", i, node->filename, node->text);
162
163 printf(" (%d words)\n", cupsArrayCount(node->words));
164 }
165 }
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 }