]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpadmin.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / systemv / lpadmin.c
index 492ff9d6fa360946164c3f64aadb22f1b0c79b80..f9a1970b5c704d515251402b395486b694832616 100644 (file)
@@ -1,16 +1,14 @@
 /*
- * "$Id$"
- *
  * "lpadmin" command for CUPS.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2006 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
@@ -20,6 +18,7 @@
 #define _CUPS_NO_DEPRECATED
 #define _PPD_DEPRECATED
 #include <cups/cups-private.h>
+#include <cups/ppd-private.h>
 
 
 /*
@@ -55,10 +54,11 @@ main(int  argc,                     /* I - Number of command-line arguments */
   http_t       *http;          /* Connection to server */
   char         *printer,       /* Destination printer */
                *pclass,        /* Printer class name */
+               *opt,           /* Option pointer */
                *val;           /* Pointer to allow/deny value */
   int          num_options;    /* Number of options */
   cups_option_t        *options;       /* Options */
-  char         *file,          /* New PPD file/interface script */
+  char         *file,          /* New PPD file */
                evefile[1024] = "";
                                /* IPP Everywhere PPD */
   const char   *ppd_name,      /* ppd-name value */
@@ -74,549 +74,518 @@ main(int  argc,                   /* I - Number of command-line arguments */
   file        = NULL;
 
   for (i = 1; i < argc; i ++)
+  {
     if (argv[i][0] == '-')
-      switch (argv[i][1])
+    {
+      for (opt = argv[i] + 1; *opt; opt ++)
       {
-        case 'c' : /* Add printer to class */
-           if (!http)
-           {
-              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+       switch (*opt)
+       {
+         case 'c' : /* Add printer to class */
+             if (!http)
+             {
+               http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+
+               if (http == NULL)
+               {
+                 _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno));
+                 return (1);
+               }
+             }
 
-             if (http == NULL)
+             if (printer == NULL)
              {
-               _cupsLangPrintf(stderr,
-                               _("lpadmin: Unable to connect to server: %s"),
-                               strerror(errno));
+               _cupsLangPuts(stderr,
+                             _("lpadmin: Unable to add a printer to the class:\n"
+                               "         You must specify a printer name first."));
                return (1);
              }
-            }
-
-           if (printer == NULL)
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Unable to add a printer to the class:\n"
-                             "         You must specify a printer name "
-                             "first."));
-             return (1);
-           }
 
-           if (argv[i][2])
-             pclass = argv[i] + 2;
-           else
-           {
-             i ++;
+             if (opt[1] != '\0')
+             {
+               pclass = opt + 1;
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
 
-             if (i >= argc)
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected class name after \"-c\" option."));
+                 return (1);
+               }
+
+               pclass = argv[i];
+             }
+
+             if (!validate_name(pclass))
              {
                _cupsLangPuts(stderr,
-                             _("lpadmin: Expected class name after \"-c\" "
-                               "option."));
+                             _("lpadmin: Class name can only contain printable "
+                               "characters."));
                return (1);
              }
 
-             pclass = argv[i];
-           }
-
-            if (!validate_name(pclass))
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Class name can only contain printable "
-                             "characters."));
-             return (1);
-           }
+             if (add_printer_to_class(http, printer, pclass))
+               return (1);
+             break;
 
-           if (add_printer_to_class(http, printer, pclass))
-             return (1);
-           break;
+         case 'd' : /* Set as default destination */
+             if (!http)
+             {
+               http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
-        case 'd' : /* Set as default destination */
-           if (!http)
-           {
-              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+               if (http == NULL)
+               {
+                 _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno));
+                 return (1);
+               }
+             }
 
-             if (http == NULL)
+             if (opt[1] != '\0')
              {
-               _cupsLangPrintf(stderr,
-                               _("lpadmin: Unable to connect to server: %s"),
-                               strerror(errno));
-               return (1);
+               printer = opt + 1;
+               opt += strlen(opt) - 1;
              }
-            }
+             else
+             {
+               i ++;
 
-           if (argv[i][2])
-             printer = argv[i] + 2;
-           else
-           {
-             i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected printer name after \"-d\" option."));
+                 return (1);
+               }
 
