From 3d9c4b0ac52dc8d6bb2f3b4eaa676641f70f2cd5 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Tue, 1 Dec 2009 15:11:45 +0000 Subject: [PATCH] Added `--addon'/`-A', in addition to $PLTADDONDIR from revision 17121. svn: r17136 --- collects/scribblings/inside/hooks.scrbl | 7 ++++ .../scribblings/reference/filesystem.scrbl | 13 +++++--- src/mzscheme/cmdline.inc | 32 ++++++++++++++++++- src/mzscheme/include/scheme.h | 1 + src/mzscheme/src/file.c | 12 ++++++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/collects/scribblings/inside/hooks.scrbl b/collects/scribblings/inside/hooks.scrbl index 52b38198d4..f792483917 100644 --- a/collects/scribblings/inside/hooks.scrbl +++ b/collects/scribblings/inside/hooks.scrbl @@ -57,6 +57,13 @@ Sets the path to be returned by @scheme[(find-system-path 'collects-dir)].} +@function[(void scheme_set_addon_path + [Scheme_Object* path])]{ + +Sets the path to be returned by @scheme[(find-system-path +'addon-dir)].} + + @function[(void scheme_init_collection_paths_post [Scheme_Env* env] [Scheme_Object* pre_extra_paths] diff --git a/collects/scribblings/reference/filesystem.scrbl b/collects/scribblings/reference/filesystem.scrbl index 9e094ada08..edc90374b2 100644 --- a/collects/scribblings/reference/filesystem.scrbl +++ b/collects/scribblings/reference/filesystem.scrbl @@ -80,10 +80,15 @@ by @scheme[kind], which must be one of the following: ]} - @item{@indexed-scheme['addon-dir] --- a directory for installing PLT Scheme - extensions. It's the same as @scheme['pref-dir], except under Mac OS - X, where it is @filepath{Library/PLT Scheme} in the user's home - directory. This directory might not exist.} + @item{@indexed-scheme['addon-dir] --- a directory for installing PLT + Scheme extensions. This directory is specified by the + @indexed-envvar{PLTADDONDIR} environment variable, and it can be + overridden by the @DFlag{addon} or @Flag{A} command-line flag. If no + environment variable or flag is specified, or if the value is not a + legal path name, then this directory defaults to + @filepath{Library/PLT Scheme} in the user's home directory under Mac + OS X and @scheme['pref-dir] otherwise. This directory might not + exist.} @item{@indexed-scheme['doc-dir] --- the standard directory for storing the current user's documents. Under Unix, it's the same as diff --git a/src/mzscheme/cmdline.inc b/src/mzscheme/cmdline.inc index 250b7a5b16..ef5510a7af 100644 --- a/src/mzscheme/cmdline.inc +++ b/src/mzscheme/cmdline.inc @@ -456,7 +456,9 @@ static int run_from_cmd_line(int argc, char *_argv[], GC_CAN_IGNORE char **argv = _argv; Scheme_Env *global_env; char *prog, *sprog = NULL; - Scheme_Object *sch_argv, *collects_path = NULL, *collects_extra = NULL; + Scheme_Object *sch_argv, + *collects_path = NULL, *collects_extra = NULL, + *addon_dir = NULL; int i; #ifndef DONT_PARSE_COMMAND_LINE char **evals_and_loads, *real_switch = NULL, specific_switch[2]; @@ -693,6 +695,8 @@ static int run_from_cmd_line(int argc, char *_argv[], argv[0] = "-X"; else if (!strcmp("--search", argv[0])) argv[0] = "-S"; + else if (!strcmp("--addon", argv[0])) + argv[0] = "-A"; # ifdef CMDLINE_STDIO_FLAG else if (!strcmp("--stdio", argv[0])) argv[0] = "-z"; @@ -738,6 +742,17 @@ static int run_from_cmd_line(int argc, char *_argv[], collects_path = scheme_make_path(argv[0]); was_config_flag = 1; break; + case 'A': + if (argc < 2) { + PRINTF("%s: missing path after %s switch\n", + prog, real_switch); + goto show_need_help; + } + argv++; + --argc; + addon_dir = scheme_make_path(argv[0]); + was_config_flag = 1; + break; case 'U': scheme_set_ignore_user_paths(1); was_config_flag = 1; @@ -1041,6 +1056,20 @@ static int run_from_cmd_line(int argc, char *_argv[], } #ifndef NO_FILE_SYSTEM_UTILS + /* Setup path for "addon" directory: */ + { +#ifdef GETENV_FUNCTION + if (!addon_dir) { + char *s; + s = getenv("PLTADDONDIR"); + if (s) { + s = scheme_expand_filename(s, -1, NULL, NULL, 0); + if (s) addon_dir = scheme_make_path(s); + } + } +#endif + if (addon_dir) scheme_set_addon_dir(addon_dir); + } /* Setup path for "collects" collection directory: */ { Scheme_Object *l, *r; @@ -1149,6 +1178,7 @@ static int run_from_cmd_line(int argc, char *_argv[], " -I : Set to \n" " -X , --collects : Main collects at \n" " -S , --search : More collects at (after main collects)\n" + " -A , --addon : Addon directory at \n" " -U, --no-user-path : Ignore user-specific collects, etc.\n" " -N , --name : Sets `(find-system-path 'run-file)' to \n" # ifdef MZ_USE_JIT diff --git a/src/mzscheme/include/scheme.h b/src/mzscheme/include/scheme.h index 891b1c4caa..53e15c63f0 100644 --- a/src/mzscheme/include/scheme.h +++ b/src/mzscheme/include/scheme.h @@ -1745,6 +1745,7 @@ MZ_EXTERN Scheme_Object *scheme_set_exec_cmd(char *s); MZ_EXTERN Scheme_Object *scheme_set_run_cmd(char *s); MZ_EXTERN void scheme_set_collects_path(Scheme_Object *p); MZ_EXTERN void scheme_set_original_dir(Scheme_Object *d); +MZ_EXTERN void scheme_set_addon_dir(Scheme_Object *p); MZ_EXTERN void scheme_init_collection_paths(Scheme_Env *global_env, Scheme_Object *extra_dirs); MZ_EXTERN void scheme_init_collection_paths_post(Scheme_Env *global_env, Scheme_Object *extra_dirs, Scheme_Object *extra_post_dirs); diff --git a/src/mzscheme/src/file.c b/src/mzscheme/src/file.c index ef2652bfc0..a056c3556b 100644 --- a/src/mzscheme/src/file.c +++ b/src/mzscheme/src/file.c @@ -227,7 +227,8 @@ static Scheme_Object *init_dir_symbol, *init_file_symbol, *sys_dir_symbol; static Scheme_Object *exec_file_symbol, *run_file_symbol, *collects_dir_symbol; static Scheme_Object *pref_file_symbol, *orig_dir_symbol, *addon_dir_symbol; -static Scheme_Object *exec_cmd, *run_cmd, *collects_path, *original_pwd; +static Scheme_Object *exec_cmd, *run_cmd; +static Scheme_Object *collects_path, *original_pwd = NULL, *addon_dir = NULL; #endif static Scheme_Object *windows_symbol, *unix_symbol; @@ -5734,6 +5735,7 @@ find_system_path(int argc, Scheme_Object **argv) } else if (argv[0] == orig_dir_symbol) { return original_pwd; } else if (argv[0] == addon_dir_symbol) { + if (addon_dir) return addon_dir; which = id_addon_dir; } else { scheme_wrong_type("find-system-path", "system-path-symbol", @@ -6023,6 +6025,14 @@ void scheme_set_original_dir(Scheme_Object *d) original_pwd = d; } +void scheme_set_addon_dir(Scheme_Object *p) +{ + if (!addon_dir) { + REGISTER_SO(addon_dir); + } + addon_dir = p; +} + /********************************************************************************/ #ifdef DOS_FILE_SYSTEM