1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * test-cat-zip.c: test program to list content and dump raw stream data
5 * Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
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.
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.
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
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>
32 ls_R (GsfInput *input)
35 char const *name = gsf_input_name (GSF_INPUT (input));
36 gboolean is_dir = GSF_IS_INFILE (input) &&
37 (gsf_infile_num_children (GSF_INFILE (input)) >= 0);
39 printf ("%c '%s'\t\t%" GSF_OFF_T_FORMAT "\n",
41 (name != NULL) ? name : "",
42 gsf_input_size (GSF_INPUT (input)));
46 for (i = 0 ; i < gsf_infile_num_children (GSF_INFILE (input)) ; i++)
47 ls_R (gsf_infile_child_by_index (GSF_INFILE (input), i));
51 g_object_unref (G_OBJECT (input));
55 test (int argc, char *argv[])
61 fprintf (stderr, "%s\n", argv [1]);
62 input = gsf_input_stdio_new (argv[1], &err);
65 g_return_val_if_fail (err != NULL, 1);
67 g_warning ("'%s' error: %s", argv[1], err->message);
72 input = gsf_input_uncompress (input);
73 infile = gsf_infile_zip_new (input, &err);
74 g_object_unref (G_OBJECT (input));
77 g_return_val_if_fail (err != NULL, 1);
79 g_warning ("'%s' Not an OLE file: %s", argv[1], err->message);
86 GsfInput *child, *ptr = GSF_INPUT (infile);
87 for (i = 2 ; i < argc && ptr != NULL; i++, ptr = child) {
88 fprintf (stderr, "--> '%s'\n", argv [i]);
89 if (GSF_IS_INFILE (ptr) &&
90 gsf_infile_num_children (GSF_INFILE (ptr)) >= 0) {
91 child = gsf_infile_child_by_name (GSF_INFILE (ptr), argv [i]);
94 g_warning ("No child named '%s'", argv [i]);
99 g_warning ("stream is not a directory '%s'", argv [i]);
103 g_object_unref (G_OBJECT (ptr));
106 if (GSF_IS_INFILE (ptr) &&
107 gsf_infile_num_children (GSF_INFILE (ptr)) >= 0)
108 ls_R (ptr); /* unrefs infile */
110 gsf_input_dump (GSF_INPUT (ptr), FALSE);
111 g_object_unref (G_OBJECT (ptr));
115 ls_R (GSF_INPUT (infile)); /* unrefs infile */
121 main (int argc, char *argv[])
126 fprintf (stderr, "%s : file stream stream ...\n", argv [0]);
131 res = test (argc, argv);