-             if (i >= argc)
+               printer = argv[i];
+             }
+
+             if (!validate_name(printer))
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected printer name after \"-d\" "
-                               "option."));
+               _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain printable characters."));
                return (1);
              }
 
-             printer = argv[i];
-           }
-
-            if (!validate_name(printer))
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Printer name can only contain "
-                             "printable characters."));
-             return (1);
-           }
-
-            if (default_printer(http, printer))
-             return (1);
+             if (default_printer(http, printer))
+               return (1);
 
-           i = argc;
-           break;
+             i = argc;
+             break;
 
-        case 'h' : /* Connect to host */
-           if (http)
-           {
-             httpClose(http);
-             http = NULL;
-           }
-
-           if (argv[i][2] != '\0')
-             cupsSetServer(argv[i] + 2);
-           else
-           {
-             i ++;
+         case 'h' : /* Connect to host */
+             if (http)
+             {
+               httpClose(http);
+               http = NULL;
+             }
 
-             if (i >= argc)
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected hostname after \"-h\" "
-                               "option."));
-               return (1);
-              }
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
 
-              cupsSetServer(argv[i]);
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected hostname after \"-h\" option."));
+                 return (1);
+               }
 
-        case 'i' : /* Use the specified interface script */
-           if (argv[i][2])
-             file = argv[i] + 2;
-           else
-           {
-             i ++;
+               cupsSetServer(argv[i]);
+             }
+             break;
 
-             if (i >= argc)
+         case 'P' : /* Use the specified PPD file */
+         case 'i' : /* Use the specified PPD file */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected interface after \"-i\" "
-                               "option."));
-               return (1);
+               file = opt + 1;
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             file = argv[i];
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("lpadmin: Expected PPD after \"-%c\" option."), argv[i - 1][1]);
+                 return (1);
+               }
 
-        case 'E' : /* Enable the printer */
-           if (printer == NULL)
-           {
+               file = argv[i];
+             }
+             break;
+
+         case 'E' : /* Enable the printer/enable encryption */
+             if (printer == NULL)
+             {
 #ifdef HAVE_SSL
-             cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);
+               cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);
 
-             if (http)
-               httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
+               if (http)
+                 httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
 #else
-              _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."),
-                             argv[0]);
+               _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]);
 #endif /* HAVE_SSL */
-             break;
-           }
-
-           if (!http)
-           {
-              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+               break;
+             }
 
-             if (http == NULL)
+             if (!http)
              {
-               _cupsLangPrintf(stderr,
-                               _("lpadmin: Unable to connect to server: %s"),
-                               strerror(errno));
-               return (1);
+               http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+
+               if (http == NULL)
+               {
+                 _cupsLangPrintf(stderr,
+                                 _("lpadmin: Unable to connect to server: %s"),
+                                 strerror(errno));
+                 return (1);
+               }
              }
-            }
 
-            if (enable_printer(http, printer))
-             return (1);
-            break;
-
-        case 'm' : /* Use the specified standard script/PPD file */
-           if (argv[i][2])
-             num_options = cupsAddOption("ppd-name", argv[i] + 2, num_options,
-                                         &options);
-           else
-           {
-             i ++;
+             if (enable_printer(http, printer))
+               return (1);
+             break;
 
-             if (i >= argc)
+         case 'm' : /* Use the specified standard script/PPD file */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected model after \"-m\" "
-                               "option."));
-               return (1);
+               num_options = cupsAddOption("ppd-name", opt + 1, num_options, &options);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             num_options = cupsAddOption("ppd-name", argv[i], num_options,
-                                         &options);
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected model after \"-m\" option."));
+                 return (1);
+               }
 
-        case 'o' : /* Set option */
-           if (argv[i][2])
-             num_options = cupsParseOptions(argv[i] + 2, num_options, &options);
-           else
-           {
-             i ++;
+               num_options = cupsAddOption("ppd-name", argv[i], num_options, &options);
+             }
+             break;
 
