~ubuntu-branches/ubuntu/jaunty/cups/jaunty

« back to all changes in this revision

Viewing changes to debian/patches/search_mime_files_in_usr_share.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt, Till Kamppeter, Martin Pitt
  • Date: 2009-02-15 18:39:03 UTC
  • mfrom: (6.1.30 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090215183903-i0nhvqyqj4vyn52a
Tags: 1.3.9-13
[ Till Kamppeter ]
* debian/local/filters/pdf-filters/filter/imagetopdf.c: Added support for
  the new "fit-to-page" option (new, more intuitive name for "fitplot").
* debian/filters/pstopdf: Only apply paper size if the "fitplot" or the
  "fit-to-page" option is set.
* debian/local/filters/cpdftocps: Only the last digit of the number of
  copies was used (LP: #309314).
* debian/local/filters/pdf-filters/pdftopdf/pdftopdf.cxx: Do not preceed the
  PDF output with a newline (LP: #303691). Only impose the page size from
  the PPD file to all pages if the "fitplot" or the "fit-to-page" option is 
  set. This prevented from automatic paper tray switching to the correct paper
  sizes when a multiple-page-size document is printed (partial fix for
  LP: #310575).
* debian/patches/pdftops-cups-1.4.dpatch: Updated from CUPS 1.4 SVN. Contains
  fixes for multiple-page-size document printing (partial fix for
  LP: #310575).
* debian/patches/pdftops-dont_fail_on_cancel.dpatch: Removed, should be
  fixed in the new upstream version of pdftops.

[ Martin Pitt ]
* debian/patches/pdftops-cups-1.4.dpatch: Add definition of
  HAVE_PDFTOPS and CUPS_PDFTOPS, so that the filter actually gets
  again built with pdftops support. (Fixes Till's change from above).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
 
## search_mime_files_in_usr_share.dpatch by  <martin.pitt@ubuntu.com>
 
2
## search_mime_files_in_usr_share.dpatch by  <till.kamppeter@gmail.com>
3
3
##
4
 
## All lines beginning with `## DP:' are a description of the patch.
5
 
## DP: http://www.cups.org/str.php?L2719
 
4
## DP: http://www.cups.org/str.php?L2719, svn trunk r7670
6
5
 
7
6
@DPATCH@
8
 
diff -urNad trunk~/scheduler/conf.c trunk/scheduler/conf.c
9
 
--- trunk~/scheduler/conf.c     2008-03-16 14:22:22.000000000 +0100
10
 
+++ trunk/scheduler/conf.c      2008-03-16 14:23:33.000000000 +0100
 
7
diff -urNad cups-1.3.8~/scheduler/conf.c cups-1.3.8/scheduler/conf.c
 
8
--- cups-1.3.8~/scheduler/conf.c        2008-08-06 22:31:38.000000000 +0200
 
9
+++ cups-1.3.8/scheduler/conf.c 2008-08-06 22:32:28.000000000 +0200
11
10
@@ -342,6 +342,7 @@
12
11
   cups_file_t  *fp;                    /* Configuration file */
13
12
   int          status;                 /* Return status */
14
13
   char         temp[1024],             /* Temporary buffer */
15
 
+               temp2[1024],            /* Temporary buffer */
 
14
+               mimedir[1024],          /* MIME directory */
16
15
                *slash;                 /* Directory separator */
17
16
   cups_lang_t  *language;              /* Language */
18
17
   struct passwd        *user;                  /* Default user */
19
 
@@ -1073,11 +1074,21 @@
20
 
 
21
 
    /*
22
 
     * Read the MIME type and conversion database...
23
 
+    * Files are read from DataDir/mime by default, and can be overridden in
24
 
+    * ServerRoot.
 
18
@@ -1100,20 +1101,25 @@
25
19
     */
26
20
 
27
21
     snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
 
22
+    snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
28
23
 
29
24
-    MimeDatabase = mimeLoad(ServerRoot, temp);
30
 
+    snprintf(temp2, sizeof(temp2), "%s/mime", DataDir);
31
 
+    MimeDatabase = mimeLoad(temp2, temp);
32
 
+    if (!MimeDatabase)
33
 
+    {
34
 
+      cupsdLogMessage(CUPSD_LOG_INFO,
35
 
+                      "Unable to load MIME database from \'%s\'!", temp2);
36
 
+    }
37
 
+
38
 
+    MimeDatabase = mimeMerge(MimeDatabase, ServerRoot, temp);
 
25
+    MimeDatabase = mimeLoadTypes(NULL, mimedir);
 
26
+    MimeDatabase = mimeLoadTypes(MimeDatabase, ServerRoot);
 
27
+    MimeDatabase = mimeLoadFilters(MimeDatabase, mimedir, temp);
 
28
+    MimeDatabase = mimeLoadFilters(MimeDatabase, ServerRoot, temp);
39
29
 
40
30
     if (!MimeDatabase)
41
31
     {
 
32
       cupsdLogMessage(CUPSD_LOG_EMERG,
 
33
-                      "Unable to load MIME database from \'%s\'!", ServerRoot);
 
34
+                      "Unable to load MIME database from \"%s\" or \"%s\"!",
 
35
+                     mimedir, ServerRoot);
 
36
       exit(errno);
 
37
     }
 
38
 
 
39
     cupsdLogMessage(CUPSD_LOG_INFO,
 
40
-                    "Loaded MIME database from \'%s\': %d types, %d filters...",
 
41
-                    ServerRoot, mimeNumTypes(MimeDatabase),
 
42
-                   mimeNumFilters(MimeDatabase));
 
43
+                    "Loaded MIME database from \"%s\" and \"%s\": %d types, "
 
44
+                   "%d filters...", mimedir, ServerRoot,
 
45
+                   mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
 
46
 
 
47
    /*
 
48
     * Create a list of MIME types for the document-format-supported
 
49
--- cups-1.3.8~/scheduler/cupsfilter.c  2008-01-16 23:20:33.000000000 +0100
 
50
+++ cups-1.3.8/scheduler/cupsfilter.c   2008-08-06 22:32:38.000000000 +0200
 
51
@@ -103,6 +103,7 @@
 
52
   int          compression;            /* Compression of file */
 
53
   int          cost;                   /* Cost of filters */
 
54
   mime_t       *mime;                  /* MIME database */
 
55
+  char         mimedir[1024];          /* MIME directory */
 
56
   char         *infile,                /* File to filter */
 
57
                *outfile;               /* File to create */
 
58
   char         cupsdconf[1024];        /* cupsd.conf file */
 
59
@@ -331,11 +332,19 @@
 
60
   if (read_cupsd_conf(cupsdconf))
 
61
     return (1);
 
62
 
 
63
-  if ((mime = mimeLoad(ServerRoot, Path)) == NULL)
 
64
+  snprintf(mimedir, sizeof(mimedir), "%s/mime", DataDir);
 
65
+
 
66
+  mime = mimeLoadTypes(NULL, mimedir);
 
67
+  mime = mimeLoadTypes(mime, ServerRoot);
 
68
+  mime = mimeLoadFilters(mime, mimedir, Path);
 
69
+  mime = mimeLoadFilters(mime, ServerRoot, Path);
 
70
+
 
71
+  if (!mime)
 
72
   {
 
73
     _cupsLangPrintf(stderr,
 
74
-                    _("%s: Unable to read MIME database from \"%s\"!\n"),
 
75
-                   command, ServerRoot);
 
76
+                    _("%s: Unable to read MIME database from \"%s\" or "
 
77
+                     "\"%s\"!\n"),
 
78
+                   command, mimedir, ServerRoot);
 
79
     return (1);
 
80
   }
 
81
 
 
82
--- cups-1.3.8~/scheduler/mime.c        2008-01-17 00:42:35.000000000 +0100
 
83
+++ cups-1.3.8/scheduler/mime.c 2008-08-06 22:32:48.000000000 +0200
 
84
@@ -72,6 +72,7 @@
 
85
                           const char *filterpath,
 
86
                           cups_array_t *filtercache);
 
87
 static void    load_types(mime_t *mime, const char *filename);
 
88
+static mime_t  *mime_new(void);
 
89
 
 
90
 
 
91
 /*
 
92
@@ -192,73 +193,50 @@
 
93
 
 
94
 /*
 
95
  * 'mimeLoad()' - Create a new MIME database from disk.
 
96
+ *
 
97
+ * This function uses @link mimeLoadFilters@ and @link mimeLoadTypes@ to
 
98
+ * create a MIME database from a single directory.
 
99
  */
 
100
 
 
101
 mime_t *                               /* O - New MIME database */
 
102
 mimeLoad(const char *pathname,         /* I - Directory to load */
 
103
          const char *filterpath)       /* I - Directory to load */
 
104
 {
 
105
-  return (mimeMerge(NULL, pathname, filterpath));
 
106
+  return (mimeLoadFilters(mimeLoadTypes(NULL, pathname), pathname, filterpath));
 
107
 }
 
108
 
 
109
 
 
110
 /*
 
111
- * 'mimeMerge()' - Merge a MIME database from disk with the current one.
 
112
+ * 'mimeLoadFilters()' - Load filter definitions from disk.
 
113
+ *
 
114
+ * This function loads all of the .convs files from the specified directory.
 
115
+ * Use @link mimeLoadTypes@ to load all types before you load the filters.
 
116
  */
 
117
 
 
118
-mime_t *                               /* O - Updated MIME database */
 
119
-mimeMerge(mime_t     *mime,            /* I - MIME database to add to */
 
120
-          const char *pathname,                /* I - Directory to load */
 
121
-          const char *filterpath)      /* I - Directory to load */
 
122
+mime_t *                               /* O - MIME database */
 
123
+mimeLoadFilters(mime_t     *mime,      /* I - MIME database */
 
124
+                const char *pathname,  /* I - Directory to load from */
 
125
+                const char *filterpath)        /* I - Default filter program directory */
 
126
 {
 
127
   cups_dir_t   *dir;                   /* Directory */
 
128
   cups_dentry_t        *dent;                  /* Directory entry */
 
129
-  char         filename[1024];         /* Full filename of types/converts file */
 
130
+  char         filename[1024];         /* Full filename of .convs file */
 
131
   cups_array_t *filtercache;           /* Filter cache */
 
132
 
 
133
 
 
134
  /*
 
135
-  * First open the directory specified by pathname...  Return NULL if nothing
 
136
-  * was read or if the pathname is NULL...
 
137
-  */
 
138
-
 
139
-  if (!pathname)
 
140
-    return (NULL);
 
141
-
 
142
-  if ((dir = cupsDirOpen(pathname)) == NULL)
 
143
-    return (NULL);
 
144
-
 
145
- /*
 
146
-  * If "mime" is NULL, make a new, blank database...
 
147
+  * Range check input...
 
148
   */
 
149
 
 
150
-  if (!mime)
 
151
-    mime = mimeNew();
 
152
-  if (!mime)
 
153
-  {
 
154
-    cupsDirClose(dir);
 
155
-    return (NULL);
 
156
-  }
 
157
+  if (!mime || !pathname || !filterpath)
 
158
+    return (mime);
 
159
 
 
160
  /*
 
161
-  * Read all the .types files...
 
162
+  * Then open the directory specified by pathname...
 
163
   */
 
164
 
 
165
-  while ((dent = cupsDirRead(dir)) != NULL)
 
166
-  {
 
167
-    if (strlen(dent->filename) > 6 &&
 
168
-        !strcmp(dent->filename + strlen(dent->filename) - 6, ".types"))
 
169
-    {
 
170
-     /*
 
171
-      * Load a mime.types file...
 
172
-      */
 
173
-
 
174
-      snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename);
 
175
-      load_types(mime, filename);
 
176
-    }
 
177
-  }
 
178
-
 
179
-  cupsDirRewind(dir);
 
180
+  if ((dir = cupsDirOpen(pathname)) == NULL)
 
181
+    return (mime);
 
182
 
 
183
  /*
 
184
   * Read all the .convs files...
 
185
@@ -289,13 +267,62 @@
 
186
 
 
187
 
 
188
 /*
 
189
- * 'mimeNew()' - Create a new, empty MIME database.
 
190
+ * 'mimeLoadTypes()' - Load type definitions from disk.
 
191
+ *
 
192
+ * This function loads all of the .types files from the specified directory.
 
193
+ * Use @link mimeLoadFilters@ to load all filters after you load the types.
 
194
  */
 
195
 
 
196
 mime_t *                               /* O - MIME database */
 
197
-mimeNew(void)
 
198
+mimeLoadTypes(mime_t     *mime,                /* I - MIME database or @code NULL@ to create a new one */
 
199
+              const char *pathname)    /* I - Directory to load from */
 
200
 {
 
201
-  return ((mime_t *)calloc(1, sizeof(mime_t)));
 
202
+  cups_dir_t   *dir;                   /* Directory */
 
203
+  cups_dentry_t        *dent;                  /* Directory entry */
 
204
+  char         filename[1024];         /* Full filename of .types file */
 
205
+
 
206
+
 
207
+ /*
 
208
+  * First open the directory specified by pathname...
 
209
+  */
 
210
+
 
211
+  if ((dir = cupsDirOpen(pathname)) == NULL)
 
212
+    return (mime);
 
213
+
 
214
+ /*
 
215
+  * If "mime" is NULL, make a new, empty database...
 
216
+  */
 
217
+
 
218
+  if (!mime)
 
219
+    mime = mime_new();
 
220
+
 
221
+  if (!mime)
 
222
+  {
 
223
+    cupsDirClose(dir);
 
224
+    return (NULL);
 
225
+  }
 
226
+
 
227
+ /*
 
228
+  * Read all the .types files...
 
229
+  */
 
230
+
 
231
+  while ((dent = cupsDirRead(dir)) != NULL)
 
232
+  {
 
233
+    if (strlen(dent->filename) > 6 &&
 
234
+        !strcmp(dent->filename + strlen(dent->filename) - 6, ".types"))
 
235
+    {
 
236
+     /*
 
237
+      * Load a mime.types file...
 
238
+      */
 
239
+
 
240
+      snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename);
 
241
+      load_types(mime, filename);
 
242
+    }
 
243
+  }
 
244
+
 
245
+  cupsDirClose(dir);
 
246
+
 
247
+  return (mime);
 
248
 }
 
249
 
 
250
 
 
251
@@ -474,6 +501,10 @@
 
252
   int          cost;                   /* Cost of filter */
 
253
 
 
254
 
 
255
+  DEBUG_printf(("load_convs(mime=%p, filename=\"%s\", filterpath=\"%s\", "
 
256
+                "filtercache=%p)\n", mime, filename, filterpath, filtercache));
 
257
+
 
258
+
 
259
  /*
 
260
   * First try to open the file...
 
261
   */
 
262
@@ -481,8 +512,6 @@
 
263
   if ((fp = cupsFileOpen(filename, "r")) == NULL)
 
264
     return;
 
265
 
 
266
-  DEBUG_printf(("\"%s\":\n", filename));
 
267
-
 
268
  /*
 
269
   * Then read each line from the file, skipping any comments in the file...
 
270
   */
 
271
@@ -493,8 +522,6 @@
 
272
     * Skip blank lines and lines starting with a #...
 
273
     */
 
274
 
 
275
-    DEBUG_puts(line);
 
276
-
 
277
     if (!line[0] || line[0] == '#')
 
278
       continue;
 
279
 
 
280
@@ -544,7 +571,8 @@
 
281
 
 
282
     if ((dsttype = mimeType(mime, super, type)) == NULL)
 
283
     {
 
284
-      DEBUG_printf(("    Destination type %s/%s not found!\n", super, type));
 
285
+      DEBUG_printf(("load_convs: Destination type %s/%s not found!\n",
 
286
+                    super, type));
 
287
       continue;
 
288
     }
 
289
 
 
290
@@ -578,7 +606,8 @@
 
291
 
 
292
       if (!add_fcache(filtercache, filter, filterpath))
 
293
       {
 
294
-        DEBUG_printf(("    Filter %s not found in %s!\n", filter, filterpath)); 
 
295
+        DEBUG_printf(("load_convs: Filter %s not found in %s!\n", filter,
 
296
+                     filterpath)); 
 
297
         continue;
 
298
       }
 
299
     }
 
300
@@ -653,6 +682,8 @@
 
301
   mime_type_t  *typeptr;               /* New MIME type */
 
302
 
 
303
 
 
304
+  DEBUG_printf(("load_types(mime=%p, filename=\"%s\")\n", mime, filename));
 
305
+
 
306
  /*
 
307
   * First try to open the file...
 
308
   */
 
309
@@ -660,8 +691,6 @@
 
310
   if ((fp = cupsFileOpen(filename, "r")) == NULL)
 
311
     return;
 
312
 
 
313
-  DEBUG_printf(("\"%s\":\n", filename));
 
314
-
 
315
  /*
 
316
   * Then read each line from the file, skipping any comments in the file...
 
317
   */
 
318
@@ -672,8 +701,6 @@
 
319
     * Skip blank lines and lines starting with a #...
 
320
     */
 
321
 
 
322
-    DEBUG_puts(line);
 
323
-
 
324
     if (!line[0] || line[0] == '#')
 
325
       continue;
 
326
 
 
327
@@ -732,5 +759,16 @@
 
328
 
 
329
 
 
330
 /*
 
331
+ * 'mime_new()' - Create a new, empty MIME database.
 
332
+ */
 
333
+
 
334
+static mime_t *                                /* O - MIME database */
 
335
+mime_new(void)
 
336
+{
 
337
+  return ((mime_t *)calloc(1, sizeof(mime_t)));
 
338
+}
 
339
+
 
340
+
 
341
+/*
 
342
  * End of "$Id: mime.c 7224 2008-01-16 23:42:35Z mike $".
 
343
  */
 
344
--- cups-1.3.8~/scheduler/mime.h        2007-07-11 23:46:42.000000000 +0200
 
345
+++ cups-1.3.8/scheduler/mime.h 2008-08-06 22:32:51.000000000 +0200
 
346
@@ -3,7 +3,7 @@
 
347
  *
 
348
  *   MIME type/conversion database definitions for the Common UNIX Printing System (CUPS).
 
349
  *
 
350
- *   Copyright 2007 by Apple Inc.
 
351
+ *   Copyright 2007-2008 by Apple Inc.
 
352
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
 
353
  *
 
354
  *   These coded instructions, statements, and computer programs are the
 
355
@@ -86,6 +86,7 @@
 
356
 typedef struct _mime_type_s            /**** MIME Type Data ****/
 
357
 {
 
358
   mime_magic_t *rules;                 /* Rules used to detect this type */
 
359
+  int          priority;               /* Priority of this type */
 
360
   char         super[MIME_MAX_SUPER],  /* Super-type name ("image", "application", etc.) */
 
361
                type[MIME_MAX_TYPE];    /* Type name ("png", "postscript", etc.) */
 
362
 } mime_type_t;
 
363
@@ -112,9 +113,9 @@
 
364
 
 
365
 extern void            mimeDelete(mime_t *mime);
 
366
 extern mime_t          *mimeLoad(const char *pathname, const char *filterpath);
 
367
-extern mime_t          *mimeMerge(mime_t *mime, const char *pathname,
 
368
-                                  const char *filterpath);
 
369
-extern mime_t          *mimeNew(void);
 
370
+extern mime_t          *mimeLoadFilters(mime_t *mime, const char *pathname,
 
371
+                                        const char *filterpath);
 
372
+extern mime_t          *mimeLoadTypes(mime_t *mime, const char *pathname);
 
373
 
 
374
 extern mime_type_t     *mimeAddType(mime_t *mime, const char *super,
 
375
                                     const char *type);
 
376
--- cups-1.3.8~/scheduler/type.c        2008-07-12 00:48:49.000000000 +0200
 
377
+++ cups-1.3.8/scheduler/type.c 2008-08-06 22:33:06.000000000 +0200
 
378
@@ -3,7 +3,7 @@
 
379
  *
 
380
  *   MIME typing routines for the Common UNIX Printing System (CUPS).
 
381
  *
 
382
- *   Copyright 2007 by Apple Inc.
 
383
+ *   Copyright 2007-2008 by Apple Inc.
 
384
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
 
385
  *
 
386
  *   These coded instructions, statements, and computer programs are the
 
387
@@ -102,6 +102,7 @@
 
388
 
 
389
   strlcpy(temp->super, super, sizeof(temp->super));
 
390
   strcpy(temp->type, type);            /* Safe: temp->type is allocated */
 
391
+  temp->priority = 100;
 
392
 
 
393
   cupsArrayAdd(mime->types, temp);
 
394
 
 
395
@@ -156,7 +157,7 @@
 
396
   logic  = MIME_MAGIC_NOP;
 
397
   invert = 0;
 
398
 
 
399
-  DEBUG_printf(("%s/%s: %s\n", mt->super, mt->type, rule));
 
400
+  DEBUG_printf(("mimeAddTypeRule: %s/%s: %s\n", mt->super, mt->type, rule));
 
401
 
 
402
   while (*rule != '\0')
 
403
   {
 
404
@@ -165,13 +166,13 @@
 
405
 
 
406
     if (*rule == '(')
 
407
     {
 
408
-      DEBUG_puts("new parenthesis group");
 
409
+      DEBUG_puts("mimeAddTypeRule: New parenthesis group");
 
410
       logic = MIME_MAGIC_NOP;
 
411
       rule ++;
 
412
     }
 
413
     else if (*rule == ')')
 
414
     {
 
415
-      DEBUG_puts("close paren...");
 
416
+      DEBUG_puts("mimeAddTypeRule: Close paren...");
 
417
       if (current == NULL || current->parent == NULL)
 
418
         return (-1);
 
419
 
 
420
@@ -207,11 +208,12 @@
 
421
         current->prev   = NULL;
 
422
        current->parent = temp;
 
423
 
 
424
-        DEBUG_printf(("creating new AND group %p...\n", temp));
 
425
+        DEBUG_printf(("mimeAddTypeRule: Creating new AND group %p...\n", temp));
 
426
       }
 
427
       else
 
428
       {
 
429
-        DEBUG_printf(("setting group %p op to AND...\n", current->parent));
 
430
+        DEBUG_printf(("mimeAddTypeRule: Setting group %p op to AND...\n",
 
431
+                     current->parent));
 
432
         current->parent->op = MIME_MAGIC_AND;
 
433
       }
 
434
 
 
435
@@ -237,7 +239,8 @@
 
436
          if ((temp = calloc(1, sizeof(mime_magic_t))) == NULL)
 
437
            return (-1);
 
438
 
 
439
-          DEBUG_printf(("creating new AND group %p inside OR group\n", temp));
 
440
+          DEBUG_printf(("mimeAddTypeRule: Creating new AND group %p inside OR "
 
441
+                       "group\n", temp));
 
442
 
 
443
           while (current->prev != NULL)
 
444
          {
 
445
@@ -257,7 +260,7 @@
 
446
          * This isn't the top rule, so go up one level...
 
447
          */
 
448
 
 
449
-          DEBUG_puts("going up one level");
 
450
+          DEBUG_puts("mimeAddTypeRule: Going up one level");
 
451
          current = current->parent;
 
452
        }
 
453
       }
 
454
@@ -267,7 +270,7 @@
 
455
     }
 
