]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - ppdc/ppdc-source.cxx
Fix .PHONY declaration
[thirdparty/cups.git] / ppdc / ppdc-source.cxx
index 43084498b3f831bc50fd5a88aa1c9f09c63e06b8..7b77c2ee7d84511bdbcbed1d47aa1cc27e144830 100644 (file)
@@ -1,59 +1,14 @@
 //
-// "$Id$"
-//
-//   Source class for the CUPS PPD Compiler.
-//
-//   Copyright 2007-2011 by Apple Inc.
-//   Copyright 2002-2007 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:
-//
-//   ppdcSource::ppdcSource()         - Load a driver source file.
-//   ppdcSource::~ppdcSource()        - Free a driver source file.
-//   ppdcSource::add_include()        - Add an include directory.
-//   ppdcSource::find_driver()        - Find a driver.
-//   ppdcSource::find_include()       - Find an include file.
-//   ppdcSource::find_po()            - Find a message catalog for the given
-//                                      locale...
-//   ppdcSource::find_size()          - Find a media size.
-//   ppdcSource::find_variable()      - Find a variable.
-//   ppdcSource::get_attr()           - Get an attribute.
-//   ppdcSource::get_boolean()        - Get a boolean value.
-//   ppdcSource::get_choice()         - Get a choice.
-//   ppdcSource::get_color_model()    - Get an old-style color model option.
-//   ppdcSource::get_color_order()    - Get an old-style color order value.
-//   ppdcSource::get_color_profile()  - Get a color profile definition.
-//   ppdcSource::get_color_space()    - Get an old-style colorspace value.
-//   ppdcSource::get_constraint()     - Get a constraint.
-//   ppdcSource::get_custom_size()    - Get a custom media size definition from
-//                                      a file.
-//   ppdcSource::get_duplex()         - Get a duplex option.
-//   ppdcSource::get_filter()         - Get a filter.
-//   ppdcSource::get_float()          - Get a single floating-point number.
-//   ppdcSource::get_font()           - Get a font definition.
-//   ppdcSource::get_generic()        - Get a generic old-style option.
-//   ppdcSource::get_group()          - Get an option group.
-//   ppdcSource::get_installable()    - Get an installable option.
-//   ppdcSource::get_integer()        - Get an integer value from a file.
-//   ppdcSource::get_measurement()    - Get a measurement value.
-//   ppdcSource::get_option()         - Get an option definition.
-//   ppdcSource::get_po()             - Get a message catalog.
-//   ppdcSource::get_resolution()     - Get an old-style resolution option.
-//   ppdcSource::get_simple_profile() - Get a simple color profile definition.
-//   ppdcSource::get_size()           - Get a media size definition from a file.
-//   ppdcSource::get_token()          - Get a token from a file.
-//   ppdcSource::get_variable()       - Get a variable definition.
-//   ppdcSource::quotef()             - Write a formatted, quoted string...
-//   ppdcSource::read_file()          - Read a driver source file.
-//   ppdcSource::scan_file()          - Scan a driver source file.
-//   ppdcSource::set_variable()       - Set a variable.
-//   ppdcSource::write_file()         - Write the current source data to a file.
+// Source class for the CUPS PPD Compiler.
+//
+// Copyright 2007-2014 by Apple Inc.
+// Copyright 2002-2007 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
+// missing or damaged, see the license at "http://www.cups.org/".
 //
 
 //
 #include <unistd.h>
 #include <cups/raster.h>
 #include "data/epson.h"
-#include "data/escp.h"
 #include "data/hp.h"
 #include "data/label.h"
-#include "data/pcl.h"
 #ifndef WIN32
 #  include <sys/utsname.h>
 #endif // !WIN32
