diff options
author | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2006-02-20 18:43:55 +0000 |
---|---|---|
committer | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2006-02-20 18:43:55 +0000 |
commit | bd7854cb4d663bb0e561eaf5b01bbd47baa71d22 (patch) | |
tree | bca042d698732a5e19035c88c6ffc39d80f543f1 /cups/attr.c | |
parent | 4400e98de24bd267328aa20d57951fb6678297fe (diff) | |
download | cups-bd7854cb4d663bb0e561eaf5b01bbd47baa71d22.tar.gz |
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@60 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups/attr.c')
-rw-r--r-- | cups/attr.c | 89 |
1 files changed, 19 insertions, 70 deletions
diff --git a/cups/attr.c b/cups/attr.c index 36f911d0b..96b89ea05 100644 --- a/cups/attr.c +++ b/cups/attr.c @@ -1,10 +1,10 @@ /* - * "$Id: attr.c 4785 2005-10-13 19:39:05Z mike $" + * "$Id: attr.c 5119 2006-02-16 15:52:06Z mike $" * * PPD model-specific attribute routines for the Common UNIX Printing System * (CUPS). * - * Copyright 1997-2005 by Easy Software Products. + * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the * property of Easy Software Products and are protected by Federal @@ -39,13 +39,6 @@ /* - * Private function... - */ - -extern int _ppd_attr_compare(ppd_attr_t **a, ppd_attr_t **b); - - -/* * 'ppdFindAttr()' - Find the first matching attribute... * * @since CUPS 1.1.19@ @@ -56,64 +49,30 @@ ppdFindAttr(ppd_file_t *ppd, /* I - PPD file data */ const char *name, /* I - Attribute name */ const char *spec) /* I - Specifier string or NULL */ { - ppd_attr_t key, /* Search key */ - *keyptr, /* Pointer to key */ - **match; /* Matching attribute */ + ppd_attr_t key; /* Search key */ /* * Range check input... */ - if (ppd == NULL || name == NULL || ppd->num_attrs == 0) + if (!ppd || !name || ppd->num_attrs == 0) return (NULL); /* - * Do a binary search for a matching attribute... + * Search for a matching attribute... */ memset(&key, 0, sizeof(key)); - strncpy(key.name, name, sizeof(key.name) - 1); + strlcpy(key.name, name, sizeof(key.name)); if (spec) - strncpy(key.spec, spec, sizeof(key.spec) - 1); - - keyptr = &key; - - match = bsearch(&keyptr, ppd->attrs, ppd->num_attrs, sizeof(ppd_attr_t *), - (int (*)(const void *, const void *))_ppd_attr_compare); - - if (match == NULL) - { - /* - * No match! - */ - - ppd->cur_attr = -1; - return (NULL); - } - - if (match > ppd->attrs && spec == NULL) - { - /* - * Find the first attribute with the same name... - */ - - while (match > ppd->attrs) - { - if (strcmp(match[-1]->name, name) != 0) - break; - - match --; - } - } + strlcpy(key.spec, spec, sizeof(key.spec)); /* - * Save the current attribute and return its value... + * Return the first matching attribute, if any... */ - ppd->cur_attr = match - ppd->attrs; - - return (*match); + return ((ppd_attr_t *)cupsArrayFind(ppd->sorted_attrs, &key)); } @@ -128,46 +87,36 @@ ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */ const char *name, /* I - Attribute name */ const char *spec) /* I - Specifier string or NULL */ { - ppd_attr_t **match; /* Matching attribute */ + ppd_attr_t *attr; /* Current attribute */ /* * Range check input... */ - if (ppd == NULL || name == NULL || ppd->num_attrs == 0 || ppd->cur_attr < 0) + if (!ppd || !name || ppd->num_attrs == 0 || + !cupsArrayCurrent(ppd->sorted_attrs)) return (NULL); /* * See if there are more attributes to return... */ - ppd->cur_attr ++; - - if (ppd->cur_attr >= ppd->num_attrs) - { - /* - * Nope... - */ - - ppd->cur_attr = -1; + if ((attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) == NULL) return (NULL); - } /* * Check the next attribute to see if it is a match... */ - match = ppd->attrs + ppd->cur_attr; - - if (strcmp((*match)->name, name) != 0 || - (spec != NULL && strcmp((*match)->spec, spec) != 0)) + if (strcasecmp(attr->name, name) || (spec && strcasecmp(attr->spec, spec))) { /* - * Nope... + * Nope, reset the current pointer to the end of the array... */ - ppd->cur_attr = -1; + cupsArrayIndex(ppd->sorted_attrs, cupsArrayCount(ppd->sorted_attrs)); + return (NULL); } @@ -175,10 +124,10 @@ ppdFindNextAttr(ppd_file_t *ppd, /* I - PPD file data */ * Return the next attribute's value... */ - return (*match); + return (attr); } /* - * End of "$Id: attr.c 4785 2005-10-13 19:39:05Z mike $". + * End of "$Id: attr.c 5119 2006-02-16 15:52:06Z mike $". */ |