2010-01-29 00:53:53 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2010-02-01 21:25:40 +00:00
|
|
|
* Copyright (C) 2001-2010 David Capello
|
2010-01-29 00:53:53 +00:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-03-30 13:22:47 +00:00
|
|
|
#include "Vaca/Application.h"
|
2010-03-13 01:16:05 +00:00
|
|
|
#include "Vaca/String.h"
|
2010-01-29 00:53:53 +00:00
|
|
|
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/check_args.h"
|
|
|
|
#include "core/cfg.h"
|
|
|
|
#include "console.h"
|
2010-03-13 01:16:05 +00:00
|
|
|
|
|
|
|
using namespace Vaca;
|
2010-01-29 00:53:53 +00:00
|
|
|
|
2010-03-13 01:16:05 +00:00
|
|
|
CheckArgs::CheckArgs()
|
2010-01-29 00:53:53 +00:00
|
|
|
{
|
2010-03-30 13:22:47 +00:00
|
|
|
const std::vector<String>& args(Application::getArgs());
|
2010-03-13 01:16:05 +00:00
|
|
|
|
|
|
|
// Exe name
|
|
|
|
m_exeName = args[0];
|
|
|
|
|
|
|
|
// Convert arguments to recognized options
|
2010-01-29 00:53:53 +00:00
|
|
|
Console console;
|
2010-03-13 01:16:05 +00:00
|
|
|
size_t i, n, len;
|
2010-01-29 00:53:53 +00:00
|
|
|
|
2010-03-13 01:16:05 +00:00
|
|
|
for (i=1; i<args.size(); i++) {
|
|
|
|
const String& arg(args[i]);
|
2010-01-29 00:53:53 +00:00
|
|
|
|
|
|
|
for (n=0; arg[n] == '-'; n++);
|
2010-03-13 01:16:05 +00:00
|
|
|
len = arg.size()-n;
|
2010-01-29 00:53:53 +00:00
|
|
|
|
2010-03-13 01:16:05 +00:00
|
|
|
// Option
|
2010-01-29 00:53:53 +00:00
|
|
|
if ((n > 0) && (len > 0)) {
|
2010-03-13 01:16:05 +00:00
|
|
|
String option = arg.substr(n);
|
|
|
|
|
|
|
|
// Use other palette file
|
|
|
|
if (option == L"palette") {
|
|
|
|
if (++i < args.size())
|
|
|
|
m_paletteFilename = args[i];
|
2010-01-29 00:53:53 +00:00
|
|
|
else
|
|
|
|
usage(false);
|
|
|
|
}
|
2010-03-13 01:16:05 +00:00
|
|
|
// Video resolution
|
|
|
|
else if (option == L"resolution") {
|
|
|
|
if (++i < args.size()) {
|
|
|
|
// The following argument should indicate the resolution
|
|
|
|
// in a format like: 320x240[x8]
|
|
|
|
std::vector<String> parts;
|
|
|
|
split_string(args[i], parts, L"x");
|
|
|
|
|
|
|
|
switch (parts.size()) {
|
2010-01-29 00:53:53 +00:00
|
|
|
case 1:
|
2010-03-13 01:16:05 +00:00
|
|
|
set_config_int("GfxMode", "Depth", convert_to<double>(parts[0]));
|
2010-01-29 00:53:53 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2010-03-13 01:16:05 +00:00
|
|
|
set_config_int("GfxMode", "Width", convert_to<double>(parts[0]));
|
|
|
|
set_config_int("GfxMode", "Height", convert_to<double>(parts[1]));
|
|
|
|
if (parts.size() == 3)
|
|
|
|
set_config_int("GfxMode", "Depth", convert_to<double>(parts[2]));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(false);
|
2010-01-29 00:53:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.printf(_("%s: option \"res\" requires an argument\n"),
|
2010-03-13 01:16:05 +00:00
|
|
|
m_exeName.c_str());
|
2010-01-29 00:53:53 +00:00
|
|
|
usage(false);
|
|
|
|
}
|
|
|
|
}
|
2010-03-13 01:16:05 +00:00
|
|
|
// Verbose mode
|
|
|
|
else if (option == L"verbose") {
|
2010-01-29 00:53:53 +00:00
|
|
|
ase_mode |= MODE_VERBOSE;
|
|
|
|
}
|
2010-03-13 01:16:05 +00:00
|
|
|
// Show help
|
|
|
|
else if (option == L"help") {
|
2010-01-29 00:53:53 +00:00
|
|
|
usage(true);
|
|
|
|
}
|
2010-03-13 01:16:05 +00:00
|
|
|
// Show version
|
|
|
|
else if (option == L"version") {
|
2010-01-29 00:53:53 +00:00
|
|
|
ase_mode |= MODE_BATCH;
|
|
|
|
|
2010-03-01 00:16:58 +00:00
|
|
|
console.printf("%s %s\n", PACKAGE, VERSION);
|
2010-01-29 00:53:53 +00:00
|
|
|
}
|
2010-03-13 01:16:05 +00:00
|
|
|
// Invalid argument
|
2010-01-29 00:53:53 +00:00
|
|
|
else {
|
|
|
|
usage(false);
|
|
|
|
}
|
|
|
|
}
|
2010-03-13 01:16:05 +00:00
|
|
|
// Graphic file to open
|
|
|
|
else if (n == 0) {
|
|
|
|
m_options.push_back(new Option(Option::OpenSprite, args[i]));
|
|
|
|
}
|
2010-01-29 00:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GUI is the default mode
|
|
|
|
if (!(ase_mode & MODE_BATCH))
|
|
|
|
ase_mode |= MODE_GUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckArgs::~CheckArgs()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckArgs::clear()
|
|
|
|
{
|
|
|
|
for (iterator it = begin(); it != end(); ++it) {
|
|
|
|
Option* option = *it;
|
|
|
|
delete option;
|
|
|
|
}
|
2010-03-26 11:42:53 +00:00
|
|
|
m_options.clear();
|
2010-01-29 00:53:53 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 00:09:46 +00:00
|
|
|
// Shows the available options for the program
|
2010-03-13 01:16:05 +00:00
|
|
|
void CheckArgs::usage(bool showHelp)
|
2010-01-29 00:53:53 +00:00
|
|
|
{
|
|
|
|
Console console;
|
|
|
|
|
|
|
|
ase_mode |= MODE_BATCH;
|
|
|
|
|
|
|
|
// show options
|
2010-03-13 01:16:05 +00:00
|
|
|
if (showHelp) {
|
2010-01-29 00:53:53 +00:00
|
|
|
// copyright
|
|
|
|
console.printf
|
2010-03-01 00:16:58 +00:00
|
|
|
("%s v%s | animated sprite editor\n%s\n\n",
|
|
|
|
PACKAGE, VERSION, COPYRIGHT);
|
2010-01-29 00:53:53 +00:00
|
|
|
|
|
|
|
// usage
|
|
|
|
console.printf
|
|
|
|
("%s\n %s [%s] [%s]...\n\n",
|
2010-03-13 01:16:05 +00:00
|
|
|
_("Usage:"), m_exeName.c_str(), _("OPTION"), _("FILE"));
|
2010-01-29 00:53:53 +00:00
|
|
|
|
|
|
|
/* options */
|
|
|
|
console.printf
|
|
|
|
("%s:\n"
|
|
|
|
" -palette GFX-FILE %s\n"
|
|
|
|
" -resolution WxH[xBPP] %s\n"
|
|
|
|
" -verbose %s\n"
|
|
|
|
" -help %s\n"
|
|
|
|
" -version %s\n"
|
|
|
|
"\n",
|
|
|
|
_("Options"),
|
|
|
|
_("Use a specific palette by default"),
|
|
|
|
_("Change the resolution to use"),
|
|
|
|
_("Explain what is being done (in stderr or a log file)"),
|
|
|
|
_("Display this help and exits"),
|
|
|
|
_("Output version information and exit"));
|
|
|
|
|
|
|
|
/* web-site */
|
|
|
|
console.printf
|
2010-03-01 00:16:58 +00:00
|
|
|
("Find more information in %s web site: %s\n\n",
|
|
|
|
PACKAGE, WEBSITE);
|
2010-01-29 00:53:53 +00:00
|
|
|
}
|
|
|
|
/* how to show options */
|
|
|
|
else {
|
|
|
|
console.printf(_("Try \"%s --help\" for more information.\n"),
|
2010-03-13 01:16:05 +00:00
|
|
|
m_exeName.c_str());
|
2010-01-29 00:53:53 +00:00
|
|
|
}
|
|
|
|
}
|