00001 #include <iostream>
00002 #include <popt.h>
00003 #include "config.h"
00004 #include "xmlconfiguration.hh"
00005 #include "anoid.hh"
00006 #include "glcontext.hh"
00007 #include "loader.hh"
00008
00009 namespace anoid {
00010 namespace main {
00011
00012 using namespace std;
00013 using namespace config;
00014
00015 #ifdef DEBUG
00016 char *debugfile = 0;
00017 bool debug = false;
00018 #endif
00019 bool version = false;
00020 bool warranty = false;
00021 bool copying = false;
00022 char *context = 0;
00023 char *classes = 0;
00024
00025 int main(int argc, const char *argv[]) {
00026 struct poptOption info_options[] = {
00027 {
00028 "version",
00029 '\0',
00030 POPT_ARG_NONE,
00031 &version,
00032 0,
00033 "Print current version of Anoid NG.",
00034 0
00035 },
00036 {
00037 "copying",
00038 '\0',
00039 POPT_ARG_NONE,
00040 ©ing,
00041 0,
00042 "Print copying license.",
00043 0
00044 },
00045 {
00046 "warranty",
00047 '\0',
00048 POPT_ARG_NONE,
00049 &warranty,
00050 0,
00051 "Print warranty notice.",
00052 0
00053 },
00054 {0}
00055 };
00056
00057 #ifdef DEBUG
00058 struct poptOption log_options[] = {
00059 {
00060 "debug",
00061 'd',
00062 POPT_ARG_NONE,
00063 &debug,
00064 0,
00065 "Toggle debug output. This flag is ignored if"
00066 " --debug-log-file is used.",
00067 0
00068 },
00069 {
00070 "debug-log-file",
00071 '\0',
00072 POPT_ARG_STRING,
00073 &debugfile,
00074 0,
00075 "Log-file for debug output.",
00076 "<filename>"
00077 },
00078 {0}
00079 };
00080 #endif
00081
00082 struct poptOption options[] = {
00083 {
00084 0,
00085 '\0',
00086 POPT_ARG_INCLUDE_TABLE,
00087 &info_options,
00088 0,
00089 "Information options",
00090 0
00091 },
00092 #ifdef DEBUG
00093 {
00094 0,
00095 '\0',
00096 POPT_ARG_INCLUDE_TABLE,
00097 &log_options,
00098 0,
00099 "Log options",
00100 0
00101 },
00102 #endif
00103 {
00104 "context",
00105 'C',
00106 POPT_ARG_STRING,
00107 &context,
00108 0,
00109 "Graphics context to use.",
00110 "[GL|null]"
00111 },
00112 {
00113 "classes",
00114 'c',
00115 POPT_ARG_STRING,
00116 &classes,
00117 0,
00118 "XML information with information about classes.",
00119 0
00120 },
00121 POPT_AUTOHELP
00122 {0}
00123 };
00124
00125 poptContext ctxt = poptGetContext(0, argc, argv, options, 0);
00126 poptSetOtherOptionHelp(ctxt, "<level file>");
00127
00128 int opt = poptGetNextOpt(ctxt);
00129 if (opt < -1) {
00130
00131 cerr << argv[0] << ": " << poptStrerror(opt) << " `"
00132 << poptBadOption(ctxt, POPT_BADOPTION_NOALIAS)
00133 << "'" << endl
00134 << "Try `" << argv[0] << " --help' for more information" << endl;
00135 return 1;
00136 }
00137
00138 if (version) {
00139 cout << PACKAGE << " version " << VERSION << endl;
00140
00141 exit(0);
00142 }
00143
00144 if (warranty) {
00145 cout << PACKAGE << " version " << VERSION << endl;
00146
00147
00148 cout << " NO WARRANTY" << endl << endl;
00149 cout << "BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY" << endl
00150 << "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN" << endl
00151 << "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES" << endl
00152 << "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED" << endl
00153 << "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF" << endl
00154 << "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS" << endl
00155 << "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE" << endl
00156 << "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING," << endl
00157 << "REPAIR OR CORRECTION." << endl
00158 << endl
00159 << "IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING" << endl
00160 << "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR" << endl
00161 << "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES," << endl
00162 << "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING" << endl
00163 << "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED" << endl
00164 << "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY" << endl
00165 << "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER" << endl
00166 << "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE" << endl
00167 << "POSSIBILITY OF SUCH DAMAGES.\n";
00168 exit(0);
00169 }
00170 if (copying) {
00171 cout << PACKAGE << " version " << VERSION << endl;
00172
00173
00174 cout << "This program is free software; you can redistribute it and/or modify" << endl
00175 << "it under the terms of the GNU General Public License as published by" << endl
00176 << "the Free Software Foundation; either version 2 of the License, or" << endl
00177 << "(at your option) any later version." << endl
00178 << endl
00179 << "This program is distributed in the hope that it will be useful," << endl
00180 << "but WITHOUT ANY WARRANTY; without even the implied warranty of" << endl
00181 << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" << endl
00182 << "GNU General Public License for more details." << endl
00183 << endl
00184 << "You should have received a copy of the GNU General Public License" << endl
00185 << "along with this program; if not, write to the Free Software" << endl
00186 << "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" << endl;
00187 exit(0);
00188 }
00189
00190 #ifdef DEBUG
00191 if (debugfile) debug = true;
00192 #endif
00193
00194 if (context == 0) {
00195 context = "GL";
00196 }
00197 if (strcmp(context, "GL")) {
00198 cerr << "A `" << context << "'-context has not been implemented yet, defaulting to `GL'." << endl;
00199 }
00200
00201 if (classes == NULL)
00202 classes = "./loader.xml";
00203
00204 XMLConfiguration config(classes);
00205 anoid::loader::loader.includeInformation(config);
00206
00207 anoid::context::Context *context = new anoid::context::GLContext();
00208 Anoid anoid(context);
00209
00210 const char *fname;
00211 while (fname = poptGetArg(ctxt)) {
00212 char *tmp = strdup(fname);
00213 XMLConfiguration config(tmp);
00214 anoid.loadLevel(config);
00215 anoid.runLevel();
00216 free(tmp);
00217 }
00218
00219 delete context;
00220
00221 return 0;
00222 }
00223
00224 };
00225 };
00226
00227 int main(int argc, const char *argv[]) {
00228 return anoid::main::main(argc, argv);
00229 }