@@ -237,9 +190,9 @@ ppdcSource::find_include(
   {
     // Check for the local file relative to the current directory...
     if (base && *base && f[0] != '/')
-      snprintf(n, nlen, "%s/%s", base, f);
+      snprintf(n, (size_t)nlen, "%s/%s", base, f);
     else
-      strlcpy(n, f, nlen);
+      strlcpy(n, f, (size_t)nlen);
 
     if (!access(n, 0))
       return (n);
@@ -255,7 +208,7 @@ ppdcSource::find_include(
   {
     for (dir = (ppdcString *)includes->first(); dir; dir = (ppdcString *)includes->next())
     {
-      snprintf(n, nlen, "%s/%s", dir->value, f);
+      snprintf(n, (size_t)nlen, "%s/%s", dir->value, f);
       if (!access(n, 0))
         return (n);
     }
@@ -264,11 +217,11 @@ ppdcSource::find_include(
   // Search the standard include directories...
   _cups_globals_t *cg = _cupsGlobals();        // Global data
 
-  snprintf(n, nlen, "%s/ppdc/%s", cg->cups_datadir, f);
+  snprintf(n, (size_t)nlen, "%s/ppdc/%s", cg->cups_datadir, f);
   if (!access(n, 0))
     return (n);
 
-  snprintf(n, nlen, "%s/po/%s", cg->cups_datadir, f);
+  snprintf(n, (size_t)nlen, "%s/po/%s", cg->cups_datadir, f);
   if (!access(n, 0))
     return (n);
   else
@@ -277,7 +230,7 @@ ppdcSource::find_include(
 
 
 //
-// 'ppdcSource::find_po()' - Find a message catalog for the given locale...
+// 'ppdcSource::find_po()' - Find a message catalog for the given locale.
 //
 
 ppdcCatalog *                          // O - Message catalog or NULL
@@ -945,7 +898,7 @@ ppdcSource::get_filter(ppdcFile *fp)        // I - File to read
     while (isspace(*ptr))
       ptr ++;
 
-    strcpy(program, ptr);
+    strlcpy(program, ptr, sizeof(program));
   }
   else
   {
@@ -1340,7 +1293,8 @@ ppdcSource::get_integer(const char *v)    // I - Value string
         // NAME logicop value
        for (newv = (char *)v + 1;
             *newv && (isalnum(*newv & 255) || *newv == '_');
-            newv ++);
+            newv ++)
+         /* do nothing */;
 
         ch    = *newv;
        *newv = '\0';
@@ -1707,7 +1661,7 @@ ppdcSource::get_po(ppdcFile *fp)  // I - File to read
   if ((baseptr = strrchr(basedir, '/')) != NULL)
     *baseptr = '\0';
   else
-    strcpy(basedir, ".");
+    strlcpy(basedir, ".", sizeof(basedir));
 
   // Find the po file...
   pofilename[0] = '\0';
@@ -1811,26 +1765,26 @@ ppdcSource::get_resolution(ppdcFile *fp)// I - File to read
 
   if (color_order >= 0)
   {
-    snprintf(commptr, sizeof(command) - (commptr - command),
+    snprintf(commptr, sizeof(command) - (size_t)(commptr - command),
              "/cupsColorOrder %d", color_order);
     commptr += strlen(commptr);
   }
 
   if (color_space >= 0)
   {
-    snprintf(commptr, sizeof(command) - (commptr - command),
+    snprintf(commptr, sizeof(command) - (size_t)(commptr - command),
              "/cupsColorSpace %d", color_space);
     commptr += strlen(commptr);
   }
 
   if (compression >= 0)
   {
-    snprintf(commptr, sizeof(command) - (commptr - command),
+    snprintf(commptr, sizeof(command) - (size_t)(commptr - command),
              "/cupsCompression %d", compression);
     commptr += strlen(commptr);
   }
 
-  snprintf(commptr, sizeof(command) - (commptr - command), ">>setpagedevice");
+  snprintf(commptr, sizeof(command) - (size_t)(commptr - command), ">>setpagedevice");
 
   // Return the new choice...
   return (new ppdcChoice(name, text, command));
@@ -2015,7 +1969,7 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
         if (!isalnum(ch) && ch != '_')
          break;
        else if (nameptr < (name + sizeof(name) - 1))
-         *nameptr++ = fp->get();
+         *nameptr++ = (char)fp->get();
       }
 
       if (nameptr == name)
@@ -2025,7 +1979,7 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
        {
          // $$ = $
          if (bufptr < bufend)
-           *bufptr++ = fp->get();
+           *bufptr++ = (char)fp->get();
        }
        else
        {
@@ -2045,7 +1999,7 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
        var = find_variable(name);
        if (var)
        {
-         strlcpy(bufptr, var->value->value, bufend - bufptr + 1);
+         strlcpy(bufptr, var->value->value, (size_t)(bufend - bufptr + 1));
          bufptr += strlen(bufptr);
        }
        else
@@ -2055,7 +2009,7 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
                            _("ppdc: Undefined variable (%s) on line %d of "
                              "%s."), name, fp->line, fp->filename);
 
-         snprintf(bufptr, bufend - bufptr + 1, "$%s", name);
+         snprintf(bufptr, (size_t)(bufend - bufptr + 1), "$%s", name);
          bufptr += strlen(bufptr);
        }
       }
@@ -2097,7 +2051,7 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
         empty = 0;
 
        if (bufptr < bufend)
-         *bufptr++ = ch;
+         *bufptr++ = (char)ch;
       }
     }
     else if (ch == '\'' || ch == '\"')
@@ -2113,7 +2067,7 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
       {
         // Insert the opposing quote char...
        if (bufptr < bufend)
-          *bufptr++ = ch;
+          *bufptr++ = (char)ch;
       }
       else
       {
@@ -2129,14 +2083,14 @@ ppdcSource::get_token(ppdcFile *fp,     // I - File to read
       startline = fp->line;
 
       if (bufptr < bufend)
-       *bufptr++ = ch;
+       *bufptr++ = (char)ch;
     }
     else if ((ch == ')' && quote == '(') || (ch == '>' && quote == '<'))
     {
       quote = 0;
 
       if (bufptr < bufend)
-       *bufptr++ = ch;
+       *bufptr++ = (char)ch;
     }
     else if (ch == '\\')
     {
@@ -2146,13 +2100,13 @@ ppdcSource::get_token(ppdcFile *fp,     // I - File to read
         break;
 
       if (bufptr < bufend)
-        *bufptr++ = ch;
+        *bufptr++ = (char)ch;
     }
     else if (bufptr < bufend)
     {
       empty = 0;
 
-      *bufptr++ = ch;
+      *bufptr++ = (char)ch;
 
       if ((ch == '{' || ch == '}') && !quote)
         break;
@@ -2172,7 +2126,6 @@ ppdcSource::get_token(ppdcFile *fp,       // I - File to read
   else
   {
     *bufptr = '\0';
-//    puts(buffer);
     return (buffer);
   }
 }
@@ -2275,6 +2228,8 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
       }
       else if (*format == 'h' || *format == 'l' || *format == 'L')
         size = *format++;
+      else
+        size = '\0';
 
       if (!*format)
         break;
@@ -2291,7 +2246,7 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
            if ((format - bufformat + 1) > (int)sizeof(tformat))
              break;
 
-           strncpy(tformat, bufformat, format - bufformat);
+           memcpy(tformat, bufformat, (size_t)(format - bufformat));
            tformat[format - bufformat] = '\0';
 
            bytes += cupsFilePrintf(fp, tformat, va_arg(ap, double));
@@ -2308,17 +2263,25 @@ ppdcSource::quotef(cups_file_t *fp,     // I - File to write to
            if ((format - bufformat + 1) > (int)sizeof(tformat))
              break;
 
-           strncpy(tformat, bufformat, format - bufformat);
+           memcpy(tformat, bufformat, (size_t)(format - bufformat));
            tformat[format - bufformat] = '\0';
 
-           bytes += cupsFilePrintf(fp, tformat, va_arg(ap, int));
+#  ifdef HAVE_LONG_LONG
+            if (size == 'L')
+             bytes += cupsFilePrintf(fp, tformat, va_arg(ap, long long));
+           else
+#  endif /* HAVE_LONG_LONG */
+            if (size == 'l')
+             bytes += cupsFilePrintf(fp, tformat, va_arg(ap, long));
+           else
+             bytes += cupsFilePrintf(fp, tformat, va_arg(ap, int));
            break;
 
        case 'p' : // Pointer value
            if ((format - bufformat + 1) > (int)sizeof(tformat))
              break;
 
-           strncpy(tformat, bufformat, format - bufformat);
+           memcpy(tformat, bufformat, (size_t)(format - bufformat));
            tformat[format - bufformat] = '\0';
 
            bytes += cupsFilePrintf(fp, tformat, va_arg(ap, void *));
@@ -2332,7 +2295,7 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
            }
            else
            {
-             cupsFileWrite(fp, va_arg(ap, char *), width);
+             cupsFileWrite(fp, va_arg(ap, char *), (size_t)width);
              bytes += width;
            }
            break;
@@ -2341,7 +2304,7 @@ ppdcSource::quotef(cups_file_t *fp,       // I - File to write to
            if ((s = va_arg(ap, char *)) == NULL)
              s = (char *)"(nil)";
 
-           slen = strlen(s);
+           slen = (int)strlen(s);
            if (slen > width && prec != width)
              width = slen;
 
@@ -2621,7 +2584,7 @@ ppdcSource::scan_file(ppdcFile   *fp,     // I - File to read
       if ((baseptr = strrchr(basedir, '/')) != NULL)
        *baseptr = '\0';
       else
-       strcpy(basedir, ".");
+       strlcpy(basedir, ".", sizeof(basedir));
 
       // Find the include file...
       if (find_include(inctemp, basedir, incname, sizeof(incname)))
@@ -3541,64 +3504,6 @@ ppdcSource::write_file(const char *f)    // I - File to write
     {
       switch (d->type)
       {
-        case PPDC_DRIVER_ESCP :
-           cupsFilePuts(fp, "  ModelNumber (");
-
-           if (d->model_number & ESCP_DOTMATRIX)
-             cupsFilePuts(fp, " $ESCP_DOTMATRIX");
-           if (d->model_number & ESCP_MICROWEAVE)
-             cupsFilePuts(fp, " $ESCP_MICROWEAVE");
-           if (d->model_number & ESCP_STAGGER)
-             cupsFilePuts(fp, " $ESCP_STAGGER");
-           if (d->model_number & ESCP_ESCK)
-             cupsFilePuts(fp, " $ESCP_ESCK");
-           if (d->model_number & ESCP_EXT_UNITS)
-             cupsFilePuts(fp, " $ESCP_EXT_UNITS");
-           if (d->model_number & ESCP_EXT_MARGINS)
-             cupsFilePuts(fp, " $ESCP_EXT_MARGINS");
-           if (d->model_number & ESCP_USB)
-             cupsFilePuts(fp, " $ESCP_USB");
-           if (d->model_number & ESCP_PAGE_SIZE)
-             cupsFilePuts(fp, " $ESCP_PAGE_SIZE");
-           if (d->model_number & ESCP_RASTER_ESCI)
-             cupsFilePuts(fp, " $ESCP_RASTER_ESCI");
-           if (d->model_number & ESCP_REMOTE)
-             cupsFilePuts(fp, " $ESCP_REMOTE");
-
-           cupsFilePuts(fp, ")\n");
-           break;
-
-       case PPDC_DRIVER_PCL :
-           cupsFilePuts(fp, "  ModelNumber (");
-
-           if (d->model_number & PCL_PAPER_SIZE)
-             cupsFilePuts(fp, " $PCL_PAPER_SIZE");
-           if (d->model_number & PCL_INKJET)
-             cupsFilePuts(fp, " $PCL_INKJET");
-           if (d->model_number & PCL_RASTER_END_COLOR)
-             cupsFilePuts(fp, " $PCL_RASTER_END_COLOR");
-           if (d->model_number & PCL_RASTER_CID)
-             cupsFilePuts(fp, " $PCL_RASTER_CID");
-           if (d->model_number & PCL_RASTER_CRD)
-             cupsFilePuts(fp, " $PCL_RASTER_CRD");
-           if (d->model_number & PCL_RASTER_SIMPLE)
-             cupsFilePuts(fp, " $PCL_RASTER_SIMPLE");
-           if (d->model_number & PCL_RASTER_RGB24)
-             cupsFilePuts(fp, " $PCL_RASTER_RGB24");
-           if (d->model_number & PCL_PJL)
-             cupsFilePuts(fp, " $PCL_PJL");
-           if (d->model_number & PCL_PJL_PAPERWIDTH)
-             cupsFilePuts(fp, " $PCL_PJL_PAPERWIDTH");
-           if (d->model_number & PCL_PJL_HPGL2)
-             cupsFilePuts(fp, " $PCL_PJL_HPGL2");
-           if (d->model_number & PCL_PJL_PCL3GUI)
-             cupsFilePuts(fp, " $PCL_PJL_PCL3GUI");
-           if (d->model_number & PCL_PJL_RESOLUTION)
-             cupsFilePuts(fp, " $PCL_PJL_RESOLUTION");
-
-           cupsFilePuts(fp, ")\n");
-           break;
-
        case PPDC_DRIVER_LABEL :
            cupsFilePuts(fp, "  ModelNumber ");
 
@@ -3893,8 +3798,3 @@ ppdcSource::write_file(const char *f)     // I - File to write
 
   return (0);
 }
-
-
-//
-// End of "$Id$".
-//