456
     else if (*rule == '!')
 
457
     {
 
458
-      DEBUG_puts("NOT");
 
459
+      DEBUG_puts("mimeAddTypeRule: NOT");
 
460
       invert = 1;
 
461
       rule ++;
 
462
     }
 
463
@@ -395,6 +398,11 @@
 
464
          op = MIME_MAGIC_LOCALE;
 
465
        else if (!strcmp(name, "contains"))
 
466
          op = MIME_MAGIC_CONTAINS;
 
467
+       else if (!strcmp(name, "priority") && num_values == 1)
 
468
+       {
 
469
+         mt->priority = atoi(value[0]);
 
470
+         continue;
 
471
+       }
 
472
        else
 
473
          return (-1);
 
474
       }
 
475
@@ -433,7 +441,8 @@
 
476
         * Add parenthetical grouping...
 
477
        */
 
478
 
 
479
-        DEBUG_printf(("making new OR group %p for parenthesis...\n", temp));
 
480
+        DEBUG_printf(("mimeAddTypeRule: Making new OR group %p for "
 
481
+                     "parenthesis...\n", temp));
 
482
 
 
483
         temp->op = MIME_MAGIC_OR;
 
484
 
 
485
@@ -446,8 +455,8 @@
 
486
         logic = MIME_MAGIC_OR;
 
