]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/testhi.c
french translation correction
[thirdparty/cups.git] / cgi-bin / testhi.c
index 2340c94a50d4ffb1887c21cd6ad4ef73110c3b8d..dec6bdf765e4135a4a9323782e1b1ddec80ef3df 100644 (file)
@@ -1,14 +1,10 @@
 /*
  * 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.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. 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, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -23,6 +19,7 @@
  */
 
 static void    list_nodes(const char *title, cups_array_t *nodes);
+static int     usage(void);
 
 
 /*
@@ -33,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);
@@ -50,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)
     {
@@ -60,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);
@@ -99,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);
+}