comparison src/octave.cc @ 139:d80376609fd1

[project @ 1993-09-29 23:23:37 by jwe] Handle long options.
author jwe
date Wed, 29 Sep 1993 23:23:37 +0000
parents 3abd838cc4b3
children 7849db4b6dbc
comparison
equal deleted inserted replaced
138:b3b67829e001 139:d80376609fd1
26 #ifdef __GNUG__ 26 #ifdef __GNUG__
27 #pragma implementation 27 #pragma implementation
28 #endif 28 #endif
29 29
30 #include <sys/types.h> 30 #include <sys/types.h>
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
31 #include <sys/stat.h> 34 #include <sys/stat.h>
32 #include <time.h> 35 #include <time.h>
33 #include <pwd.h> 36 #include <pwd.h>
34 #include <setjmp.h> 37 #include <setjmp.h>
35 #include <stdlib.h> 38 #include <stdlib.h>
36 #include <string.h> 39 #include <string.h>
37 #include <signal.h> 40 #include <signal.h>
38 #include <assert.h> 41 #include <assert.h>
39 #include <iostream.h> 42 #include <iostream.h>
40 #include <fstream.h> 43 #include <fstream.h>
41 #include <GetOpt.h> 44
45 #include "getopt.h"
42 46
43 #include "sighandlers.h" 47 #include "sighandlers.h"
44 #include "variables.h" 48 #include "variables.h"
45 #include "error.h" 49 #include "error.h"
46 #include "tree-const.h" 50 #include "tree-const.h"
114 118
115 // Nonzero means we don\'t print the usual startup message. 119 // Nonzero means we don\'t print the usual startup message.
116 static int inhibit_startup_message = 0; 120 static int inhibit_startup_message = 0;
117 121
118 // Usage message 122 // Usage message
119 static const char *usage_string = "octave [-?dfhiqvx] [-p path] [file]"; 123 static const char *usage_string =
124 "octave [-?dfhiqvx] [-p path] [--debug] [--help] [--interactive]\n\
125 [--norc] [--path path] [--quiet] [--version] [--echo-commands]\n\
126 [file]";
120 127
121 // This is here so that it\'s more likely that the usage message and 128 // This is here so that it\'s more likely that the usage message and
122 // the real set of options will agree. 129 // the real set of options will agree.
123 static const char *getopt_option_string = "?dfhip:qvx"; 130 static const char *short_opts = "?dfhip:qvx";
131
132 // Long options.
133 static struct option long_opts[] =
134 {
135 { "debug", 0, 0, 'd' },
136 { "help", 0, 0, 'h' },
137 { "interactive", 0, 0, 'i' },
138 { "norc", 0, 0, 'f' },
139 { "path", 1, 0, 'p' },
140 { "quiet", 0, 0, 'q' },
141 { "version", 0, 0, 'v' },
142 { "echo-commands", 0, 0, 'x' },
143 { 0, 0, 0, 0 }
144 };
124 145
125 /* 146 /*
126 * Initialize some global variables for later use. 147 * Initialize some global variables for later use.
127 */ 148 */
128 static void 149 static void
260 cout << "\n" 281 cout << "\n"
261 << " Octave, version " << version_string 282 << " Octave, version " << version_string
262 << ". Copyright (C) 1992, 1993, John W. Eaton.\n" 283 << ". Copyright (C) 1992, 1993, John W. Eaton.\n"
263 << " This is free software with ABSOLUTELY NO WARRANTY.\n" 284 << " This is free software with ABSOLUTELY NO WARRANTY.\n"
264 << "\n" 285 << "\n"
265 << " " << usage_string 286 << " usage: " << usage_string
266 << "\n" 287 << "\n\n"
267 << " d : enter parser debugging mode\n" 288 << " d : enter parser debugging mode\n"
268 << " f : don't read ~/.octaverc or .octaverc at startup\n" 289 << " f : don't read ~/.octaverc or .octaverc at startup\n"
269 << " h|? : print short help message and exit\n" 290 << " h|? : print short help message and exit\n"
270 << " i : force interactive behavior\n" 291 << " i : force interactive behavior\n"
271 << " q : don't print message at startup\n" 292 << " q : don't print message at startup\n"
293 << " v : print version number and exit\n"
272 << " x : echo commands as they are executed\n" 294 << " x : echo commands as they are executed\n"
273 << "\n" 295 << "\n"
274 << " file : execute commands from named file\n" 296 << " file : execute commands from named file\n"
275 << "\n"; 297 << "\n";
276 298
281 * Terse usage messsage. 303 * Terse usage messsage.
282 */ 304 */
283 static void 305 static void
284 usage (void) 306 usage (void)
285 { 307 {
286 usage (usage_string); 308 cerr << "usage: " << usage_string << "\n";
287 exit (1); 309 exit (1);
288 } 310 }
289 311
290 /* 312 /*
291 * Fix up things before exiting. 313 * Fix up things before exiting.
326 348
327 // Do this first, since some command line arguments may override the 349 // Do this first, since some command line arguments may override the
328 // defaults. 350 // defaults.
329 initialize_globals (argv[0]); 351 initialize_globals (argv[0]);
330 352
331 // If the 353 int optc;
332 GetOpt getopt (argc, argv, getopt_option_string); 354 while ((optc = getopt_long (argc, argv, short_opts, long_opts, 0)) != EOF)
333 int option_char; 355 {
334 356 switch (optc)
335 while ((option_char = getopt ()) != EOF)
336 {
337 switch (option_char)
338 { 357 {
339 case 'd': 358 case 'd':
340 yydebug++; 359 yydebug++;
341 break; 360 break;
342 case 'f': 361 case 'f':
348 break; 367 break;
349 case 'i': 368 case 'i':
350 forced_interactive = 1; 369 forced_interactive = 1;
351 break; 370 break;
352 case 'p': 371 case 'p':
353 if (getopt.optarg != (char *) NULL) 372 if (optarg != (char *) NULL)
354 load_path = strsave (getopt.optarg); 373 load_path = strsave (optarg);
355 break; 374 break;
356 case 'q': 375 case 'q':
357 inhibit_startup_message = 1; 376 inhibit_startup_message = 1;
358 break; 377 break;
359 case 'x': 378 case 'x':
406 // Avoid counting commands executed from startup files. 425 // Avoid counting commands executed from startup files.
407 current_command_number = 1; 426 current_command_number = 1;
408 427
409 // If there is an extra argument, see if it names a file to read. 428 // If there is an extra argument, see if it names a file to read.
410 429
411 if (getopt.optind != argc) 430 if (optind != argc)
412 { 431 {
413 FILE *infile = get_input_from_file (argv[getopt.optind]); 432 FILE *infile = get_input_from_file (argv[optind]);
414 if (infile == (FILE *) NULL) 433 if (infile == (FILE *) NULL)
415 clean_up_and_exit (1); 434 clean_up_and_exit (1);
416 else 435 else
417 switch_to_buffer (create_buffer (infile)); 436 switch_to_buffer (create_buffer (infile));
418 } 437 }