From 67516fd13d3c6162a10b34c0cc19b464df14258a Mon Sep 17 00:00:00 2001 From: Cameron Hall Date: Thu, 2 Nov 2017 00:39:49 -0500 Subject: [PATCH 1/4] add command line option for user dir --- ball/main.c | 15 ++++++++++++++- putt/main.c | 8 +++++++- share/base_config.c | 9 ++++++--- share/base_config.h | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ball/main.c b/ball/main.c index bd8fd8b54..9276a8f2a 100644 --- a/ball/main.c +++ b/ball/main.c @@ -317,6 +317,7 @@ static int loop(void) /*---------------------------------------------------------------------------*/ static char *opt_data; +static char *opt_user; static char *opt_replay; static char *opt_level; @@ -326,6 +327,7 @@ static char *opt_level; " -h, --help show this usage message.\n" \ " -v, --version show version.\n" \ " -d, --data use 'dir' as game data directory.\n" \ + " -d, --user use 'dir' as user data directory.\n" \ " -r, --replay play the replay 'file'.\n" \ " -l, --level load the level 'file'\n" @@ -363,6 +365,17 @@ static void opt_parse(int argc, char **argv) continue; } + if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--user") == 0) + { + if (i + 1 == argc) + { + opt_error(argv[i]); + exit(EXIT_FAILURE); + } + opt_user = argv[++i]; + continue; + } + if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--replay") == 0) { if (i + 1 == argc) @@ -490,7 +503,7 @@ int main(int argc, char *argv[]) opt_parse(argc, argv); - config_paths(opt_data); + config_paths(opt_data, opt_user); log_init("Neverball", "neverball.log"); make_dirs_and_migrate(); diff --git a/putt/main.c b/putt/main.c index 6f6b9b300..a185a8253 100644 --- a/putt/main.c +++ b/putt/main.c @@ -239,6 +239,7 @@ static int loop(void) /*---------------------------------------------------------------------------*/ static char *opt_data; +static char *opt_user; static char *opt_hole; static void opt_parse(int argc, char **argv) @@ -252,6 +253,11 @@ static void opt_parse(int argc, char **argv) if (++i < argc) opt_data = argv[i]; } + else if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--user") == 0) + { + if (++i < argc) + opt_user = argv[i]; + } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--hole") == 0) { if (++i < argc) @@ -294,7 +300,7 @@ int main(int argc, char *argv[]) opt_parse(argc, argv); - config_paths(opt_data); + config_paths(opt_data, opt_user); log_init("Neverputt", "neverputt.log"); fs_mkdir("Screenshots"); diff --git a/share/base_config.c b/share/base_config.c index bc51823eb..b6b4c3722 100644 --- a/share/base_config.c +++ b/share/base_config.c @@ -48,8 +48,11 @@ static const char *pick_data_path(const char *arg_data_path) return dir; } -static const char *pick_home_path(void) +static const char *pick_home_path(const char *arg_user_path) { + if (arg_user_path) + return arg_user_path; + #ifdef _WIN32 static char path[MAX_PATH]; @@ -74,7 +77,7 @@ static const char *pick_home_path(void) #endif } -void config_paths(const char *arg_data_path) +void config_paths(const char *arg_data_path, const char *arg_user_path) { const char *data, *home, *user; @@ -94,7 +97,7 @@ void config_paths(const char *arg_data_path) /* User directory. */ - home = pick_home_path(); + home = pick_home_path(arg_user_path); user = concat_string(home, "/", CONFIG_USER, NULL); /* Set up directory for writing, create if needed. */ diff --git a/share/base_config.h b/share/base_config.h index df4860df6..396958ed8 100644 --- a/share/base_config.h +++ b/share/base_config.h @@ -77,7 +77,7 @@ /*---------------------------------------------------------------------------*/ -void config_paths(const char *); +void config_paths(const char *, const char *); /*---------------------------------------------------------------------------*/ From 1dc0850dd0a7c4a8019119b2053ec72eefaba9a6 Mon Sep 17 00:00:00 2001 From: Cameron Hall Date: Thu, 2 Nov 2017 01:14:50 -0500 Subject: [PATCH 2/4] oops -u, not -d --- ball/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ball/main.c b/ball/main.c index 9276a8f2a..cd133e807 100644 --- a/ball/main.c +++ b/ball/main.c @@ -327,7 +327,7 @@ static char *opt_level; " -h, --help show this usage message.\n" \ " -v, --version show version.\n" \ " -d, --data use 'dir' as game data directory.\n" \ - " -d, --user use 'dir' as user data directory.\n" \ + " -u, --user use 'dir' as user data directory.\n" \ " -r, --replay play the replay 'file'.\n" \ " -l, --level load the level 'file'\n" From a3e5fc27bb7721ad44941d2bf4ef81cfd0b97599 Mon Sep 17 00:00:00 2001 From: camthesaxman Date: Thu, 9 Nov 2017 12:12:52 -0600 Subject: [PATCH 3/4] Actually mean the user directory when specifying --user --- share/base_config.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/share/base_config.c b/share/base_config.c index b6b4c3722..18082bccb 100644 --- a/share/base_config.c +++ b/share/base_config.c @@ -48,11 +48,8 @@ static const char *pick_data_path(const char *arg_data_path) return dir; } -static const char *pick_home_path(const char *arg_user_path) +static const char *pick_home_path(void) { - if (arg_user_path) - return arg_user_path; - #ifdef _WIN32 static char path[MAX_PATH]; @@ -97,8 +94,13 @@ void config_paths(const char *arg_data_path, const char *arg_user_path) /* User directory. */ - home = pick_home_path(arg_user_path); - user = concat_string(home, "/", CONFIG_USER, NULL); + if (arg_user_path) + user = arg_user_path; + else + { + home = pick_home_path(); + user = concat_string(home, "/", CONFIG_USER, NULL); + } /* Set up directory for writing, create if needed. */ From b59360f6d47a5b36b78035100a64d4a8ba8f5022 Mon Sep 17 00:00:00 2001 From: camthesaxman Date: Thu, 9 Nov 2017 12:17:02 -0600 Subject: [PATCH 4/4] use spaces instead of tabs --- share/base_config.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/share/base_config.c b/share/base_config.c index 18082bccb..df90d4794 100644 --- a/share/base_config.c +++ b/share/base_config.c @@ -94,13 +94,13 @@ void config_paths(const char *arg_data_path, const char *arg_user_path) /* User directory. */ - if (arg_user_path) - user = arg_user_path; - else - { - home = pick_home_path(); - user = concat_string(home, "/", CONFIG_USER, NULL); - } + if (arg_user_path) + user = arg_user_path; + else + { + home = pick_home_path(); + user = concat_string(home, "/", CONFIG_USER, NULL); + } /* Set up directory for writing, create if needed. */