| 1 |
/* |
| 2 |
Copyright (C) 1999/2000/2001/2002 Kai Sterker <[email protected]> |
| 3 |
Part of the Adonthell Project <http://adonthell.nongnu.org> |
| 4 |
|
| 5 |
Dlgedit 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 2 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
Dlgedit 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 Dlgedit. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
/** |
| 20 |
* @file main.cc |
| 21 |
* |
| 22 |
* @author Kai Sterker |
| 23 |
* @brief The main function of dlgedit. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifdef HAVE_CONFIG_H |
| 27 |
#include <config.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#include <gtk/gtk.h> |
| 31 |
#include <iostream> |
| 32 |
#include <locale.h> |
| 33 |
#include "game.h" |
| 34 |
#include "gettext.h" |
| 35 |
#include "cfg_io.h" |
| 36 |
#include "dlg_cmdline.h" |
| 37 |
#include "dlg_compiler.h" |
| 38 |
#include "gui_dlgedit.h" |
| 39 |
|
| 40 |
int main (int argc, char *argv[]) |
| 41 |
{ |
| 42 |
// dlgedit configuration |
| 43 |
CfgIO config; |
| 44 |
|
| 45 |
// Init GTK+ |
| 46 |
gtk_init (&argc, &argv); |
| 47 |
|
| 48 |
// parse command line |
| 49 |
if (!DlgCmdline::parse (argc, argv)) |
| 50 |
return 1; |
| 51 |
|
| 52 |
// Init i18n |
| 53 |
setlocale (LC_ALL, ""); |
| 54 |
|
| 55 |
// init game directory |
| 56 |
game::init (DlgCmdline::datadir); |
| 57 |
|
| 58 |
// start in gui mode |
| 59 |
if (!DlgCmdline::compile) |
| 60 |
{ |
| 61 |
// Create the User Interface |
| 62 |
GuiDlgedit dlgedit; |
| 63 |
|
| 64 |
// are there any sources given? |
| 65 |
if (DlgCmdline::sources >= argc) |
| 66 |
{ |
| 67 |
// Nope -> create a new dialogue |
| 68 |
dlgedit.newDialogue (); |
| 69 |
} |
| 70 |
else |
| 71 |
{ |
| 72 |
// Yep -> load all of them |
| 73 |
while (DlgCmdline::sources < argc) |
| 74 |
dlgedit.loadDialogue (argv[DlgCmdline::sources++]); |
| 75 |
} |
| 76 |
|
| 77 |
// Start the main loop |
| 78 |
gtk_main (); |
| 79 |
} |
| 80 |
|
| 81 |
// just compile what we're given and exit |
| 82 |
else |
| 83 |
{ |
| 84 |
DlgModule *module; |
| 85 |
std::string dialogue; |
| 86 |
std::string directory = g_get_current_dir(); |
| 87 |
|
| 88 |
while (DlgCmdline::sources < argc) |
| 89 |
{ |
| 90 |
dialogue = argv[DlgCmdline::sources++]; |
| 91 |
|
| 92 |
// make sure that file has an absolute path |
| 93 |
std::string file = ((dialogue[0] == '/' || dialogue[1] == ':') ? dialogue : directory + std::string ("/") + dialogue); |
| 94 |
gchar *fname = g_path_get_basename (file.c_str ()); |
| 95 |
|
| 96 |
// check whether the file is a valid dialogue |
| 97 |
if (!GuiDlgedit::checkDialogue (dialogue)) |
| 98 |
{ |
| 99 |
std::cout << "Loading of '" << dialogue << "' failed\n"; |
| 100 |
g_free(fname); |
| 101 |
continue; |
| 102 |
} |
| 103 |
|
| 104 |
// get the name to use for the dialogue |
| 105 |
std::string filename (fname); |
| 106 |
|
| 107 |
// remove file extension |
| 108 |
unsigned long pos = filename.rfind (FILE_EXT); |
| 109 |
if (pos != filename.npos) filename.erase (pos); |
| 110 |
|
| 111 |
module = new DlgModule (g_path_get_dirname (file.c_str ()), filename, "-1", ""); |
| 112 |
|
| 113 |
// try to load from file |
| 114 |
if (!module->load ()) |
| 115 |
{ |
| 116 |
std::cout << "Loading of '" << dialogue << "' failed\n"; |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
std::cout << "Compiling '" << dialogue << "' ...\n"; |
| 121 |
|
| 122 |
// try to compile the dialogue |
| 123 |
DlgCompiler compiler (module); |
| 124 |
|
| 125 |
// compile |
| 126 |
compiler.run (); |
| 127 |
} |
| 128 |
|
| 129 |
g_free(fname); |
| 130 |
delete module; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
// good bye |
| 135 |
return 0; |
| 136 |
} |