]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lp.c
Merge pull request #5621 from zdohnal/cgigetarray-sigsegv
[thirdparty/cups.git] / systemv / lp.c
index bc09b4b20613229dcd0428eaaf4d0a5aca156e05..298c158257ea90f100b5e345a64f705fcc3b7885 100644 (file)
@@ -1,14 +1,11 @@
 /*
  * "lp" command for CUPS.
  *
- * Copyright 2007-2016 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
+ * Copyright © 2007-2019 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
- * 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.
  */
 
 /*
@@ -22,9 +19,9 @@
  * Local functions.
  */
 
-int    restart_job(const char *command, int job_id);
-int    set_job_attrs(const char *command, int job_id, int num_options,
-                     cups_option_t *options);
+static int     restart_job(const char *command, int job_id);
+static int     set_job_attrs(const char *command, int job_id, int num_options, cups_option_t *options);
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
@@ -86,7 +83,9 @@ main(int  argc,                               /* I - Number of command-line arguments */
 
   for (i = 1; i < argc; i ++)
   {
-    if (argv[i][0] == '-' && argv[i][1] && !end_options)
+    if (!strcmp(argv[i], "--help"))
+      usage();
+    else if (argv[i][0] == '-' && argv[i][1] && !end_options)
     {
       for (opt = argv[i] + 1; *opt; opt ++)
       {
@@ -112,7 +111,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                cupsSetUser(argv[i]);
@@ -135,7 +134,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected destination after \"-d\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                printer = argv[i];
@@ -176,7 +175,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected form after \"-f\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
              }
 
@@ -196,7 +195,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                cupsSetServer(argv[i]);
@@ -216,7 +215,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Expected job ID after \"-i\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                val = argv[i];
@@ -269,7 +268,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected copies after \"-n\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                num_copies = atoi(argv[i]);
@@ -299,7 +298,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected option=value after \"-o\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                num_options = cupsParseOptions(argv[i], num_options, &options);
@@ -320,7 +319,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if ((i + 1) >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected priority after \"-%c\" option."), argv[0], *opt);
-                 return (1);
+                 usage();
                }
 
                i ++;
@@ -365,7 +364,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected title after \"-t\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                title = argv[i];
@@ -384,7 +383,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected mode list after \"-y\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
              }
 
@@ -404,7 +403,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected hold name after \"-H\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                val = argv[i];
@@ -447,7 +446,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected page list after \"-P\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                val = argv[i];
@@ -468,7 +467,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected character set after \"-S\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
              }
 
@@ -487,7 +486,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected content type after \"-T\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
              }
 
@@ -498,7 +497,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
              if (opt[1] != '\0')
              {
                _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."), argv[0], argv[i]);
-               return (1);
+               usage();
              }
 
              end_options = 1;
@@ -506,7 +505,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
          default :
              _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), argv[0], *opt);
-             return (1);
+             usage();
        }
       }
     }
@@ -586,33 +585,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
   if (printer == NULL)
   {
-    val = NULL;
-
-    if ((printer = getenv("LPDEST")) == NULL)
-    {
-      if ((printer = getenv("PRINTER")) != NULL)
-      {
-        if (!strcmp(printer, "lp"))
-          printer = NULL;
-       else
-         val = "PRINTER";
-      }
-    }
-    else
-      val = "LPDEST";
-
-    if (printer && !cupsGetNamedDest(NULL, printer, NULL))
-      _cupsLangPrintf(stderr,
-                     _("%s: Error - %s environment variable names "
-                       "non-existent destination \"%s\"."), argv[0], val,
-                     printer);
-    else if (cupsLastError() == IPP_NOT_FOUND)
-      _cupsLangPrintf(stderr,
-                     _("%s: Error - no default destination available."),
-                     argv[0]);
+    if (!cupsGetNamedDest(NULL, NULL, NULL) && cupsLastError() == IPP_STATUS_ERROR_NOT_FOUND)
+      _cupsLangPrintf(stderr, _("%s: Error - %s"), argv[0], cupsLastErrorString());
     else
-      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."),
-                     argv[0]);
+      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."), argv[0]);
 
     return (1);
   }