-             if (i >= argc)
+         case 'o' : /* Set option */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected name=value after \"-o\" "
-                               "option."));
-               return (1);
+               num_options = cupsParseOptions(opt + 1, num_options, &options);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             num_options = cupsParseOptions(argv[i], num_options, &options);
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected name=value after \"-o\" option."));
+                 return (1);
+               }
 
-        case 'p' : /* Add/modify a printer */
-           if (argv[i][2])
-             printer = argv[i] + 2;
-           else
-           {
-             i ++;
+               num_options = cupsParseOptions(argv[i], num_options, &options);
+             }
+             break;
 
-             if (i >= argc)
+         case 'p' : /* Add/modify a printer */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected printer after \"-p\" "
-                               "option."));
-               return (1);
+               printer = opt + 1;
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             printer = argv[i];
-           }
-
-            if (!validate_name(printer))
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Printer name can only contain "
-                             "printable characters."));
-             return (1);
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected printer after \"-p\" option."));
+                 return (1);
+               }
 
-        case 'r' : /* Remove printer from class */
-           if (!http)
-           {
-              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+               printer = argv[i];
+             }
 
-             if (http == NULL)
+             if (!validate_name(printer))
              {
-               _cupsLangPrintf(stderr,
-                               _("lpadmin: Unable to connect to server: %s"),
-                               strerror(errno));
+               _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain printable characters."));
                return (1);
              }
-            }
-
-           if (printer == NULL)
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Unable to remove a printer from the "
-                             "class:\n"
-                             "         You must specify a printer name "
-                             "first."));
-             return (1);
-           }
+             break;
 
-           if (argv[i][2])
-             pclass = argv[i] + 2;
-           else
-           {
-             i ++;
+         case 'r' : /* Remove printer from class */
+             if (!http)
+             {
+               http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+
+               if (http == NULL)
+               {
+                 _cupsLangPrintf(stderr,
+                                 _("lpadmin: Unable to connect to server: %s"),
+                                 strerror(errno));
+                 return (1);
+               }
+             }
 
-             if (i >= argc)
+             if (printer == NULL)
              {
                _cupsLangPuts(stderr,
-                             _("lpadmin: Expected class after \"-r\" "
-                               "option."));
+                             _("lpadmin: Unable to remove a printer from the class:\n"
+                               "         You must specify a printer name first."));
                return (1);
              }
 
-             pclass = argv[i];
-           }
-
-            if (!validate_name(pclass))
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Class name can only contain printable "
-                             "characters."));
-             return (1);
-           }
+             if (opt[1] != '\0')
+             {
+               pclass = opt + 1;
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
 
-            if (delete_printer_from_class(http, printer, pclass))
-             return (1);
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected class after \"-r\" option."));
+                 return (1);
+               }
 
-        case 'R' : /* Remove option */
-           if (!http)
-           {
-              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+               pclass = argv[i];
+             }
 
-             if (http == NULL)
+             if (!validate_name(pclass))
              {
-               _cupsLangPrintf(stderr,
-                               _("lpadmin: Unable to connect to server: %s"),
-                               strerror(errno));
+               _cupsLangPuts(stderr, _("lpadmin: Class name can only contain printable characters."));
                return (1);
              }
-            }
-
-           if (printer == NULL)
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Unable to delete option:\n"
-                             "         You must specify a printer name "
-                             "first."));
-             return (1);
-           }
 
-           if (argv[i][2])
-             val = argv[i] + 2;
-           else
-           {
-             i ++;
+             if (delete_printer_from_class(http, printer, pclass))
+               return (1);
+             break;
 
-             if (i >= argc)
+         case 'R' : /* Remove option */
+             if (!http)
+             {
+               http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+
+               if (http == NULL)
+               {
+                 _cupsLangPrintf(stderr, _("lpadmin: Unable to connect to server: %s"), strerror(errno));
+                 return (1);
+               }
+             }
+
+             if (printer == NULL)
              {
                _cupsLangPuts(stderr,
-                             _("lpadmin: Expected name after \"-R\" "
-                               "option."));
+                             _("lpadmin: Unable to delete option:\n"
+                               "         You must specify a printer name first."));
                return (1);
              }
 
