]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpinfo.c
Normalize lp/lpr help text.
[thirdparty/cups.git] / systemv / lpinfo.c
index ebbfbe9c9cf897be3f3448bd86253521a818c251..bb4db596777882a7185eb5c367975df7b2d84e44 100644 (file)
@@ -1,43 +1,26 @@
 /*
- * "$Id: lpinfo.c 7810 2008-07-29 01:11:15Z mike $"
+ * "lpinfo" command for CUPS.
  *
- *   "lpinfo" command for the Common UNIX Printing System (CUPS).
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2009 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/".
- *
- * Contents:
- *
- *   main()         - Parse options and show information.
- *   device_cb      - Device callback.
- *   show_devices() - Show available devices.
- *   show_models()  - Show available PPDs.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <cups/debug.h>
+#include <cups/cups-private.h>
+#include <cups/adminutil.h>
 
 
 /*
  * Local functions...
  */
 
-static void    device_cb(const char *device_clas, const char *device_id,
+static void    device_cb(const char *device_class, const char *device_id,
                          const char *device_info,
                          const char *device_make_and_model,
                          const char *device_uri, const char *device_location,
@@ -50,6 +33,7 @@ static int    show_models(int long_status,
                            const char *make_model, const char *product,
                            const char *include_schemes,
                            const char *exclude_schemes);
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
@@ -62,7 +46,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
 {
   int          i;                      /* Looping var */
   int          long_status;            /* Long listing? */
-  const char   *device_id,             /* 1284 device ID */
+  const char   *opt,                   /* Option pointer */
+               *device_id,             /* 1284 device ID */
                *language,              /* Language */
                *make_model,            /* Make and model */
                *product,               /* Product */
@@ -83,194 +68,177 @@ main(int  argc,                           /* I - Number of command-line arguments */
   timeout         = CUPS_TIMEOUT_DEFAULT;
 
   for (i = 1; i < argc; i ++)
-    if (argv[i][0] == '-')
-      switch (argv[i][1])
+  {
+    if (!strcmp(argv[i], "--device-id"))
+    {
+      i ++;
+
+      if (i < argc)
+       device_id = argv[i];
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected 1284 device ID string after \"--device-id\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--device-id=", 12) && argv[i][12])
+    {
+      device_id = argv[i] + 12;
+    }
+    else if (!strcmp(argv[i], "--exclude-schemes"))
+    {
+      i ++;
+
+      if (i < argc)
+       exclude_schemes = argv[i];
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected scheme list after \"--exclude-schemes\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--exclude-schemes=", 18) && argv[i][18])
+    {
+      exclude_schemes = argv[i] + 18;
+    }
+    else if (!strcmp(argv[i], "--help"))
+      usage();
+    else if (!strcmp(argv[i], "--include-schemes"))
+    {
+      i ++;
+
+      if (i < argc)
+       include_schemes = argv[i];
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected scheme list after \"--include-schemes\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--include-schemes=", 18) && argv[i][18])
+    {
+      include_schemes = argv[i] + 18;
+    }
+    else if (!strcmp(argv[i], "--language"))
+    {
+      i ++;
+      if (i < argc)
+       language = argv[i];
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected language after \"--language\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--language=", 11) && argv[i][11])
+    {
+      language = argv[i] + 11;
+    }
+    else if (!strcmp(argv[i], "--make-and-model"))
+    {
+      i ++;
+      if (i < argc)
+       make_model= argv[i];
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected make and model after \"--make-and-model\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--make-and-model=", 17) && argv[i][17])
+    {
+      make_model = argv[i] + 17;
+    }
+    else if (!strcmp(argv[i], "--product"))
+    {
+      i ++;
+      if (i < argc)
+       product = argv[i];
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected product string after \"--product\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--product=", 10) && argv[i][10])
+    {
+      product = argv[i] + 10;
+    }
+    else if (!strcmp(argv[i], "--timeout"))
+    {
+      i ++;
+      if (i < argc)
+       timeout = atoi(argv[i]);
+      else
+      {
+       _cupsLangPuts(stderr, _("lpinfo: Expected timeout after \"--timeout\"."));
+       usage();
+      }
+    }
+    else if (!strncmp(argv[i], "--timeout=", 10) && argv[i][10])
+    {
+      timeout = atoi(argv[i] + 10);
+    }
+    else if (argv[i][0] == '-')
+    {
+      for (opt = argv[i] + 1; *opt; opt ++)
       {
-        case 'E' : /* Encrypt */
+       switch (*opt)
+       {
+         case 'E' : /* Encrypt */
 #ifdef HAVE_SSL
-           cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
+             cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr,
-                           _("%s: Sorry, no encryption support compiled in\n"),
-                           argv[0]);
+             _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]);
 #endif /* HAVE_SSL */
