]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/emit.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / emit.c
index cc8bdddfef282311f2042177e83cd66397546c8c..777488ff150277ca67dc1436818a6853aa76b9f3 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $"
+ * "$Id$"
  *
  *   PPD code emission routines for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -87,7 +87,7 @@ ppdCollect(ppd_file_t    *ppd,                /* I - PPD file data */
  * The choices array should be freed using @code free@ when you are
  * finished with it.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 int                                    /* O - Number of options marked */
@@ -260,7 +260,7 @@ ppdEmit(ppd_file_t    *ppd,         /* I - PPD file record */
  *
  * When "limit" is zero, this function is identical to ppdEmit().
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on failure */
@@ -286,7 +286,7 @@ ppdEmitAfterOrder(
   * Get the string...
   */
 
-  buffer = ppdEmitString(ppd, section, min_order);
+  buffer = ppdEmitString(ppd, section, limit ? min_order : 0.0f);
 
  /*
   * Write it as needed and return...
@@ -417,7 +417,7 @@ ppdEmitJCL(ppd_file_t *ppd,         /* I - PPD file record */
 
     if ((charset = ppdFindAttr(ppd, "cupsPJLCharset", NULL)) != NULL)
     {
-      if (!charset->value || strcasecmp(charset->value, "UTF-8"))
+      if (!charset->value || _cups_strcasecmp(charset->value, "UTF-8"))
         charset = NULL;
     }
 
@@ -479,7 +479,8 @@ ppdEmitJCL(ppd_file_t *ppd,         /* I - PPD file record */
       */
 
       for (title += 7; *title && isdigit(*title & 255); title ++);
-      for (; *title && isspace(*title & 255); title ++);
+      while (_cups_isspace(*title))
+        title ++;
 
       if ((ptr = strstr(title, " - ")) != NULL)
       {
@@ -518,15 +519,27 @@ ppdEmitJCL(ppd_file_t *ppd,               /* I - PPD file record */
     */
 
     if (display && strcmp(display->value, "job"))
-    {
       fprintf(fp, "@PJL JOB NAME = \"%s\"\n", temp);
-
-      if (display && !strcmp(display->value, "rdymsg"))
-        fprintf(fp, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg);
-    }
+    else if (display && !strcmp(display->value, "rdymsg"))
+      fprintf(fp, "@PJL RDYMSG DISPLAY = \"%s\"\n", displaymsg);
     else
       fprintf(fp, "@PJL JOB NAME = \"%s\" DISPLAY = \"%s\"\n", temp,
              displaymsg);
+
+   /*
+    * Replace double quotes with single quotes and UTF-8 characters with
+    * question marks so that the user does not cause a PJL syntax error.
+    */
+
+    strlcpy(temp, user, sizeof(temp));
+
+    for (ptr = temp; *ptr; ptr ++)
+      if (*ptr == '\"')
+        *ptr = '\'';
+      else if (!charset && (*ptr & 128))
+        *ptr = '?';
+
+    fprintf(fp, "@PJL SET USERNAME = \"%s\"\n", temp);
   }
   else
     fputs(ppd->jcl_begin, fp);
@@ -541,7 +554,7 @@ ppdEmitJCL(ppd_file_t *ppd,         /* I - PPD file record */
 /*
  * 'ppdEmitJCLEnd()' - Emit JCLEnd code to a file.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on failure */
@@ -600,7 +613,7 @@ ppdEmitJCLEnd(ppd_file_t *ppd,              /* I - PPD file record */
  * The return string is allocated on the heap and should be freed using
  * @code free@ when you are done with it.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 char *                                 /* O - String containing option code or @code NULL@ if there is no option code */
@@ -653,7 +666,7 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
   {
     if (section == PPD_ORDER_JCL)
     {
-      if (!strcasecmp(choices[i]->choice, "Custom") &&
+      if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
          (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
              != NULL)
       {
@@ -678,7 +691,8 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
            case PPD_CUSTOM_PASSCODE :
            case PPD_CUSTOM_PASSWORD :
            case PPD_CUSTOM_STRING :
-               bufsize += strlen(cparam->current.custom_string);
+               if (cparam->current.custom_string)
+                 bufsize += strlen(cparam->current.custom_string);
                break;
           }
        }
@@ -688,16 +702,16 @@ ppdEmitString(ppd_file_t    *ppd, /* I - PPD file record */
     {
       bufsize += 3;                    /* [{\n */
 
-      if ((!strcasecmp(choices[i]->option->keyword, "PageSize") ||
-           !strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
-          !strcasecmp(choices[i]->choice, "Custom"))
+      if ((!_cups_strcasecmp(choices[i]->option->keyword, "PageSize") ||
+           !_cups_strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
+          !_cups_strcasecmp(choices[i]->choice, "Custom"))
       {
         DEBUG_puts("2ppdEmitString: Custom size set!");
 
         bufsize += 37;                 /* %%BeginFeature: *CustomPageSize True\n */
         bufsize += 50;                 /* Five 9-digit numbers + newline */
       }
-      else if (!strcasecmp(choices[i]->choice, "Custom") &&
+      else if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
                (coption = ppdFindCustomOption(ppd,
                                              choices[i]->option->keyword))
                   != NULL)
@@ -705,7 +719,7 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
         bufsize += 23 + strlen(choices[i]->option->keyword) + 6;
                                        /* %%BeginFeature: *Customkeyword True\n */
 
-        
+
         for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
             cparam;
             cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
@@ -723,7 +737,9 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
            case PPD_CUSTOM_PASSCODE :
            case PPD_CUSTOM_PASSWORD :
            case PPD_CUSTOM_STRING :
-               bufsize += 3 + 4 * strlen(cparam->current.custom_string);
+               bufsize += 3;
+               if (cparam->current.custom_string)
+                 bufsize += 4 * strlen(cparam->current.custom_string);
                break;
           }
        }
@@ -766,7 +782,7 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
   for (i = 0, bufptr = buffer; i < count; i ++, bufptr += strlen(bufptr))
     if (section == PPD_ORDER_JCL)
     {
-      if (!strcasecmp(choices[i]->choice, "Custom") &&
+      if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
          choices[i]->code &&
           (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
              != NULL)
@@ -792,8 +808,8 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
              */
 
               pnum = *cptr++ - '0';
-             while (isalnum(*cptr & 255))
-               pnum = pnum * 10 + *cptr - '0';
+             while (isdigit(*cptr & 255))
+               pnum = pnum * 10 + *cptr++ - '0';
 
               for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
                   cparam;
@@ -823,9 +839,12 @@ ppdEmitString(ppd_file_t    *ppd,  /* I - PPD file record */
                  case PPD_CUSTOM_PASSCODE :
                  case PPD_CUSTOM_PASSWORD :
                  case PPD_CUSTOM_STRING :
-                     strlcpy(bufptr, cparam->current.custom_string,
-                             bufend - bufptr);
-                     bufptr += strlen(bufptr);
+                     if (cparam->current.custom_string)
+                     {
+                       strlcpy(bufptr, cparam->current.custom_string,
+                               bufend - bufptr);
+                       bufptr += strlen(bufptr);
+                     }
                      break;
                }
              }
@@ -864,9 +883,9 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
       DEBUG_printf(("2ppdEmitString: Adding code for %s=%s...",
                    choices[i]->option->keyword, choices[i]->choice));
 
-      if ((!strcasecmp(choices[i]->option->keyword, "PageSize") ||
-           !strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
-          !strcasecmp(choices[i]->choice, "Custom"))
+      if ((!_cups_strcasecmp(choices[i]->option->keyword, "PageSize") ||
+           !_cups_strcasecmp(choices[i]->option->keyword, "PageRegion")) &&
+          !_cups_strcasecmp(choices[i]->choice, "Custom"))
       {
        /*
         * Variable size; write out standard size options, using the
@@ -979,7 +998,7 @@ ppdEmitString(ppd_file_t    *ppd,   /* I - PPD file record */
           bufptr += strlen(bufptr);
        }
       }
-      else if (!strcasecmp(choices[i]->choice, "Custom") &&
+      else if (!_cups_strcasecmp(choices[i]->choice, "Custom") &&
                (coption = ppdFindCustomOption(ppd, choices[i]->option->keyword))
                   != NULL)
       {
@@ -1028,14 +1047,19 @@ ppdEmitString(ppd_file_t    *ppd,       /* I - PPD file record */
            case PPD_CUSTOM_STRING :
                *bufptr++ = '(';
 
-               for (s = cparam->current.custom_string; *s; s ++)
-                 if (*s < ' ' || *s == '(' || *s == ')' || *s >= 127)
+               if (cparam->current.custom_string)
+               {
+                 for (s = cparam->current.custom_string; *s; s ++)
                  {
-                   snprintf(bufptr, bufend - bufptr + 1, "\\%03o", *s & 255);
-                   bufptr += strlen(bufptr);
+                   if (*s < ' ' || *s == '(' || *s == ')' || *s >= 127)
+                   {
+                     snprintf(bufptr, bufend - bufptr + 1, "\\%03o", *s & 255);
+                     bufptr += strlen(bufptr);
+                   }
+                   else
+                     *bufptr++ = *s;
                  }
-                 else
-                   *bufptr++ = *s;
+               }
 
                *bufptr++ = ')';
                *bufptr++ = '\n';
@@ -1149,9 +1173,9 @@ ppd_handle_media(ppd_file_t *ppd) /* I - PPD file */
   if (!rpr)
     rpr = ppdFindAttr(ppd, "RequiresPageRegion", "All");
 
-  if (!strcasecmp(size->name, "Custom") ||
+  if (!_cups_strcasecmp(size->name, "Custom") ||
       (!manual_feed && !input_slot) ||
-      (manual_feed && !strcasecmp(manual_feed->choice, "False") &&
+      (manual_feed && !_cups_strcasecmp(manual_feed->choice, "False") &&
        (!input_slot || (input_slot->code && !input_slot->code[0]))) ||
       (!rpr && ppd->num_filters > 0))
   {
@@ -1161,7 +1185,7 @@ ppd_handle_media(ppd_file_t *ppd) /* I - PPD file */
 
     ppdMarkOption(ppd, "PageSize", size->name);
   }
-  else if (rpr && rpr->value && !strcasecmp(rpr->value, "True"))
+  else if (rpr && rpr->value && !_cups_strcasecmp(rpr->value, "True"))
   {
    /*
     * Use PageRegion code...
@@ -1201,5 +1225,5 @@ ppd_handle_media(ppd_file_t *ppd) /* I - PPD file */
 
 
 /*
- * End of "$Id: emit.c 7863 2008-08-26 03:39:59Z mike $".
+ * End of "$Id$".
  */