]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add performance testing to MIME test program - basically type all of the
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 2 Feb 2006 15:55:08 +0000 (15:55 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Thu, 2 Feb 2006 15:55:08 +0000 (15:55 +0000)
source files in the CUPS tree and figure out how to convert to
application/vnd.cups-postscript.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5050 7a7537e8-13f0-0310-91df-b6672ffda945

scheduler/testmime.c

index b19546885e914f446bee438a232ec1ce8032c6fc..e0d3e0076f8050fa50732f145d3d85166280369b 100644 (file)
@@ -23,7 +23,9 @@
  *
  * Contents:
  *
- *   main() - Main entry for the test program.
+ *   main()        - Main entry for the test program.
+ *   print_rules() - Print the rules for a file type...
+ *   type_dir()    - Show the MIME types for a given directory.
  */
 
 /*
 #include <stdlib.h>
 #include <cups/string.h>
 #include "mime.h"
+#include <cups/dir.h>
 
 
 /*
  * Local functions...
  */
 
-static void print_rules(mime_magic_t *rules);
+static void    print_rules(mime_magic_t *rules);
+static void    type_dir(mime_t *mime, const char *dirname);
 
 
 /*
@@ -153,6 +157,8 @@ main(int  argc,                             /* I - Number of command-line args */
              filter->src->super, filter->src->type,
             filter->dst->super, filter->dst->type,
             filter->filter, filter->cost);
+
+    type_dir(mime, "..");
   }
 
   return (0);
@@ -247,6 +253,77 @@ print_rules(mime_magic_t *rules)   /* I - Rules to print */
 }
 
 
+/*
+ * 'type_dir()' - Show the MIME types for a given directory.
+ */
+
+static void
+type_dir(mime_t     *mime,             /* I - MIME database */
+         const char *dirname)          /* I - Directory */
+{
+  cups_dir_t   *dir;                   /* Directory */
+  cups_dentry_t        *dent;                  /* Directory entry */
+  char         filename[1024];         /* File to type */
+  mime_type_t  *filetype;              /* File type */
+  int          compression;            /* Compressed file? */
+  mime_type_t  *pstype;                /* application/vnd.cups-postscript */
+  cups_array_t *filters;               /* Filters to pstype */
+  mime_filter_t        *filter;                /* Current filter */
+  int          cost;                   /* Filter cost */
+
+
+  dir = cupsDirOpen(dirname);
+  if (!dir)
+    return;
+
+  pstype = mimeType(mime, "application", "vnd.cups-postscript");
+
+  while ((dent = cupsDirRead(dir)) != NULL)
+  {
+    snprintf(filename, sizeof(filename), "%s/%s", dirname, dent->filename);
+
+    if (S_ISDIR(dent->fileinfo.st_mode))
+      type_dir(mime, filename);
+
+    if (!S_ISREG(dent->fileinfo.st_mode))
+      continue;
+
+    filetype = mimeFileType(mime, filename, &compression);
+
+    if (filetype)
+    {
+      printf("%s: %s/%s%s\n", filename, filetype->super, filetype->type,
+             compression ? " (compressed)" : "");
+
+      filters = mimeFilter(mime, filetype, pstype, &cost, 10);
+
+      if (!filters)
+       puts("    No filters to convert application/vnd.cups-postscript.");
+      else
+      {
+        printf("    Filter cost = %d\n", cost);
+
+        filter = (mime_filter_t *)cupsArrayFirst(filters);
+       printf("    %s", filter->filter);
+
+       for (filter = (mime_filter_t *)cupsArrayNext(filters);
+            filter;
+            filter = (mime_filter_t *)cupsArrayNext(filters))
+         printf(" | %s", filter->filter);
+
+        putchar('\n');
+
+        cupsArrayDelete(filters);
+      }
+    }
+    else
+      printf("%s: unknown%s\n", filename, compression ? " (compressed)" : "");
+  }
+
+  cupsDirClose(dir);
+}
+
+
 /*
  * End of "$Id$".
  */