1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-ls-zip.c: test program to list content of zip files.
4  *
5  * Copyright (C) 2002-2006	Tambet Ingo (tambet@ximian.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 <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 #include <stdlib.h>
29 #include <ctype.h>
30 
31 static int
test(int argc,char * argv[])32 test (int argc, char *argv[])
33 {
34 	GsfInput  *input;
35 	GsfInfile *infile;
36 	GError    *err = NULL;
37 	gint       i, j;
38 
39 	for (i = 1; i < argc; i++) {
40 		fprintf (stderr, "%s\n", argv [i]);
41 		input = gsf_input_stdio_new (argv[i], &err);
42 		if (input == NULL) {
43 
44 			g_return_val_if_fail (err != NULL, 1);
45 
46 			g_warning ("'%s' error: %s", argv[i], err->message);
47 			g_error_free (err);
48 			return 1;
49 		}
50 
51 		input = gsf_input_uncompress (input);
52 		infile = gsf_infile_zip_new (input, &err);
53 		g_object_unref (G_OBJECT (input));
54 
55 		if (infile == NULL) {
56 			g_return_val_if_fail (err != NULL, 1);
57 
58 			g_warning ("'%s' Not a zip file: %s", argv[i], err->message);
59 			g_error_free (err);
60 			return 1;
61 		}
62 
63 		for (j = 0; j < gsf_infile_num_children (infile); j++) {
64 			GsfInput *child = gsf_infile_child_by_index (infile, j);
65 
66 			g_print ("\t%s\t\t%" GSF_OFF_T_FORMAT "\n", gsf_input_name (child), gsf_input_size (child));
67 			g_object_unref (G_OBJECT (child));
68 		}
69 
70 		g_object_unref (G_OBJECT (infile));
71 	}
72 
73 	return 0;
74 }
75 
76 int
main(int argc,char * argv[])77 main (int argc, char *argv[])
78 {
79 	int res;
80 
81 	if (argc < 2) {
82 		fprintf (stderr, "%s : file.zip  ...\n", argv [0]);
83 		return 1;
84 	}
85 
86 	gsf_init ();
87 	res = test (argc, argv);
88 	gsf_shutdown ();
89 
90 	return res;
91 }
92