487
       }
 
488
 
 
489
-      DEBUG_printf(("adding %p: %s, op = %d, logic = %d, invert = %d\n",
 
490
-                    temp, name, op, logic, invert));
 
491
+      DEBUG_printf(("mimeAddTypeRule: adding %p: %s, op=%d, logic=%d, "
 
492
+                    "invert=%d\n", temp, name, op, logic, invert));
 
493
 
 
494
      /*
 
495
       * Fill in data for the rule...
 
496
@@ -530,14 +539,12 @@
 
497
 {
 
498
   _mime_filebuf_t      fb;             /* File buffer */
 
499
   const char           *base;          /* Base filename of file */
 
500
-  mime_type_t          *type;          /* File type */
 
501
+  mime_type_t          *type,          /* File type */
 
502
+                       *best;          /* Best match */
 
503
 
 
504
 
 
505
   DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", filename=\"%s\", "
 
506
-                "compression=%p)\n",
 
507
-                mime, pathname ? pathname : "(nil)",
 
508
-               filename ? filename : "(nil)",
 
509
-               compression));
 
510
+                "compression=%p)\n", mime, pathname, filename, compression));
 
511
 
 
512
  /*
 
513
   * Range check input parameters...
 
514
@@ -576,11 +583,14 @@
 
515
   * Then check it against all known types...
 
516
   */
 
