]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/help.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cgi-bin / help.c
index d616f28bdff381cfb8239327471b1c965319dd7f..8f6aa54994a6b18f32752c80f4f0c38ec0c3eb67 100644 (file)
@@ -1,29 +1,10 @@
 /*
- * "$Id$"
+ * Online help CGI for CUPS.
  *
- *   On-line help CGI for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2011 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 1997-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- * Contents:
- *
- *   main() - Main entry for CGI.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -48,7 +29,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
   const char   *query;                 /* Search query */
   const char   *cache_dir;             /* CUPS_CACHEDIR environment variable */
   const char   *docroot;               /* CUPS_DOCROOT environment variable */
-  const char   *helpfile;              /* Current help file */
+  const char   *helpfile,              /* Current help file */
+               *helptitle = NULL;      /* Current help title */
   const char   *topic;                 /* Current topic */
   char         topic_data[1024];       /* Topic form data */
   const char   *section;               /* Current section */
@@ -56,6 +38,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
                directory[1024];        /* Directory */
   cups_file_t  *fp;                    /* Help file */
   char         line[1024];             /* Line from file */
+  int          printable;              /* Show printable version? */
 
 
  /*
@@ -64,11 +47,14 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   cgiInitialize();
 
+  printable = cgiGetVariable("PRINTABLE") != NULL;
+
  /*
   * Set the web interface section...
   */
 
   cgiSetVariable("SECTION", "help");
+  cgiSetVariable("REFRESH_PAGE", "");
 
  /*
   * Load the help index...
@@ -92,8 +78,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
   {
     perror(filename);
 
-    cgiStartHTML("Help");
-    cgiSetVariable("ERROR", "Unable to load help index!");
+    cgiStartHTML(cgiText(_("Online Help")));
+    cgiSetVariable("ERROR", cgiText(_("Unable to load help index.")));
     cgiCopyTemplateLang("error.tmpl");
     cgiEndHTML();
 
@@ -108,14 +94,15 @@ main(int  argc,                            /* I - Number of command-line arguments */
   */
 
   for (i = 0; i < argc; i ++)
-    fprintf(stderr, "argv[%d]=\"%s\"\n", i, argv[i]);
+    fprintf(stderr, "DEBUG: argv[%d]=\"%s\"\n", i, argv[i]);
 
   if ((helpfile = getenv("PATH_INFO")) != NULL)
