]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/cupsaccept.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / systemv / cupsaccept.c
index 784138ee2fe8c80f2098ed14eb5497dba1756f68..22fb01be1935dd4a82f6b8b70e12eaa6c6e46f32 100644 (file)
@@ -1,21 +1,12 @@
 /*
- * "$Id$"
+ * "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
+ * CUPS.
  *
- *   "cupsaccept", "cupsdisable", "cupsenable", and "cupsreject" commands for
- *   CUPS.
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2010 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 accept/reject jobs or disable/enable printers.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
 #include <cups/cups-private.h>
 
 
+/*
+ * Local functions...
+ */
+
+static void    usage(const char *command) _CUPS_NORETURN;
+
+
 /*
  * 'main()' - Parse options and accept/reject jobs or disable/enable printers.
  */
@@ -35,6 +33,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
 {
   int          i;                      /* Looping var */
   char         *command,               /* Command to do */
+               *opt,                   /* Option pointer */
                uri[1024],              /* Printer URI */
                *reason;                /* Reason for reject/disable */
   ipp_t                *request;               /* IPP request */
@@ -55,13 +54,13 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   cancel = 0;
 
-  if (!strcmp(command, "cupsaccept") || !strcmp(command, "accept"))
+  if (!strcmp(command, "cupsaccept"))
     op = CUPS_ACCEPT_JOBS;
-  else if (!strcmp(command, "cupsreject") || !strcmp(command, "reject"))
+  else if (!strcmp(command, "cupsreject"))
     op = CUPS_REJECT_JOBS;
-  else if (!strcmp(command, "cupsdisable") || !strcmp(command, "disable"))
+  else if (!strcmp(command, "cupsdisable"))
     op = IPP_PAUSE_PRINTER;
-  else if (!strcmp(command, "cupsenable") || !strcmp(command, "enable"))
+  else if (!strcmp(command, "cupsenable"))
     op = IPP_RESUME_PRINTER;
   else
   {
@@ -76,94 +75,92 @@ main(int  argc,                             /* I - Number of command-line arguments */
   */
 
   for (i = 1; i < argc; i ++)
-    if (argv[i][0] == '-')
+  {
+    if (!strcmp(argv[i], "--help"))
+      usage(command);
+    else if (!strcmp(argv[i], "--hold"))
+      op = IPP_HOLD_NEW_JOBS;
+    else if (!strcmp(argv[i], "--release"))
+      op = IPP_RELEASE_HELD_NEW_JOBS;
+    else if (argv[i][0] == '-')
     {
-      switch (argv[i][1])
+      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."), command);
+             _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), command);
 #endif /* HAVE_SSL */
-           break;
-
-        case 'U' : /* Username */
-           if (argv[i][2] != '\0')
-             cupsSetUser(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+             break;
+
+         case 'U' : /* Username */
+             if (opt[1] != '\0')
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected username after "
-                                 "\"-U\" option."), command);
-               return (1);
+               cupsSetUser(opt + 1);
+               opt += strlen(opt) - 1;
              }
+             else
+             {
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), command);
+                 usage(command);
+               }
+
+               cupsSetUser(argv[i]);
+             }
+             break;
+
+         case 'c' : /* Cancel jobs */
+             cancel = 1;
+             break;
 
-              cupsSetUser(argv[i]);
-           }
-           break;
-           
-        case 'c' : /* Cancel jobs */
-           cancel = 1;
-           break;
-
-        case 'h' : /* Connect to host */
-           if (argv[i][2] != '\0')
-             cupsSetServer(argv[i] + 2);
-           else
-           {
-             i ++;
-             if (i >= argc)
+         case 'h' : /* Connect to host */
+             if (opt[1] != '\0')
+             {
+               cupsSetServer(opt + 1);
+               opt += strlen(opt) - 1;
+             }
+             else
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected hostname after "
-                                 "\"-h\" option."), command);
-               return (1);
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-h\" option."), command);
+                 usage(command);
+               }
+
+               cupsSetServer(argv[i]);
              }
+             break;
 
-              cupsSetServer(argv[i]);
-           }
-           break;
-
-        case 'r' : /* Reason for cancellation */
-           if (argv[i][2] != '\0')
-             reason = argv[i] + 2;
-           else
-           {
-             i ++;
-             if (i >= argc)
+         case 'r' : /* Reason for cancellation */
+             if (opt[1] != '\0')
+             {
+               reason = opt + 1;
+               opt += strlen(opt) - 1;
+             }
+             else
              {
-               _cupsLangPrintf(stderr,
-                               _("%s: Error - expected reason text after "
-                                 "\"-r\" option."), command);
-               return (1);
+               i ++;
+               if (i >= argc)
+               {
+                 _cupsLangPrintf(stderr, _("%s: Error - expected reason text after \"-r\" option."), command);
+                 usage(command);
+               }
+
+               reason = argv[i];
              }
+             break;
 
-             reason = argv[i];
-           }
-           break;
-
-        case '-' :
-           if (!strcmp(argv[i], "--hold"))
-             op = IPP_HOLD_NEW_JOBS;
-           else if (!strcmp(argv[i], "--release"))
-             op = IPP_RELEASE_HELD_NEW_JOBS;
-           else
-           {
-             _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."),
-                             command, argv[i]);
-             return (1);
-           }
-           break;
-
-       default :
-           _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."),
-                           command, argv[i][1]);
-           return (1);
+         default :
+             _cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."), command, *opt);
+             usage(command);
+       }
       }
     }
     else
@@ -229,11 +226,29 @@ main(int  argc,                           /* I - Number of command-line arguments */
        }
       }
     }
+  }
 
   return (0);
 }
 
 
 /*
- * End of "$Id$".
+ * 'usage()' - Show program usage and exit.
  */
+
+static void
+usage(const char *command)             /* I - Command name */
+{
+  _cupsLangPrintf(stdout, _("Usage: %s [options] destination(s)"), command);
+  _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, _("-r reason               Specify a reason message that others can see"));
+  _cupsLangPuts(stdout, _("-U username             Specify the username to use for authentication"));
+  if (!strcmp(command, "cupsdisable"))
+    _cupsLangPuts(stdout, _("--hold                  Hold new jobs"));
+  if (!strcmp(command, "cupsenable"))
+    _cupsLangPuts(stdout, _("--release               Release previously held jobs"));
+
+  exit(1);
+}