<commit_before>/*
Copyright (c) 2013 <NAME>, <NAME>
Copyright (c) 2012 <NAME>, <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#include "crown.h"
#include "memory.h"
#include "input.h"
#include "console_server.h"
#include "bundle_compiler.h"
#include "device.h"
#include "command_line.h"
#include "json_parser.h"
#include "keyboard.h"
#include "mouse.h"
#include "touch.h"
#include "main.h"
#include "audio.h"
#include "physics.h"
#include "disk_filesystem.h"
#include "config.h"
#include "math_utils.h"
#include <bgfx.h>

namespace crown
{
static void help(const char* msg = NULL)
{
	if (msg)
	{
		printf("Error: %s\n", msg);
	}

	printf(
		"Usage: crown [options]\n"
		"Options:\n\n"

		"  -h --help                  Show this help.\n"
		"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
		"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
		"                             Used only by tools.\n"

		"\nAvailable only in debug and development builds:\n\n"

		"  --source-dir <path>        Use <path> as the source directory for resource compilation.\n"
		"  --compile                  Do a full compile of the resources.\n"
		"  --platform <platform>      Compile resources for the given <platform>.\n"
		"      Possible values for <platform> are:\n"
		"          linux\n"
		"          android\n"
		"          windows\n"
		"  --continue                 Continue the execution after the resource compilation step.\n"
		"  --host                     Read resources from a remote engine instance.\n"
		"  --wait-console             Wait for a console connection before starting up.\n"
	);
}

CommandLineSettings parse_command_line(int argc, char** argv)
{
	CommandLineSettings cls;
	cls.source_dir = NULL;
	cls.bundle_dir = NULL;
	cls.platform = NULL;
	cls.wait_console = false;
	cls.do_compile = false;
	cls.do_continue = false;
	cls.parent_window = 0;

	CommandLine cmd(argc, argv);

	if (cmd.has_argument("help", 'h'))
	{
		help();
		exit(EXIT_FAILURE);
	}

	cls.source_dir = cmd.get_parameter("source-dir");
	if (!cls.source_dir)
	{
		help("Source directory must be specified.");
		exit(EXIT_FAILURE);
	}
	
	cls.bundle_dir = cmd.get_parameter("bundle-dir");
	if (!cls.bundle_dir)
	{
		help("Bundle directory must be specified.");
		exit(EXIT_FAILURE);
	}

	cls.platform = cmd.get_parameter("platform");
	if (!cls.platform)
	{
		help("Platform must be specified.");
		exit(EXIT_FAILURE);
	}

	cls.platform = cmd.get_parameter("platform");
	cls.wait_console = cmd.has_argument("wait-console");
	cls.do_compile = cmd.has_argument("compile");
	cls.do_continue = cmd.has_argument("continue");

	const char* parent = cmd.get_parameter("parent-window");
	if (parent)
	{
		cls.parent_window = string::parse_uint(parent);
	}

	return cls;
}

ConfigSettings parse_config_file(Filesystem& fs)
{
	ConfigSettings cs;
	cs.console_port = 10001;
	cs.boot_package = 0;
	cs.boot_script = 0;
	cs.window_width = CROWN_DEFAULT_WINDOW_WIDTH;
	cs.window_height = CROWN_DEFAULT_WINDOW_HEIGHT;

	File* tmpfile = fs.open("crown.config", FOM_READ);
	JSONParser config(*tmpfile);
	fs.close(tmpfile);
	JSONElement root = config.root();<commit_msg>Require --platform only when compiling<commit_after>/*
Copyright (c) 2013 <NAME>, <NAME>
Copyright (c) 2012 <NAME>, <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#include "crown.h"
#include "memory.h"
#include "input.h"
#include "console_server.h"
#include "bundle_compiler.h"
#include "device.h"
#include "command_line.h"
#include "json_parser.h"
#include "keyboard.h"
#include "mouse.h"
#include "touch.h"
#include "main.h"
#include "audio.h"
#include "physics.h"
#include "disk_filesystem.h"
#include "config.h"
#include "math_utils.h"
#include <bgfx.h>

namespace crown
{
static void help(const char* msg = NULL)
{
	if (msg)
	{
		printf("Error: %s\n", msg);
	}

	printf(
		"Usage: crown [options]\n"
		"Options:\n\n"

		"  -h --help                  Show this help.\n"
		"  --bundle-dir <path>        Use <path> as the source directory for compiled resources.\n"
		"  --parent-window <handle>   Set the parent window <handle> of the main window.\n"
		"                             Used only by tools.\n"

		"\nAvailable only in debug and development builds:\n\n"

		"  --source-dir <path>        Use <path> as the source directory for resource compilation.\n"
		"  --compile                  Do a full compile of the resources.\n"
		"  --platform <platform>      Compile resources for the given <platform>.\n"
		"      Possible values for <platform> are:\n"
		"          linux\n"
		"          android\n"
		"          windows\n"
		"  --continue                 Continue the execution after the resource compilation step.\n"
		"  --host                     Read resources from a remote engine instance.\n"
		"  --wait-console             Wait for a console connection before starting up.\n"
	);
}

CommandLineSettings parse_command_line(int argc, char** argv)
{
	CommandLineSettings cls;
	cls.source_dir = NULL;
	cls.bundle_dir = NULL;
	cls.platform = NULL;
	cls.wait_console = false;
	cls.do_compile = false;
	cls.do_continue = false;
	cls.parent_window = 0;

	CommandLine cmd(argc, argv);

	if (cmd.has_argument("help", 'h'))
	{
		help();
		exit(EXIT_FAILURE);
	}

	cls.source_dir = cmd.get_parameter("source-dir");
	if (!cls.source_dir)
	{
		help("Source directory must be specified.");
		exit(EXIT_FAILURE);
	}
	
	cls.bundle_dir = cmd.get_parameter("bundle-dir");
	if (!cls.bundle_dir)
	{
		help("Bundle directory must be specified.");
		exit(EXIT_FAILURE);
	}

	cls.platform = cmd.get_parameter("platform");
	cls.wait_console = cmd.has_argument("wait-console");
	cls.do_compile = cmd.has_argument("compile");
	cls.do_continue = cmd.has_argument("continue");

	cls.platform = cmd.get_parameter("platform");
	if (cls.do_compile && !cls.platform)
	{
		help("Platform must be specified.");
		exit(EXIT_FAILURE);
	}

	const char* parent = cmd.get_parameter("parent-window");
	if (parent)
	{
		cls.parent_window = string::parse_uint(parent);
	}

	return cls;
}

ConfigSettings parse_config_file(Filesystem& fs)
{
	ConfigSettings cs;
	cs.console_port = 10001;
	cs.boot_package = 0;
	cs.boot_script = 0;
	cs.window_width = CROWN_DEFAULT_WINDOW_WIDTH;
	cs.window_height = CROWN_DEFAULT_WINDOW_HEIGHT;

	File* tmpfile = fs.open("crown.config", FOM_READ);
	JSONParser config(*tmpfile);
	fs.close(tmpfile);
	JSONElement root = config.root();
{'fraction_non_alphanumeric': 0.11454740097537766, 'fraction_numerical': 0.003806351849649102, 'mean_word_length': 3.645303867403315, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6295586', 'n_tokens_mistral': 2768, 'n_tokens_neox': 2628, 'n_words': 858}