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 /scheduler/filter.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 'scheduler/filter.c')
-rw-r--r-- | scheduler/filter.c | 140 |
1 files changed, 102 insertions, 38 deletions
diff --git a/scheduler/filter.c b/scheduler/filter.c index c783b5db7..f315910af 100644 --- a/scheduler/filter.c +++ b/scheduler/filter.c @@ -1,5 +1,5 @@ /* - * "$Id: filter.c 4970 2006-01-24 14:05:45Z mike $" + * "$Id: filter.c 5083 2006-02-06 02:57:43Z mike $" * * File type conversion routines for the Common UNIX Printing System (CUPS). * @@ -24,8 +24,10 @@ * Contents: * * mimeAddFilter() - Add a filter to the current MIME database. - * mimeFilter() - Find the fastest way to convert from one type to another. + * mimeFilter() - Find the fastest way to convert from one type to + * another. * compare_filters() - Compare two filters... + * find_filters() - Find the filters to convert from one type to another. * lookup() - Lookup a filter... */ @@ -43,10 +45,24 @@ /* + * Local types... + */ + +typedef struct _mime_typelist_s /**** List of source types ****/ +{ + struct _mime_typelist_s *next; /* Next source type */ + mime_type_t *src; /* Source type */ +} _mime_typelist_t; + + +/* * Local functions... */ static int compare_filters(mime_filter_t *, mime_filter_t *); +static cups_array_t *find_filters(mime_t *mime, mime_type_t *src, + mime_type_t *dst, int *cost, + _mime_typelist_t *visited); static mime_filter_t *lookup(mime_t *, mime_type_t *, mime_type_t *); @@ -132,33 +148,78 @@ cups_array_t * /* O - Array of filters to run */ mimeFilter(mime_t *mime, /* I - MIME database */ mime_type_t *src, /* I - Source file type */ mime_type_t *dst, /* I - Destination file type */ - int *cost, /* O - Cost of filters */ - int max_depth) /* I - Maximum depth of search */ + int *cost) /* O - Cost of filters */ { - int tempcost, /* Temporary cost */ - mincost; /* Current minimum */ - cups_array_t *temp, /* Temporary filter */ - *mintemp; /* Current minimum */ - mime_filter_t *current; /* Current filter */ - - /* * Range-check the input... */ DEBUG_printf(("mimeFilter(mime=%p, src=%p(%s/%s), dst=%p(%s/%s), " - "cost=%p(%d), max_depth=%d)\n", + "cost=%p(%d))\n", mime, src, src ? src->super : "?", src ? src->type : "?", dst, dst ? dst->super : "?", dst ? dst->type : "?", - cost, cost ? *cost : 0, max_depth)); + cost, cost ? *cost : 0)); + if (cost) *cost = 0; - if (!mime || !src || !dst || !cost || max_depth <= 0) + if (!mime || !src || !dst) return (NULL); /* + * Find the filters... + */ + + return (find_filters(mime, src, dst, cost, NULL)); +} + + +/* + * 'compare_filters()' - Compare two filters... + */ + +static int /* O - Comparison result */ +compare_filters(mime_filter_t *f0, /* I - First filter */ + mime_filter_t *f1) /* I - Second filter */ +{ + int i; /* Result of comparison */ + + + if ((i = strcmp(f0->src->super, f1->src->super)) == 0) + if ((i = strcmp(f0->src->type, f1->src->type)) == 0) + if ((i = strcmp(f0->dst->super, f1->dst->super)) == 0) + i = strcmp(f0->dst->type, f1->dst->type); + + return (i); +} + + +/* + * 'find_filters()' - Find the filters to convert from one type to another. + */ + +cups_array_t * /* O - Array of filters to run */ +find_filters(mime_t *mime, /* I - MIME database */ + mime_type_t *src, /* I - Source file type */ + mime_type_t *dst, /* I - Destination file type */ + int *cost, /* O - Cost of filters */ + _mime_typelist_t *list) /* I - Source types we've used */ +{ + int tempcost, /* Temporary cost */ + mincost; /* Current minimum */ + cups_array_t *temp, /* Temporary filter */ + *mintemp; /* Current minimum */ + mime_filter_t *current; /* Current filter */ + _mime_typelist_t listnode, /* New list node */ + *listptr; /* Pointer in list */ + + + DEBUG_printf(("find_filters(mime=%p, src=%p(%s/%s), dst=%p(%s/%s), " + "cost=%p, list=%p)\n", mime, src, src->super, src->type, + dst, dst->super, dst->type, cost, list)); + + /* * See if there is a filter that can convert the files directly... */ @@ -168,6 +229,8 @@ mimeFilter(mime_t *mime, /* I - MIME database */ * Got a direct filter! */ + DEBUG_puts("Direct filter found!"); + if ((mintemp = cupsArrayNew(NULL, NULL)) == NULL) return (NULL); @@ -176,7 +239,7 @@ mimeFilter(mime_t *mime, /* I - MIME database */ mincost = current->cost; DEBUG_puts(" Found direct filter:"); - DEBUG_printf((" %s (cost=%d)\n", mintemp->filter, mincost)); + DEBUG_printf((" %s (cost=%d)\n", current->filter, mincost)); } else { @@ -189,6 +252,12 @@ mimeFilter(mime_t *mime, /* I - MIME database */ } /* + * Initialize this node in the type list... + */ + + listnode.next = list; + + /* * OK, now look for filters from the source type to any other type... */ @@ -198,12 +267,26 @@ mimeFilter(mime_t *mime, /* I - MIME database */ if (current->src == src) { /* + * See if we have already tried the destination type as a source + * type (this avoids extra filter looping...) + */ + + for (listptr = list; listptr; listptr = listptr->next) + if (current->dst == listptr->src) + break; + + if (listptr) + continue; + + /* * See if we have any filters that can convert from the destination type * of this filter to the final type... */ + listnode.src = current->src; + cupsArraySave(mime->filters); - temp = mimeFilter(mime, current->dst, dst, &tempcost, max_depth - 1); + temp = find_filters(mime, current->dst, dst, &tempcost, &listnode); cupsArrayRestore(mime->filters); if (!temp) @@ -245,7 +328,8 @@ mimeFilter(mime_t *mime, /* I - MIME database */ printf(" %s\n", current->filter); #endif /* DEBUG */ - *cost = mincost; + if (cost) + *cost = mincost; return (mintemp); } @@ -257,26 +341,6 @@ mimeFilter(mime_t *mime, /* I - MIME database */ /* - * 'compare_filters()' - Compare two filters... - */ - -static int /* O - Comparison result */ -compare_filters(mime_filter_t *f0, /* I - First filter */ - mime_filter_t *f1) /* I - Second filter */ -{ - int i; /* Result of comparison */ - - - if ((i = strcmp(f0->src->super, f1->src->super)) == 0) - if ((i = strcmp(f0->src->type, f1->src->type)) == 0) - if ((i = strcmp(f0->dst->super, f1->dst->super)) == 0) - i = strcmp(f0->dst->type, f1->dst->type); - - return (i); -} - - -/* * 'lookup()' - Lookup a filter... */ @@ -296,5 +360,5 @@ lookup(mime_t *mime, /* I - MIME database */ /* - * End of "$Id: filter.c 4970 2006-01-24 14:05:45Z mike $". + * End of "$Id: filter.c 5083 2006-02-06 02:57:43Z mike $". */ |