-           break;
-
-        case 'h' : /* Connect to host */
-           if (argv[i][2] != '\0')
-             cupsSetServer(argv[i] + 2);
-           else
-           {
-             i ++;
+             break;
 
-             if (i >= argc)
-             {
-               _cupsLangPuts(stderr,
-                             _("Error: need hostname after \'-h\' option\n"));
-               return (1);
-              }
-
-             cupsSetServer(argv[i]);
-           }
-           break;
-
-        case 'l' : /* Show long listing */
-           long_status = 1;
-           break;
-
-        case 'm' : /* Show models */
-            if (show_models(long_status, device_id, language, make_model,
-                           product, include_schemes, exclude_schemes))
-             return (1);
-           break;
-           
-        case 'v' : /* Show available devices */
-            if (show_devices(long_status, timeout, include_schemes,
-                            exclude_schemes))
-             return (1);
-           break;
-
-        case '-' : /* --something */
-            if (!strcmp(argv[i], "--device-id"))
-           {
-             i ++;
-
-             if (i < argc)
-               device_id = argv[i];
-             else
+         case 'h' : /* Connect to host */
+             if (opt[1] != '\0')
              {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected 1284 device ID string "
-                               "after --device-id\n"));
-               return (1);
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
              }
-           }
-           else if (!strncmp(argv[i], "--device-id=", 12) && argv[i][12])
-           {
-             device_id = argv[i] + 12;
-           }
-            else if (!strcmp(argv[i], "--exclude-schemes"))
-           {
-             i ++;
-
-             if (i < argc)
-               exclude_schemes = argv[i];
              else
              {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected scheme list after "
-                               "--exclude-schemes\n"));
-               return (1);
-             }
-           }
-           else if (!strncmp(argv[i], "--exclude-schemes=", 18) && argv[i][18])
-           {
-             exclude_schemes = argv[i] + 18;
-           }
-            else if (!strcmp(argv[i], "--include-schemes"))
-           {
-             i ++;
-
-             if (i < argc)
-               include_schemes = argv[i];
-             else
-             {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected scheme list after "
-                               "--include-schemes\n"));
-               return (1);
-             }
-           }
-           else if (!strncmp(argv[i], "--include-schemes=", 18) && argv[i][18])
-           {
-             include_schemes = argv[i] + 18;
-           }
-            else if (!strcmp(argv[i], "--language"))
-           {
-             i ++;
-             if (i < argc)
-               language = argv[i];
-             else
-             {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected language after "
-                               "--language\n"));
-               return (1);
-             }
-           }
-           else if (!strncmp(argv[i], "--language=", 11) && argv[i][11])
-           {
-             language = argv[i] + 11;
-           }
-            else if (!strcmp(argv[i], "--make-and-model"))
-           {
-             i ++;
-             if (i < argc)
-               make_model= argv[i];
-             else
-             {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected make and model after "
-                               "--make-and-model\n"));
-               return (1);
+               i ++;
+
+               if (i >= argc)
+               {
+                 _cupsLangPuts(stderr, _("Error: need hostname after \"-h\" option."));
+                 usage();
+               }
+
+               cupsSetServer(argv[i]);
              }
-           }
-           else if (!strncmp(argv[i], "--make-and-model=", 17) && argv[i][17])
-           {
-             make_model = argv[i] + 17;
-           }
-            else if (!strcmp(argv[i], "--product"))
-           {
-             i ++;
-             if (i < argc)
-               product = argv[i];
-             else
-             {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected product string after "
-                               "--product\n"));
+             break;
+
+         case 'l' : /* Show long listing */
+             long_status = 1;
+             break;
+
+         case 'm' : /* Show models */
+             if (show_models(long_status, device_id, language, make_model, product, include_schemes, exclude_schemes))
                return (1);
-             }
-           }
-           else if (!strncmp(argv[i], "--product=", 10) && argv[i][10])
-           {
-             product = argv[i] + 10;
-           }
-            else if (!strcmp(argv[i], "--timeout"))
-           {
-             i ++;
-             if (i < argc)
-               timeout = atoi(argv[i]);
-             else
-             {
-               _cupsLangPuts(stderr,
-                             _("lpinfo: Expected timeout after --timeout\n"));
+             break;
+
+         case 'v' : /* Show available devices */
+             if (show_devices(long_status, timeout, include_schemes, exclude_schemes))
                return (1);
-             }
-           }
-           else if (!strncmp(argv[i], "--timeout=", 10) && argv[i][10])
-           {
-             timeout = atoi(argv[i] + 10);
-           }
-           else
-           {
-             _cupsLangPrintf(stderr, _("lpinfo: Unknown option \'%s\'\n"),
-                             argv[i]);
-             return (1);
-           }
-           break;
-
-       default :
-           _cupsLangPrintf(stderr, _("lpinfo: Unknown option \'%c\'\n"),
-                           argv[i][1]);
-           return (1);
+             break;
+
+         default :
+             _cupsLangPrintf(stderr, _("%s: Unknown option \"%c\"."), argv[0], *opt);
+             usage();
+       }
       }
