diff options
| author | Karl Heuer | 1994-09-26 18:14:29 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-09-26 18:14:29 +0000 |
| commit | e292536097e00610a9e9325a304bcadb69945388 (patch) | |
| tree | f4f18311a8edba33651e860373e7cbdfb78c1658 /src | |
| parent | 6618806e6bd00103db21d592f4327ba7142659b1 (diff) | |
| download | emacs-e292536097e00610a9e9325a304bcadb69945388.tar.gz emacs-e292536097e00610a9e9325a304bcadb69945388.zip | |
(argmatch): New function.
(main): Recognize --longopt synonyms for all options handled here. Add --help
and --version.
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs.c | 164 |
1 files changed, 122 insertions, 42 deletions
diff --git a/src/emacs.c b/src/emacs.c index f430a198600..8af46a64f5d 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -332,6 +332,67 @@ __main () | |||
| 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; |
| @@ -345,7 +406,7 @@ main (argc, argv, envp) | |||
| 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. */ |
| @@ -376,6 +437,8 @@ main (argc, argv, envp) | |||
| 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; |
| @@ -384,11 +447,11 @@ main (argc, argv, envp) | |||
| 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 |
| @@ -463,44 +526,50 @@ main (argc, argv, envp) | |||
| 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 | { | ||
| 494 | skip_args += 1; | ||
| 495 | inhibit_window_system = 1; | ||
| 496 | } | ||
| 497 | 557 | ||
| 498 | /* Handle the -batch switch, which means don't do interactive display. */ | 558 | /* 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)) |
| 561 | noninteractive = 1; | ||
| 562 | |||
| 563 | /* Handle the --help option, which gives a usage message.. */ | ||
| 564 | if (argmatch (argv, "-help", "--help", 3, NULL, &skip_args)) | ||
| 501 | { | 565 | { |
| 502 | skip_args += 1; | 566 | printf ("\ |
| 503 | noninteractive = 1; | 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) |
| @@ -739,13 +808,14 @@ main (argc, argv, envp) | |||
| 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 */ |
| @@ -762,6 +832,16 @@ main (argc, argv, envp) | |||
| 762 | tzset (); | 832 | tzset (); |
| 763 | #endif /* defined (sun) || defined (LOCALTIME_CACHE) */ | 833 | #endif /* defined (sun) || defined (LOCALTIME_CACHE) */ |
| 764 | 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 | } | ||
| 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 */ |