]>
Commit | Line | Data |
---|---|---|
1f0275e3 MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * Web search program for www.cups.org. | |
5 | * | |
b0f6947b | 6 | * Copyright 2007-2009 by Apple Inc. |
1f0275e3 MS |
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 | ||
b0f6947b MS |
36 | static void list_nodes(help_index_t *hi, const char *title, |
37 | cups_array_t *nodes); | |
1f0275e3 MS |
38 | |
39 | ||
40 | /* | |
41 | * 'main()' - Test the help index code. | |
42 | */ | |
43 | ||
44 | int /* O - Exit status */ | |
45 | main(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) | |
b0f6947b | 73 | list_nodes(hi, argv[1], search->sorted); |
1f0275e3 MS |
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 | ||
87 | static void | |
b0f6947b MS |
88 | list_nodes(help_index_t *hi, /* I - Help index */ |
89 | const char *title, /* I - Title string */ | |
1f0275e3 MS |
90 | cups_array_t *nodes) /* I - Nodes */ |
91 | { | |
b0f6947b MS |
92 | help_node_t *node, /* Current node */ |
93 | *file; /* File node */ | |
1f0275e3 MS |
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) | |
b0f6947b MS |
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 | } | |
1f0275e3 | 107 | else |
b0f6947b MS |
108 | printf("%d|%s|%s|%s\n", node->score, node->filename, node->text, |
109 | node->text); | |
1f0275e3 MS |
110 | } |
111 | } | |
112 | ||
113 | ||
114 | /* | |
115 | * End of "$Id$". | |
116 | */ |