"Initial commit to Gerrit"
[profile/ivi/libgsf.git] / tools / gsf-vba-dump.c
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * gsf-vba-dump.c:
4  *
5  * Copyright (C) 2002-2008      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-input-memory.h>
24 #include <gsf/gsf-utils.h>
25 #include <gsf/gsf-infile.h>
26 #include <gsf/gsf-infile-msole.h>
27 #include <gsf/gsf-infile-msvba.h>
28 #include <gsf/gsf-infile-zip.h>
29 #include <gsf/gsf-open-pkg-utils.h>
30
31 #include <stdio.h>
32
33 static void
34 cb_dump_vba (char const *name, guint8 const *src_code)
35 {
36         printf ("<module name=\"%s\">\n<![CDATA[%s]]>\n</module>\n", name, src_code);
37 }
38
39 static int
40 test (int argc, char *argv[])
41 {
42         GsfInput  *input;
43         GError    *err = NULL;
44         int i;
45
46         for (i = 1 ; i < argc ; i++) {
47                 input = gsf_input_mmap_new (argv[i], NULL);
48                 if (input == NULL)      /* Only report error if stdio fails too */
49                         input = gsf_input_stdio_new (argv[i], &err);
50
51                 if (input != NULL) {
52                         GsfInfileMSVBA *vba = gsf_input_find_vba (input, &err);
53                         if (NULL != vba) {
54                                 GHashTable *modules = gsf_infile_msvba_get_modules (vba);
55                                 if (NULL != modules)
56                                         g_hash_table_foreach (modules,
57                                                 (GHFunc) cb_dump_vba, NULL);
58                                 g_object_unref (G_OBJECT (vba));
59                         }
60                         g_object_unref (G_OBJECT (input));
61                 }
62
63                 if (err != NULL) {
64                         g_warning ("'%s' error: %s", argv[i], err->message);
65                         g_error_free (err);
66                 }
67         }
68
69         return 0;
70 }
71
72 int
73 main (int argc, char *argv[])
74 {
75         int res;
76
77         gsf_init ();
78         res = test (argc, argv);
79         gsf_shutdown ();
80
81         return res;
82 }