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-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
|
|
|
//#ifdef _GNU_SOURCE
|
|
|
|
//#include <getopt.h>
|
|
|
|
//#endif
|
2006-01-25 18:50:36 +01:00
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
#include <glibmm/optioncontext.h>
|
|
|
|
|
|
|
|
|
|
|
|
//#include <cstdio>
|
2006-01-25 18:50:36 +01:00
|
|
|
#include <cstdlib>
|
2006-07-06 02:05:50 +02:00
|
|
|
//#include <unistd.h>
|
2006-01-25 18:50:36 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
using namespace sgpem;
|
|
|
|
|
2006-01-25 18:50:36 +01:00
|
|
|
// Static declarations:
|
|
|
|
static void display_help();
|
|
|
|
|
|
|
|
void
|
2006-06-29 10:44:30 +02:00
|
|
|
parse_options(int& argc, char**& argv)
|
2006-01-25 18:50:36 +01:00
|
|
|
{
|
2006-07-06 02:05:50 +02:00
|
|
|
// FIXME this code causes a segfault some time after the method is returned (!!!),
|
|
|
|
// ddd says the problem originates from libglib. Any clue?
|
|
|
|
|
|
|
|
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
|
|
|
// Here we try to sort out the order of creation of the Option* objects, but it's useless...
|
|
|
|
|
|
|
|
OptionContext context("SGPEMv2, a graphical simulator for process "
|
|
|
|
"scheduling in a multitasking computer");
|
2006-01-25 18:50:36 +01:00
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
OptionGroup group("options", "options");
|
|
|
|
|
|
|
|
// Prepare the option entries
|
|
|
|
|
|
|
|
OptionEntry no_gui;
|
|
|
|
OptionEntry policies_dir;
|
|
|
|
OptionEntry modules_dir;
|
|
|
|
|
|
|
|
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-03-09 11:49:41 +01:00
|
|
|
#ifdef _GNU_SOURCE
|
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-03-09 11:49:41 +01:00
|
|
|
#endif
|
2006-06-29 10:44:30 +02:00
|
|
|
|
2006-07-06 02:05:50 +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");
|
|
|
|
|
|
|
|
// Places where araguments will be saved
|
|
|
|
|
|
|
|
bool no_gui_enabled = false;
|
|
|
|
OptionGroup::vecustrings policies_dir_val;
|
|
|
|
OptionGroup::vecustrings modules_dir_val;
|
|
|
|
|
|
|
|
// Create the only group
|
|
|
|
|
|
|
|
//OptionGroup group("options", "options");
|
|
|
|
|
|
|
|
group.add_entry(no_gui, no_gui_enabled);
|
|
|
|
group.add_entry(policies_dir, policies_dir_val);
|
|
|
|
group.add_entry(modules_dir, modules_dir_val);
|
|
|
|
|
|
|
|
// Create context
|
|
|
|
|
|
|
|
//OptionContext context("SGPEMv2, a graphical simulator for process "
|
|
|
|
// "scheduling in a multitasking computer");
|
|
|
|
|
|
|
|
context.set_main_group(group);
|
|
|
|
context.set_help_enabled(true);
|
|
|
|
context.set_ignore_unknown_options(true);
|
|
|
|
|
|
|
|
// Parse options
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
context.parse(argc, argv);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
for(Glib::OptionGroup::vecustrings::const_iterator it = modules_dir_val.begin();
|
|
|
|
it != modules_dir_val.end(); ++it)
|
|
|
|
prefs.add_modules_dir(*it);
|
|
|
|
|
|
|
|
if(no_gui_enabled)
|
2006-06-29 10:44:30 +02:00
|
|
|
{
|
2006-07-06 02:05:50 +02:00
|
|
|
|
2006-06-29 10:44:30 +02:00
|
|
|
// We don't return to main, instead we
|
|
|
|
// initialize the command line version
|
|
|
|
// of sgpemv2 (?)
|
|
|
|
|
|
|
|
// FIXME : to be written!
|
|
|
|
}
|
|
|
|
}
|
2006-07-06 02:05:50 +02:00
|
|
|
catch(Glib::OptionError e)
|
|
|
|
{
|
|
|
|
std::cout << "Bad invocation: " << e.what() << std::endl;
|
|
|
|
|
|
|
|
//char *force_help_vec[] = { "sgpem", "--help" };
|
|
|
|
//char **force_help = &force_help_vec[0];
|
|
|
|
//int count = 2;
|
|
|
|
|
|
|
|
//assert(context.parse(count, force_help));
|
|
|
|
}
|
2006-06-29 10:44:30 +02:00
|
|
|
|
2006-07-06 02:05:50 +02:00
|
|
|
// and now ??? I need MORE documentation for this stuff!!!
|
|
|
|
// shame on me! it was so easy...
|
|
|
|
}
|
|
|
|
|
|
|
|
//void
|
|
|
|
//parse_options(int& argc, char**& argv)
|
|
|
|
//{
|
|
|
|
// using sgpem::GlobalPreferences;
|
|
|
|
//
|
|
|
|
// print_license();
|
|
|
|
//
|
|
|
|
// static const char* short_options = "NhP:M:";
|
|
|
|
//
|
|
|
|
//#ifdef _GNU_SOURCE
|
|
|
|
// // Initialize the array for GNU long options
|
|
|
|
// static struct option long_options[] =
|
|
|
|
// {
|
|
|
|
// {"no-gui", no_argument, NULL, 'N' },
|
|
|
|
// {"help", no_argument, NULL, 'h' },
|
|
|
|
// {"policies-dir", required_argument, NULL, 'P'},
|
|
|
|
// {"modules-dir", required_argument, NULL, 'M'}
|
|
|
|
// };
|
|
|
|
// int option_index = 0;
|
|
|
|
//#endif
|
|
|
|
//
|
|
|
|
// int opt;
|
|
|
|
// do
|
|
|
|
// {
|
|
|
|
//#ifdef _GNU_SOURCE
|
|
|
|
// opt = getopt_long(argc, argv, short_options,
|
|
|
|
// long_options, &option_index);
|
|
|
|
//#else
|
|
|
|
// opt = getopt(argc, argv, short_options);
|
|
|
|
//#endif
|
|
|
|
//
|
|
|
|
// switch(opt)
|
|
|
|
// {
|
|
|
|
// case - 1:
|
|
|
|
// // We have finished normally
|
|
|
|
// break;
|
|
|
|
// case 'N' :
|
|
|
|
// // We don't return to main, instead we
|
|
|
|
// // initialize the command line version
|
|
|
|
// // of sgpemv2 (?)
|
|
|
|
//
|
|
|
|
// // FIXME : to be written!
|
|
|
|
// break;
|
|
|
|
// case 'P':
|
|
|
|
// GlobalPreferences::get_instance().add_policies_dir(optarg);
|
|
|
|
// break;
|
|
|
|
// case 'M':
|
|
|
|
// GlobalPreferences::get_instance().add_modules_dir(optarg);
|
|
|
|
// break;
|
|
|
|
// case ':':
|
|
|
|
// printf(_("[EE] Wrong number of parameters. Please see \n"
|
|
|
|
// "%s --help\n"), argv[0]);
|
|
|
|
// exit(-1);
|
|
|
|
// case 'h' :
|
|
|
|
// default :
|
|
|
|
// display_help();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// while( opt != -1 );
|
|
|
|
//
|
|
|
|
// // Set these two to start from additional filenames on the cmdline:
|
|
|
|
// argc -= optind;
|
|
|
|
// argv += optind;
|
|
|
|
//}
|
2006-01-25 18:50:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-01-27 11:04:49 +01:00
|
|
|
display_help()
|
|
|
|
{
|
2006-06-29 10:44:30 +02:00
|
|
|
printf( _("SGPEMv2 is an educational software acting as a process scheduling simulator\n"
|
|
|
|
"\n\nUsage : sgpemv2 [options] filename"
|
|
|
|
"\n\nOptions:\n"
|
|
|
|
"\t-h, --help this help you're reading\n"
|
|
|
|
"\t-N, --no-gui starts the program in command line mode\n"
|
|
|
|
"\t-P dir, --policies-dir=dir\n"
|
|
|
|
"\t add this directory to the default modules\n"
|
|
|
|
"\t search path\n"
|
|
|
|
"\t-M dir, --modules-dir=dir\n"
|
|
|
|
"\t add this directory to default plugin\n"
|
|
|
|
"\t search path\n"
|
|
|
|
"\nFilename:\n"
|
|
|
|
"\t a valid SGPEMv2 XML file\n"
|
|
|
|
"\t to be opened.\n"
|
|
|
|
"\nLong options are available only on GNU systems.\n\n" ) );
|
|
|
|
exit(0);
|
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
|
|
|
}
|
|
|
|
|
2006-02-19 23:36:24 +01:00
|
|
|
|