517
 
 
518
-  for (type = (mime_type_t *)cupsArrayFirst(mime->types);
 
519
+  for (type = (mime_type_t *)cupsArrayFirst(mime->types), best = NULL;
 
520
        type;
 
521
        type = (mime_type_t *)cupsArrayNext(mime->types))
 
522
     if (checkrules(base, &fb, type->rules))
 
523
-      break;
 
524
+    {
 
525
+      if (!best || type->priority > best->priority)
 
526
+        best = type;
 
527
+    }
 
528
 
 
529
  /*
 
530
   * Finally, close the file and return a match (if any)...
 
531
@@ -591,7 +601,7 @@
 
532
 
 
533
   cupsFileClose(fb.fp);
 
534
 
 
535
-  return (type);
 
536
+  return (best);
 
537
 }
 
538
 
 
539
 
 
540
@@ -791,7 +801,7 @@
 
541
          break;
 
542
 
 
543
       case MIME_MAGIC_STRING :
 
544
-          DEBUG_printf(("    string(%d, \"%s\")\n", rules->offset,
 
545
+          DEBUG_printf(("checkrules: string(%d, \"%s\")\n", rules->offset,
 
546
                        rules->value.stringv));
 
547
 
 
548
          /*
 
549
@@ -810,7 +820,7 @@
 
550
                                      sizeof(fb->buffer));
 
551
            fb->offset = rules->offset;
 
552
 
 
553
-            DEBUG_printf(("        loaded %d byte fb->buffer at %d, starts "
 
554
+            DEBUG_printf(("checkrules: loaded %d byte fb->buffer at %d, starts "
 
555
                          "with \"%c%c%c%c\"...\n",
 
556
                          fb->length, fb->offset, fb->buffer[0], fb->buffer[1],
 
557
                          fb->buffer[2], fb->buffer[3]));
 
558
@@ -826,7 +836,7 @@
 
559
          else
 
560
             result = (memcmp(fb->buffer + rules->offset - fb->offset,
 
561
                             rules->value.stringv, rules->length) == 0);
 
562
-          DEBUG_printf(("    result=%d\n", result));
 
563
+          DEBUG_printf(("checkrules: result=%d\n", result));
 
564
          break;
 
565
 
 
566
       case MIME_MAGIC_ISTRING :
 
567
@@ -1027,8 +1037,8 @@
 
568
     * the the rule set is false...
 
569
     */
 
570
 
 
571
-    DEBUG_printf(("    result of test %p (MIME_MAGIC_%s) is %d\n", rules,
 
572
-                  debug_tests[rules->op], result));
 
573
+    DEBUG_printf(("checkrules: result of test %p (MIME_MAGIC_%s) is %d\n",
 
574
+                  rules, debug_tests[rules->op], result));
 
575
 
 
576
     if ((result && logic == MIME_MAGIC_OR) ||
 
577
         (!result && logic == MIME_MAGIC_AND))