1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-zip1.c:
4  *
5  * Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
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 <gsf/gsf-input-stdio.h>
23 #include <gsf/gsf-utils.h>
24 #include <gsf/gsf-infile.h>
25 #include <gsf/gsf-infile-zip.h>
26 
27 #include <stdio.h>
28 
29 static void
ls_R(GsfInput * input)30 ls_R (GsfInput *input)
31 {
32 	int i;
33 	gboolean is_dir = GSF_IS_INFILE (input) &&
34 		(gsf_infile_num_children (GSF_INFILE (input)) >= 0);
35 
36 	g_print ("%c '%s' %" GSF_OFF_T_FORMAT "\n",
37 		(is_dir ? 'd' : ' '),
38 		gsf_input_name (GSF_INPUT (input)),
39 		gsf_input_size (GSF_INPUT (input)));
40 
41 	if (!is_dir)
42 		return;
43 
44 	g_print ("{");
45 	for (i = 0 ; i < gsf_infile_num_children (GSF_INFILE (input)) ; i++)
46 		ls_R (gsf_infile_child_by_index (GSF_INFILE (input), i));
47 	g_print ("}");
48 }
49 
50 static int
test(int argc,char * argv[])51 test (int argc, char *argv[])
52 {
53 	GsfInput  *input;
54 	GsfInfile *infile;
55 	GError    *err = NULL;
56 	int i;
57 
58 	for (i = 1 ; i < argc ; i++) {
59 		g_print ("%s", argv[i]);
60 		input = gsf_input_stdio_new (argv[i], &err);
61 		if (input == NULL) {
62 
63 			g_return_val_if_fail (err != NULL, 1);
64 
65 			g_warning ("'%s' error: %s", argv[i], err->message);
66 			g_error_free (err);
67 			err = NULL;
68 			continue;
69 		}
70 
71 		infile = gsf_infile_zip_new (input, &err);
72 		if (infile == NULL) {
73 
74 			g_return_val_if_fail (err != NULL, 1);
75 
76 			g_warning ("'%s' Not a Zip file: %s", argv[i], err->message);
77 			g_error_free (err);
78 			err = NULL;
79 			continue;
80 		}
81 
82 		ls_R (GSF_INPUT (infile));
83 		g_object_unref (G_OBJECT (infile));
84 		g_object_unref (G_OBJECT (input));
85 	}
86 
87 	return 0;
88 }
89 
90 int
main(int argc,char * argv[])91 main (int argc, char *argv[])
92 {
93 	int res;
94 
95 	gsf_init ();
96 	res = test (argc, argv);
97 	gsf_shutdown ();
98 
99 	return res;
100 }
101