@@ -674,7 +650,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
  * 'restart_job()' - Restart a job.
  */
 
-int                                    /* O - Exit status */
+static int                             /* O - Exit status */
 restart_job(const char *command,       /* I - Command name */
             int        job_id)         /* I - Job ID */
 {
@@ -716,11 +692,12 @@ restart_job(const char *command,  /* I - Command name */
  * 'set_job_attrs()' - Set job attributes.
  */
 
-int                                    /* O - Exit status */
-set_job_attrs(const char    *command,  /* I - Command name */
-              int           job_id,    /* I - Job ID */
-              int           num_options,/* I - Number of options */
-             cups_option_t *options)   /* I - Options */
+static int                             /* O - Exit status */
+set_job_attrs(
+    const char    *command,            /* I - Command name */
+    int           job_id,              /* I - Job ID */
+    int           num_options,         /* I - Number of options */
+    cups_option_t *options)            /* I - Options */
 {
   ipp_t                *request;               /* IPP request */
   char         uri[HTTP_MAX_URI];      /* URI for job */
@@ -759,3 +736,48 @@ set_job_attrs(const char    *command,      /* I - Command name */
 
   return (0);
 }
+
+
+/*
+ * 'usage()' - Show program usage and exit.
+ */
+
+static void
+usage(void)
+{
+  _cupsLangPuts(stdout, _("Usage: lp [options] [--] [file(s)]\n"
+                          "       lp [options] -i id"));
+  _cupsLangPuts(stdout, _("Options:"));
+  _cupsLangPuts(stdout, _("-c                      Make a copy of the print file(s)"));
+  _cupsLangPuts(stdout, _("-d destination          Specify the destination"));
+  _cupsLangPuts(stdout, _("-E                      Encrypt the connection to the server"));
+  _cupsLangPuts(stdout, _("-h server[:port]        Connect to the named server and port"));
+  _cupsLangPuts(stdout, _("-H HH:MM                Hold the job until the specified UTC time"));
+  _cupsLangPuts(stdout, _("-H hold                 Hold the job until released/resumed"));
+  _cupsLangPuts(stdout, _("-H immediate            Print the job as soon as possible"));
+  _cupsLangPuts(stdout, _("-H restart              Reprint the job"));
+  _cupsLangPuts(stdout, _("-H resume               Resume a held job"));
+  _cupsLangPuts(stdout, _("-i id                   Specify an existing job ID to modify"));
+  _cupsLangPuts(stdout, _("-m                      Send an email notification when the job completes"));
+  _cupsLangPuts(stdout, _("-n num-copies           Specify the number of copies to print"));
+  _cupsLangPuts(stdout, _("-o option[=value]       Specify a printer-specific option"));
+  _cupsLangPuts(stdout, _("-o job-sheets=standard  Print a banner page with the job"));
+  _cupsLangPuts(stdout, _("-o media=size           Specify the media size to use"));
+  _cupsLangPuts(stdout, _("-o number-up=N          Specify that input pages should be printed N-up (1, 2, 4, 6, 9, and 16 are supported)"));
+  _cupsLangPuts(stdout, _("-o orientation-requested=N\n"
+                          "                        Specify portrait (3) or landscape (4) orientation"));
+  _cupsLangPuts(stdout, _("-o print-quality=N      Specify the print quality - draft (3), normal (4), or best (5)"));
+  _cupsLangPuts(stdout, _("-o sides=one-sided      Specify 1-sided printing"));
+  _cupsLangPuts(stdout, _("-o sides=two-sided-long-edge\n"
+                          "                        Specify 2-sided portrait printing"));
+  _cupsLangPuts(stdout, _("-o sides=two-sided-short-edge\n"
+                          "                        Specify 2-sided landscape printing"));
+  _cupsLangPuts(stdout, _("-P page-list            Specify a list of pages to print"));
+  _cupsLangPuts(stdout, _("-q priority             Specify the priority from low (1) to high (100)"));
+  _cupsLangPuts(stdout, _("-s                      Be silent"));
+  _cupsLangPuts(stdout, _("-t title                Specify the job title"));
+  _cupsLangPuts(stdout, _("-U username             Specify the username to use for authentication"));
+
+
+  exit(1);
+}