summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authorMichael Sweet <michael.r.sweet@gmail.com>2017-12-19 00:03:54 -0500
committerMichael Sweet <michael.r.sweet@gmail.com>2017-12-19 00:05:30 -0500
commitcfd375ad1067d78222661655a06c1caff3149495 (patch)
tree205ac4018874829a4f4b3bdc1a9eabaebf518470 /cgi-bin
parentc88f441f945d8698fd0554a0077ba8c7662d80ef (diff)
downloadcups-cfd375ad1067d78222661655a06c1caff3149495.tar.gz
Online help fixes.
cgi-bin/help-index.c: - Fix indexing of indented comments, body elements, etc. - Add support for anchors via ID attribute. - Fix anchor scanning bug when the anchor name is quoted. cgi-bin/testhi.c: - Add support for specifying section and directory to index. doc/help/*.html: - Fix headings and anchors.
Diffstat (limited to 'cgi-bin')
-rw-r--r--cgi-bin/help-index.c27
-rw-r--r--cgi-bin/testhi.c94
2 files changed, 106 insertions, 15 deletions
diff --git a/cgi-bin/help-index.c b/cgi-bin/help-index.c
index db7d16124..8e00f0467 100644
--- a/cgi-bin/help-index.c
+++ b/cgi-bin/help-index.c
@@ -1,7 +1,7 @@
/*
* Online help index routines for CUPS.
*
- * Copyright 2007-2015 by Apple Inc.
+ * 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.
@@ -894,13 +894,13 @@ help_load_file(
* Look for "<TITLE>", "<A NAME", or "<!-- SECTION:" prefix...
*/
- if (!_cups_strncasecmp(line, "<!-- SECTION:", 13))
+ if ((ptr = strstr(line, "<!-- SECTION:")) != NULL)
{
/*
* Got section line, copy it!
*/
- for (ptr = line + 13; isspace(*ptr & 255); ptr ++);
+ for (ptr += 13; isspace(*ptr & 255); ptr ++);
strlcpy(section, ptr, sizeof(section));
if ((ptr = strstr(section, "-->")) != NULL)
@@ -930,14 +930,23 @@ help_load_file(
anchor = NULL;
ptr += 6;
}
- else if (!_cups_strncasecmp(ptr, "A NAME=", 7))
+ else
{
+ char *idptr; /* Pointer to ID */
+
+ if (!_cups_strncasecmp(ptr, "A NAME=", 7))
+ ptr += 7;
+ else if ((idptr = strstr(ptr, " ID=")) != NULL)
+ ptr = idptr + 4;
+ else if ((idptr = strstr(ptr, " id=")) != NULL)
+ ptr = idptr + 4;
+ else
+ continue;
+
/*
* Found an anchor...
*/
- ptr += 7;
-
if (*ptr == '\"' || *ptr == '\'')
{
/*
@@ -961,7 +970,7 @@ help_load_file(
for (ptr = anchor; *ptr && *ptr != '>' && !isspace(*ptr & 255); ptr ++);
- if (*ptr)
+ if (*ptr != '>')
*ptr++ = '\0';
else
break;
@@ -977,10 +986,8 @@ help_load_file(
if (*ptr != '>')
break;
- ptr ++;
+ *ptr++ = '\0';
}
- else
- continue;
/*
* Now collect text for the link...
diff --git a/cgi-bin/testhi.c b/cgi-bin/testhi.c
index be5fd9cee..dec6bdf76 100644
--- a/cgi-bin/testhi.c
+++ b/cgi-bin/testhi.c
@@ -1,7 +1,7 @@
/*
* Help index test program for CUPS.
*
- * Copyright 2007-2011 by Apple Inc.
+ * 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.
@@ -19,6 +19,7 @@
*/
static void list_nodes(const char *title, cups_array_t *nodes);
+static int usage(void);
/*
@@ -29,15 +30,82 @@ 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", ".");
+ hi = helpLoadIndex("testhi.index", dir);
list_nodes("nodes", hi->nodes);
list_nodes("sorted", hi->sorted);
@@ -46,9 +114,9 @@ main(int argc, /* I - Number of command-line arguments */
* Do any searches...
*/
- if (argc > 1)
+ if (q)
{
- search = helpSearchIndex(hi, argv[1], NULL, argv[2]);
+ search = helpSearchIndex(hi, q, section, filename);
if (search)
{
@@ -56,7 +124,7 @@ main(int argc, /* I - Number of command-line arguments */
helpDeleteIndex(search);
}
else
- printf("%s (0 nodes)\n", argv[1]);
+ printf("%s (0 nodes)\n", q);
}
helpDeleteIndex(hi);
@@ -95,3 +163,19 @@ list_nodes(const char *title, /* I - Title string */
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);
+}