]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/mark.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / mark.c
index 33202bda9c0a81fdd6c20672aabb7f5690959297..a7d8fd7bd4dcf7178de2f5bd3bd8ea90997b15b5 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: mark.c 4980 2006-01-25 19:57:45Z mike $"
+ * "$Id: mark.c 5528 2006-05-15 20:03:12Z mike $"
  *
  *   Option marking routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -31,6 +31,8 @@
  *   ppdFindChoice()       - Return a pointer to an option choice.
  *   ppdFindMarkedChoice() - Return the marked choice for the specified option.
  *   ppdFindOption()       - Return a pointer to the specified option.
+ *   ppdFirstOption()      - Return the first option in the PPD file.
+ *   ppdNextOption()       - Return the next option in the PPD file.
  *   ppdIsMarked()         - Check to see if an option is marked...
  *   ppdMarkDefaults()     - Mark all default options in the PPD file.
  *   ppdMarkOption()       - Mark an option in a PPD file.
@@ -41,7 +43,7 @@
  * Include necessary headers...
  */
 
-#include "ppd.h"
+#include "cups.h"
 #include "string.h"
 #include "debug.h"
 
@@ -239,9 +241,6 @@ ppd_option_t *                              /* O - Pointer to option or NULL */
 ppdFindOption(ppd_file_t *ppd,         /* I - PPD file data */
               const char *option)      /* I - Option/Keyword name */
 {
-  ppd_option_t key;                    /* Option search key */
-
-
  /*
   * Range check input...
   */
@@ -249,13 +248,39 @@ ppdFindOption(ppd_file_t *ppd,            /* I - PPD file data */
   if (!ppd || !option)
     return (NULL);
 
- /*
-  * Search...
-  */
+  if (ppd->options)
+  {
+   /*
+    * Search in the array...
+    */
+
+    ppd_option_t       key;            /* Option search key */
+
 
-  strlcpy(key.keyword, option, sizeof(key.keyword));
+    strlcpy(key.keyword, option, sizeof(key.keyword));
 
-  return ((ppd_option_t *)cupsArrayFind(ppd->options, &key));
+    return ((ppd_option_t *)cupsArrayFind(ppd->options, &key));
+  }
+  else
+  {
+   /*
+    * Search in each group...
+    */
+
+    int                        i, j;           /* Looping vars */
+    ppd_group_t                *group;         /* Current group */
+    ppd_option_t       *optptr;        /* Current option */
+
+
+    for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
+      for (j = group->num_options, optptr = group->options;
+           j > 0;
+          j --, optptr ++)
+        if (!strcasecmp(optptr->keyword, option))
+         return (optptr);
+
+    return (NULL);
+  }
 }
 
 
@@ -321,7 +346,11 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
   int          i, j;                   /* Looping vars */
   ppd_option_t *o;                     /* Option pointer */
   ppd_choice_t *c;                     /* Choice pointer */
+  struct lconv *loc;                   /* Locale data */
+
 
+  DEBUG_printf(("ppdMarkOption(ppd=%p, option=\"%s\", choice=\"%s\")\n",
+               ppd, option, choice));
 
  /*
   * Range check input...
@@ -349,8 +378,9 @@ ppdMarkOption(ppd_file_t *ppd,              /* I - PPD file record */
   if ((o = ppdFindOption(ppd, option)) == NULL)
     return (0);
 
+  loc = localeconv();
 
-  if (!strncasecmp(choice, "Custom.", 7) /* TODO || strchr(choice, '=') */ )
+  if (!strncasecmp(choice, "Custom.", 7))
   {
    /*
     * Handle a custom option...
@@ -375,14 +405,7 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
 
       ppd_coption_t    *coption;       /* Custom option */
       ppd_cparam_t     *cparam;        /* Custom parameter */
-      char             units[33];      /* Custom points units */
-
-
-     /*
-      * TODO: Detect and support custom option values using the
-      * collection format "{Name1=foo Name2=bar}".  For now, just
-      * support Custom.value for single-valued custom options.
-      */
+      char             *units;         /* Custom points units */
 
       if ((coption = ppdFindCustomOption(ppd, option)) != NULL)
       {
@@ -394,24 +417,27 @@ ppdMarkOption(ppd_file_t *ppd,            /* I - PPD file record */
          case PPD_CUSTOM_CURVE :
          case PPD_CUSTOM_INVCURVE :
          case PPD_CUSTOM_REAL :
-             cparam->current.custom_real = atof(choice + 7);
+             cparam->current.custom_real = _cupsStrScand(choice + 7, NULL,
+                                                         loc);
              break;
 
          case PPD_CUSTOM_POINTS :
-             if (sscanf(choice + 7, "%f%s", &(cparam->current.custom_points),
-                        units) < 2)
-               strcpy(units, "pt");
-
-              if (!strcasecmp(units, "cm"))
-               cparam->current.custom_points *= 72.0 / 2.54;         
-              else if (!strcasecmp(units, "mm"))
-               cparam->current.custom_points *= 72.0 / 25.4;         
-              else if (!strcasecmp(units, "m"))
-               cparam->current.custom_points *= 72.0 / 0.0254;       
-              else if (!strcasecmp(units, "in"))
-               cparam->current.custom_points *= 72.0;        
-              else if (!strcasecmp(units, "ft"))
-               cparam->current.custom_points *= 12 * 72.0;           
+             cparam->current.custom_points = _cupsStrScand(choice + 7,
+                                                           &units, loc);
+
+              if (units)
+             {
+               if (!strcasecmp(units, "cm"))
+                 cparam->current.custom_points *= 72.0 / 2.54;       
+               else if (!strcasecmp(units, "mm"))
+                 cparam->current.custom_points *= 72.0 / 25.4;       
+               else if (!strcasecmp(units, "m"))
+                 cparam->current.custom_points *= 72.0 / 0.0254;             
+               else if (!strcasecmp(units, "in"))
+                 cparam->current.custom_points *= 72.0;              
+               else if (!strcasecmp(units, "ft"))
+                 cparam->current.custom_points *= 12 * 72.0;         
+              }
              break;
 
          case PPD_CUSTOM_INT :
@@ -430,6 +456,78 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
       }
     }
   }
+  else if (choice[0] == '{')
+  {
+   /*
+    * Handle multi-value custom options...
+    */
+
+    ppd_coption_t      *coption;       /* Custom option */
+    ppd_cparam_t       *cparam;        /* Custom parameter */
+    char               *units;         /* Custom points units */
+    int                        num_vals;       /* Number of values */
+    cups_option_t      *vals,          /* Values */
+                       *val;           /* Value */
+
+
+    if ((c = ppdFindChoice(o, "Custom")) == NULL)
+      return (0);
+
+    if ((coption = ppdFindCustomOption(ppd, option)) != NULL)
+    {
+      num_vals = cupsParseOptions(choice + 1, 0, &vals);
+
+      for (i = 0, val = vals; i < num_vals; i ++, val ++)
+      {
+        if ((cparam = ppdFindCustomParam(coption, val->name)) == NULL)
+         continue;
+
+       switch (cparam->type)
+       {
+         case PPD_CUSTOM_CURVE :
+         case PPD_CUSTOM_INVCURVE :
+         case PPD_CUSTOM_REAL :
+             cparam->current.custom_real = _cupsStrScand(val->value, NULL,
+                                                         loc);
+             break;
+
+         case PPD_CUSTOM_POINTS :
+             cparam->current.custom_points = _cupsStrScand(val->value, &units,
+                                                           loc);
+
+             if (units)
+             {
+               if (!strcasecmp(units, "cm"))
+                 cparam->current.custom_points *= 72.0 / 2.54;       
+               else if (!strcasecmp(units, "mm"))
+                 cparam->current.custom_points *= 72.0 / 25.4;       
+               else if (!strcasecmp(units, "m"))
+                 cparam->current.custom_points *= 72.0 / 0.0254;             
+               else if (!strcasecmp(units, "in"))
+                 cparam->current.custom_points *= 72.0;              
+               else if (!strcasecmp(units, "ft"))
+                 cparam->current.custom_points *= 12 * 72.0;         
+             }
+             break;
+
+         case PPD_CUSTOM_INT :
+             cparam->current.custom_int = atoi(val->value);
+             break;
+
+         case PPD_CUSTOM_PASSCODE :
+         case PPD_CUSTOM_PASSWORD :
+         case PPD_CUSTOM_STRING :
+             if (cparam->current.custom_string)
+               free(cparam->current.custom_string);
+
+             cparam->current.custom_string = strdup(val->value);
+             break;
+       }
+      }
+
+      cupsFreeOptions(num_vals, vals);
+    }
+  }
   else
   {
     for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
@@ -465,7 +563,7 @@ ppdMarkOption(ppd_file_t *ppd,              /* I - PPD file record */
          */
 
          for (j = 0; j < ppd->num_sizes; j ++)
-           ppd->sizes[i].marked = !strcasecmp(ppd->sizes[i].name,
+           ppd->sizes[j].marked = !strcasecmp(ppd->sizes[j].name,
                                               choice);
 
         /*
@@ -477,7 +575,7 @@ ppdMarkOption(ppd_file_t *ppd,              /* I - PPD file record */
          {
            if ((o = ppdFindOption(ppd, "PageRegion")) != NULL)
              for (j = 0; j < o->num_choices; j ++)
-               o->choices[i].marked = 0;
+               o->choices[j].marked = 0;
          }
          else
          {
@@ -519,6 +617,42 @@ ppdMarkOption(ppd_file_t *ppd,             /* I - PPD file record */
 }
 
 
+/*
+ * 'ppdFirstOption()' - Return the first option in the PPD file.
+ *
+ * Options are returned from all groups in sorted order.
+ *
+ * @since CUPS 1.2@
+ */
+
+ppd_option_t *                         /* O - First option or NULL */
+ppdFirstOption(ppd_file_t *ppd)                /* I - PPD file */
+{
+  if (!ppd)
+    return (NULL);
+  else
+    return ((ppd_option_t *)cupsArrayFirst(ppd->options));
+}
+
+
+/*
+ * 'ppdNextOption()' - Return the next option in the PPD file.
+ *
+ * Options are returned from all groups in sorted order.
+ *
+ * @since CUPS 1.2@
+ */
+
+ppd_option_t *                         /* O - Next option or NULL */
+ppdNextOption(ppd_file_t *ppd)         /* I - PPD file */
+{
+  if (!ppd)
+    return (NULL);
+  else
+    return ((ppd_option_t *)cupsArrayNext(ppd->options));
+}
+
+
 /*
  * 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
  */
@@ -545,5 +679,5 @@ ppd_defaults(ppd_file_t  *ppd,      /* I - PPD file */
 
 
 /*
- * End of "$Id: mark.c 4980 2006-01-25 19:57:45Z mike $".
+ * End of "$Id: mark.c 5528 2006-05-15 20:03:12Z mike $".
  */