-             val = argv[i];
-           }
-
-            if (delete_printer_option(http, printer, val))
-             return (1);
-           break;
-
-        case 'U' : /* Username */
-           if (argv[i][2] != '\0')
-             cupsSetUser(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+             if (opt[1] != '\0')
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected username after "
-                                 "\"-U\" option."), argv[0]);
-               return (1);
+               val = opt + 1;
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-              cupsSetUser(argv[i]);
-           }
-           break;
-
-        case 'u' : /* Allow/deny users */
-           if (argv[i][2])
-             val = argv[i] + 2;
-           else
-           {
-             i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected name after \"-R\" option."));
+                 return (1);
+               }
 
-             if (i >= argc)
-             {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected allow/deny:userlist after "
-                               "\"-u\" option."));
-               return (1);
+               val = argv[i];
              }
 
-              val = argv[i];
-           }
-
-            if (!_cups_strncasecmp(val, "allow:", 6))
-             num_options = cupsAddOption("requesting-user-name-allowed",
-                                         val + 6, num_options, &options);
-            else if (!_cups_strncasecmp(val, "deny:", 5))
-             num_options = cupsAddOption("requesting-user-name-denied",
-                                         val + 5, num_options, &options);
-            else
-           {
-             _cupsLangPrintf(stderr,
-                             _("lpadmin: Unknown allow/deny option \"%s\"."),
-                             val);
-             return (1);
-           }
-           break;
+             if (delete_printer_option(http, printer, val))
+               return (1);
+             break;
 
-        case 'v' : /* Set the device-uri attribute */
-           if (argv[i][2])
-             num_options = cupsAddOption("device-uri", argv[i] + 2,
-                                         num_options, &options);
-           else
-           {
-             i ++;
+         case 'U' : /* Username */
+             if (opt[1] != '\0')
+             {
+               cupsSetUser(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
+                 return (1);
+               }
+
+               cupsSetUser(argv[i]);
+             }
+             break;
 
-             if (i >= argc)
+         case 'u' : /* Allow/deny users */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected device URI after \"-v\" "
-                               "option."));
-               return (1);
+               val = opt + 1;
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             num_options = cupsAddOption("device-uri", argv[i],
-                                         num_options, &options);
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected allow/deny:userlist after \"-u\" option."));
+                 return (1);
+               }
 
-        case 'x' : /* Delete a printer */
-           if (!http)
-           {
-              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+               val = argv[i];
+             }
 
-             if (http == NULL)
+             if (!_cups_strncasecmp(val, "allow:", 6))
+               num_options = cupsAddOption("requesting-user-name-allowed", val + 6, num_options, &options);
+             else if (!_cups_strncasecmp(val, "deny:", 5))
+               num_options = cupsAddOption("requesting-user-name-denied", val + 5, num_options, &options);
+             else
              {
-               _cupsLangPrintf(stderr,
-                               _("lpadmin: Unable to connect to server: %s"),
-                               strerror(errno));
+               _cupsLangPrintf(stderr, _("lpadmin: Unknown allow/deny option \"%s\"."), val);
                return (1);
              }
-            }
-
-           if (argv[i][2])
-             printer = argv[i] + 2;
-           else
-           {
-             i ++;
+             break;
 
-             if (i >= argc)
+         case 'v' : /* Set the device-uri attribute */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected printer or class after "
-                               "\"-x\" option."));
-               return (1);
+               num_options = cupsAddOption("device-uri", opt + 1, num_options, &options);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             printer = argv[i];
-           }
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected device URI after \"-v\" option."));
+                 return (1);
+               }
 
-            if (!validate_name(printer))
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Printer name can only contain "
-                             "printable characters."));
-             return (1);
-           }
+               num_options = cupsAddOption("device-uri", argv[i], num_options, &options);
+             }
+             break;
 
-            if (delete_printer(http, printer))
-             return (1);
+         case 'x' : /* Delete a printer */
+             if (!http)
+             {
+               http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
+
+               if (http == NULL)
+               {
+                 _cupsLangPrintf(stderr,
+                                 _("lpadmin: Unable to connect to server: %s"),
+                                 strerror(errno));
+                 return (1);
+               }
+             }
 
