cast 0 so comparisons with pointers doesn't generate a compiler warning
[gnash.git] / utilities / soldumper.cpp
blob68f12f01de1811434da8d965c3941447ff7d042a
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
23 #include "GnashFileUtilities.h"
24 #include <iostream>
25 #include <cstdarg>
26 #include <cstring>
28 #ifdef ENABLE_NLS
29 # include <clocale>
30 #endif
32 extern "C"{
33 #ifdef HAVE_GETOPT_H
34 #include <getopt.h>
35 #endif
36 #ifndef __GNUC__
37 extern int optind, getopt(int, char *const *, const char *);
38 extern char *optarg;
39 #endif
42 #include "log.h"
43 #include "rc.h"
44 #include "amf.h"
45 #include "sol.h"
47 using namespace std;
48 using namespace gnash;
50 namespace {
51 gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
52 gnash::RcInitFile& rcfile = gnash::RcInitFile::getDefaultInstance();
55 #ifdef BOOST_NO_EXCEPTIONS
56 namespace boost
59 void throw_exception(std::exception const & e)
61 std::abort();
64 #endif
66 const char *SOLDUMPER_VERSION = "0.5";
68 /// \brief Display the command line arguments
69 static void
70 usage(ostream &o)
72 o << _("This program dumps the internal data of a .sol file")
73 << endl;
74 o << _("Usage: soldumper [h] filename") << endl;
75 o << _("-h\tHelp") << endl;
76 o << _("-f\tForce local directory access") << endl;
77 o << _("-l\tList all .sol files in default dir") << endl;
80 int
81 main(int argc, char *argv[])
83 unsigned int i;
84 int c;
85 bool localdir = false;
86 bool listdir = false;
87 //int size = 0;
88 string filespec, realname, tmpname;
89 struct dirent *entry;
90 vector<const char *> dirlist;
92 // Enable native language support, i.e. internationalization
93 #ifdef ENABLE_NLS
94 std::setlocale (LC_ALL, "");
95 bindtextdomain (PACKAGE, LOCALEDIR);
96 textdomain (PACKAGE);
97 #endif
98 // scan for the two main standard GNU options
99 for (c = 0; c < argc; c++) {
100 if (strcmp("--help", argv[c]) == 0) {
101 usage(cout);
102 exit(EXIT_SUCCESS);
104 if (strcmp("--version", argv[c]) == 0) {
105 printf (_("Gnash soldumper version: %s, Gnash version: %s\n"),
106 SOLDUMPER_VERSION, VERSION);
107 exit(EXIT_SUCCESS);
111 /* This initializes the DBG_MSG macros */
112 while ((c = getopt (argc, argv, "hvfl")) != -1) {
113 switch (c) {
114 case 'h':
115 usage(cout);
116 exit(EXIT_SUCCESS);
117 break;
119 case 'v':
120 dbglogfile.setVerbosity();
121 cout << _("Verbose output turned on") << endl;
122 break;
124 case 'f':
125 cout << _("forcing local directory access only") << endl;
126 localdir = true;
127 break;
129 case 'l':
130 cout << _("List .sol files in the default directory") << endl;
131 listdir = true;
132 break;
134 default:
135 usage(cerr);
136 break;
141 // If no command line arguments have been supplied, do nothing but
142 // print the usage message.
143 if (argc < 2) {
144 usage(cerr);
145 exit(EXIT_FAILURE);
148 // get the file name from the command line
149 if (optind < argc) {
150 filespec = argv[optind];
151 cout << "Will use \"" << filespec << "\" for sol files location" << endl;
154 // List the .sol files in the default directory
155 if (listdir) {
156 const char *dirname;
157 if ((localdir) || (filespec[0] == '/') || (filespec[0] == '.')) {
158 if (filespec.size() == 0) {
159 dirname = "./";
160 } else {
161 dirname = filespec.c_str();
163 } else {
164 dirname = rcfile.getSOLSafeDir().c_str();
166 DIR *library_dir = NULL;
167 library_dir = opendir (dirname);
168 if (library_dir != NULL) {
169 // By convention, the first two entries in each directory are
170 // for . and .. (``dot'' and ``dot dot''), so we ignore those. The
171 // next directory read will get a real file, if any exists.
172 entry = readdir(library_dir);
173 entry = readdir(library_dir);
175 if (library_dir != NULL) {
176 for (i=0; entry>static_cast<struct dirent *>(0); i++) {
177 entry = readdir(library_dir);
178 if (entry != NULL) {
179 //string::size_type pos;
180 if (strstr(entry->d_name, ".sol")) {
181 cout << "Found SOL: " << entry->d_name << endl;
186 exit(EXIT_SUCCESS);
189 string newspec;
190 if ((localdir) || (filespec[0] == '/') || (filespec[0] == '.')) {
191 newspec = filespec;
192 } else {
193 newspec = rcfile.getSOLSafeDir();
194 newspec += "/";
195 newspec += filespec;
198 cygnal::SOL sol;
200 if (sol.readFile(newspec)) {
201 cout << "SOL file \"" << newspec << "\" read in" << endl;
202 } else {
203 cerr << "SOL file \"" << newspec << "\" does not exist!" << endl;
206 sol.dump();
209 // Local Variables:
210 // mode: C++
211 // indent-tabs-mode: t
212 // End: