/*
- * "$Id: page.c 4494 2005-02-18 02:18:11Z mike $"
+ * "$Id: page.c 5548 2006-05-19 19:38:31Z mike $"
*
* Page size functions for the Common UNIX Printing System (CUPS).
*
* 'ppdPageSize()' - Get the page size record for the given size.
*/
-ppd_size_t * /* O - Size record for page or NULL */
-ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
- const char *name) /* I - Size name */
+ppd_size_t * /* O - Size record for page or NULL */
+ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
+ const char *name) /* I - Size name */
{
- int i; /* Looping var */
- float w, l; /* Width and length of page */
- char units[255]; /* Page size units... */
+ int i; /* Looping var */
+ float w, l; /* Width and length of page */
+ char *nameptr; /* Pointer into name */
+ struct lconv *loc; /* Locale data */
- if (ppd == NULL)
+ if (!ppd)
return (NULL);
- if (name != NULL)
+ if (name)
{
- if (strncmp(name, "Custom.", 7) == 0 && ppd->variable_sizes)
+ if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes)
{
/*
* Find the custom page size...
*/
for (i = 0; i < ppd->num_sizes; i ++)
- if (strcmp("Custom", ppd->sizes[i].name) == 0)
+ if (!strcmp("Custom", ppd->sizes[i].name))
break;
if (i == ppd->num_sizes)
* Custom.WIDTHxLENGTH[pt] - Size in points
*/
- units[0] = '\0';
- if (sscanf(name + 7, "%fx%f%254s", &w, &l, units) < 2)
+ loc = localeconv();
+ w = _cupsStrScand(name + 7, &nameptr, loc);
+ if (!nameptr || *nameptr != 'x')
return (NULL);
- if (strcasecmp(units, "in") == 0)
+ l = _cupsStrScand(nameptr + 1, &nameptr, loc);
+ if (!nameptr)
+ return (NULL);
+
+ if (!strcasecmp(nameptr, "in"))
{
ppd->sizes[i].width = w * 72.0f;
ppd->sizes[i].length = l * 72.0f;
ppd->sizes[i].right = w * 72.0f - ppd->custom_margins[2];
ppd->sizes[i].top = l * 72.0f - ppd->custom_margins[3];
}
- else if (strcasecmp(units, "cm") == 0)
+ else if (!strcasecmp(nameptr, "cm"))
{
ppd->sizes[i].width = w / 2.54f * 72.0f;
ppd->sizes[i].length = l / 2.54f * 72.0f;
ppd->sizes[i].right = w / 2.54f * 72.0f - ppd->custom_margins[2];
ppd->sizes[i].top = l / 2.54f * 72.0f - ppd->custom_margins[3];
}
- else if (strcasecmp(units, "mm") == 0)
+ else if (!strcasecmp(nameptr, "mm"))
{
ppd->sizes[i].width = w / 25.4f * 72.0f;
ppd->sizes[i].length = l / 25.4f * 72.0f;
*/
for (i = 0; i < ppd->num_sizes; i ++)
- if (strcmp(name, ppd->sizes[i].name) == 0)
+ if (!strcasecmp(name, ppd->sizes[i].name))
return (ppd->sizes + i);
}
}
/*
- * End of "$Id: page.c 4494 2005-02-18 02:18:11Z mike $".
+ * End of "$Id: page.c 5548 2006-05-19 19:38:31Z mike $".
*/