# HG changeset patch # User jwe # Date 815400756 0 # Node ID f18871f4df2bbcd38c60a0121e48ffe5d65a2847 # Parent 004842061dcf70265e95330e7e7ec71fa37fc06d [project @ 1995-11-03 12:06:56 by jwe] diff --git a/src/help.cc b/src/help.cc --- a/src/help.cc +++ b/src/help.cc @@ -529,7 +529,7 @@ ostrstream cmd_buf; - cmd_buf << "info --file " << user_pref.info_file; + cmd_buf << user_pref.info_prog << " --file " << user_pref.info_file; char *directory_name = strsave (user_pref.info_file); char *file = strrchr (directory_name, '/'); diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -101,13 +101,22 @@ // Guess what? char *the_current_working_directory = 0; -// Load path specified on command line. (--path path; -p path) +// The path that will be searched for programs that we execute. +// (--exec-path path) +char *exec_path = 0; + +// Load path specified on command line. +// (--path path; -p path) char *load_path = 0; // Name of the info file specified on command line. -// (--info-file file; -i file) +// (--info-file file) char *info_file = 0; +// Name of the info reader we'd like to use. +// (--info-program program) +char *info_prog = 0; + // Name of the editor to be invoked by the edit_history command. char *editor = 0; @@ -174,9 +183,10 @@ // Usage message static const char *usage_string = - "octave [-?Vdfhiqvx] [-p path] [--debug] [--help] [--ignore-init-file]\n\ - [--info-file file] [--interactive] [--path path] [--silent]\n\ - [--traditional] [--verbose] [--version] [--echo-commands] [file]"; + "octave [-?Vdfhiqvx] [--debug] [--echo-commands] [--exec-path path]\n\ + [--help] [--ignore-init-file] [--info-file file] [--info-program prog]\n\ + [--interactive] [-p path] [--path path] [--silent] [--traditional]\n\ + [--verbose] [--version] [file]"; // This is here so that it's more likely that the usage message and // the real set of options will agree. Note: the `+' must come first @@ -185,23 +195,27 @@ // Long options. See the comments in getopt.h for the meanings of the // fields in this structure. -#define INFO_FILE_OPTION 1 -#define TRADITIONAL_OPTION 2 +#define EXEC_PATH_OPTION 1 +#define INFO_FILE_OPTION 2 +#define INFO_PROG_OPTION 3 +#define TRADITIONAL_OPTION 4 static struct option long_opts[] = { { "debug", no_argument, 0, 'd' }, + { "echo-commands", no_argument, 0, 'x' }, + { "exec-path", required_argument, 0, EXEC_PATH_OPTION }, { "help", no_argument, 0, 'h' }, { "interactive", no_argument, 0, 'i' }, { "info-file", required_argument, 0, INFO_FILE_OPTION }, + { "info-program", required_argument, 0, INFO_PROG_OPTION }, + { "ignore-init-file", no_argument, 0, 'f' }, { "norc", no_argument, 0, 'f' }, - { "ignore-init-file", no_argument, 0, 'f' }, { "path", required_argument, 0, 'p' }, { "quiet", no_argument, 0, 'q' }, { "silent", no_argument, 0, 'q' }, { "traditional", no_argument, 0, TRADITIONAL_OPTION }, { "verbose", no_argument, 0, 'V' }, { "version", no_argument, 0, 'v' }, - { "echo-commands", no_argument, 0, 'x' }, { 0, 0, 0, 0 } }; @@ -259,30 +273,6 @@ else home_directory = strsave ("I have no home!"); - char *shell_path = getenv ("PATH"); - char *arch_dir = octave_arch_lib_dir (); - char *bin_dir = octave_bin_dir (); - - int len = strlen (arch_dir) + strlen (bin_dir) + 7; - - char *putenv_cmd = 0; - - if (shell_path) - { - len += strlen (shell_path) + 1; - putenv_cmd = new char [len]; - sprintf (putenv_cmd, - "PATH=%s" SEPCHAR_STR "%s" SEPCHAR_STR "%s", - arch_dir, bin_dir, shell_path); - } - else - { - putenv_cmd = new char [len]; - sprintf (putenv_cmd, "PATH=%s" SEPCHAR_STR "%s", arch_dir, bin_dir); - } - - putenv (putenv_cmd); - // This may seem odd, but doing it this way means that we don't have // to modify the kpathsea library... @@ -296,8 +286,8 @@ if (oh) { - len = strlen (oh) + 18; - putenv_cmd = new char [len]; + int len = strlen (oh) + 18; + char *putenv_cmd = new char [len]; sprintf (putenv_cmd, "TEXMF=%s/lib/octave", oh); putenv (putenv_cmd); } @@ -305,10 +295,14 @@ putenv (strsave ("TEXMF=" OCTAVE_DATADIR "/octave")); } + exec_path = default_exec_path (); + load_path = default_path (); info_file = default_info_file (); + info_prog = default_info_prog (); + editor = default_editor (); } @@ -483,22 +477,27 @@ static void verbose_usage (void) { - cout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\n\ -Usage: " << usage_string << "\n\ + cout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ +\n\ +Usage: octave [options]\n\ +\n\ +Options:\n\ \n\ - -d, --debug enter parser debugging mode\n\ - -f, --ignore-init-file don't read any initialization files\n\ - -h, -?, --help print short help message and exit\n\ - -i, --interactive force interactive behavior\n\ - --info-file FILE use top-level info file FILE\n\ - -p PATH, --path PATH set initial LOADPATH to PATH\n\ - -q, --silent don't print message at startup\n\ - --traditional set compatibility variables\n\ - -V, --verbose enable verbose output in some cases\n\ - -v, --version print version number and exit\n\ - -x, --echo-commands echo commands as they are executed\n\ + -d, --debug Enter parser debugging mode.\n\ + -x, --echo-commands Echo commands as they are executed.\n\ + --exec-path PATH Set path for executing subprograms.\n\ + -h, -?, --help Print short help message and exit.\n\ + -f, --ignore-init-file Don't read any initialization files.\n\ + --info-file FILE Use top-level info file FILE.\n\ + --info-program PROGRAM Use PROGRAM for reading info files.\n\ + -i, --interactive Force interactive behavior.\n\ + -p PATH, --path PATH Set initial LOADPATH to PATH.\n\ + -q, --silent Don't print message at startup.\n\ + --traditional Set compatibility variables.\n\ + -V, --verbose Enable verbose output in some cases.\n\ + -v, --version Print version number and exit.\n\ \n\ - FILE execute commands from FILE\n\ + FILE Execute commands from FILE.\n\ \n"; exit (0); @@ -646,11 +645,21 @@ print_version_and_exit (); break; + case EXEC_PATH_OPTION: + if (optarg) + exec_path = strsave (optarg); + break; + case INFO_FILE_OPTION: if (optarg) info_file = strsave (optarg); break; + case INFO_PROG_OPTION: + if (optarg) + info_prog = strsave (optarg); + break; + case TRADITIONAL_OPTION: traditional = 1; break; diff --git a/src/toplev.h b/src/toplev.h --- a/src/toplev.h +++ b/src/toplev.h @@ -60,12 +60,18 @@ // Guess what? extern char *the_current_working_directory; +// The path that will be searched for programs that we execute. +extern char *exec_path; + // Load path specified on command line. extern char *load_path; // Name of the info file specified on command line. extern char *info_file; +// Name of the info reader we'd like to use. +extern char *info_prog; + // Name of the editor to be invoked by the edit_history command. extern char *editor; diff --git a/src/user-prefs.cc b/src/user-prefs.cc --- a/src/user-prefs.cc +++ b/src/user-prefs.cc @@ -25,6 +25,8 @@ #include #endif +#include +#include #include #include "error.h" @@ -80,9 +82,11 @@ user_pref.default_save_format = 0; user_pref.editor = 0; + user_pref.exec_path = 0; user_pref.gnuplot_binary = 0; user_pref.imagepath = 0; user_pref.info_file = 0; + user_pref.info_prog = 0; user_pref.loadpath = 0; user_pref.pager_binary = 0; user_pref.ps1 = 0; @@ -724,6 +728,82 @@ } int +sv_exec_path (void) +{ + int status = 0; + + char *exec_path = builtin_string_variable ("EXEC_PATH"); + if (exec_path) + { + char *arch_dir = octave_arch_lib_dir (); + char *bin_dir = octave_bin_dir (); + + int len = strlen (arch_dir) + strlen (bin_dir) + strlen (SEPCHAR_STR); + + static char *putenv_cmd = 0; + + delete [] putenv_cmd; + + putenv_cmd = 0; + + int eplen = strlen (exec_path); + + if (eplen > 0) + { + int prepend = (exec_path[0] == ':'); + int append = (eplen > 1 && exec_path[eplen-1] == ':'); + + if (prepend) + { + if (append) + { + putenv_cmd = new char [2 * len + eplen + 6]; + sprintf (putenv_cmd, + "PATH=%s" SEPCHAR_STR "%s%s%s" SEPCHAR_STR "%s", + arch_dir, bin_dir, exec_path, arch_dir, bin_dir); + } + else + { + putenv_cmd = new char [len + eplen + 6]; + sprintf (putenv_cmd, + "PATH=%s" SEPCHAR_STR "%s%s", + arch_dir, bin_dir, exec_path); + } + } + else + { + if (append) + { + putenv_cmd = new char [len + eplen + 6]; + sprintf (putenv_cmd, + "PATH=%s%s" SEPCHAR_STR "%s", + exec_path, arch_dir, bin_dir); + } + else + { + putenv_cmd = new char [len + eplen + 6]; + sprintf (putenv_cmd, "PATH=%s", exec_path); + } + } + } + else + { + putenv_cmd = new char [len+6]; + sprintf (putenv_cmd, "PATH=%s" SEPCHAR_STR "%s", arch_dir, bin_dir); + } + + putenv (putenv_cmd); + } + else + { + gripe_invalid_value_specified ("EXEC_PATH"); + status = -1; + } + + return status; +} + +int sv_gnuplot_binary (void) { int status = 0; @@ -784,6 +864,26 @@ } int +sv_info_prog (void) +{ + int status = 0; + + char *s = builtin_string_variable ("INFO_PROGRAM"); + if (s) + { + delete [] user_pref.info_prog; + user_pref.info_prog = s; + } + else + { + gripe_invalid_value_specified ("INFO_PROGRAM"); + status = -1; + } + + return status; +} + +int sv_loadpath (void) { int status = 0; diff --git a/src/user-prefs.h b/src/user-prefs.h --- a/src/user-prefs.h +++ b/src/user-prefs.h @@ -64,9 +64,11 @@ char *default_save_format; char *editor; + char *exec_path; char *gnuplot_binary; char *imagepath; char *info_file; + char *info_prog; char *loadpath; char *pager_binary; char *ps1; @@ -118,9 +120,11 @@ extern int sv_default_save_format (void); extern int sv_editor (void); +extern int sv_exec_path (void); extern int sv_gnuplot_binary (void); extern int sv_imagepath (void); extern int sv_info_file (void); +extern int sv_info_prog (void); extern int sv_loadpath (void); extern int sv_pager_binary (void); extern int sv_ps1 (void); diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -435,6 +435,25 @@ return retval; } +char * +default_exec_path (void) +{ + static char *exec_path_string = 0; + delete [] exec_path_string; + char *octave_exec_path = getenv ("OCTAVE_EXEC_PATH"); + if (octave_exec_path) + exec_path_string = strsave (octave_exec_path); + else + { + char *shell_path = getenv ("PATH"); + if (shell_path) + exec_path_string = strconcat (":", shell_path); + else + exec_path_string = strsave (""); + } + return exec_path_string; +} + // Handle OCTAVE_PATH from the environment like TeX handles TEXINPUTS. // If the path starts with `:', prepend the standard path. If it ends // with `:' append the standard path. If it begins and ends with @@ -473,6 +492,22 @@ } char * +default_info_prog (void) +{ + static char *info_prog_string = 0; + delete [] info_prog_string; + char *oct_info_prog = getenv ("OCTAVE_INFO_PROGRAM"); + if (oct_info_prog) + info_prog_string = strsave (oct_info_prog); + else + { + char *archdir = octave_arch_lib_dir (); + info_prog_string = strconcat (archdir, "/info"); + } + return info_prog_string; +} + +char * default_editor (void) { static char *editor_string = 0; @@ -1572,6 +1607,9 @@ DEFVAR ("EDITOR", SBV_EDITOR, editor, 0, sv_editor, "name of the editor to be invoked by the edit_history command"); + DEFVAR ("EXEC_PATH", SBV_EXEC_PATH, exec_path, 0, sv_exec_path, + "colon separated list of directories to search for programs to run"); + DEFCONST ("I", SBV_I, Complex (0.0, 1.0), 0, 0, "sqrt (-1)"); @@ -1581,6 +1619,9 @@ DEFVAR ("INFO_FILE", SBV_INFO_FILE, info_file, 0, sv_info_file, "name of the Octave info file"); + DEFVAR ("INFO_PROGRAM", SBV_INFO_PROGRAM, info_prog, 0, sv_info_prog, + "name of the Octave info reader"); + DEFCONST ("J", SBV_J, Complex (0.0, 1.0), 0, 0, "sqrt (-1)"); diff --git a/src/variables.h b/src/variables.h --- a/src/variables.h +++ b/src/variables.h @@ -129,8 +129,10 @@ extern char *octave_lib_dir (void); extern char *octave_arch_lib_dir (void); extern char *octave_bin_dir (void); +extern char *default_exec_path (void); extern char *default_path (void); extern char *default_info_file (void); +extern char *default_info_prog (void); extern char *default_editor (void); extern char *get_local_site_defaults (void); extern char *get_site_defaults (void);