static void
do_dump (void)
{
	char *from;
	MateVFSHandle *from_handle;
	MateVFSResult  result;
	guint32         offset;

	from = get_fname ();

	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		return;

	for (offset = 0; 1; ) {
		MateVFSFileSize bytes_read;
		guint8           data [1024];
		
		result = mate_vfs_read (from_handle, data, 1024, &bytes_read);
		if (show_if_error (result, "read ", from))
			return;

		if (bytes_read == 0)
			break;

		ms_ole_dump (data, bytes_read, offset);
		
		offset += bytes_read;
	}

	result = mate_vfs_close (from_handle);
	if (show_if_error (result, "close ", from))
		return;
}
static gboolean
kill_file_cb (gpointer	key,
	      gpointer	value,
	      gpointer	user_data)
{
	MateVFSResult result;

	result = mate_vfs_close (value);
	show_if_error (result, "closing ", key);
	g_free (key);

	return TRUE;
}
int
main (int argc, char **argv)
{
	MateVFSResult    result;
	MateVFSHandle   *handle;
	gchar             buffer[1024];
	MateVFSFileSize  bytes_read;
	MateVFSURI 	 *uri;
	gchar            *text_uri;

	if (argc != 2) {
		printf ("Usage: %s <uri>\n", argv[0]);
		return 1;
	}

	if (! mate_vfs_init ()) {
		fprintf (stderr, "Cannot initialize mate-vfs.\n");
		return 1;
	}

	uri = mate_vfs_uri_new (argv[1]);
	if (uri == NULL) {
		fprintf (stderr, "URI not valid.\n");
		return 1;
	}

	text_uri = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE);

	result = mate_vfs_open_uri (&handle, uri, MATE_VFS_OPEN_WRITE);
	show_result (result, "open", text_uri);

	while( result==MATE_VFS_OK && !feof(stdin)) {
		MateVFSFileSize temp;

		bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin);
		if(!bytes_read) break;
		buffer[bytes_read] = 0;
		result = mate_vfs_write (handle, buffer, bytes_read,
				 	&temp);
		show_result (result, "write", text_uri);
	
	}

	result = mate_vfs_close (handle);
	show_result (result, "close", text_uri);

	g_free (text_uri);

	return 0;
}
static void
close_file (const char *str)
{
	MateVFSResult result;
	gpointer hash_key, value;

	if (!str)
		fprintf (vfserr, "Can't close NULL handles\n");

	else if (g_hash_table_lookup_extended (files, str, &hash_key, &value)) {
		g_hash_table_remove (files, str);

		result = mate_vfs_close ((MateVFSHandle *)value);
		show_if_error (result, "closing ", (char *)hash_key);

		g_free (hash_key);
	} else

		fprintf (vfserr, "Unknown file handle '%s'\n", str);
}
static void
do_cat (void)
{
	char *from;
	MateVFSHandle *from_handle;
	MateVFSResult  result;

	from = get_fname ();

	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		return;

	while (1) {
		MateVFSFileSize bytes_read;
		guint8           data [1025];
		
		result = mate_vfs_read (from_handle, data, 1024, &bytes_read);
		if (show_if_error (result, "read ", from))
			return;

		if (bytes_read == 0)
			break;
		
		if (bytes_read >  0 &&
		    bytes_read <= 1024)
			data [bytes_read] = '\0';
		else {
			data [1024] = '\0';
			g_warning ("Wierd error from vfs_read");
		}
		fprintf (stdout, "%s", data);
	}

	result = mate_vfs_close (from_handle);
	if (show_if_error (result, "close ", from))
		return;
	fprintf (stdout, "\n");
}
static void
do_cp (void)
{
	char *from = NULL;
	char *to = NULL;
	MateVFSHandle *from_handle = NULL;
	MateVFSHandle *to_handle = NULL;
	MateVFSResult  result;

	from = get_fname ();

	if (from)
		to = get_fname ();
	else {
		fprintf (vfserr, "cp <from> <to>\n");
		goto out;
	}
       
	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		goto out;

	result = mate_vfs_open (&to_handle, to, MATE_VFS_OPEN_WRITE);
	if (result == MATE_VFS_ERROR_NOT_FOUND)
		result = mate_vfs_create (&to_handle, to, MATE_VFS_OPEN_WRITE, FALSE,
					   MATE_VFS_PERM_USER_ALL);
	if (show_if_error (result, "open ", to))
		goto out;

	while (1) {
		MateVFSFileSize bytes_read;
		MateVFSFileSize bytes_written;
		guint8           data [1024];
		
		result = mate_vfs_read (from_handle, data, 1024, &bytes_read);
		if (show_if_error (result, "read ", from))
			goto out;

		if (bytes_read == 0)
			break;
		
		result = mate_vfs_write (to_handle, data, bytes_read, &bytes_written);
		if (show_if_error (result, "write ", to))
			goto out;

		if (bytes_read != bytes_written)
			fprintf (vfserr, "Didn't write it all");
	}

 out:
	g_free (from);
	g_free (to);

	if (to_handle) {
		result = mate_vfs_close (to_handle);
		if (show_if_error (result, "close ", to))
			/* Nothing */;
	}

	if (from_handle) {
		result = mate_vfs_close (from_handle);
		if (show_if_error (result, "close ", from))
			/* Nothing */;
	}
}