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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/*
* Help index test program for CUPS.
*
* Copyright © 2020-2024 by OpenPrinting.
* Copyright © 2007-2017 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
*/
/*
* Include necessary headers...
*/
#include "cgi.h"
/*
* Local functions...
*/
static void list_nodes(const char *title, cups_array_t *nodes);
static int usage(void);
/*
* 'main()' - Test the help index code.
*/
int /* O - Exit status */
main(int argc, /* I - Number of command-line arguments */
char *argv[]) /* I - Command-line arguments */
{
int i; /* Looping var */
help_index_t *hi, /* Help index */
*search; /* Search index */
const char *opt, /* Current option character */
*dir = ".", /* Directory to index */
*q = NULL, /* Query string */
*section = NULL, /* Section string */
*filename = NULL; /* Filename string */
/*
* Parse the command-line...
*/
for (i = 1; i < argc; i ++)
{
if (argv[i][0] == '-')
{
if (!strcmp(argv[i], "--help"))
{
usage();
return (0);
}
for (opt = argv[i] + 1; *opt; opt ++)
{
switch (*opt)
{
case 'd' : /* -d directory */
i ++;
if (i < argc)
{
dir = argv[i];
}
else
{
fputs("testhi: Missing directory for \"-d\" option.\n", stderr);
return (usage());
}
break;
case 's' : /* -s section */
i ++;
if (i < argc)
{
section = argv[i];
}
else
{
fputs("testhi: Missing section name for \"-s\" option.\n", stderr);
return (usage());
}
break;
default :
fprintf(stderr, "testhi: Unknown option \"-%c\".\n", *opt);
return (usage());
}
}
}
else if (!q)
q = argv[i];
else if (!filename)
filename = argv[i];
else
{
fprintf(stderr, "testhi: Unknown argument \"%s\".\n", argv[i]);
return (usage());
}
}
/*
* Load the help index...
*/
hi = helpLoadIndex("testhi.index", dir);
list_nodes("nodes", hi->nodes);
list_nodes("sorted", hi->sorted);
/*
* Do any searches...
*/
if (q)
{
search = helpSearchIndex(hi, q, section, filename);
if (search)
{
list_nodes(argv[1], search->sorted);
helpDeleteIndex(search);
}
else
printf("%s (0 nodes)\n", q);
}
helpDeleteIndex(hi);
/*
* Return with no errors...
*/
return (0);
}
/*
* 'list_nodes()' - List nodes in an array...
*/
static void
list_nodes(const char *title, /* I - Title string */
cups_array_t *nodes) /* I - Nodes */
{
int i; /* Looping var */
help_node_t *node; /* Current node */
printf("%s (%d nodes):\n", title, cupsArrayCount(nodes));
for (i = 1, node = (help_node_t *)cupsArrayFirst(nodes);
node;
i ++, node = (help_node_t *)cupsArrayNext(nodes))
{
if (node->anchor)
printf(" %d: %s#%s \"%s\"", i, node->filename, node->anchor,
node->text);
else
printf(" %d: %s \"%s\"", i, node->filename, node->text);
printf(" (%d words)\n", cupsArrayCount(node->words));
}
}
/*
* 'usage()' - Show program usage.
*/
static int /* O - Exit status */
usage(void)
{
puts("Usage: ./testhi [options] [\"query\"] [filename]");
puts("Options:");
puts("-d directory Specify index directory.");
puts("-s section Specify search section.");
return (1);
}
|