]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testconflicts.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / cups / testconflicts.c
index 291739a2684a69908259dc5eefdea8a962ff954d..6ea70fa33a6796fc4b931b95a5b4d62acbcaea6e 100644 (file)
@@ -1,21 +1,9 @@
 /*
- * "$Id$"
+ * PPD constraint test program for CUPS.
  *
- *   PPD constraint test program for the Common UNIX Printing System (CUPS).
+ * Copyright 2008-2012 by Apple Inc.
  *
- *   Copyright 2008-2009 by Apple Inc.
- *
- *   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/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   main() - Main entry.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -23,7 +11,8 @@
  */
 
 #include "cups.h"
-#include "string.h"
+#include "ppd.h"
+#include "string-private.h"
 
 
 /*
@@ -36,7 +25,10 @@ main(int  argc,                              /* I - Number of command-line arguments */
 {
   int          i;                      /* Looping var */
   ppd_file_t   *ppd;                   /* PPD file loaded from disk */
-  char         line[256];              /* Input buffer */
+  char         line[256],              /* Input buffer */
+               *ptr,                   /* Pointer into buffer */
+               *optr,                  /* Pointer to first option name */
+               *cptr;                  /* Pointer to first choice */
   int          num_options;            /* Number of options */
   cups_option_t        *options;               /* Options */
   char         *option,                /* Current option */
@@ -73,11 +65,12 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
     if (!cupsResolveConflicts(ppd, option, choice, &num_options, &options))
       puts("Unable to resolve conflicts!");
-    else if (num_options > 0)
+    else if ((!option && num_options > 0) || (option && num_options > 1))
     {
       fputs("Resolved conflicts with the following options:\n   ", stdout);
       for (i = 0; i < num_options; i ++)
-       printf(" %s=%s", options[i].name, options[i].value);
+        if (!option || _cups_strcasecmp(option, options[i].name))
+         printf(" %s=%s", options[i].name, options[i].value);
       putchar('\n');
 
       cupsFreeOptions(num_options, options);
@@ -86,7 +79,13 @@ main(int  argc,                              /* I - Number of command-line arguments */
     if (option)
     {
       free(option);
+      option = NULL;
+    }
+
+    if (choice)
+    {
       free(choice);
+      choice = NULL;
     }
 
     printf("\nNew Option(s): ");
@@ -94,22 +93,29 @@ main(int  argc,                             /* I - Number of command-line arguments */
     if (!fgets(line, sizeof(line), stdin) || line[0] == '\n')
       break;
 
-    num_options = cupsParseOptions(line, 0, &options);
-    if (num_options > 0)
-    {
-      option = strdup(options[0].name);
-      choice = strdup(options[0].value);
-    }
+    for (ptr = line; isspace(*ptr & 255); ptr ++);
+    for (optr = ptr; *ptr && *ptr != '='; ptr ++);
+    if (!*ptr)
+      break;
+    for (*ptr++ = '\0', cptr = ptr; *ptr && !isspace(*ptr & 255); ptr ++);
+    if (!*ptr)
+      break;
+    *ptr++ = '\0';
 
+    option      = strdup(optr);
+    choice      = strdup(cptr);
+    num_options = cupsParseOptions(ptr, 0, &options);
+
+    ppdMarkOption(ppd, option, choice);
     if (cupsMarkOptions(ppd, num_options, options))
       puts("Options Conflict!");
     cupsFreeOptions(num_options, options);
   }
 
+  if (option)
+    free(option);
+  if (choice)
+    free(choice);
+
   return (0);
 }
-
-
-/*
- * End of "$Id$".
- */