1 /* test-mime.c - Test for the mime type sniffing features of GNOME
2 Virtual File System Library
4 Copyright (C) 2000 Eazel
6 The Gnome Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The Gnome Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the Gnome Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Author: Pavel Cisler <pavel@eazel.com>
25 #include <bonobo-activation/bonobo-activation.h>
26 #include <libgnomevfs/gnome-vfs-init.h>
27 #include <libgnomevfs/gnome-vfs-mime-magic.h>
28 #include <libgnomevfs/gnome-vfs-mime-utils.h>
29 #include <libgnomevfs/gnome-vfs-mime-info.h>
30 #include <libgnomevfs/gnome-vfs-mime.h>
31 #include <libgnomevfs/gnome-vfs-utils.h>
38 #include <glib/gstrfuncs.h>
39 #include <glib/gutils.h>
42 is_good_scheme_char (char c)
44 return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
48 is_uri (const char *str)
52 if (! g_ascii_isalpha (*str)) {
57 while (is_good_scheme_char (*p)) {
60 return *p == ':' && strchr (p, '/') != NULL;
64 main (int argc, char **argv)
72 const char *table_path;
86 if (!gnome_vfs_init ()) {
87 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
91 if (argc == 1 || strcmp (argv[1], "--help") == 0) {
92 fprintf (stderr, "Usage: %s [--magicOnly | --suffixOnly] [--dumpTable] "
93 " [--loadTable <table path>] fileToCheck1 [fileToCheck2 ...] \n", *argv);
99 for (; *argv; argv++) {
100 if (strcmp (*argv, "--magicOnly") == 0) {
102 } else if (strcmp (*argv, "--suffixOnly") == 0) {
104 } else if (strcmp (*argv, "--dumpTable") == 0) {
106 } else if (strcmp (*argv, "--speedTest") == 0) {
108 } else if (strcmp (*argv, "--loadTable") == 0) {
111 fprintf (stderr, "Table path expected.\n");
115 if (stat(table_path, &tmp) != 0) {
116 fprintf (stderr, "Table path %s not found.\n", table_path);
125 if (table_path != NULL) {
126 gnome_vfs_mime_test_get_magic_table (table_path);
130 gnome_vfs_mime_dump_magic_table ();
134 timer = g_timer_new ();
135 g_timer_start (timer);
136 for (i = 0; i < 100; i++) {
137 gnome_vfs_mime_info_reload ();
139 fprintf (stderr, "Mime reload took %g(ms)\n",
140 g_timer_elapsed (timer, NULL) * 10.0);
143 for (; *argv != NULL; argv++) {
144 uri_string = g_strdup (*argv);
145 if (is_uri (uri_string)) {
146 uri = gnome_vfs_uri_new (*argv);
151 if (uri_string[0] == '/') {
154 curdir = g_get_current_dir ();
155 path = g_strconcat (curdir, "/", uri_string, NULL);
159 uri_string = gnome_vfs_get_uri_from_local_path (path);
161 uri = gnome_vfs_uri_new (uri_string);
164 printf ("%s is neither a full URI nor an absolute filename\n", *argv);
169 result = gnome_vfs_get_mime_type_from_file_data (uri);
170 } else if (suffix_only) {
171 result = gnome_vfs_get_mime_type_from_uri (uri);
173 result = gnome_vfs_get_mime_type (uri_string);
176 printf ("looks like %s is %s\n", *argv, result);
177 gnome_vfs_uri_unref (uri);
180 return bonobo_activation_debug_shutdown ();