]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - ppdc/ppdpo.cxx
Add _CUPS_NORETURN to missing functions
[thirdparty/cups.git] / ppdc / ppdpo.cxx
index cbd2270142144aac8a8d76a49d36ea479109e065..498b34e3d7f0d3c7ab4d3ac67c921f8cd99aa796 100644 (file)
@@ -1,29 +1,17 @@
 //
-// "$Id$"
+// PPD file message catalog program for the CUPS PPD Compiler.
 //
-//   PPD file message catalog program for the CUPS PPD Compiler.
+// Copyright 2007-2015 by Apple Inc.
+// Copyright 2002-2005 by Easy Software Products.
 //
-//   Copyright 2007-2008 by Apple Inc.
-//   Copyright 2002-2005 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
-//   file is missing or damaged, see the license at "http://www.cups.org/".
-//
-// Contents:
-//
-//   main()           - Main entry for the PPD compiler.
-//   add_ui_strings() - Add all UI strings from the driver.
-//   usage()          - Show usage and exit.
+// Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
 //
 
 //
 // Include necessary headers...
 //
 
-#include "ppdc.h"
+#include "ppdc-private.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -33,7 +21,7 @@
 //
 
 static void    add_ui_strings(ppdcDriver *d, ppdcCatalog *catalog);
-static void    usage(void);
+static void    usage(void) _CUPS_NORETURN;
 
 
 //
@@ -51,11 +39,14 @@ main(int  argc,                             // I - Number of command-line arguments
   char         *opt;                   // Current option
   int          verbose;                // Verbosity
   const char   *outfile;               // Output file
+  char         *value;                 // Value in option
 
 
+  _cupsSetLocale(argv);
+
   // Scan the command-line...
   catalog = new ppdcCatalog("en");
-  src     = 0;
+  src     = new ppdcSource();
   verbose = 0;
   outfile = 0;
 
@@ -65,13 +56,30 @@ main(int  argc,                             // I - Number of command-line arguments
       for (opt = argv[i] + 1; *opt; opt ++)
         switch (*opt)
        {
+          case 'D' :                   // Define variable
+             i ++;
+             if (i >= argc)
+               usage();
+
+              if ((value = strchr(argv[i], '=')) != NULL)
+             {
+               *value++ = '\0';
+
+               src->set_variable(argv[i], value);
+             }
+             else
+               src->set_variable(argv[i], "1");
+              break;
+
           case 'I' :                   // Include directory...
              i ++;
              if (i >= argc)
                usage();
 
               if (verbose > 1)
-               printf("ppdc: Adding include directory \"%s\"...\n", argv[i]);
+               _cupsLangPrintf(stdout,
+                               _("ppdc: Adding include directory \"%s\"."),
+                               argv[i]);
 
              ppdcSource::add_include(argv[i]);
              break;
@@ -99,24 +107,32 @@ main(int  argc,                            // I - Number of command-line arguments
     {
       // Open and load the driver info file...
       if (verbose > 1)
-        printf("ppdc: Loading driver information file \"%s\"...\n", argv[i]);
+        _cupsLangPrintf(stdout,
+                       _("ppdc: Loading driver information file \"%s\"."),
+                       argv[i]);
 
-      src = new ppdcSource(argv[i]);
+      src->read_file(argv[i]);
+    }
 
-      // Add UI strings...
-      for (d = (ppdcDriver *)src->drivers->first();
-           d;
-          d = (ppdcDriver *)src->drivers->next())
-      {
-       if (verbose)
-         printf("ppdc: Adding/updating UI text from %s...\n", argv[i]);
+  // If no drivers have been loaded, display the program usage message.
+  if ((d = (ppdcDriver *)src->drivers->first()) != NULL)
+  {
+    // Add UI strings...
+    while (d != NULL)
+    {
+      if (verbose)
+       _cupsLangPrintf(stderr, _("ppdc: Adding/updating UI text from %s."), argv[i]);
 
-        add_ui_strings(d, catalog);
-      }
+      add_ui_strings(d, catalog);
 
-      // Delete the printer driver information...
-      delete src;
+      d = (ppdcDriver *)src->drivers->next();
     }
+  }
+  else
+    usage();
+
+  // Delete the printer driver information...
+  src->release();
 
   // Write the message catalog...
   if (!outfile)
@@ -124,11 +140,7 @@ main(int  argc,                            // I - Number of command-line arguments
   else
     catalog->save_messages(outfile);
 
-  delete catalog;
-
-  // If no drivers have been loaded, display the program usage message.
-  if (!src)
-    usage();
+  catalog->release();
 
   // Return with no errors.
   return (0);
@@ -167,7 +179,7 @@ add_ui_strings(ppdcDriver  *d,              // I - Driver data
     if (!g->options->count)
       continue;
 
-    if (strcasecmp(g->name->value, "General"))
+    if (_cups_strcasecmp(g->name->value, "General"))
       catalog->add_message(g->text->value);
 
     for (o = (ppdcOption *)g->options->first();
@@ -177,7 +189,7 @@ add_ui_strings(ppdcDriver  *d,              // I - Driver data
       if (!o->choices->count)
         continue;
 
-      if (o->text->value && strcmp(o->name->value, o->text->value))
+      if (o->text->value)
         catalog->add_message(o->text->value);
       else
         catalog->add_message(o->name->value);
@@ -185,7 +197,7 @@ add_ui_strings(ppdcDriver  *d,              // I - Driver data
       for (c = (ppdcChoice *)o->choices->first();
            c;
           c = (ppdcChoice *)o->choices->next())
-       if (c->text->value && strcmp(c->name->value, c->text->value))
+       if (c->text->value)
           catalog->add_message(c->text->value);
         else
           catalog->add_message(c->name->value);
@@ -226,15 +238,14 @@ add_ui_strings(ppdcDriver  *d,            // I - Driver data
 static void
 usage(void)
 {
-  puts("Usage: ppdpo [options] -o filename.po filename.drv [ ... filenameN.drv ]");
-  puts("Options:");
-  puts("  -I include-dir    Add include directory to search path.");
-  puts("  -v                Be verbose (more v's for more verbosity).");
+  _cupsLangPuts(stdout, _("Usage: ppdpo [options] -o filename.po filename.drv "
+                          "[ ... filenameN.drv ]"));
+  _cupsLangPuts(stdout, _("Options:"));
+  _cupsLangPuts(stdout, _("  -D name=value           Set named variable to "
+                          "value."));
+  _cupsLangPuts(stdout, _("  -I include-dir          Add include directory to "
+                          "search path."));
+  _cupsLangPuts(stdout, _("  -v                      Be verbose."));
 
   exit(1);
 }
-
-
-//
-// End of "$Id$".
-//