2006-01-25 18:50:36 +01:00
|
|
|
// src/parseopts.cc - Copyright 2005, 2006, University
|
|
|
|
// of Padova, dept. of Pure and Applied
|
|
|
|
// Mathematics
|
|
|
|
//
|
|
|
|
// This file is part of SGPEMv2.
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// SGPEMv2 is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with SGPEMv2; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
2006-06-12 16:04:06 +02:00
|
|
|
#include "backend/global_preferences.hh"
|
2006-07-06 11:49:35 +02:00
|
|
|
#include "backend/plugin_manager.hh"
|
2006-07-06 14:23:29 +02:00
|
|
|
#include "gui_builder.hh"
|
2006-02-09 20:43:24 +01:00
|
|
|
#include "parse_opts.hh"
|
2006-01-25 18:50:36 +01:00
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
#include <glibmm/optioncontext.h>
|
2006-07-06 11:49:35 +02:00
|
|
|
#include <gtkmm/main.h>
|
2006-07-06 02:05:50 +02:00
|
|
|
|
2006-01-25 18:50:36 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
using namespace sgpem;
|
|
|
|
|
2006-01-25 18:50:36 +01:00
|
|
|
|
|
|
|
void
|
2006-07-06 11:49:35 +02:00
|
|
|
parse_options(int argc, char** argv)
|
2006-01-25 18:50:36 +01:00
|
|
|
{
|
2006-07-06 02:05:50 +02:00
|
|
|
using Glib::OptionEntry;
|
|
|
|
using Glib::OptionContext;
|
|
|
|
using Glib::OptionGroup;
|
2006-01-25 18:50:36 +01:00
|
|
|
|
2006-06-29 10:44:30 +02:00
|
|
|
print_license();
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
// Prepare the option entries
|
|
|
|
|
|
|
|
OptionEntry no_gui;
|
|
|
|
OptionEntry policies_dir;
|
|
|
|
OptionEntry modules_dir;
|
2006-07-06 11:49:35 +02:00
|
|
|
OptionEntry filename;
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
no_gui.set_short_name('N');
|
|
|
|
policies_dir.set_short_name('P');
|
|
|
|
modules_dir.set_short_name('M');
|
2006-06-29 10:44:30 +02:00
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
no_gui.set_long_name("no-gui");
|
|
|
|
policies_dir.set_long_name("policies-dir");
|
|
|
|
modules_dir.set_long_name("modules_dir");
|
2006-07-06 11:49:35 +02:00
|
|
|
filename.set_long_name(G_OPTION_REMAINING);
|
2006-06-29 10:44:30 +02:00
|
|
|
|
2006-07-06 11:49:35 +02:00
|
|
|
no_gui.set_description(_("starts the program in command line mode"));
|
|
|
|
policies_dir.set_description(_("adds this directory to the default modules search path"));
|
|
|
|
modules_dir.set_description(_("adds this directory to default plugin search path"));
|
|
|
|
filename.set_description(_("a list of savefiles; only the first will be opened"));
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
// Places where araguments will be saved
|
|
|
|
bool no_gui_enabled = false;
|
|
|
|
OptionGroup::vecustrings policies_dir_val;
|
|
|
|
OptionGroup::vecustrings modules_dir_val;
|
2006-07-06 11:49:35 +02:00
|
|
|
OptionGroup::vecstrings fnames;
|
|
|
|
|
|
|
|
no_gui.set_flags(OptionEntry::FLAG_NO_ARG);
|
|
|
|
filename.set_flags(OptionEntry::FLAG_FILENAME | OptionEntry::FLAG_OPTIONAL_ARG);
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
// Create the only group
|
2006-07-06 11:49:35 +02:00
|
|
|
OptionGroup group("options", "options");
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
group.add_entry(no_gui, no_gui_enabled);
|
|
|
|
group.add_entry(policies_dir, policies_dir_val);
|
|
|
|
group.add_entry(modules_dir, modules_dir_val);
|
2006-07-06 11:49:35 +02:00
|
|
|
group.add_entry_filename(filename, fnames);
|
2006-07-06 02:05:50 +02:00
|
|
|
|
2006-07-06 11:49:35 +02:00
|
|
|
// Create context
|
|
|
|
OptionContext context(_("SGPEMv2, a graphical simulator for process "
|
|
|
|
"scheduling in a multitasking computer"));
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
context.set_main_group(group);
|
|
|
|
context.set_help_enabled(true);
|
2006-07-06 11:49:35 +02:00
|
|
|
context.set_ignore_unknown_options(false);
|
2006-07-06 02:05:50 +02:00
|
|
|
|
|
|
|
try
|
2006-07-06 11:49:35 +02:00
|
|
|
{
|
|
|
|
// Parse options, initialising the Gtk::Main at the same time
|
2006-07-06 13:26:23 +02:00
|
|
|
Gtk::Main main_loop(argc, argv, context);
|
2006-07-06 11:49:35 +02:00
|
|
|
|
|
|
|
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
|
|
|
|
|
|
|
for(Glib::OptionGroup::vecustrings::const_iterator it = policies_dir_val.begin();
|
|
|
|
it != policies_dir_val.end(); ++it)
|
|
|
|
prefs.add_policies_dir(*it);
|
2006-07-06 02:05:50 +02:00
|
|
|
|
2006-07-06 11:49:35 +02:00
|
|
|
for(Glib::OptionGroup::vecustrings::const_iterator it = modules_dir_val.begin();
|
|
|
|
it != modules_dir_val.end(); ++it)
|
|
|
|
prefs.add_modules_dir(*it);
|
|
|
|
|
|
|
|
|
|
|
|
// Now that GlobalPreferences has been initialized properly,
|
|
|
|
// initialize plugins, too
|
|
|
|
PluginManager::get_instance();
|
|
|
|
|
|
|
|
if(no_gui_enabled)
|
|
|
|
{
|
|
|
|
// We don't return to main, instead we
|
|
|
|
// initialize the command line version
|
|
|
|
// of sgpemv2 (?)
|
|
|
|
throw Glib::OptionError(Glib::OptionError::FAILED, _("The `No-GUI' option isn't active yet."));
|
|
|
|
|
|
|
|
// FIXME : to be written!
|
2006-07-06 13:26:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-06 14:23:29 +02:00
|
|
|
GuiBuilder* gui = new GuiBuilder();
|
2006-07-06 13:26:23 +02:00
|
|
|
if(fnames.begin() != fnames.end())
|
2006-07-06 14:23:29 +02:00
|
|
|
gui->open_file(*fnames.begin());
|
|
|
|
main_loop.run(gui->get_initial_window());
|
|
|
|
delete gui;
|
2006-07-06 11:49:35 +02:00
|
|
|
}
|
|
|
|
} // ~ try
|
2006-07-06 02:05:50 +02:00
|
|
|
catch(Glib::OptionError e)
|
2006-07-06 11:49:35 +02:00
|
|
|
{
|
|
|
|
std::cout << _("Bad invocation: ") << e.what() << std::endl;
|
|
|
|
std::cout << _("Use the `-?' or `--help' option to see the help") << std::endl;
|
|
|
|
}
|
2006-07-06 02:05:50 +02:00
|
|
|
}
|
|
|
|
|
2006-01-25 18:50:36 +01:00
|
|
|
|
2006-06-29 10:44:30 +02:00
|
|
|
void
|
|
|
|
print_license()
|
2006-01-25 18:50:36 +01:00
|
|
|
{
|
2006-06-29 10:44:30 +02:00
|
|
|
// Do _NOT_ translate this text.
|
|
|
|
std::cerr <<
|
|
|
|
"SGPEMv2, Copyright (C) 2005, 2006 University of Padova,\n"
|
|
|
|
" dept. of Pure and Applied Mathematics.\n"
|
|
|
|
"SGPEMv2 comes with ABSOLUTELY NO WARRANTY. This is free \n"
|
|
|
|
"software, and you are welcome to redistribute it under \n"
|
|
|
|
"the terms of the GNU General Public License; for details\n"
|
|
|
|
"see file COPYING contained in the source package. \n"
|
|
|
|
<< std::endl;
|
2006-01-25 18:50:36 +01:00
|
|
|
}
|