1/*
2 * "$Id: websearch.c 1533 2009-05-22 21:55:51Z msweet $"
3 *
4 *   Web search program for www.cups.org.
5 *
6 *   Copyright 2007-2009 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 * Usage:
16 *
17 *   websearch directory "search string"
18 *
19 * Contents:
20 *
21 *   main()       - Search a directory of help files.
22 *   list_nodes() - List matching nodes.
23 */
24
25/*
26 * Include necessary headers...
27 */
28
29#include "cgi.h"
30
31
32/*
33 * Local functions...
34 */
35
36static void	list_nodes(help_index_t *hi, const char *title,
37		           cups_array_t *nodes);
38
39
40/*
41 * 'main()' - Test the help index code.
42 */
43
44int					/* O - Exit status */
45main(int  argc,				/* I - Number of command-line args */
46     char *argv[])			/* I - Command-line arguments */
47{
48  help_index_t	*hi,			/* Help index */
49		*search;		/* Search index */
50  char		indexname[1024];	/* Name of index file */
51
52
53  if (argc != 3)
54  {
55    puts("Usage: websearch directory \"search terms\"");
56    return (1);
57  }
58
59 /*
60  * Load the help index...
61  */
62
63  snprintf(indexname, sizeof(indexname), "%s/.index", argv[1]);
64  hi = helpLoadIndex(indexname, argv[1]);
65
66 /*
67  * Do any searches...
68  */
69
70  search = helpSearchIndex(hi, argv[2], NULL, NULL);
71
72  if (search)
73    list_nodes(hi, argv[1], search->sorted);
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(help_index_t *hi,		/* I - Help index */
89           const char   *title,		/* I - Title string */
90	   cups_array_t *nodes)		/* I - Nodes */
91{
92  help_node_t	*node,			/* Current node */
93		*file;			/* File node */
94
95
96  printf("%d\n", cupsArrayCount(nodes));
97  for (node = (help_node_t *)cupsArrayFirst(nodes);
98       node;
99       node = (help_node_t *)cupsArrayNext(nodes))
100  {
101    if (node->anchor)
102    {
103      file = helpFindNode(hi, node->filename, NULL);
104      printf("%d|%s#%s|%s|%s\n", node->score, node->filename, node->anchor,
105             node->text, file ? file->text : node->filename);
106    }
107    else
108      printf("%d|%s|%s|%s\n", node->score, node->filename, node->text,
109             node->text);
110  }
111}
112
113
114/*
115 * End of "$Id: websearch.c 1533 2009-05-22 21:55:51Z msweet $".
116 */
117