1/*
2 * "$Id: testhi.c 11093 2013-07-03 20:48:42Z msweet $"
3 *
4 *   Help index test program for CUPS.
5 *
6 *   Copyright 2007-2011 by Apple Inc.
7 *   Copyright 1997-2007 by Easy Software Products.
8 *
9 *   These coded instructions, statements, and computer programs are the
10 *   property of Apple Inc. and are protected by Federal copyright
11 *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
12 *   which should have been included with this file.  If this file is
13 *   file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * Contents:
16 *
17 *   main()       - Test the help index code.
18 *   list_nodes() - List nodes in an array...
19 */
20
21/*
22 * Include necessary headers...
23 */
24
25#include "cgi.h"
26
27
28/*
29 * Local functions...
30 */
31
32static void	list_nodes(const char *title, cups_array_t *nodes);
33
34
35/*
36 * 'main()' - Test the help index code.
37 */
38
39int					/* O - Exit status */
40main(int  argc,				/* I - Number of command-line arguments */
41     char *argv[])			/* I - Command-line arguments */
42{
43  help_index_t	*hi,			/* Help index */
44		*search;		/* Search index */
45
46
47 /*
48  * Load the help index...
49  */
50
51  hi = helpLoadIndex("testhi.index", ".");
52
53  list_nodes("nodes", hi->nodes);
54  list_nodes("sorted", hi->sorted);
55
56 /*
57  * Do any searches...
58  */
59
60  if (argc > 1)
61  {
62    search = helpSearchIndex(hi, argv[1], NULL, argv[2]);
63
64    if (search)
65    {
66      list_nodes(argv[1], search->sorted);
67      helpDeleteIndex(search);
68    }
69    else
70      printf("%s (0 nodes)\n", argv[1]);
71  }
72
73  helpDeleteIndex(hi);
74
75 /*
76  * Return with no errors...
77  */
78
79  return (0);
80}
81
82
83/*
84 * 'list_nodes()' - List nodes in an array...
85 */
86
87static void
88list_nodes(const char   *title,		/* I - Title string */
89	   cups_array_t *nodes)		/* I - Nodes */
90{
91  int		i;			/* Looping var */
92  help_node_t	*node;			/* Current node */
93
94
95  printf("%s (%d nodes):\n", title, cupsArrayCount(nodes));
96  for (i = 1, node = (help_node_t *)cupsArrayFirst(nodes);
97       node;
98       i ++, node = (help_node_t *)cupsArrayNext(nodes))
99  {
100    if (node->anchor)
101      printf("    %d: %s#%s \"%s\"", i, node->filename, node->anchor,
102             node->text);
103    else
104      printf("    %d: %s \"%s\"", i, node->filename, node->text);
105
106    printf(" (%d words)\n", cupsArrayCount(node->words));
107  }
108}
109
110
111/*
112 * End of "$Id: testhi.c 11093 2013-07-03 20:48:42Z msweet $".
113 */
114