+  {
     helpfile ++;
-  else if (strstr(argv[0], "help.cgi"))
-    helpfile = NULL;
-  else
-    helpfile = argv[0];
+
+    if (!*helpfile)
+      helpfile = NULL;
+  }
 
   if (helpfile)
   {
@@ -132,8 +119,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
     {
       perror(filename);
 
-      cgiStartHTML("Help");
-      cgiSetVariable("ERROR", "Unable to access help file!");
+      cgiStartHTML(cgiText(_("Online Help")));
+      cgiSetVariable("ERROR", cgiText(_("Unable to access help file.")));
       cgiCopyTemplateLang("error.tmpl");
       cgiEndHTML();
 
@@ -142,8 +129,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
     if ((n = helpFindNode(hi, helpfile, NULL)) == NULL)
     {
-      cgiStartHTML("Help");
-      cgiSetVariable("ERROR", "Help file not in index!");
+      cgiStartHTML(cgiText(_("Online Help")));
+      cgiSetVariable("ERROR", cgiText(_("Help file not in index.")));
       cgiCopyTemplateLang("error.tmpl");
       cgiEndHTML();
 
@@ -151,17 +138,20 @@ main(int  argc,                           /* I - Number of command-line arguments */
     }
 
    /*
-    * Set the page title and save the help file...
+    * Save the page title and help file...
     */
 
-    cgiSetVariable("HELPFILE", helpfile);
-    cgiSetVariable("HELPTITLE", n->text);
+    helptitle = n->text;
+    topic     = n->section;
 
    /*
     * Send a standard page header...
     */
 
-    cgiStartHTML(n->text);
+    if (printable)
+      puts("Content-Type: text/html;charset=utf-8\n");
+    else
+      cgiStartHTML(n->text);
   }
   else
   {
@@ -169,17 +159,34 @@ main(int  argc,                           /* I - Number of command-line arguments */
     * Send a standard page header...
     */
 
-    cgiStartHTML("Help");
+    cgiStartHTML(cgiText(_("Online Help")));
+
+    topic = cgiGetVariable("TOPIC");
   }
 
  /*
   * Do a search as needed...
   */
 
+  if (cgiGetVariable("CLEAR"))
+    cgiSetVariable("QUERY", "");
+
   query = cgiGetVariable("QUERY");
-  topic = cgiGetVariable("TOPIC");
   si    = helpSearchIndex(hi, query, topic, helpfile);
 
+  cgiClearVariables();
+  if (query)
+    cgiSetVariable("QUERY", query);
+  if (topic)
+    cgiSetVariable("TOPIC", topic);
+  if (helpfile)
+    cgiSetVariable("HELPFILE", helpfile);
+  if (helptitle)
+    cgiSetVariable("HELPTITLE", helptitle);
+
+  fprintf(stderr, "DEBUG: query=\"%s\", topic=\"%s\"\n",
+          query ? query : "(null)", topic ? topic : "(null)");
+
   if (si)
   {
     help_node_t        *nn;                    /* Parent node */
@@ -189,9 +196,9 @@ main(int  argc,                             /* I - Number of command-line arguments */
             "DEBUG: si=%p, si->sorted=%p, cupsArrayCount(si->sorted)=%d\n", si,
             si->sorted, cupsArrayCount(si->sorted));
 
-    for (n = (help_node_t *)cupsArrayFirst(si->sorted);
+    for (i = 0, n = (help_node_t *)cupsArrayFirst(si->sorted);
          n;
-        n = (help_node_t *)cupsArrayNext(si->sorted))
+        i ++, n = (help_node_t *)cupsArrayNext(si->sorted))
     {
       if (helpfile && n->anchor)
         snprintf(line, sizeof(line), "#%s", n->anchor);
@@ -260,7 +267,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       section = n->section;
     }
 
-    if (!topic || strcmp(n->section, topic))
+    if (!topic || !n->section || strcmp(n->section, topic))
       continue;
 
    /*
@@ -308,7 +315,10 @@ main(int  argc,                            /* I - Number of command-line arguments */
   * Show the search and bookmark content...
   */
 
-  cgiCopyTemplateLang("help-header.tmpl");
+  if (!helpfile || !printable)
+    cgiCopyTemplateLang("help-header.tmpl");
+  else
+    cgiCopyTemplateLang("help-printable.tmpl");
 
  /*
   * If we are viewing a file, copy it in now...
@@ -327,12 +337,12 @@ main(int  argc,                           /* I - Number of command-line arguments */
       {
         if (inbody)
        {
-         if (!strncasecmp(line, "</BODY>", 7))
+         if (!_cups_strncasecmp(line, "</BODY>", 7))
            break;
 
          printf("%s\n", line);
         }
-       else if (!strncasecmp(line, "<BODY", 5))
+       else if (!_cups_strncasecmp(line, "<BODY", 5))
          inbody = 1;
       }
 
@@ -341,7 +351,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     else
     {
       perror(filename);
-      cgiSetVariable("ERROR", "Unable to open help file.");
+      cgiSetVariable("ERROR", cgiText(_("Unable to open help file.")));
       cgiCopyTemplateLang("error.tmpl");
     }
   }
@@ -350,7 +360,13 @@ main(int  argc,                            /* I - Number of command-line arguments */
   * Send a standard trailer...
   */
 
-  cgiEndHTML();
+  if (!printable)
+  {
+    cgiCopyTemplateLang("help-trailer.tmpl");
+    cgiEndHTML();
+  }
+  else
+    puts("</BODY>\n</HTML>");
 
  /*
   * Delete the index...
@@ -364,8 +380,3 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   return (0);
 }
-
-
-/*
- * End of "$Id$".
- */