comparison src/octave.cc @ 1613:f18871f4df2b

[project @ 1995-11-03 12:06:56 by jwe]
author jwe
date Fri, 03 Nov 1995 12:12:36 +0000
parents 004842061dcf
children e846e361a265
comparison
equal deleted inserted replaced
1612:004842061dcf 1613:f18871f4df2b
99 char *home_directory = 0; 99 char *home_directory = 0;
100 100
101 // Guess what? 101 // Guess what?
102 char *the_current_working_directory = 0; 102 char *the_current_working_directory = 0;
103 103
104 // Load path specified on command line. (--path path; -p path) 104 // The path that will be searched for programs that we execute.
105 // (--exec-path path)
106 char *exec_path = 0;
107
108 // Load path specified on command line.
109 // (--path path; -p path)
105 char *load_path = 0; 110 char *load_path = 0;
106 111
107 // Name of the info file specified on command line. 112 // Name of the info file specified on command line.
108 // (--info-file file; -i file) 113 // (--info-file file)
109 char *info_file = 0; 114 char *info_file = 0;
115
116 // Name of the info reader we'd like to use.
117 // (--info-program program)
118 char *info_prog = 0;
110 119
111 // Name of the editor to be invoked by the edit_history command. 120 // Name of the editor to be invoked by the edit_history command.
112 char *editor = 0; 121 char *editor = 0;
113 122
114 // If nonzero, don't do fancy line editing. 123 // If nonzero, don't do fancy line editing.
172 // (--traditional) 181 // (--traditional)
173 static int traditional = 0; 182 static int traditional = 0;
174 183
175 // Usage message 184 // Usage message
176 static const char *usage_string = 185 static const char *usage_string =
177 "octave [-?Vdfhiqvx] [-p path] [--debug] [--help] [--ignore-init-file]\n\ 186 "octave [-?Vdfhiqvx] [--debug] [--echo-commands] [--exec-path path]\n\
178 [--info-file file] [--interactive] [--path path] [--silent]\n\ 187 [--help] [--ignore-init-file] [--info-file file] [--info-program prog]\n\
179 [--traditional] [--verbose] [--version] [--echo-commands] [file]"; 188 [--interactive] [-p path] [--path path] [--silent] [--traditional]\n\
189 [--verbose] [--version] [file]";
180 190
181 // This is here so that it's more likely that the usage message and 191 // This is here so that it's more likely that the usage message and
182 // the real set of options will agree. Note: the `+' must come first 192 // the real set of options will agree. Note: the `+' must come first
183 // to prevent getopt from permuting arguments! 193 // to prevent getopt from permuting arguments!
184 static const char *short_opts = "+?Vdfhip:qvx"; 194 static const char *short_opts = "+?Vdfhip:qvx";
185 195
186 // Long options. See the comments in getopt.h for the meanings of the 196 // Long options. See the comments in getopt.h for the meanings of the
187 // fields in this structure. 197 // fields in this structure.
188 #define INFO_FILE_OPTION 1 198 #define EXEC_PATH_OPTION 1
189 #define TRADITIONAL_OPTION 2 199 #define INFO_FILE_OPTION 2
200 #define INFO_PROG_OPTION 3
201 #define TRADITIONAL_OPTION 4
190 static struct option long_opts[] = 202 static struct option long_opts[] =
191 { 203 {
192 { "debug", no_argument, 0, 'd' }, 204 { "debug", no_argument, 0, 'd' },
205 { "echo-commands", no_argument, 0, 'x' },
206 { "exec-path", required_argument, 0, EXEC_PATH_OPTION },
193 { "help", no_argument, 0, 'h' }, 207 { "help", no_argument, 0, 'h' },
194 { "interactive", no_argument, 0, 'i' }, 208 { "interactive", no_argument, 0, 'i' },
195 { "info-file", required_argument, 0, INFO_FILE_OPTION }, 209 { "info-file", required_argument, 0, INFO_FILE_OPTION },
210 { "info-program", required_argument, 0, INFO_PROG_OPTION },
211 { "ignore-init-file", no_argument, 0, 'f' },
196 { "norc", no_argument, 0, 'f' }, 212 { "norc", no_argument, 0, 'f' },
197 { "ignore-init-file", no_argument, 0, 'f' },
198 { "path", required_argument, 0, 'p' }, 213 { "path", required_argument, 0, 'p' },
199 { "quiet", no_argument, 0, 'q' }, 214 { "quiet", no_argument, 0, 'q' },
200 { "silent", no_argument, 0, 'q' }, 215 { "silent", no_argument, 0, 'q' },
201 { "traditional", no_argument, 0, TRADITIONAL_OPTION }, 216 { "traditional", no_argument, 0, TRADITIONAL_OPTION },
202 { "verbose", no_argument, 0, 'V' }, 217 { "verbose", no_argument, 0, 'V' },
203 { "version", no_argument, 0, 'v' }, 218 { "version", no_argument, 0, 'v' },
204 { "echo-commands", no_argument, 0, 'x' },
205 { 0, 0, 0, 0 } 219 { 0, 0, 0, 0 }
206 }; 220 };
207 221
208 // Store the command-line options for later use. 222 // Store the command-line options for later use.
209 223
257 if (hd) 271 if (hd)
258 home_directory = strsave (hd); 272 home_directory = strsave (hd);
259 else 273 else
260 home_directory = strsave ("I have no home!"); 274 home_directory = strsave ("I have no home!");
261 275
262 char *shell_path = getenv ("PATH");
263 char *arch_dir = octave_arch_lib_dir ();
264 char *bin_dir = octave_bin_dir ();
265
266 int len = strlen (arch_dir) + strlen (bin_dir) + 7;
267
268 char *putenv_cmd = 0;
269
270 if (shell_path)
271 {
272 len += strlen (shell_path) + 1;
273 putenv_cmd = new char [len];
274 sprintf (putenv_cmd,
275 "PATH=%s" SEPCHAR_STR "%s" SEPCHAR_STR "%s",
276 arch_dir, bin_dir, shell_path);
277 }
278 else
279 {
280 putenv_cmd = new char [len];
281 sprintf (putenv_cmd, "PATH=%s" SEPCHAR_STR "%s", arch_dir, bin_dir);
282 }
283
284 putenv (putenv_cmd);
285
286 // This may seem odd, but doing it this way means that we don't have 276 // This may seem odd, but doing it this way means that we don't have
287 // to modify the kpathsea library... 277 // to modify the kpathsea library...
288 278
289 char *odb = getenv ("OCTAVE_DB_DIR"); 279 char *odb = getenv ("OCTAVE_DB_DIR");
290 280
294 { 284 {
295 char *oh = getenv ("OCTAVE_HOME"); 285 char *oh = getenv ("OCTAVE_HOME");
296 286
297 if (oh) 287 if (oh)
298 { 288 {
299 len = strlen (oh) + 18; 289 int len = strlen (oh) + 18;
300 putenv_cmd = new char [len]; 290 char *putenv_cmd = new char [len];
301 sprintf (putenv_cmd, "TEXMF=%s/lib/octave", oh); 291 sprintf (putenv_cmd, "TEXMF=%s/lib/octave", oh);
302 putenv (putenv_cmd); 292 putenv (putenv_cmd);
303 } 293 }
304 else 294 else
305 putenv (strsave ("TEXMF=" OCTAVE_DATADIR "/octave")); 295 putenv (strsave ("TEXMF=" OCTAVE_DATADIR "/octave"));
306 } 296 }
307 297
298 exec_path = default_exec_path ();
299
308 load_path = default_path (); 300 load_path = default_path ();
309 301
310 info_file = default_info_file (); 302 info_file = default_info_file ();
303
304 info_prog = default_info_prog ();
311 305
312 editor = default_editor (); 306 editor = default_editor ();
313 } 307 }
314 308
315 void 309 void
481 // Usage message with extra help. 475 // Usage message with extra help.
482 476
483 static void 477 static void
484 verbose_usage (void) 478 verbose_usage (void)
485 { 479 {
486 cout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\n\ 480 cout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\
487 Usage: " << usage_string << "\n\
488 \n\ 481 \n\
489 -d, --debug enter parser debugging mode\n\ 482 Usage: octave [options]\n\
490 -f, --ignore-init-file don't read any initialization files\n\
491 -h, -?, --help print short help message and exit\n\
492 -i, --interactive force interactive behavior\n\
493 --info-file FILE use top-level info file FILE\n\
494 -p PATH, --path PATH set initial LOADPATH to PATH\n\
495 -q, --silent don't print message at startup\n\
496 --traditional set compatibility variables\n\
497 -V, --verbose enable verbose output in some cases\n\
498 -v, --version print version number and exit\n\
499 -x, --echo-commands echo commands as they are executed\n\
500 \n\ 483 \n\
501 FILE execute commands from FILE\n\ 484 Options:\n\
485 \n\
486 -d, --debug Enter parser debugging mode.\n\
487 -x, --echo-commands Echo commands as they are executed.\n\
488 --exec-path PATH Set path for executing subprograms.\n\
489 -h, -?, --help Print short help message and exit.\n\
490 -f, --ignore-init-file Don't read any initialization files.\n\
491 --info-file FILE Use top-level info file FILE.\n\
492 --info-program PROGRAM Use PROGRAM for reading info files.\n\
493 -i, --interactive Force interactive behavior.\n\
494 -p PATH, --path PATH Set initial LOADPATH to PATH.\n\
495 -q, --silent Don't print message at startup.\n\
496 --traditional Set compatibility variables.\n\
497 -V, --verbose Enable verbose output in some cases.\n\
498 -v, --version Print version number and exit.\n\
499 \n\
500 FILE Execute commands from FILE.\n\
502 \n"; 501 \n";
503 502
504 exit (0); 503 exit (0);
505 } 504 }
506 505
644 643
645 case 'v': 644 case 'v':
646 print_version_and_exit (); 645 print_version_and_exit ();
647 break; 646 break;
648 647
648 case EXEC_PATH_OPTION:
649 if (optarg)
650 exec_path = strsave (optarg);
651 break;
652
649 case INFO_FILE_OPTION: 653 case INFO_FILE_OPTION:
650 if (optarg) 654 if (optarg)
651 info_file = strsave (optarg); 655 info_file = strsave (optarg);
656 break;
657
658 case INFO_PROG_OPTION:
659 if (optarg)
660 info_prog = strsave (optarg);
652 break; 661 break;
653 662
654 case TRADITIONAL_OPTION: 663 case TRADITIONAL_OPTION:
655 traditional = 1; 664 traditional = 1;
656 break; 665 break;