]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/filter.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / filter.c
index 92d68f8626f0e67a0aee4be5788eead424b0b871..bb63900726cdc6690b84714369386669c0089921 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: filter.c 5196 2006-02-27 21:23:00Z mike $"
+ * "$Id: filter.c 5493 2006-05-05 16:33:57Z mike $"
  *
  *   File type conversion routines for the Common UNIX Printing System (CUPS).
  *
@@ -60,6 +60,7 @@ typedef struct _mime_typelist_s               /**** List of source types ****/
  */
 
 static int             compare_filters(mime_filter_t *, mime_filter_t *);
+static int             compare_srcs(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);
@@ -167,6 +168,23 @@ mimeFilter(mime_t      *mime,              /* I - MIME database */
   if (!mime || !src || !dst)
     return (NULL);
 
+ /*
+  * (Re)build the source lookup array as needed...
+  */
+
+  if (!mime->srcs)
+  {
+    mime_filter_t      *current;       /* Current filter */
+
+
+    mime->srcs = cupsArrayNew((cups_array_func_t)compare_srcs, NULL);
+
+    for (current = mimeFirstFilter(mime);
+         current;
+        current = mimeNextFilter(mime))
+      cupsArrayAdd(mime->srcs, current);
+  }
+
  /*
   * Find the filters...
   */
@@ -195,6 +213,24 @@ compare_filters(mime_filter_t *f0, /* I - First filter */
 }
 
 
+/*
+ * 'compare_srcs()' - Compare two srcs...
+ */
+
+static int                             /* O - Comparison result */
+compare_srcs(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)
+    i = strcmp(f0->src->type, f1->src->type);
+
+  return (i);
+}
+
+
 /*
  * 'find_filters()' - Find the filters to convert from one type to another.
  */
@@ -210,7 +246,8 @@ find_filters(mime_t           *mime,        /* I - MIME database */
                        mincost;        /* Current minimum */
   cups_array_t         *temp,          /* Temporary filter */
                        *mintemp;       /* Current minimum */
-  mime_filter_t                *current;       /* Current filter */
+  mime_filter_t                *current,       /* Current filter */
+                       srckey;         /* Source type key */
   _mime_typelist_t     listnode,       /* New list node */
                        *listptr;       /* Pointer in list */
 
@@ -238,6 +275,9 @@ find_filters(mime_t           *mime,        /* I - MIME database */
 
     mincost = current->cost;
 
+    if (!cost)
+      return (mintemp);
+
     DEBUG_puts("    Found direct filter:");
     DEBUG_printf(("    %s (cost=%d)\n", current->filter, mincost));
   }
@@ -261,58 +301,67 @@ find_filters(mime_t           *mime,      /* I - MIME database */
   * OK, now look for filters from the source type to any other type...
   */
 
-  for (current = (mime_filter_t *)cupsArrayFirst(mime->filters);
-       current;
-       current = (mime_filter_t *)cupsArrayNext(mime->filters))
-    if (current->src == src)
-    {
-     /*
-      * See if we have already tried the destination type as a source
-      * type (this avoids extra filter looping...)
-      */
+  srckey.src = src;
 
-      for (listptr = list; listptr; listptr = listptr->next)
-        if (current->dst == listptr->src)
-         break;
+  for (current = (mime_filter_t *)cupsArrayFind(mime->srcs, &srckey);
+       current && current->src == src;
+       current = (mime_filter_t *)cupsArrayNext(mime->srcs))
+  {
+   /*
+    * See if we have already tried the destination type as a source
+    * type (this avoids extra filter looping...)
+    */
 
-      if (listptr)
-        continue;
+    mime_type_t *current_dst;          /* Current destination type */
 
-     /*
-      * See if we have any filters that can convert from the destination type
-      * of this filter to the final type...
-      */
 
-      listnode.src = current->src;
+    for (listptr = list, current_dst = current->dst;
+        listptr;
+        listptr = listptr->next)
+      if (current_dst == listptr->src)
+       break;
+
+    if (listptr)
+      continue;
 
-      cupsArraySave(mime->filters);
-      temp = find_filters(mime, current->dst, dst, &tempcost, &listnode);
-      cupsArrayRestore(mime->filters);
+   /*
+    * See if we have any filters that can convert from the destination type
+    * of this filter to the final type...
+    */
+
+    listnode.src = current->src;
 
-      if (!temp)
-        continue;
+    cupsArraySave(mime->srcs);
+    temp = find_filters(mime, current->dst, dst, &tempcost, &listnode);
+    cupsArrayRestore(mime->srcs);
+
+    if (!temp)
+      continue;
+
+    if (!cost)
+      return (temp);
+
+   /*
+    * Found a match; see if this one is less costly than the last (if
+    * any...)
+    */
+
+    if (tempcost < mincost)
+    {
+      cupsArrayDelete(mintemp);
 
      /*
-      * Found a match; see if this one is less costly than the last (if
-      * any...)
+      * Hey, we got a match!  Add the current filter to the beginning of the
+      * filter list...
       */
 
-      if (tempcost < mincost)
-      {
-        cupsArrayDelete(mintemp);
-
-       /*
-       * Hey, we got a match!  Add the current filter to the beginning of the
-       * filter list...
-       */
-
-        mintemp = temp;
-       mincost = tempcost + current->cost;
-       cupsArrayInsert(mintemp, current);
-      }
-      else
-        cupsArrayDelete(temp);
+      mintemp = temp;
+      mincost = tempcost + current->cost;
+      cupsArrayInsert(mintemp, current);
     }
+    else
+      cupsArrayDelete(temp);
+  }
 
   if (mintemp)
   {
@@ -360,5 +409,5 @@ lookup(mime_t      *mime,           /* I - MIME database */
 
 
 /*
- * End of "$Id: filter.c 5196 2006-02-27 21:23:00Z mike $".
+ * End of "$Id: filter.c 5493 2006-05-05 16:33:57Z mike $".
  */