mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-01 10:21:04 +00:00
Added Vaca::String class.
Added Vaca::Exception class. Added Vaca::System class. Added vaca_main(). The main/WinMain is defined inside vaca library.
This commit is contained in:
parent
9e46555a65
commit
5ae14b550b
@ -509,11 +509,15 @@ VACA_DIR = third_party/vaca
|
||||
VACA_SOURCES = \
|
||||
$(VACA_DIR)/src/Component.cpp \
|
||||
$(VACA_DIR)/src/Debug.cpp \
|
||||
$(VACA_DIR)/src/Exception.cpp \
|
||||
$(VACA_DIR)/src/Mutex.cpp \
|
||||
$(VACA_DIR)/src/Point.cpp \
|
||||
$(VACA_DIR)/src/Referenceable.cpp \
|
||||
$(VACA_DIR)/src/Rect.cpp \
|
||||
$(VACA_DIR)/src/Referenceable.cpp \
|
||||
$(VACA_DIR)/src/Size.cpp \
|
||||
$(VACA_DIR)/src/String.cpp \
|
||||
$(VACA_DIR)/src/System.cpp \
|
||||
$(VACA_DIR)/src/Vaca.cpp \
|
||||
$(VACA_DIR)/src/win32/Mutex.cpp
|
||||
|
||||
VACA_OBJS = $(addprefix $(OBJ_DIR)/vaca., \
|
||||
|
@ -39,7 +39,7 @@ LFLAGS = -NOLOGO -SUBSYSTEM:WINDOWS -MACHINE:X86
|
||||
|
||||
LIBS = User32.lib Shell32.lib ComCtl32.lib ComDlg32.lib Gdi32.lib \
|
||||
Msimg32.lib WinMM.lib AdvAPI32.lib Ole32.lib ShLwApi.lib Vfw32.Lib \
|
||||
ddraw.lib dxguid.lib dsound.lib dinput8.lib
|
||||
wininet.lib ddraw.lib dxguid.lib dsound.lib dinput8.lib
|
||||
|
||||
ifdef DEBUGMODE
|
||||
ifdef STATIC_ALLEG_LINK
|
||||
|
23
src/app.cpp
23
src/app.cpp
@ -30,6 +30,8 @@
|
||||
#include "jinete/jinete.h"
|
||||
#include "jinete/jintern.h"
|
||||
|
||||
#include "Vaca/String.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "ase_exception.h"
|
||||
#include "commands/commands.h"
|
||||
@ -78,7 +80,7 @@ class App::Modules
|
||||
public:
|
||||
// ASE Modules
|
||||
ConfigModule m_config_module;
|
||||
CheckArgs m_check_args;
|
||||
CheckArgs m_checkArgs;
|
||||
LoggerModule m_logger_module;
|
||||
IntlModule m_intl_module;
|
||||
FileSystemModule m_file_system_module;
|
||||
@ -86,11 +88,6 @@ public:
|
||||
RasterModule m_raster;
|
||||
CommandsModule m_commands_modules;
|
||||
UIContext m_ui_context;
|
||||
|
||||
Modules(int argc, char* argv[])
|
||||
: m_check_args(argc, argv)
|
||||
{ }
|
||||
~Modules() { }
|
||||
};
|
||||
|
||||
App* App::m_instance = NULL;
|
||||
@ -113,7 +110,7 @@ static void tabsbar_select_callback(Widget* tabs, void *data, int button);
|
||||
|
||||
// Initializes the application loading the modules, setting the
|
||||
// graphics mode, loading the configuration and resources, etc.
|
||||
App::App(int argc, char* argv[])
|
||||
App::App()
|
||||
: m_modules(NULL)
|
||||
, m_legacy(NULL)
|
||||
{
|
||||
@ -121,7 +118,7 @@ App::App(int argc, char* argv[])
|
||||
m_instance = this;
|
||||
|
||||
// create private implementation data
|
||||
m_modules = new Modules(argc, argv);
|
||||
m_modules = new Modules();
|
||||
m_legacy = new LegacyModules(ase_mode & MODE_GUI ? REQUIRE_INTERFACE: 0);
|
||||
|
||||
// init editor cursor
|
||||
@ -235,15 +232,15 @@ int App::run()
|
||||
PRINTF("Processing options...\n");
|
||||
|
||||
for (CheckArgs::iterator
|
||||
it = m_modules->m_check_args.begin();
|
||||
it != m_modules->m_check_args.end(); ++it) {
|
||||
it = m_modules->m_checkArgs.begin();
|
||||
it != m_modules->m_checkArgs.end(); ++it) {
|
||||
CheckArgs::Option* option = *it;
|
||||
|
||||
switch (option->type()) {
|
||||
|
||||
case CheckArgs::Option::OpenSprite: {
|
||||
/* load the sprite */
|
||||
Sprite *sprite = sprite_load(option->data());
|
||||
Sprite* sprite = sprite_load(Vaca::convert_to<std::string>(option->data()).c_str());
|
||||
if (!sprite) {
|
||||
/* error */
|
||||
if (ase_mode & MODE_GUI)
|
||||
@ -262,14 +259,14 @@ int App::run()
|
||||
set_sprite_in_more_reliable_editor(context->get_first_sprite());
|
||||
|
||||
/* recent file */
|
||||
recent_file(option->data());
|
||||
recent_file(Vaca::convert_to<std::string>(option->data()).c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_modules->m_check_args.clear();
|
||||
m_modules->m_checkArgs.clear();
|
||||
|
||||
/* just batch mode */
|
||||
if (ase_mode & MODE_BATCH) {
|
||||
|
@ -41,7 +41,7 @@ class App
|
||||
LegacyModules* m_legacy;
|
||||
|
||||
public:
|
||||
App(int argc, char* argv[]);
|
||||
App();
|
||||
~App();
|
||||
|
||||
static App* instance() { return m_instance; }
|
||||
|
@ -18,96 +18,97 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/unicode.h>
|
||||
#include "Vaca/String.h"
|
||||
#include "Vaca/System.h"
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/check_args.h"
|
||||
#include "core/cfg.h"
|
||||
#include "console.h"
|
||||
|
||||
CheckArgs::CheckArgs(int argc, char* argv[])
|
||||
: m_exe_name(argv[0])
|
||||
{
|
||||
Console console;
|
||||
int i, n, len;
|
||||
char *arg;
|
||||
|
||||
for (i=1; i<argc; i++) {
|
||||
arg = argv[i];
|
||||
using namespace Vaca;
|
||||
|
||||
CheckArgs::CheckArgs()
|
||||
{
|
||||
const std::vector<String>& args(System::getArgs());
|
||||
|
||||
// Exe name
|
||||
m_exeName = args[0];
|
||||
|
||||
// Convert arguments to recognized options
|
||||
Console console;
|
||||
size_t i, n, len;
|
||||
|
||||
for (i=1; i<args.size(); i++) {
|
||||
const String& arg(args[i]);
|
||||
|
||||
for (n=0; arg[n] == '-'; n++);
|
||||
len = strlen(arg+n);
|
||||
len = arg.size()-n;
|
||||
|
||||
/* option */
|
||||
// Option
|
||||
if ((n > 0) && (len > 0)) {
|
||||
/* use other palette file */
|
||||
if (strncmp(arg+n, "palette", len) == 0) {
|
||||
if (++i < argc)
|
||||
m_palette_filename = argv[i];
|
||||
String option = arg.substr(n);
|
||||
|
||||
// Use other palette file
|
||||
if (option == L"palette") {
|
||||
if (++i < args.size())
|
||||
m_paletteFilename = args[i];
|
||||
else
|
||||
usage(false);
|
||||
}
|
||||
/* video resolution */
|
||||
else if (strncmp(arg+n, "resolution", len) == 0) {
|
||||
if (++i < argc) {
|
||||
int c, num1=0, num2=0, num3=0;
|
||||
char *tok;
|
||||
// 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");
|
||||
|
||||
/* el próximo argumento debe indicar un formato de
|
||||
resolución algo como esto: 320x240[x8] o [8] */
|
||||
c = 0;
|
||||
|
||||
for (tok=ustrtok(argv[i], "x"); tok;
|
||||
tok=ustrtok(NULL, "x")) {
|
||||
switch (c) {
|
||||
case 0: num1 = ustrtol(tok, NULL, 10); break;
|
||||
case 1: num2 = ustrtol(tok, NULL, 10); break;
|
||||
case 2: num3 = ustrtol(tok, NULL, 10); break;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
switch (parts.size()) {
|
||||
case 1:
|
||||
set_config_int("GfxMode", "Depth", num1);
|
||||
set_config_int("GfxMode", "Depth", convert_to<double>(parts[0]));
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
set_config_int("GfxMode", "Width", num1);
|
||||
set_config_int("GfxMode", "Height", num2);
|
||||
if (c == 3)
|
||||
set_config_int("GfxMode", "Depth", num3);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.printf(_("%s: option \"res\" requires an argument\n"),
|
||||
m_exe_name);
|
||||
m_exeName.c_str());
|
||||
usage(false);
|
||||
}
|
||||
}
|
||||
/* verbose mode */
|
||||
else if (strncmp(arg+n, "verbose", len) == 0) {
|
||||
// Verbose mode
|
||||
else if (option == L"verbose") {
|
||||
ase_mode |= MODE_VERBOSE;
|
||||
}
|
||||
/* show help */
|
||||
else if (strncmp(arg+n, "help", len) == 0) {
|
||||
// Show help
|
||||
else if (option == L"help") {
|
||||
usage(true);
|
||||
}
|
||||
/* show version */
|
||||
else if (strncmp(arg+n, "version", len) == 0) {
|
||||
// Show version
|
||||
else if (option == L"version") {
|
||||
ase_mode |= MODE_BATCH;
|
||||
|
||||
console.printf("%s %s\n", PACKAGE, VERSION);
|
||||
}
|
||||
/* invalid argument */
|
||||
// Invalid argument
|
||||
else {
|
||||
usage(false);
|
||||
}
|
||||
}
|
||||
/* graphic file to open */
|
||||
else if (n == 0)
|
||||
m_options.push_back(new Option(Option::OpenSprite, argv[i]));
|
||||
// Graphic file to open
|
||||
else if (n == 0) {
|
||||
m_options.push_back(new Option(Option::OpenSprite, args[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// GUI is the default mode
|
||||
@ -129,14 +130,14 @@ void CheckArgs::clear()
|
||||
}
|
||||
|
||||
// Shows the available options for the program
|
||||
void CheckArgs::usage(bool show_help)
|
||||
void CheckArgs::usage(bool showHelp)
|
||||
{
|
||||
Console console;
|
||||
|
||||
ase_mode |= MODE_BATCH;
|
||||
|
||||
// show options
|
||||
if (show_help) {
|
||||
if (showHelp) {
|
||||
// copyright
|
||||
console.printf
|
||||
("%s v%s | animated sprite editor\n%s\n\n",
|
||||
@ -145,7 +146,7 @@ void CheckArgs::usage(bool show_help)
|
||||
// usage
|
||||
console.printf
|
||||
("%s\n %s [%s] [%s]...\n\n",
|
||||
_("Usage:"), m_exe_name, _("OPTION"), _("FILE"));
|
||||
_("Usage:"), m_exeName.c_str(), _("OPTION"), _("FILE"));
|
||||
|
||||
/* options */
|
||||
console.printf
|
||||
@ -171,6 +172,6 @@ void CheckArgs::usage(bool show_help)
|
||||
/* how to show options */
|
||||
else {
|
||||
console.printf(_("Try \"%s --help\" for more information.\n"),
|
||||
m_exe_name);
|
||||
m_exeName.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,11 @@
|
||||
#ifndef CORE_CHECK_ARGS_H_INCLUDED
|
||||
#define CORE_CHECK_ARGS_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "Vaca/String.h"
|
||||
#include <vector>
|
||||
|
||||
using Vaca::String;
|
||||
|
||||
/**
|
||||
* Looks the input arguments in the command line.
|
||||
*/
|
||||
@ -34,28 +36,28 @@ public:
|
||||
class Option
|
||||
{
|
||||
int m_type;
|
||||
std::string m_data;
|
||||
String m_data;
|
||||
|
||||
public:
|
||||
enum {
|
||||
OpenSprite,
|
||||
};
|
||||
|
||||
Option(int type, const char* data) : m_type(type), m_data(data) { }
|
||||
Option(int type, const String& data) : m_type(type), m_data(data) { }
|
||||
|
||||
int type() const { return m_type; }
|
||||
const char* data() const { return m_data.c_str(); }
|
||||
const String& data() const { return m_data; }
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<Option*> m_options;
|
||||
std::string m_palette_filename;
|
||||
const char* m_exe_name;
|
||||
String m_paletteFilename;
|
||||
String m_exeName;
|
||||
|
||||
public:
|
||||
typedef std::vector<Option*>::iterator iterator;
|
||||
|
||||
CheckArgs(int argc, char *argv[]);
|
||||
CheckArgs();
|
||||
~CheckArgs();
|
||||
|
||||
void clear();
|
||||
@ -63,10 +65,10 @@ public:
|
||||
iterator begin() { return m_options.begin(); }
|
||||
iterator end() { return m_options.end(); }
|
||||
|
||||
std::string get_palette_filename() { return m_palette_filename; }
|
||||
String getPaletteFilename() const { return m_paletteFilename; }
|
||||
|
||||
private:
|
||||
void usage(bool show_help);
|
||||
void usage(bool showHelp);
|
||||
|
||||
};
|
||||
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -56,10 +56,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Here ASE starts.
|
||||
*/
|
||||
int main(int argc, char* argv[])
|
||||
// ASE entry point (this function is called from Vaca library)
|
||||
int vaca_main()
|
||||
{
|
||||
int status = 1; // 1 = error
|
||||
|
||||
@ -74,7 +72,7 @@ int main(int argc, char* argv[])
|
||||
#endif DEBUGMODE
|
||||
|
||||
Jinete jinete;
|
||||
App app(argc, argv);
|
||||
App app;
|
||||
|
||||
status = app.run();
|
||||
|
||||
@ -97,5 +95,3 @@ int main(int argc, char* argv[])
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
END_OF_MAIN();
|
||||
|
68
third_party/vaca/include/Vaca/Exception.h
vendored
Normal file
68
third_party/vaca/include/Vaca/Exception.h
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_EXCEPTION_H
|
||||
#define VACA_EXCEPTION_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include <exception>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
Exception generated from Vaca.
|
||||
|
||||
Base class for every exception generated by Vaca objects.
|
||||
*/
|
||||
class VACA_DLL Exception : public std::exception
|
||||
{
|
||||
String m_message;
|
||||
int m_errorCode;
|
||||
std::string m_what;
|
||||
|
||||
public:
|
||||
|
||||
Exception();
|
||||
Exception(const String& message);
|
||||
virtual ~Exception() throw();
|
||||
|
||||
virtual const char* what() const throw();
|
||||
virtual const String& getMessage() const throw();
|
||||
|
||||
private:
|
||||
|
||||
void initialize();
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_EXCEPTION_H
|
141
third_party/vaca/include/Vaca/String.h
vendored
Normal file
141
third_party/vaca/include/Vaca/String.h
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_STRING_H
|
||||
#define VACA_STRING_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
/**
|
||||
@defgroup string_utils String Utilities
|
||||
@{
|
||||
*/
|
||||
|
||||
// ============================================================
|
||||
// UTILITARY
|
||||
// ============================================================
|
||||
|
||||
VACA_DLL String format_string(const Char* fmt, ...);
|
||||
|
||||
VACA_DLL String trim_string(const String& str);
|
||||
VACA_DLL String trim_string(const Char* str);
|
||||
|
||||
VACA_DLL std::string to_utf8(const String& string);
|
||||
VACA_DLL String from_utf8(const std::string& string);
|
||||
|
||||
// Split a string in parts
|
||||
VACA_DLL void split_string(const String& string, std::vector<String>& parts, const String& separators);
|
||||
|
||||
// ============================================================
|
||||
// CONVERSION
|
||||
// ============================================================
|
||||
|
||||
// you have to use a specialization
|
||||
template<typename To, typename From>
|
||||
To convert_to(const From& from) {
|
||||
enum { not_supported = 1/(1 == 0) }; // static_assert(false)
|
||||
}
|
||||
|
||||
// convert from String
|
||||
template<> VACA_DLL std::string convert_to(const String& from);
|
||||
template<> VACA_DLL int convert_to(const String& from);
|
||||
template<> VACA_DLL long convert_to(const String& from);
|
||||
template<> VACA_DLL unsigned int convert_to(const String& from);
|
||||
template<> VACA_DLL unsigned long convert_to(const String& from);
|
||||
template<> VACA_DLL float convert_to(const String& from);
|
||||
template<> VACA_DLL double convert_to(const String& from);
|
||||
template<> VACA_DLL std::string convert_to(const Char* const& from);
|
||||
|
||||
template<> inline std::string convert_to(Char* const& from) {
|
||||
// return convert_to<std::string, const Char* const&>(from);
|
||||
return convert_to<std::string, Char*>(from);
|
||||
}
|
||||
|
||||
// template<> inline std::string convert_to(const Char* from) {
|
||||
// return convert_to<std::string, const Char* const&>(from);
|
||||
// }
|
||||
|
||||
// template<> inline std::string convert_to(const Char from[]) {
|
||||
// return convert_to<std::string, const Char* const&>(from);
|
||||
// }
|
||||
|
||||
// Convert to String
|
||||
template<> VACA_DLL String convert_to(const std::string& from);
|
||||
template<> VACA_DLL String convert_to(const int& from);
|
||||
template<> VACA_DLL String convert_to(const long& from);
|
||||
template<> VACA_DLL String convert_to(const unsigned int& from);
|
||||
template<> VACA_DLL String convert_to(const unsigned long& from);
|
||||
template<> VACA_DLL String convert_to(const float& from);
|
||||
template<> VACA_DLL String convert_to(const double& from);
|
||||
template<> VACA_DLL String convert_to(const char* const& from);
|
||||
|
||||
template<> inline String convert_to(char* const& from) {
|
||||
// return convert_to<String, const char* const&>(from);
|
||||
return convert_to<String, char*>(from);
|
||||
}
|
||||
|
||||
// template<> inline String convert_to(const char* from) {
|
||||
// return convert_to<String, const char* const&>(from);
|
||||
// }
|
||||
|
||||
// template<> inline String convert_to(const char from[]) {
|
||||
// return convert_to<String, const char* const&>(from);
|
||||
// }
|
||||
|
||||
// Copy to a raw string
|
||||
VACA_DLL void copy_string_to(const String& src, Char* dest, int size);
|
||||
|
||||
// ============================================================
|
||||
// FILE NAMES, PATHS AND URLS
|
||||
// ============================================================
|
||||
|
||||
VACA_DLL String operator/(const String& path, const String& comp);
|
||||
VACA_DLL String& operator/=(String& path, const String& comp);
|
||||
|
||||
VACA_DLL String file_path(const String& fullpath);
|
||||
VACA_DLL String file_name(const String& fullpath);
|
||||
VACA_DLL String file_extension(const String& fullpath);
|
||||
VACA_DLL String file_title(const String& fullpath);
|
||||
|
||||
VACA_DLL String url_host(const String& url);
|
||||
VACA_DLL String url_object(const String& url);
|
||||
|
||||
VACA_DLL String encode_url(const String& url);
|
||||
VACA_DLL String decode_url(const String& url);
|
||||
|
||||
/** @} */
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_STRING_H
|
66
third_party/vaca/include/Vaca/System.h
vendored
Normal file
66
third_party/vaca/include/Vaca/System.h
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef VACA_SYSTEM_H
|
||||
#define VACA_SYSTEM_H
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Vaca {
|
||||
|
||||
namespace details { class MainArgs; }
|
||||
|
||||
/**
|
||||
Class to access to operating system information.
|
||||
|
||||
It is more like a namespace than a class, because all member
|
||||
functions are static.
|
||||
*/
|
||||
class VACA_DLL System
|
||||
{
|
||||
friend class details::MainArgs;
|
||||
|
||||
public:
|
||||
|
||||
static size_t getArgc();
|
||||
static const String& getArgv(size_t i);
|
||||
static const std::vector<String>& getArgs();
|
||||
|
||||
private:
|
||||
|
||||
static void setArgs(const std::vector<String>& args);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Vaca
|
||||
|
||||
#endif // VACA_SYSTEM_H
|
143
third_party/vaca/src/Exception.cpp
vendored
Normal file
143
third_party/vaca/src/Exception.cpp
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/Exception.h"
|
||||
#include "Vaca/String.h"
|
||||
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <lmerr.h>
|
||||
#include <wininet.h>
|
||||
#endif
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
/**
|
||||
Creates generic exception with an empty error message.
|
||||
*/
|
||||
Exception::Exception()
|
||||
: std::exception()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
Creates an exception with the specified error message.
|
||||
|
||||
@param message Error message.
|
||||
*/
|
||||
Exception::Exception(const String& message)
|
||||
: std::exception()
|
||||
, m_message(message)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
Destroys the exception.
|
||||
*/
|
||||
Exception::~Exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a printable C-string of the error.
|
||||
|
||||
It could contain more information about the error than just the
|
||||
specified "message" in the constructor.
|
||||
|
||||
@win32
|
||||
The @msdn{GetLastError} is used to get more information about
|
||||
the error.
|
||||
@endwin32
|
||||
*/
|
||||
const char* Exception::what() const throw()
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the message specified in the constructor or an empty string
|
||||
if the default constructor was used.
|
||||
*/
|
||||
const String& Exception::getMessage() const throw()
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
||||
void Exception::initialize()
|
||||
{
|
||||
#ifdef VACA_ON_WINDOWS
|
||||
HMODULE hmodule = NULL;
|
||||
DWORD flags =
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
LPSTR msgbuf = NULL;
|
||||
|
||||
m_errorCode = GetLastError();
|
||||
|
||||
// is it an network-error?
|
||||
if (m_errorCode >= NERR_BASE && m_errorCode <= MAX_NERR) {
|
||||
hmodule = LoadLibraryExA("netmsg.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
|
||||
if (hmodule)
|
||||
flags |= FORMAT_MESSAGE_FROM_HMODULE;
|
||||
}
|
||||
else if (m_errorCode >= INTERNET_ERROR_BASE && m_errorCode <= INTERNET_ERROR_LAST) {
|
||||
hmodule = LoadLibraryExA("wininet.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
|
||||
if (hmodule)
|
||||
flags |= FORMAT_MESSAGE_FROM_HMODULE;
|
||||
}
|
||||
|
||||
// get the error message in ASCII
|
||||
if (!FormatMessageA(flags,
|
||||
hmodule,
|
||||
m_errorCode,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPSTR>(&msgbuf),
|
||||
0, NULL)) {
|
||||
// error we can't load the string
|
||||
msgbuf = NULL;
|
||||
}
|
||||
|
||||
if (hmodule)
|
||||
FreeLibrary(hmodule);
|
||||
|
||||
m_what += convert_to<std::string>(format_string(L"%d", m_errorCode));
|
||||
m_what += " - ";
|
||||
if (msgbuf) {
|
||||
m_what += msgbuf;
|
||||
LocalFree(msgbuf);
|
||||
}
|
||||
m_what += convert_to<std::string>(m_message);
|
||||
#endif
|
||||
}
|
393
third_party/vaca/src/String.cpp
vendored
Normal file
393
third_party/vaca/src/String.cpp
vendored
Normal file
@ -0,0 +1,393 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/String.h"
|
||||
#include "Vaca/Debug.h"
|
||||
#include "Vaca/Exception.h"
|
||||
#include <cstdio>
|
||||
#include <cwchar>
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
#include <vector>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
String Vaca::format_string(const Char* fmt, ...)
|
||||
{
|
||||
std::auto_ptr<Char> buf;
|
||||
int size = 512;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<Char>(new Char[size <<= 1]);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
#if defined(VACA_ON_WINDOWS)
|
||||
int written = _vsnwprintf(buf.get(), size, fmt, ap);
|
||||
#elif defined(VACA_ON_UNIXLIKE)
|
||||
int written = vswprintf(buf.get(), size, fmt, ap);
|
||||
#else
|
||||
#error Implement this in your platform
|
||||
#endif
|
||||
va_end(ap);
|
||||
|
||||
if (written == size) {
|
||||
if (buf.get()[size] == 0)
|
||||
break;
|
||||
}
|
||||
else if (written >= 0 && written < size) {
|
||||
assert(buf.get()[written] == 0);
|
||||
break;
|
||||
}
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return String(buf.get());
|
||||
}
|
||||
|
||||
String Vaca::trim_string(const String& str)
|
||||
{
|
||||
return trim_string(str.c_str());
|
||||
}
|
||||
|
||||
String Vaca::trim_string(const Char* str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
|
||||
String res(str);
|
||||
while (!res.empty() && std::isspace(res.at(0)))
|
||||
res.erase(res.begin());
|
||||
while (!res.empty() && std::isspace(res.at(res.size()-1)))
|
||||
res.erase(res.end()-1);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct is_separator
|
||||
{
|
||||
const String* separators;
|
||||
is_separator(const String* separators) : separators(separators) { }
|
||||
bool operator()(Char chr)
|
||||
{
|
||||
for (String::const_iterator
|
||||
it = separators->begin(),
|
||||
end = separators->end(); it != end; ++it) {
|
||||
if (chr == *it)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void Vaca::split_string(const String& string, std::vector<String>& parts, const String& separators)
|
||||
{
|
||||
size_t elements = 1 + std::count_if(string.begin(), string.end(), is_separator(&separators));
|
||||
parts.resize(elements);
|
||||
|
||||
size_t beg = 0, end;
|
||||
while (true) {
|
||||
end = string.find_first_of(separators);
|
||||
if (end != String::npos) {
|
||||
parts.push_back(string.substr(beg, end - beg));
|
||||
beg = end+1;
|
||||
}
|
||||
else {
|
||||
parts.push_back(string.substr(beg));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<> int Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (int)std::wcstol(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> long Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (long)std::wcstol(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> unsigned int Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (unsigned int)std::wcstoul(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> unsigned long Vaca::convert_to(const String& from)
|
||||
{
|
||||
return (unsigned long)std::wcstoul(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> float Vaca::convert_to(const String& from)
|
||||
{
|
||||
return std::wcstod(from.c_str(), NULL);
|
||||
}
|
||||
|
||||
template<> double Vaca::convert_to(const String& from)
|
||||
{
|
||||
return std::wcstod(from.c_str(), NULL);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const int& from)
|
||||
{
|
||||
return format_string(L"%d", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const long& from)
|
||||
{
|
||||
return format_string(L"%ld", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const unsigned int& from)
|
||||
{
|
||||
return format_string(L"%u", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const unsigned long& from)
|
||||
{
|
||||
return format_string(L"%lu", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const float& from)
|
||||
{
|
||||
return format_string(L"%.16g", from);
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const double& from)
|
||||
{
|
||||
return format_string(L"%.16g", from);
|
||||
}
|
||||
|
||||
/**
|
||||
Commondly used to give strings to Win32 API or from Win32 API (in
|
||||
structures and messages).
|
||||
*/
|
||||
void Vaca::copy_string_to(const String& src, Char* dest, int size)
|
||||
{
|
||||
std::wcsncpy(dest, src.c_str(), size);
|
||||
dest[size-1] = L'\0';
|
||||
}
|
||||
|
||||
/**
|
||||
Concatenates two path components.
|
||||
|
||||
It is useful if the string represent a path and we have to add a
|
||||
file name. For example:
|
||||
@code
|
||||
String path(L"C:\\myproject\\src");
|
||||
assert(path / L"main.h" == L"C:\\myproject\\src\\main.h");
|
||||
@endcode
|
||||
|
||||
@param component
|
||||
The string to be added at the end of the string
|
||||
(separated by a slash).
|
||||
*/
|
||||
String Vaca::operator/(const String& path, const String& comp)
|
||||
{
|
||||
String res(path);
|
||||
|
||||
if (!res.empty() && *(res.end()-1) != L'/' && *(res.end()-1) != L'\\')
|
||||
res.push_back(L'\\');
|
||||
|
||||
res += comp;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Adds a path component at the end of the path.
|
||||
|
||||
It is useful if the string represent a path and we have to add a
|
||||
file name. For example:
|
||||
@code
|
||||
String path(L"C:\\myproject\\src");
|
||||
path /= L"main.h";
|
||||
assert(path == L"C:\\myproject\\src\\main.h");
|
||||
@endcode
|
||||
|
||||
@param component
|
||||
The string to be added at the end of the string
|
||||
(separated by a slash).
|
||||
*/
|
||||
String& Vaca::operator/=(String& path, const String& comp)
|
||||
{
|
||||
if (!path.empty() && *(path.end()-1) != L'/' && *(path.end()-1) != L'\\')
|
||||
path.push_back(L'\\');
|
||||
|
||||
path += comp;
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file path (the path of "C:\foo\main.cpp" is "C:\foo"
|
||||
without the file name).
|
||||
|
||||
@see file_name
|
||||
*/
|
||||
String Vaca::file_path(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String res;
|
||||
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit)
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
break;
|
||||
|
||||
if (rit != fullpath.rend()) {
|
||||
++rit;
|
||||
std::copy(fullpath.begin(), String::const_iterator(rit.base()),
|
||||
std::back_inserter(res));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file name (the file name of "C:\foo\main.cpp" is
|
||||
"main.cpp", without the path).
|
||||
|
||||
@see file_path, file_title
|
||||
*/
|
||||
String Vaca::file_name(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String res;
|
||||
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit)
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
break;
|
||||
|
||||
std::copy(String::const_iterator(rit.base()), fullpath.end(),
|
||||
std::back_inserter(res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file extension (the extension of "C:\foo\main.cpp" is
|
||||
"cpp", without the path and its title).
|
||||
|
||||
@warning
|
||||
For a file name like "pack.tar.gz" the extension is "gz".
|
||||
|
||||
@see file_path, file_title
|
||||
*/
|
||||
String Vaca::file_extension(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String res;
|
||||
|
||||
// search for the first dot from the end of the string
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit) {
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
return res;
|
||||
else if (*rit == L'.')
|
||||
break;
|
||||
}
|
||||
|
||||
if (rit != fullpath.rend()) {
|
||||
std::copy(String::const_iterator(rit.base()), fullpath.end(),
|
||||
std::back_inserter(res));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the file title (the title of "C:\foo\main.cpp" is "main",
|
||||
without the path and without the extension).
|
||||
|
||||
@warning
|
||||
For a file name like "pack.tar.gz" the title is "pack.tar".
|
||||
|
||||
@see file_path, file_extension
|
||||
*/
|
||||
String Vaca::file_title(const String& fullpath)
|
||||
{
|
||||
String::const_reverse_iterator rit;
|
||||
String::const_iterator last_dot = fullpath.end();
|
||||
String res;
|
||||
|
||||
for (rit=fullpath.rbegin(); rit!=fullpath.rend(); ++rit) {
|
||||
if (*rit == L'\\' || *rit == L'/')
|
||||
break;
|
||||
else if (*rit == L'.' && last_dot == fullpath.end())
|
||||
last_dot = rit.base()-1;
|
||||
}
|
||||
|
||||
for (String::const_iterator it(rit.base()); it!=fullpath.end(); ++it) {
|
||||
if (it == last_dot)
|
||||
break;
|
||||
else
|
||||
res.push_back(*it);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
String Vaca::url_host(const String& url)
|
||||
{
|
||||
String host;
|
||||
int len = url.size();
|
||||
for (int c=0; c<len; ++c) {
|
||||
if (url[c] == L':' && url[c+1] == L'/' && url[c+2] == L'/') {
|
||||
for (c+=3; c<len && url[c] != L'/'; ++c)
|
||||
host.push_back(url[c]);
|
||||
}
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
String Vaca::url_object(const String& url)
|
||||
{
|
||||
String object;
|
||||
int len = url.size();
|
||||
for (int c=0; c<len; ++c) {
|
||||
if (url[c] == ':' && url[c+1] == '/' && url[c+2] == '/') {
|
||||
for (c+=3; c<len && url[c] != '/'; ++c)
|
||||
;
|
||||
for (; c<len; ++c)
|
||||
object.push_back(url[c]);
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
#if defined(VACA_ON_WINDOWS)
|
||||
#include "win32/String.h"
|
||||
#elif defined(VACA_ALLEGRO)
|
||||
#include "allegro/String.h"
|
||||
#endif
|
61
third_party/vaca/src/System.cpp
vendored
Normal file
61
third_party/vaca/src/System.cpp
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/System.h"
|
||||
|
||||
using namespace Vaca;
|
||||
|
||||
static std::vector<String> g_args;
|
||||
|
||||
size_t System::getArgc()
|
||||
{
|
||||
return g_args.size();
|
||||
}
|
||||
|
||||
const String& System::getArgv(size_t i)
|
||||
{
|
||||
return g_args[i];
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the parameters in the command line.
|
||||
|
||||
@c System::getArgs()[0] is the name of the executable file.
|
||||
*/
|
||||
const std::vector<String>& System::getArgs()
|
||||
{
|
||||
return g_args;
|
||||
}
|
||||
|
||||
void System::setArgs(const std::vector<String>& args)
|
||||
{
|
||||
g_args = args;
|
||||
}
|
48
third_party/vaca/src/Vaca.cpp
vendored
Normal file
48
third_party/vaca/src/Vaca.cpp
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Vaca/base.h"
|
||||
#include "Vaca/System.h"
|
||||
|
||||
/**
|
||||
You have to define a vaca_main() function which is the starting
|
||||
point of your application.
|
||||
*/
|
||||
extern int vaca_main();
|
||||
|
||||
|
||||
#if defined(VACA_WINDOWS)
|
||||
#include "win32/WinMain.h"
|
||||
#elif defined(VACA_ALLEGRO)
|
||||
#include "allegro/main.h"
|
||||
#else
|
||||
#error Define VACA_WINDOWS or VACA_ALLEGRO to compile Vaca library
|
||||
#endif
|
81
third_party/vaca/src/allegro/String.h
vendored
Normal file
81
third_party/vaca/src/allegro/String.h
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
// TODO
|
||||
// std::string Vaca::to_utf8(const String& string);
|
||||
// String Vaca::from_utf8(const std::string& string);
|
||||
|
||||
template<> std::string Vaca::convert_to(const Char* const& from)
|
||||
{
|
||||
int len = std::wcslen(from)+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
if (uconvert((const char*)from, U_UNICODE, ansiBuf.get(), U_ASCII, len))
|
||||
return std::string(ansiBuf.get());
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const String& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
if (uconvert((const char*)from.c_str(), U_UNICODE, ansiBuf.get(), U_ASCII, len))
|
||||
return std::string(ansiBuf.get());
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const char* const& from)
|
||||
{
|
||||
int len = strlen(from)+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
if (uconvert(from, U_ASCII, (char*)wideBuf.get(), U_UNICODE, len))
|
||||
return String(wideBuf.get());
|
||||
else
|
||||
return L"";
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const std::string& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
if (uconvert(from.c_str(), U_ASCII, (char*)wideBuf.get(), U_UNICODE, len))
|
||||
return String(wideBuf.get());
|
||||
else
|
||||
return L"";
|
||||
}
|
||||
|
||||
// TODO
|
||||
// String Vaca::encode_url(const String& url);
|
||||
// String Vaca::decode_url(const String& url);
|
||||
|
55
third_party/vaca/src/allegro/main.h
vendored
Normal file
55
third_party/vaca/src/allegro/main.h
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <allegro.h>
|
||||
#include "Vaca/String.h"
|
||||
|
||||
class Vaca::details::MainArgs
|
||||
{
|
||||
public:
|
||||
static void setArgs(int argc, char* argv[])
|
||||
{
|
||||
std::vector<String> args;
|
||||
args.reserve(argc);
|
||||
for (int i=0; i<argc; ++i)
|
||||
args.push_back(convert_to<String>(argv[i]));
|
||||
|
||||
System::setArgs(args);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Vaca::details::MainArgs::setArgs(argc, argv);
|
||||
return vaca_main();
|
||||
}
|
||||
|
||||
END_OF_MAIN();
|
158
third_party/vaca/src/win32/String.h
vendored
Normal file
158
third_party/vaca/src/win32/String.h
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
std::string Vaca::to_utf8(const String& string)
|
||||
{
|
||||
int required_size =
|
||||
WideCharToMultiByte(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
NULL, 0, NULL, NULL);
|
||||
|
||||
if (required_size == 0)
|
||||
return std::string();
|
||||
|
||||
std::vector<char> buf(++required_size);
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
&buf[0], required_size,
|
||||
NULL, NULL);
|
||||
|
||||
return std::string(&buf[0]);
|
||||
}
|
||||
|
||||
String Vaca::from_utf8(const std::string& string)
|
||||
{
|
||||
int required_size =
|
||||
MultiByteToWideChar(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
NULL, 0);
|
||||
|
||||
if (required_size == 0)
|
||||
return String();
|
||||
|
||||
std::vector<wchar_t> buf(++required_size);
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0,
|
||||
string.c_str(), string.size(),
|
||||
&buf[0], required_size);
|
||||
|
||||
return String(&buf[0]);
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const Char* const& from)
|
||||
{
|
||||
int len = std::wcslen(from)+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
int ret = WideCharToMultiByte(CP_ACP, 0, from, len, ansiBuf.get(), len, NULL, NULL);
|
||||
if (ret == 0)
|
||||
return "";
|
||||
else
|
||||
return std::string(ansiBuf.get());
|
||||
}
|
||||
|
||||
template<> std::string Vaca::convert_to(const String& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<char> ansiBuf(new char[len]);
|
||||
int ret = WideCharToMultiByte(CP_ACP, 0, from.c_str(), len, ansiBuf.get(), len, NULL, NULL);
|
||||
if (ret == 0)
|
||||
return "";
|
||||
else
|
||||
return std::string(ansiBuf.get());
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const char* const& from)
|
||||
{
|
||||
int len = strlen(from)+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
int ret = MultiByteToWideChar(CP_ACP, 0, from, len, wideBuf.get(), len);
|
||||
if (ret == 0)
|
||||
return L"";
|
||||
else
|
||||
return String(wideBuf.get());
|
||||
}
|
||||
|
||||
template<> String Vaca::convert_to(const std::string& from)
|
||||
{
|
||||
int len = from.size()+1;
|
||||
std::auto_ptr<Char> wideBuf(new Char[len]);
|
||||
int ret = MultiByteToWideChar(CP_ACP, 0, from.c_str(), len, wideBuf.get(), len);
|
||||
if (ret == 0)
|
||||
return L"";
|
||||
else
|
||||
return String(wideBuf.get());
|
||||
}
|
||||
|
||||
String Vaca::encode_url(const String& url)
|
||||
{
|
||||
std::auto_ptr<Char> buf;
|
||||
DWORD size = 1024;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<Char>(new Char[size]);
|
||||
|
||||
if (::InternetCanonicalizeUrlW(url.c_str(), buf.get(), &size, 0))
|
||||
break;
|
||||
|
||||
if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
throw Exception(); // TODO improve the exception type/information
|
||||
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return String(buf.get());
|
||||
}
|
||||
|
||||
String Vaca::decode_url(const String& url)
|
||||
{
|
||||
std::auto_ptr<Char> buf;
|
||||
DWORD size = 1024;
|
||||
|
||||
while (true) {
|
||||
buf = std::auto_ptr<Char>(new Char[size]);
|
||||
|
||||
if (::InternetCanonicalizeUrlW(url.c_str(), buf.get(), &size,
|
||||
ICU_DECODE | ICU_NO_ENCODE))
|
||||
break;
|
||||
|
||||
if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
throw Exception(); // TODO improve the exception type/information
|
||||
|
||||
// else continue growing the buffer...
|
||||
}
|
||||
|
||||
return String(buf.get());
|
||||
}
|
65
third_party/vaca/src/win32/WinMain.h
vendored
Normal file
65
third_party/vaca/src/win32/WinMain.h
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// Vaca - Visual Application Components Abstraction
|
||||
// Copyright (c) 2005-2009 David Capello
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of the author nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
class Vaca::details::MainArgs
|
||||
{
|
||||
public:
|
||||
static void setArgs()
|
||||
{
|
||||
// Convert the command-line to a vector of arguments using Win32 API
|
||||
std::vector<String> args;
|
||||
LPWSTR* arglist;
|
||||
int argc;
|
||||
|
||||
arglist = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
||||
if (arglist != NULL) {
|
||||
args.reserve(argc);
|
||||
for (int i=0; i<argc; ++i)
|
||||
args.push_back(arglist[i]);
|
||||
|
||||
::LocalFree(arglist);
|
||||
}
|
||||
|
||||
System::setArgs(args);
|
||||
}
|
||||
};
|
||||
|
||||
int PASCAL WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
Vaca::details::MainArgs::setArgs();
|
||||
return vaca_main();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user