]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/websearch.c
Merge changes from CUPS 1.4svn-r7874.
[thirdparty/cups.git] / cgi-bin / websearch.c
1 /*
2 * "$Id$"
3 *
4 * Web search program for www.cups.org.
5 *
6 * Copyright 2007-2008 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
36 static void list_nodes(const char *title, cups_array_t *nodes);
37
38
39 /*
40 * 'main()' - Test the help index code.
41 */
42
43 int /* O - Exit status */
44 main(int argc, /* I - Number of command-line args */
45 char *argv[]) /* I - Command-line arguments */
46 {
47 help_index_t *hi, /* Help index */
48 *search; /* Search index */
49 char indexname[1024]; /* Name of index file */
50
51
52 if (argc != 3)
53 {
54 puts("Usage: websearch directory \"search terms\"");
55 return (1);
56 }
57
58 /*
59 * Load the help index...
60 */
61
62 snprintf(indexname, sizeof(indexname), "%s/.index", argv[1]);
63 hi = helpLoadIndex(indexname, argv[1]);
64
65 /*
66 * Do any searches...
67 */
68
69 search = helpSearchIndex(hi, argv[2], NULL, NULL);
70
71 if (search)
72 list_nodes(argv[1], search->sorted);
73
74 /*
75 * Return with no errors...
76 */
77
78 return (0);
79 }
80
81
82 /*
83 * 'list_nodes()' - List nodes in an array...
84 */
85
86 static void
87 list_nodes(const char *title, /* I - Title string */
88 cups_array_t *nodes) /* I - Nodes */
89 {
90 help_node_t *node; /* Current node */
91
92
93 printf("%d\n", cupsArrayCount(nodes));
94 for (node = (help_node_t *)cupsArrayFirst(nodes);
95 node;
96 node = (help_node_t *)cupsArrayNext(nodes))
97 {
98 if (node->anchor)
99 printf("%d|%s#%s|%s\n", node->score, node->filename, node->anchor,
100 node->text);
101 else
102 printf("%d|%s|%s\n", node->score, node->filename, node->text);
103 }
104 }
105
106
107 /*
108 * End of "$Id$".
109 */