]>
git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/testhi.c
2 * Help index test program for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
21 static void list_nodes(const char *title
, cups_array_t
*nodes
);
22 static int usage(void);
26 * 'main()' - Test the help index code.
29 int /* O - Exit status */
30 main(int argc
, /* I - Number of command-line arguments */
31 char *argv
[]) /* I - Command-line arguments */
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 */
44 * Parse the command-line...
47 for (i
= 1; i
< argc
; i
++)
49 if (argv
[i
][0] == '-')
51 if (!strcmp(argv
[i
], "--help"))
57 for (opt
= argv
[i
] + 1; *opt
; opt
++)
61 case 'd' : /* -d directory */
69 fputs("testhi: Missing directory for \"-d\" option.\n", stderr
);
74 case 's' : /* -s section */
82 fputs("testhi: Missing section name for \"-s\" option.\n", stderr
);
88 fprintf(stderr
, "testhi: Unknown option \"-%c\".\n", *opt
);
99 fprintf(stderr
, "testhi: Unknown argument \"%s\".\n", argv
[i
]);
105 * Load the help index...
108 hi
= helpLoadIndex("testhi.index", dir
);
110 list_nodes("nodes", hi
->nodes
);
111 list_nodes("sorted", hi
->sorted
);
119 search
= helpSearchIndex(hi
, q
, section
, filename
);
123 list_nodes(argv
[1], search
->sorted
);
124 helpDeleteIndex(search
);
127 printf("%s (0 nodes)\n", q
);
133 * Return with no errors...
141 * 'list_nodes()' - List nodes in an array...
145 list_nodes(const char *title
, /* I - Title string */
146 cups_array_t
*nodes
) /* I - Nodes */
148 int i
; /* Looping var */
149 help_node_t
*node
; /* Current node */
152 printf("%s (%d nodes):\n", title
, cupsArrayCount(nodes
));
153 for (i
= 1, node
= (help_node_t
*)cupsArrayFirst(nodes
);
155 i
++, node
= (help_node_t
*)cupsArrayNext(nodes
))
158 printf(" %d: %s#%s \"%s\"", i
, node
->filename
, node
->anchor
,
161 printf(" %d: %s \"%s\"", i
, node
->filename
, node
->text
);
163 printf(" (%d words)\n", cupsArrayCount(node
->words
));
169 * 'usage()' - Show program usage.
172 static int /* O - Exit status */
175 puts("Usage: ./testhi [options] [\"query\"] [filename]");
177 puts("-d directory Specify index directory.");
178 puts("-s section Specify search section.");