-           i = argc;
-           break;
+             if (opt[1] != '\0')
+             {
+               printer = opt + 1;
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
 
-        case 'D' : /* Set the printer-info attribute */
-           if (argv[i][2])
-             num_options = cupsAddOption("printer-info", argv[i] + 2,
-                                         num_options, &options);
-           else
-           {
-             i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected printer or class after \"-x\" option."));
+                 return (1);
+               }
 
-             if (i >= argc)
+               printer = argv[i];
+             }
+
+             if (!validate_name(printer))
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected description after "
-                               "\"-D\" option."));
+               _cupsLangPuts(stderr, _("lpadmin: Printer name can only contain printable characters."));
                return (1);
              }
 
-             num_options = cupsAddOption("printer-info", argv[i],
-                                         num_options, &options);
-           }
-           break;
+             if (delete_printer(http, printer))
+               return (1);
+
+             i = argc;
+             break;
 
-        case 'I' : /* Set the supported file types (ignored) */
-           i ++;
+         case 'D' : /* Set the printer-info attribute */
+             if (opt[1] != '\0')
+             {
+               num_options = cupsAddOption("printer-info", opt + 1, num_options, &options);
+               opt += strlen(opt) - 1;
+             }
+             else
+             {
+               i ++;
 
-           if (i >= argc)
-           {
-             _cupsLangPuts(stderr,
-                           _("lpadmin: Expected file type(s) after \"-I\" "
-                             "option."));
-             return (1);
-           }
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected description after \"-D\" option."));
+                 return (1);
+               }
 
-           _cupsLangPuts(stderr,
-                         _("lpadmin: Warning - content type list ignored."));
-           break;
+               num_options = cupsAddOption("printer-info", argv[i], num_options, &options);
+             }
+             break;
 
-        case 'L' : /* Set the printer-location attribute */
-           if (argv[i][2])
-             num_options = cupsAddOption("printer-location", argv[i] + 2,
-                                         num_options, &options);
-           else
-           {
+         case 'I' : /* Set the supported file types (ignored) */
              i ++;
 
              if (i >= argc)
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected location after \"-L\" "
-                               "option."));
+               _cupsLangPuts(stderr, _("lpadmin: Expected file type(s) after \"-I\" option."));
                return (1);
              }
 
-             num_options = cupsAddOption("printer-location", argv[i],
-                                         num_options, &options);
-           }
-           break;
-
-        case 'P' : /* Use the specified PPD file */
-           if (argv[i][2])
-             file = argv[i] + 2;
-           else
-           {
-             i ++;
+             _cupsLangPuts(stderr, _("lpadmin: Warning - content type list ignored."));
+             break;
 
-             if (i >= argc)
+         case 'L' : /* Set the printer-location attribute */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected PPD after \"-P\" option."));
-               return (1);
+               num_options = cupsAddOption("printer-location", opt + 1, num_options, &options);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
 
-             file = argv[i];
-           }
-           break;
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("lpadmin: Expected location after \"-L\" option."));
+                 return (1);
+               }
 
-       default :
-           _cupsLangPrintf(stderr,
-                           _("lpadmin: Unknown option \"%c\"."), argv[i][1]);
-           return (1);
+               num_options = cupsAddOption("printer-location", argv[i], num_options, &options);
+             }
+             break;
+
+         default :
+             _cupsLangPrintf(stderr, _("lpadmin: Unknown option \"%c\"."), *opt);
+             return (1);
+       }
       }
+    }
     else
     {
-      _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \"%s\"."),
-                      argv[i]);
+      _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \"%s\"."), argv[i]);
       return (1);
     }
+  }
 
  /*
   * Set options as needed...
@@ -1318,7 +1287,7 @@ set_printer_options(
 {
   ipp_t                *request;               /* IPP Request */
   const char   *ppdfile;               /* PPD filename */
