//
-// "$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
{
// 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);
{
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);
}
// 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
//
-// '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
while (isspace(*ptr))
ptr ++;
- strcpy(program, ptr);
+ strlcpy(program, ptr, sizeof(program));
}
else
{
// NAME logicop value
for (newv = (char *)v + 1;
*newv && (isalnum(*newv & 255) || *newv == '_');
- newv ++);
+ newv ++)
+ /* do nothing */;
ch = *newv;
*newv = '\0';
if ((baseptr = strrchr(basedir, '/')) != NULL)
*baseptr = '\0';
else
- strcpy(basedir, ".");
+ strlcpy(basedir, ".", sizeof(basedir));
// Find the po file...
pofilename[0] = '\0';
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));
if (!isalnum(ch) && ch != '_')
break;
else if (nameptr < (name + sizeof(name) - 1))
- *nameptr++ = fp->get();
+ *nameptr++ = (char)fp->get();
}
if (nameptr == name)
{
// $$ = $
if (bufptr < bufend)
- *bufptr++ = fp->get();
+ *bufptr++ = (char)fp->get();
}
else
{
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
_("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);
}
}
empty = 0;
if (bufptr < bufend)
- *bufptr++ = ch;
+ *bufptr++ = (char)ch;
}
}
else if (ch == '\'' || ch == '\"')
{
// Insert the opposing quote char...
if (bufptr < bufend)
- *bufptr++ = ch;
+ *bufptr++ = (char)ch;
}
else
{
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 == '\\')
{
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;
else
{
*bufptr = '\0';
-// puts(buffer);
return (buffer);
}
}
}
else if (*format == 'h' || *format == 'l' || *format == 'L')
size = *format++;
+ else
+ size = '\0';
if (!*format)
break;
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));
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 *));
}
else
{
- cupsFileWrite(fp, va_arg(ap, char *), width);
+ cupsFileWrite(fp, va_arg(ap, char *), (size_t)width);
bytes += width;
}
break;
if ((s = va_arg(ap, char *)) == NULL)
s = (char *)"(nil)";
- slen = strlen(s);
+ slen = (int)strlen(s);
if (slen > width && prec != width)
width = slen;
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)))
{
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 ");
return (0);
}
-
-
-//
-// End of "$Id$".
-//