+    }
     else
     {
-      _cupsLangPrintf(stderr, _("lpinfo: Unknown argument \'%s\'\n"),
-                      argv[i]);
-      return (1);
+      _cupsLangPrintf(stderr, _("%s: Unknown argument \"%s\"."), argv[0], argv[i]);
+      usage();
     }
+  }
 
   return (0);
 }
@@ -307,12 +275,12 @@ device_cb(
                      "        info = %s\n"
                      "        make-and-model = %s\n"
                      "        device-id = %s\n"
-                     "        location = %s\n"),
+                     "        location = %s"),
                    device_uri, device_class, device_info,
                    device_make_and_model, device_id, device_location);
   }
   else
-    _cupsLangPrintf(stdout, "%s %s\n", device_class, device_uri);
+    _cupsLangPrintf(stdout, "%s %s", device_class, device_uri);
 }
 
 
@@ -330,7 +298,7 @@ show_devices(
   if (cupsGetDevices(CUPS_HTTP_DEFAULT, timeout, include_schemes,
                      exclude_schemes, device_cb, &long_status) != IPP_OK)
   {
-    _cupsLangPrintf(stderr, "lpinfo: %s\n", cupsLastErrorString());
+    _cupsLangPrintf(stderr, "lpinfo: %s", cupsLastErrorString());
     return (1);
   }
 
@@ -409,7 +377,7 @@ show_models(
 
     if (response->request.status.status_code > IPP_OK_CONFLICT)
     {
-      _cupsLangPrintf(stderr, "lpinfo: %s\n", cupsLastErrorString());
+      _cupsLangPrintf(stderr, "lpinfo: %s", cupsLastErrorString());
       ippDelete(response);
       return (1);
     }
@@ -475,21 +443,40 @@ show_models(
                        _("Model:  name = %s\n"
                          "        natural_language = %s\n"
                          "        make-and-model = %s\n"
-                         "        device-id = %s\n"),
+                         "        device-id = %s"),
                        ppd_name, ppd_language, ppd_make_model, ppd_device_id);
       }
       else
-        _cupsLangPrintf(stdout, "%s %s\n", ppd_name, ppd_make_model);
+        _cupsLangPrintf(stdout, "%s %s", ppd_name, ppd_make_model);
 
       if (attr == NULL)
         break;
     }
 
     ippDelete(response);
+
+   /*
+    * Show the "everywhere" model, which is handled by the lpadmin command...
+    */
+
+    if ((!include_schemes || strstr(include_schemes, "everywhere")) && (!exclude_schemes || !strstr(exclude_schemes, "everywhere")))
+    {
+      if (long_status)
+      {
+       _cupsLangPrintf(stdout,
+                       _("Model:  name = %s\n"
+                         "        natural_language = %s\n"
+                         "        make-and-model = %s\n"
+                         "        device-id = %s"),
+                       "everywhere", cupsLangDefault()->language, "IPP Everywhere™", "CMD:PwgRaster");
+      }
+      else
+        _cupsLangPuts(stdout, "everywhere IPP Everywhere");
+    }
   }
   else
   {
-    _cupsLangPrintf(stderr, "lpinfo: %s\n", cupsLastErrorString());
+    _cupsLangPrintf(stderr, "lpinfo: %s", cupsLastErrorString());
 
     return (1);
   }
@@ -499,5 +486,30 @@ show_models(
 
 
 /*
- * End of "$Id: lpinfo.c 7810 2008-07-29 01:11:15Z mike $".
+ * 'usage()' - Show program usage and exit.
  */
+
+static void
+usage(void)
+{
+  _cupsLangPuts(stdout, _("Usage: lpinfo [options] -m\n"
+                          "       lpinfo [options] -v"));
+  _cupsLangPuts(stdout, _("Options:"));
+  _cupsLangPuts(stdout, _("-E                      Encrypt the connection to the server"));
+  _cupsLangPuts(stdout, _("-h server[:port]        Connect to the named server and port"));
+  _cupsLangPuts(stdout, _("-l                      Show verbose (long) output"));
+  _cupsLangPuts(stdout, _("-m                      Show models"));
+  _cupsLangPuts(stdout, _("-U username             Specify the username to use for authentication"));
+  _cupsLangPuts(stdout, _("-v                      Show devices"));
+  _cupsLangPuts(stdout, _("--device-id device-id   Show models matching the given IEEE 1284 device ID"));
+  _cupsLangPuts(stdout, _("--exclude-schemes scheme-list\n"
+                          "                        Exclude the specified URI schemes"));
+  _cupsLangPuts(stdout, _("--include-schemes scheme-list\n"
+                          "                        Include only the specified URI schemes"));
+  _cupsLangPuts(stdout, _("--language locale       Show models matching the given locale"));
+  _cupsLangPuts(stdout, _("--make-and-model name   Show models matching the given make and model name"));
+  _cupsLangPuts(stdout, _("--product name          Show models matching the given PostScript product"));
+  _cupsLangPuts(stdout, _("--timeout seconds       Specify the maximum number of seconds to discover devices"));
+
+  exit(1);
+}