-  int          ppdchanged;             /* PPD changed? */
+  int          ppdchanged = 0;         /* PPD changed? */
   ppd_file_t   *ppd;                   /* PPD file */
   ppd_choice_t *choice;                /* Marked choice */
   char         uri[HTTP_MAX_URI],      /* URI for printer/class */
@@ -1328,11 +1297,13 @@ set_printer_options(
                tempfile[1024];         /* Temporary filename */
   cups_file_t  *in,                    /* PPD file */
                *out;                   /* Temporary file */
-  const char   *protocol,              /* Old protocol option */
+  const char   *ppdname,               /* ppd-name value */
+               *protocol,              /* Old protocol option */
                *customval,             /* Custom option value */
                *boolval;               /* Boolean value */
   int          wrote_ipp_supplies = 0, /* Wrote cupsIPPSupplies keyword? */
-               wrote_snmp_supplies = 0;/* Wrote cupsSNMPSupplies keyword? */
+               wrote_snmp_supplies = 0,/* Wrote cupsSNMPSupplies keyword? */
+               copied_options = 0;     /* Copied options? */
 
 
   DEBUG_printf(("set_printer_options(http=%p, printer=\"%s\", num_options=%d, "
@@ -1364,6 +1335,26 @@ set_printer_options(
 
   if (file)
     ppdfile = file;
+  else if ((ppdname = cupsGetOption("ppd-name", num_options, options)) != NULL && strcmp(ppdname, "raw") && num_options > 1)
+  {
+    if ((ppdfile = cupsGetServerPPD(http, ppdname)) != NULL)
+    {
+     /*
+      * Copy options array and remove ppd-name from it...
+      */
+
+      cups_option_t *temp = NULL, *optr;
+      int i, num_temp = 0;
+      for (i = num_options, optr = options; i > 0; i --, optr ++)
+        if (strcmp(optr->name, "ppd-name"))
+         num_temp = cupsAddOption(optr->name, optr->value, num_temp, &temp);
+
+      copied_options = 1;
+      ppdchanged     = 1;
+      num_options    = num_temp;
+      options        = temp;
+    }
+  }
   else if (request->request.op.operation_id == IPP_OP_CUPS_ADD_MODIFY_PRINTER)
     ppdfile = cupsGetPPD(printer);
   else
@@ -1388,7 +1379,15 @@ set_printer_options(
     * Set default options in the PPD file...
     */
 
-    ppd = ppdOpenFile(ppdfile);
+    if ((ppd = ppdOpenFile(ppdfile)) == NULL)
+    {
+      int              linenum;        /* Line number of error */
+      ppd_status_t     status = ppdLastError(&linenum);
+                                       /* Status code */
+
+      _cupsLangPrintf(stderr, _("lpadmin: Unable to open PPD \"%s\": %s on line %d."), ppdfile, ppdErrorString(status), linenum);
+    }
+
     ppdMarkDefaults(ppd);
     cupsMarkOptions(ppd, num_options, options);
 
@@ -1398,6 +1397,8 @@ set_printer_options(
       ippDelete(request);
       if (ppdfile != file)
         unlink(ppdfile);
+      if (copied_options)
+        cupsFreeOptions(num_options, options);
       return (1);
     }
 
@@ -1409,13 +1410,13 @@ set_printer_options(
       ippDelete(request);
       if (ppdfile != file)
        unlink(ppdfile);
+      if (copied_options)
+        cupsFreeOptions(num_options, options);
       cupsFileClose(out);
       unlink(tempfile);
       return (1);
     }
 
-    ppdchanged = 0;
-
     while (cupsFileGets(in, line, sizeof(line)))
     {
       if (!strncmp(line, "*cupsIPPSupplies:", 17) &&
@@ -1537,6 +1538,9 @@ set_printer_options(
     ippDelete(cupsDoRequest(http, request, "/admin/"));
   }
 
+  if (copied_options)
+    cupsFreeOptions(num_options, options);
+
  /*
   * Check the response...
   */
@@ -1579,8 +1583,3 @@ validate_name(const char *name)           /* I - Name to check */
 
   return ((ptr - name) < 128);
 }
-
-
-/*
- * End of "$Id$".
- */