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