1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-cp-zip.c: Test gsf_input_copy
4  *
5  * Copyright (C) 2002-2006	Dom Lachowicz <cinamod@hotmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2.1 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21 
22 #include <stdio.h>
23 #include <gsf/gsf-utils.h>
24 #include <gsf/gsf-input-gio.h>
25 #include <gsf/gsf-infile.h>
26 #include <gsf/gsf-output-gio.h>
27 #include <gsf/gsf-outfile.h>
28 #include <string.h>
29 
30 static int
test(char * argv[])31 test (char *argv[])
32 {
33 	GsfInput   *input;
34 	GsfOutput  *output;
35 	GError     *err = NULL;
36 	int         rval = 0;
37 
38 	input = strstr (argv[1], "://")
39 		? gsf_input_gio_new_for_uri (argv[1], &err)
40 		: gsf_input_gio_new_for_path (argv[1], &err);
41 	if (input == NULL) {
42 		g_return_val_if_fail (err != NULL, 1);
43 
44 		g_warning ("'%s' error: %s\n", argv[1], err->message);
45 		g_error_free (err);
46 		return 1;
47 	}
48 
49 	output = gsf_output_gio_new_for_path (argv[2], &err);
50 	if (output == NULL) {
51 
52 		g_return_val_if_fail (err != NULL, 1);
53 
54 		g_warning ("'%s' error: %s\n", argv[2], err->message);
55 		g_error_free (err);
56 
57 		g_object_unref (G_OBJECT (input));
58 		return 1;
59 	}
60 
61 	if (gsf_input_copy (input, output) == FALSE) {
62 		rval = 1;
63 		err = (GError*) gsf_output_error (output);
64 		if (err != NULL) {
65 			g_warning ("'%s' error: %s\n", argv[2], err->message);
66 		}
67 	}
68 
69 	g_object_unref (G_OBJECT (input));
70 
71 	gsf_output_close (output);
72 	g_object_unref (G_OBJECT (output));
73 
74 	return rval;
75 }
76 
77 int
main(int argc,char * argv[])78 main (int argc, char *argv[])
79 {
80 	int res;
81 
82 	if (argc != 3) {
83 		fprintf (stderr, "%s : infile outfile\n", argv [0]);
84 		return 1;
85 	}
86 
87 	gsf_init ();
88 	res = test (argv);
89 	gsf_shutdown ();
90 
91 	return res;
92 }
93