comparison src/emacs.c @ 9094:39a13b869d66

(argmatch): New function. (main): Recognize --longopt synonyms for all options handled here. Add --help and --version.
author Karl Heuer <kwzh@gnu.org>
date Mon, 26 Sep 1994 18:14:29 +0000
parents 4fd9700b07a7
children b2ca75d3a5cb
comparison
equal deleted inserted replaced
9093:f8546f467db6 9094:39a13b869d66
330 __main () 330 __main ()
331 {} 331 {}
332 #endif /* __GNUC__ */ 332 #endif /* __GNUC__ */
333 #endif /* ORDINARY_LINK */ 333 #endif /* ORDINARY_LINK */
334 334
335 /* Test whether the next argument in ARGV matches SSTR or a prefix of
336 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null
337 (the argument is supposed to have a value) store in *VALPTR either
338 the next argument or the portion of this one after the equal sign.
339 ARGV is read starting at position *SKIPPTR; this index is advanced
340 by the number of arguments used.
341
342 Too bad we can't just use getopt for all of this, but we don't have
343 enough information to do it right. */
344 static int
345 argmatch (argv, sstr, lstr, minlen, valptr, skipptr)
346 char **argv;
347 char *sstr;
348 char *lstr;
349 int minlen;
350 char **valptr;
351 int *skipptr;
352 {
353 char *p;
354 int arglen;
355 char *arg = argv[*skipptr+1];
356 if (arg == NULL)
357 return 0;
358 if (strcmp (arg, sstr) == 0)
359 {
360 if (valptr != NULL)
361 {
362 *valptr = argv[*skipptr+2];
363 *skipptr += 2;
364 }
365 else
366 *skipptr += 1;
367 return 1;
368 }
369 arglen = (valptr != NULL && (p = index (arg, '=')) != NULL
370 ? p - arg : strlen (arg));
371 if (arglen < minlen || strncmp (arg, lstr, arglen) != 0)
372 return 0;
373 else if (valptr == NULL)
374 {
375 *skipptr += 1;
376 return 1;
377 }
378 else if (p != NULL)
379 {
380 *valptr = p+1;
381 *skipptr += 1;
382 return 1;
383 }
384 else if (argv[*skipptr+2] != NULL)
385 {
386 *valptr = argv[*skipptr+2];
387 *skipptr += 2;
388 return 1;
389 }
390 else
391 {
392 return 0;
393 }
394 }
395
335 /* ARGSUSED */ 396 /* ARGSUSED */
336 main (argc, argv, envp) 397 main (argc, argv, envp)
337 int argc; 398 int argc;
338 char **argv; 399 char **argv;
339 char **envp; 400 char **envp;
343 extern int errno; 404 extern int errno;
344 extern sys_nerr; 405 extern sys_nerr;
345 406
346 /* Map in shared memory, if we are using that. */ 407 /* Map in shared memory, if we are using that. */
347 #ifdef HAVE_SHM 408 #ifdef HAVE_SHM
348 if (argc > 1 && !strcmp (argv[1], "-nl")) 409 if (argmatch (argv, "-nl", "--no-shared-memory", 6, NULL, &skip_args))
349 { 410 {
350 map_in_data (0); 411 map_in_data (0);
351 /* The shared memory was just restored, which clobbered this. */ 412 /* The shared memory was just restored, which clobbered this. */
352 skip_args = 1; 413 skip_args = 1;
353 } 414 }
374 because we don't even know which window system dependent code 435 because we don't even know which window system dependent code
375 to run until we've recognized this argument. */ 436 to run until we've recognized this argument. */
376 { 437 {
377 int i; 438 int i;
378 439
440 /* We don't check for a long option --display here, since the X code
441 won't be able to recognize that form anyway. */
379 for (i = 1; (i < argc && ! display_arg); i++) 442 for (i = 1; (i < argc && ! display_arg); i++)
380 if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "-display")) 443 if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "-display"))
381 display_arg = 1; 444 display_arg = 1;
382 } 445 }
383 #endif 446 #endif
384 447
385 #ifdef VMS 448 #ifdef VMS
386 /* If -map specified, map the data file in */ 449 /* If -map specified, map the data file in */
387 if (argc > 2 && ! strcmp (argv[1], "-map")) 450 {
388 { 451 char *file;
389 skip_args = 2; 452 if (argmatch (argv, "-map", "--map-data", 3, &mapin_file, &skip_args))
390 mapin_data (argv[2]); 453 mapin_data (file);
391 } 454 }
392 455
393 #ifdef LINK_CRTL_SHARE 456 #ifdef LINK_CRTL_SHARE
394 #ifdef SHAREABLE_LIB_BUG 457 #ifdef SHAREABLE_LIB_BUG
395 /* Bletcherous shared libraries! */ 458 /* Bletcherous shared libraries! */
396 if (!stdin) 459 if (!stdin)
461 #endif 524 #endif
462 525
463 inhibit_window_system = 0; 526 inhibit_window_system = 0;
464 527
465 /* Handle the -t switch, which specifies filename to use as terminal */ 528 /* Handle the -t switch, which specifies filename to use as terminal */
466 if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t")) 529 {
467 { 530 char *term;
468 int result; 531 if (argmatch (argv, "-t", "--terminal", 4, &term, &skip_args))
469 skip_args += 2; 532 {
470 close (0); 533 int result;
471 close (1); 534 close (0);
472 result = open (argv[skip_args], O_RDWR, 2 ); 535 close (1);
473 if (result < 0) 536 result = open (term, O_RDWR, 2 );
474 { 537 if (result < 0)
475 char *errstring = strerror (errno); 538 {
476 fprintf (stderr, "emacs: %s: %s\n", argv[skip_args], errstring); 539 char *errstring = strerror (errno);
477 exit (1); 540 fprintf (stderr, "emacs: %s: %s\n", term, errstring);
478 } 541 exit (1);
479 dup (0); 542 }
480 if (! isatty (0)) 543 dup (0);
481 { 544 if (! isatty (0))
482 fprintf (stderr, "emacs: %s: not a tty\n", argv[skip_args]); 545 {
483 exit (1); 546 fprintf (stderr, "emacs: %s: not a tty\n", term);
484 } 547 exit (1);
485 fprintf (stderr, "Using %s\n", argv[skip_args]); 548 }
549 fprintf (stderr, "Using %s\n", term);
486 #ifdef HAVE_X_WINDOWS 550 #ifdef HAVE_X_WINDOWS
487 inhibit_window_system = 1; /* -t => -nw */ 551 inhibit_window_system = 1; /* -t => -nw */
488 #endif 552 #endif
489 } 553 }
490 554 }
491 if (skip_args + 1 < argc 555 if (argmatch (argv, "-nw", "--no-windows", 6, NULL, &skip_args))
492 && (!strcmp (argv[skip_args + 1], "-nw"))) 556 inhibit_window_system = 1;
493 { 557
494 skip_args += 1; 558 /* Handle the -batch switch, which means don't do interactive display. */
495 inhibit_window_system = 1;
496 }
497
498 /* Handle the -batch switch, which means don't do interactive display. */
499 noninteractive = 0; 559 noninteractive = 0;
500 if (skip_args + 1 < argc && !strcmp (argv[skip_args + 1], "-batch")) 560 if (argmatch (argv, "-batch", "--batch", 5, NULL, &skip_args))
501 { 561 noninteractive = 1;
502 skip_args += 1; 562
503 noninteractive = 1; 563 /* Handle the --help option, which gives a usage message.. */
564 if (argmatch (argv, "-help", "--help", 3, NULL, &skip_args))
565 {
566 printf ("\
567 Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\
568 [-q] [--no-init-file] [-u user] [--user user] [--debug-init]\n\
569 \(Arguments above this line must be first; those below may be in any order)\n\
570 [-f func] [--funcall func] [-l file] [--load file] [--insert file]\n\
571 file-to-visit [--kill]\n", argv[0]);
572 exit (0);
504 } 573 }
505 574
506 if (! noninteractive) 575 if (! noninteractive)
507 { 576 {
508 #ifdef BSD_PGRPS 577 #ifdef BSD_PGRPS
737 keys_of_frame (); 806 keys_of_frame ();
738 } 807 }
739 808
740 if (!initialized) 809 if (!initialized)
741 { 810 {
811 char *file;
742 /* Handle -l loadup-and-dump, args passed by Makefile. */ 812 /* Handle -l loadup-and-dump, args passed by Makefile. */
743 if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l")) 813 if (argmatch (argv, "-l", "--load", 3, &file, &skip_args))
744 Vtop_level = Fcons (intern ("load"), 814 Vtop_level = Fcons (intern ("load"),
745 Fcons (build_string (argv[2 + skip_args]), Qnil)); 815 Fcons (build_string (file), Qnil));
746 #ifdef CANNOT_DUMP 816 #ifdef CANNOT_DUMP
747 /* Unless next switch is -nl, load "loadup.el" first thing. */ 817 /* Unless next switch is -nl, load "loadup.el" first thing. */
748 if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl"))) 818 if (!argmatch (argv, "-nl", "--no-loadup", 6, NULL, &skip_args))
749 Vtop_level = Fcons (intern ("load"), 819 Vtop_level = Fcons (intern ("load"),
750 Fcons (build_string ("loadup.el"), Qnil)); 820 Fcons (build_string ("loadup.el"), Qnil));
751 #endif /* CANNOT_DUMP */ 821 #endif /* CANNOT_DUMP */
752 } 822 }
753 823
759 called to bolt the undumping time into the undumped emacs, this 829 called to bolt the undumping time into the undumped emacs, this
760 results in localtime ignoring the TZ environment variable. 830 results in localtime ignoring the TZ environment variable.
761 This flushes the new TZ value into localtime. */ 831 This flushes the new TZ value into localtime. */
762 tzset (); 832 tzset ();
763 #endif /* defined (sun) || defined (LOCALTIME_CACHE) */ 833 #endif /* defined (sun) || defined (LOCALTIME_CACHE) */
834
835 /* Handle the GNU standard option --version. */
836 if (argmatch (argv, "-version", "--version", 3, NULL, &skip_args))
837 {
838 Lisp_Object ver;
839 ver = call0 (intern ("emacs-version"));
840 if (STRINGP (ver))
841 printf ("%s\n", XSTRING (ver)->data);
842 exit (0);
843 }
764 844
765 /* Enter editor command loop. This never returns. */ 845 /* Enter editor command loop. This never returns. */
766 Frecursive_edit (); 846 Frecursive_edit ();
767 /* NOTREACHED */ 847 /* NOTREACHED */
768 } 848 }