]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/textcommon.c
Merge changes from CUPS 1.5.1-r9875.
[thirdparty/cups.git] / filter / textcommon.c
index 66255e18a826e6af7e26d9ef6337d8561c4523b6..8101cafba873234495d697ae42290614f2cf4aa5 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: textcommon.c 4559 2005-08-04 18:40:13Z mike $"
+ * "$Id: textcommon.c 6649 2007-07-11 21:46:42Z mike $"
  *
- *   Common text filter routines for the Common UNIX Printing System (CUPS).
+ *   Common text filter routines for CUPS.
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ *   Copyright 2007-2011 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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.
  *
@@ -35,6 +26,7 @@
  */
 
 #include "textcommon.h"
+#include <cups/language-private.h>
 
 
 /*
@@ -53,7 +45,6 @@ lchar_t       **Page = NULL;          /* Page characters */
 int    NumPages = 0;           /* Number of pages in document */
 float  CharsPerInch = 10;      /* Number of character columns per inch */
 float  LinesPerInch = 6;       /* Number of lines per inch */
-int    UTF8 = 0;               /* Use UTF-8 encoding? */
 int    NumKeywords = 0;        /* Number of known keywords */
 char   **Keywords = NULL;      /* List of known keywords */
 
@@ -523,8 +514,9 @@ TextMain(const char *name,  /* I - Name of filter */
 
   if (argc < 6 || argc > 7)
   {
-    fprintf(stderr, "ERROR: %s job-id user title copies options [file]\n",
-            name);
+    _cupsLangPrintf(stderr,
+                    _("Usage: %s job-id user title copies options [file]"),
+                    name);
     return (1);
   }
 
@@ -543,7 +535,7 @@ TextMain(const char *name,  /* I - Name of filter */
 
     if ((fp = fopen(argv[6], "rb")) == NULL)
     {
-      perror("ERROR: unable to open print file - ");
+      perror("DEBUG: unable to open print file - ");
       return (1);
     }
   }
@@ -556,8 +548,8 @@ TextMain(const char *name,  /* I - Name of filter */
   num_options = cupsParseOptions(argv[5], 0, &options);
 
   if ((val = cupsGetOption("prettyprint", num_options, options)) != NULL &&
-      strcasecmp(val, "no") && strcasecmp(val, "off") &&
-      strcasecmp(val, "false"))
+      _cups_strcasecmp(val, "no") && _cups_strcasecmp(val, "off") &&
+      _cups_strcasecmp(val, "false"))
   {
     PageLeft     = 72.0f;
     PageRight    = PageWidth - 36.0f;
@@ -572,25 +564,25 @@ TextMain(const char *name,        /* I - Name of filter */
       NumKeywords = 0;
       Keywords    = NULL;
     }
-    else if (strcasecmp(val, "application/x-cshell") == 0)
+    else if (_cups_strcasecmp(val, "application/x-cshell") == 0)
     {
       PrettyPrint = PRETTY_SHELL;
       NumKeywords = sizeof(csh_keywords) / sizeof(csh_keywords[0]);
       Keywords    = csh_keywords;
     }
-    else if (strcasecmp(val, "application/x-csource") == 0)
+    else if (_cups_strcasecmp(val, "application/x-csource") == 0)
     {
       PrettyPrint = PRETTY_CODE;
       NumKeywords = sizeof(code_keywords) / sizeof(code_keywords[0]);
       Keywords    = code_keywords;
     }
-    else if (strcasecmp(val, "application/x-perl") == 0)
+    else if (_cups_strcasecmp(val, "application/x-perl") == 0)
     {
       PrettyPrint = PRETTY_PERL;
       NumKeywords = sizeof(perl_keywords) / sizeof(perl_keywords[0]);
       Keywords    = perl_keywords;
     }
-    else if (strcasecmp(val, "application/x-shell") == 0)
+    else if (_cups_strcasecmp(val, "application/x-shell") == 0)
     {
       PrettyPrint = PRETTY_SHELL;
       NumKeywords = sizeof(sh_keywords) / sizeof(sh_keywords[0]);
@@ -609,18 +601,45 @@ TextMain(const char *name,        /* I - Name of filter */
   if ((val = cupsGetOption("wrap", num_options, options)) == NULL)
     WrapLines = 1;
   else
-    WrapLines = !strcasecmp(val, "true") || !strcasecmp(val, "on") ||
-                !strcasecmp(val, "yes");
+    WrapLines = !_cups_strcasecmp(val, "true") || !_cups_strcasecmp(val, "on") ||
+                !_cups_strcasecmp(val, "yes");
 
   if ((val = cupsGetOption("columns", num_options, options)) != NULL)
+  {
     PageColumns = atoi(val);
 
+    if (PageColumns < 1)
+    {
+      _cupsLangPrintFilter(stderr, "ERROR", _("Bad columns value %d."),
+                           PageColumns);
+      return (1);
+    }
+  }
+
   if ((val = cupsGetOption("cpi", num_options, options)) != NULL)
+  {
     CharsPerInch = atof(val);
 
+    if (CharsPerInch <= 0.0)
+    {
+      _cupsLangPrintFilter(stderr, "ERROR", _("Bad cpi value %f."),
+                           CharsPerInch);
+      return (1);
+    }
+  }
+
   if ((val = cupsGetOption("lpi", num_options, options)) != NULL)
+  {
     LinesPerInch = atof(val);
 
+    if (LinesPerInch <= 0.0)
+    {
+      _cupsLangPrintFilter(stderr, "ERROR", _("Bad lpi value %f."),
+                           LinesPerInch);
+      return (1);
+    }
+  }
+
   if (PrettyPrint)
     PageTop -= 216.0f / LinesPerInch;
 
@@ -1073,7 +1092,7 @@ TextMain(const char *name,        /* I - Name of filter */
          }
 
           column ++;
-          break;          
+          break;
     }
 
    /*
@@ -1150,7 +1169,7 @@ getutf8(FILE *fp) /* I - File to read from */
   if ((ch = getc(fp)) == EOF)
     return (EOF);
 
-  if (ch < 0xc0 || !UTF8)      /* One byte character? */
+  if (ch < 0xc0)                       /* One byte character? */
     return (ch);
   else if ((ch & 0xe0) == 0xc0)
   {
@@ -1191,5 +1210,5 @@ getutf8(FILE *fp) /* I - File to read from */
 
 
 /*
- * End of "$Id: textcommon.c 4559 2005-08-04 18:40:13Z mike $".
+ * End of "$Id: textcommon.c 6649 2007-07-11 21:46:42Z mike $".
  */