~ubuntu-branches/debian/lenny/libgsf/lenny

« back to all changes in this revision

Viewing changes to tests/test-msole2.c

  • Committer: Bazaar Package Importer
  • Author(s): J.H.M. Dassen (Ray)
  • Date: 2004-06-13 13:57:29 UTC
  • Revision ID: james.westby@ubuntu.com-20040613135729-3rn08f4l9in3kfzw
Tags: upstream-1.9.1
ImportĀ upstreamĀ versionĀ 1.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * test-msole1.c: test program to list content and dump raw stream data
 
4
 *
 
5
 * Copyright (C) 2002-2003      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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
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-msole.h>
 
26
 
 
27
#include <stdio.h>
 
28
#include <string.h>
 
29
#include <stdlib.h>
 
30
#include <ctype.h>
 
31
 
 
32
static gboolean dump_as_hex = FALSE;
 
33
 
 
34
static void
 
35
ls_R (GsfInput *input)
 
36
{
 
37
        int i;
 
38
        char const *name = gsf_input_name (GSF_INPUT (input));
 
39
        gboolean is_dir = GSF_IS_INFILE (input) &&
 
40
                (gsf_infile_num_children (GSF_INFILE (input)) >= 0);
 
41
        
 
42
        printf ("%c '%s'\t\t%" GSF_OFF_T_FORMAT "\n",
 
43
                (is_dir ? 'd' : ' '),
 
44
                (name != NULL) ? name : "",
 
45
                gsf_input_size (GSF_INPUT (input)));
 
46
 
 
47
        if (is_dir) {
 
48
                puts ("{");
 
49
                for (i = 0 ; i < gsf_infile_num_children (GSF_INFILE (input)) ; i++)
 
50
                        ls_R (gsf_infile_child_by_index (GSF_INFILE (input), i));
 
51
                puts ("}");
 
52
        }
 
53
 
 
54
        g_object_unref (G_OBJECT (input));
 
55
}
 
56
 
 
57
static int
 
58
test (int argc, char *argv[])
 
59
{
 
60
        GsfInput  *input;
 
61
        GsfInfile *infile;
 
62
        GError    *err;
 
63
 
 
64
        fprintf (stderr, "%s\n", argv [1]);
 
65
        input = GSF_INPUT (gsf_input_stdio_new (argv[1], &err));
 
66
        if (input == NULL) {
 
67
 
 
68
                g_return_val_if_fail (err != NULL, 1);
 
69
 
 
70
                g_warning ("'%s' error: %s", argv[1], err->message);
 
71
                g_error_free (err);
 
72
                return 1;
 
73
        }
 
74
 
 
75
        input = gsf_input_uncompress (input);
 
76
        infile = GSF_INFILE (gsf_infile_msole_new (input, &err));
 
77
        g_object_unref (G_OBJECT (input));
 
78
 
 
79
        if (infile == NULL) {
 
80
                g_return_val_if_fail (err != NULL, 1);
 
81
 
 
82
                g_warning ("'%s' Not an OLE file: %s", argv[1], err->message);
 
83
                g_error_free (err);
 
84
                return 1;
 
85
        }
 
86
 
 
87
        if (argc > 2) {
 
88
                int i;
 
89
                GsfInput *child, *ptr = GSF_INPUT (infile);
 
90
                for (i = 2 ; i < argc && ptr != NULL; i++, ptr = child) {
 
91
                        fprintf (stderr, "--> '%s'\n", argv [i]);
 
92
                        if (GSF_IS_INFILE (ptr) &&
 
93
                            gsf_infile_num_children (GSF_INFILE (ptr)) >= 0) {
 
94
                                child = gsf_infile_child_by_name (GSF_INFILE (ptr), argv [i]);
 
95
 
 
96
                                if (child == NULL) {
 
97
                                        g_warning ("No child named '%s'", argv [i]);
 
98
                                        child = NULL;
 
99
                                        break;
 
100
                                }
 
101
                        } else {
 
102
                                g_warning ("stream is not a directory '%s'", argv [i]);
 
103
                                child = NULL;
 
104
                                break;
 
105
                        }
 
106
                        g_object_unref (G_OBJECT (ptr));
 
107
                }
 
108
                if (ptr != NULL) {
 
109
                        if (GSF_IS_INFILE (ptr) &&
 
110
                            gsf_infile_num_children (GSF_INFILE (ptr)) >= 0)
 
111
                                ls_R (ptr); /* unrefs infile */
 
112
                        else {
 
113
                                gsf_input_dump (GSF_INPUT (ptr), dump_as_hex);
 
114
                                g_object_unref (G_OBJECT (ptr));
 
115
                        }
 
116
                }
 
117
        } else
 
118
                ls_R (GSF_INPUT (infile)); /* unrefs infile */
 
119
 
 
120
        return 0;
 
121
}
 
122
 
 
123
int
 
124
main (int argc, char *argv[])
 
125
{
 
126
        int res;
 
127
 
 
128
        if (argc < 2) {
 
129
                fprintf (stderr, "%s : file [--hex] stream stream ...\n", argv [0]);
 
130
                return 1;
 
131
        }
 
132
 
 
133
        if (argv[1] != NULL && 0 == strcmp (argv[1], "--hex")) {
 
134
                dump_as_hex = TRUE;
 
135
                argv++;
 
136
                argc--;
 
137
        }
 
138
 
 
139
        gsf_init ();
 
140
        res = test (argc, argv);
 
141
        gsf_shutdown ();
 
142
 
 
143
        return res;
 
144
}