forked from cory/tildefriends
clang-format the source. Not exactly how I want it, but automated is better than perfect.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4845 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
86
src/main.c
86
src/main.c
@ -41,11 +41,15 @@ struct backtrace_state* g_backtrace_state;
|
||||
|
||||
const char* k_db_path_default = "db.sqlite";
|
||||
|
||||
#define XOPT_PARSE(name, flags, options, config_ptr, argc, argv, extrac_ptr, extrav_ptr, err_ptr, autohelp_file, autohelp_usage, autohelp_prefix, autohelp_suffix, autohelp_spacer) do { \
|
||||
xoptContext *_xopt_ctx; \
|
||||
#define XOPT_PARSE( \
|
||||
name, flags, options, config_ptr, argc, argv, extrac_ptr, extrav_ptr, err_ptr, autohelp_file, autohelp_usage, autohelp_prefix, autohelp_suffix, autohelp_spacer) \
|
||||
do \
|
||||
{ \
|
||||
xoptContext* _xopt_ctx; \
|
||||
*(err_ptr) = NULL; \
|
||||
_xopt_ctx = xopt_context((name), (options), ((flags) ^ XOPT_CTX_POSIXMEHARDER), (err_ptr)); \
|
||||
if (*(err_ptr)) break; \
|
||||
if (*(err_ptr)) \
|
||||
break; \
|
||||
*extrac_ptr = xopt_parse(_xopt_ctx, (argc), (argv), (config_ptr), (extrav_ptr), (err_ptr)); \
|
||||
if ((config_ptr)->help) \
|
||||
{ \
|
||||
@ -55,11 +59,13 @@ const char* k_db_path_default = "db.sqlite";
|
||||
__xopt_autohelp_opts.suffix = (autohelp_suffix); \
|
||||
__xopt_autohelp_opts.spacer = (autohelp_spacer); \
|
||||
xopt_autohelp(_xopt_ctx, (autohelp_file), &__xopt_autohelp_opts, (err_ptr)); \
|
||||
if (*(err_ptr)) goto __xopt_end_free_extrav; \
|
||||
if (*(err_ptr)) \
|
||||
goto __xopt_end_free_extrav; \
|
||||
free(_xopt_ctx); \
|
||||
goto xopt_help; \
|
||||
} \
|
||||
if (*(err_ptr)) goto __xopt_end_free_ctx; \
|
||||
if (*(err_ptr)) \
|
||||
goto __xopt_end_free_ctx; \
|
||||
__xopt_end_free_ctx: \
|
||||
free(_xopt_ctx); \
|
||||
break; \
|
||||
@ -77,7 +83,8 @@ static int _tf_command_run(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_sandbox(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_usage(const char* file, int argc, char* argv[]);
|
||||
|
||||
typedef struct _command_t {
|
||||
typedef struct _command_t
|
||||
{
|
||||
const char* name;
|
||||
int (*callback)(const char* file, int argc, char* argv[]);
|
||||
const char* description;
|
||||
@ -94,7 +101,8 @@ const command_t k_commands[] = {
|
||||
static int _tf_command_test(const char* file, int argc, char* argv[])
|
||||
{
|
||||
#if !defined(__ANDROID__)
|
||||
typedef struct args_t {
|
||||
typedef struct args_t
|
||||
{
|
||||
const char* tests;
|
||||
bool help;
|
||||
} args_t;
|
||||
@ -108,16 +116,16 @@ static int _tf_command_test(const char* file, int argc, char* argv[])
|
||||
args_t args = { 0 };
|
||||
const char** extras = NULL;
|
||||
int extra_count = 0;
|
||||
const char *err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "test [options]", "options:", NULL, 15);
|
||||
const char* err = NULL;
|
||||
XOPT_PARSE(
|
||||
file, XOPT_CTX_KEEPFIRST | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "test [options]", "options:", NULL, 15);
|
||||
if (err)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
return 2;
|
||||
}
|
||||
|
||||
tf_test_options_t test_options =
|
||||
{
|
||||
tf_test_options_t test_options = {
|
||||
.exe_path = file,
|
||||
.tests = args.tests,
|
||||
};
|
||||
@ -138,7 +146,8 @@ xopt_help:
|
||||
|
||||
static int _tf_command_import(const char* file, int argc, char* argv[])
|
||||
{
|
||||
typedef struct args_t {
|
||||
typedef struct args_t
|
||||
{
|
||||
const char* user;
|
||||
const char* db_path;
|
||||
bool help;
|
||||
@ -154,8 +163,9 @@ static int _tf_command_import(const char* file, int argc, char* argv[])
|
||||
args_t args = { .user = "import", .db_path = k_db_path_default };
|
||||
const char** extras = NULL;
|
||||
int extra_count = 0;
|
||||
const char *err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "import [options] [paths] ...", "options:", NULL, 15);
|
||||
const char* err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr,
|
||||
"import [options] [paths] ...", "options:", NULL, 15);
|
||||
if (err)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
@ -194,7 +204,8 @@ xopt_help:
|
||||
|
||||
static int _tf_command_export(const char* file, int argc, char* argv[])
|
||||
{
|
||||
typedef struct args_t {
|
||||
typedef struct args_t
|
||||
{
|
||||
const char* user;
|
||||
const char* db_path;
|
||||
bool help;
|
||||
@ -210,8 +221,9 @@ static int _tf_command_export(const char* file, int argc, char* argv[])
|
||||
args_t args = { .user = "core", .db_path = k_db_path_default };
|
||||
const char** extras = NULL;
|
||||
int extra_count = 0;
|
||||
const char *err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "export [options] [paths] ...", "options:", NULL, 15);
|
||||
const char* err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr,
|
||||
"export [options] [paths] ...", "options:", NULL, 15);
|
||||
if (err)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
@ -264,7 +276,8 @@ xopt_help:
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct tf_run_args_t {
|
||||
typedef struct tf_run_args_t
|
||||
{
|
||||
const char* script;
|
||||
int ssb_port;
|
||||
int http_port;
|
||||
@ -401,8 +414,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
XOPT_NULLOPTION,
|
||||
};
|
||||
|
||||
tf_run_args_t args =
|
||||
{
|
||||
tf_run_args_t args = {
|
||||
.count = 1,
|
||||
.script = "core/core.js",
|
||||
.http_port = 12345,
|
||||
@ -412,8 +424,9 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
};
|
||||
const char** extras = NULL;
|
||||
int extra_count = 0;
|
||||
const char *err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "run [options] [paths] ...", "options:", NULL, 15);
|
||||
const char* err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr,
|
||||
"run [options] [paths] ...", "options:", NULL, 15);
|
||||
|
||||
if (err)
|
||||
{
|
||||
@ -434,10 +447,9 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
{
|
||||
uv_thread_t* threads = tf_malloc(sizeof(uv_thread_t) * args.count);
|
||||
tf_run_thread_data_t* data = tf_malloc(sizeof(tf_run_thread_data_t) * args.count);
|
||||
for (int i = 0 ; i < args.count; i++)
|
||||
for (int i = 0; i < args.count; i++)
|
||||
{
|
||||
data[i] = (tf_run_thread_data_t)
|
||||
{
|
||||
data[i] = (tf_run_thread_data_t) {
|
||||
.args = args,
|
||||
.index = i,
|
||||
};
|
||||
@ -471,7 +483,8 @@ xopt_help:
|
||||
|
||||
static int _tf_command_sandbox(const char* file, int argc, char* argv[])
|
||||
{
|
||||
typedef struct args_t {
|
||||
typedef struct args_t
|
||||
{
|
||||
const char* script;
|
||||
bool help;
|
||||
} args_t;
|
||||
@ -484,8 +497,9 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[])
|
||||
args_t args = { 0 };
|
||||
const char** extras = NULL;
|
||||
int extra_count = 0;
|
||||
const char *err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "sandbox [options]", "options:", NULL, 15);
|
||||
const char* err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_POSIXMEHARDER | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr,
|
||||
"sandbox [options]", "options:", NULL, 15);
|
||||
if (err)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
@ -560,11 +574,7 @@ static void _startup(int argc, char* argv[])
|
||||
#endif
|
||||
|
||||
tf_mem_startup(tracking);
|
||||
g_backtrace_state = backtrace_create_state(
|
||||
argv[0],
|
||||
0,
|
||||
_backtrace_error,
|
||||
NULL);
|
||||
g_backtrace_state = backtrace_create_state(argv[0], 0, _backtrace_error, NULL);
|
||||
|
||||
#if defined(__linux__)
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
@ -590,9 +600,9 @@ static void _startup(int argc, char* argv[])
|
||||
{
|
||||
if (
|
||||
#if !defined(_WIN32)
|
||||
signal(SIGSYS, _error_handler) == SIG_ERR ||
|
||||
signal(SIGSYS, _error_handler) == SIG_ERR ||
|
||||
#endif
|
||||
signal(SIGSEGV, _error_handler) == SIG_ERR)
|
||||
signal(SIGSEGV, _error_handler) == SIG_ERR)
|
||||
{
|
||||
perror("signal");
|
||||
}
|
||||
@ -624,8 +634,7 @@ void tf_run_thread_start(const char* zip_path)
|
||||
_startup(0, NULL);
|
||||
uv_thread_t* thread = tf_malloc(sizeof(uv_thread_t));
|
||||
tf_run_thread_data_t* data = tf_malloc(sizeof(tf_run_thread_data_t));
|
||||
tf_run_args_t args =
|
||||
{
|
||||
tf_run_args_t args = {
|
||||
.count = 1,
|
||||
.script = "core/core.js",
|
||||
.http_port = 12345,
|
||||
@ -635,8 +644,7 @@ void tf_run_thread_start(const char* zip_path)
|
||||
.one_proc = true,
|
||||
.zip = zip_path,
|
||||
};
|
||||
*data = (tf_run_thread_data_t)
|
||||
{
|
||||
*data = (tf_run_thread_data_t) {
|
||||
.args = args,
|
||||
};
|
||||
uv_thread_create(thread, _tf_run_task_thread, data);
|
||||
|
Reference in New Issue
Block a user