Mercurial > emacs
comparison src/emacs.c @ 10111:add3c6d21876
(argmatch): Take argc as arg; don't go past end of argv.
(main): Change calls to argmatch.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 04 Dec 1994 20:59:04 +0000 |
parents | 339e129f8874 |
children | d8fb9db90d8e |
comparison
equal
deleted
inserted
replaced
10110:18d52489f138 | 10111:add3c6d21876 |
---|---|
347 | 347 |
348 Too bad we can't just use getopt for all of this, but we don't have | 348 Too bad we can't just use getopt for all of this, but we don't have |
349 enough information to do it right. */ | 349 enough information to do it right. */ |
350 | 350 |
351 static int | 351 static int |
352 argmatch (argv, sstr, lstr, minlen, valptr, skipptr) | 352 argmatch (argv, argc, sstr, lstr, minlen, valptr, skipptr) |
353 char **argv; | 353 char **argv; |
354 int argc; | |
354 char *sstr; | 355 char *sstr; |
355 char *lstr; | 356 char *lstr; |
356 int minlen; | 357 int minlen; |
357 char **valptr; | 358 char **valptr; |
358 int *skipptr; | 359 int *skipptr; |
359 { | 360 { |
360 char *p; | 361 char *p; |
361 int arglen; | 362 int arglen; |
362 char *arg = argv[*skipptr+1]; | 363 char *arg; |
364 | |
365 /* Don't access argv[argc]; give up in advance. */ | |
366 if (argc <= *skipptr + 1) | |
367 return 0; | |
368 | |
369 arg = argv[*skipptr+1]; | |
363 if (arg == NULL) | 370 if (arg == NULL) |
364 return 0; | 371 return 0; |
365 if (strcmp (arg, sstr) == 0) | 372 if (strcmp (arg, sstr) == 0) |
366 { | 373 { |
367 if (valptr != NULL) | 374 if (valptr != NULL) |
413 | 420 |
414 sort_args (argc, argv); | 421 sort_args (argc, argv); |
415 | 422 |
416 /* Map in shared memory, if we are using that. */ | 423 /* Map in shared memory, if we are using that. */ |
417 #ifdef HAVE_SHM | 424 #ifdef HAVE_SHM |
418 if (argmatch (argv, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) | 425 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) |
419 { | 426 { |
420 map_in_data (0); | 427 map_in_data (0); |
421 /* The shared memory was just restored, which clobbered this. */ | 428 /* The shared memory was just restored, which clobbered this. */ |
422 skip_args = 1; | 429 skip_args = 1; |
423 } | 430 } |
440 | 447 |
441 #ifdef VMS | 448 #ifdef VMS |
442 /* If -map specified, map the data file in */ | 449 /* If -map specified, map the data file in */ |
443 { | 450 { |
444 char *file; | 451 char *file; |
445 if (argmatch (argv, "-map", "--map-data", 3, &mapin_file, &skip_args)) | 452 if (argmatch (argv, argc, "-map", "--map-data", 3, &mapin_file, &skip_args)) |
446 mapin_data (file); | 453 mapin_data (file); |
447 } | 454 } |
448 | 455 |
449 #ifdef LINK_CRTL_SHARE | 456 #ifdef LINK_CRTL_SHARE |
450 #ifdef SHAREABLE_LIB_BUG | 457 #ifdef SHAREABLE_LIB_BUG |
519 inhibit_window_system = 0; | 526 inhibit_window_system = 0; |
520 | 527 |
521 /* Handle the -t switch, which specifies filename to use as terminal */ | 528 /* Handle the -t switch, which specifies filename to use as terminal */ |
522 { | 529 { |
523 char *term; | 530 char *term; |
524 if (argmatch (argv, "-t", "--terminal", 4, &term, &skip_args)) | 531 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) |
525 { | 532 { |
526 int result; | 533 int result; |
527 close (0); | 534 close (0); |
528 close (1); | 535 close (1); |
529 result = open (term, O_RDWR, 2 ); | 536 result = open (term, O_RDWR, 2 ); |
543 #ifdef HAVE_X_WINDOWS | 550 #ifdef HAVE_X_WINDOWS |
544 inhibit_window_system = 1; /* -t => -nw */ | 551 inhibit_window_system = 1; /* -t => -nw */ |
545 #endif | 552 #endif |
546 } | 553 } |
547 } | 554 } |
548 if (argmatch (argv, "-nw", "--no-windows", 6, NULL, &skip_args)) | 555 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) |
549 inhibit_window_system = 1; | 556 inhibit_window_system = 1; |
550 | 557 |
551 /* Handle the -batch switch, which means don't do interactive display. */ | 558 /* Handle the -batch switch, which means don't do interactive display. */ |
552 noninteractive = 0; | 559 noninteractive = 0; |
553 if (argmatch (argv, "-batch", "--batch", 5, NULL, &skip_args)) | 560 if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) |
554 noninteractive = 1; | 561 noninteractive = 1; |
555 | 562 |
556 /* Handle the --help option, which gives a usage message.. */ | 563 /* Handle the --help option, which gives a usage message.. */ |
557 if (argmatch (argv, "-help", "--help", 3, NULL, &skip_args)) | 564 if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args)) |
558 { | 565 { |
559 printf ("\ | 566 printf ("\ |
560 Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\ | 567 Usage: %s [-t term] [--terminal term] [-nw] [--no-windows] [--batch]\n\ |
561 [-q] [--no-init-file] [-u user] [--user user] [--debug-init]\n\ | 568 [-q] [--no-init-file] [-u user] [--user user] [--debug-init]\n\ |
562 \(Arguments above this line must be first; those below may be in any order)\n\ | 569 \(Arguments above this line must be first; those below may be in any order)\n\ |
573 { | 580 { |
574 char *displayname; | 581 char *displayname; |
575 int i; | 582 int i; |
576 int count_before = skip_args; | 583 int count_before = skip_args; |
577 | 584 |
578 if (argmatch (argv, "-d", "--display", 3, &displayname, &skip_args)) | 585 if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args)) |
579 display_arg = 1; | 586 display_arg = 1; |
580 else if (argmatch (argv, "-display", 0, 3, &displayname, &skip_args)) | 587 else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args)) |
581 display_arg = 1; | 588 display_arg = 1; |
582 | 589 |
583 /* If we have the form --display=NAME, | 590 /* If we have the form --display=NAME, |
584 convert it into -d name. | 591 convert it into -d name. |
585 This requires inserting a new element into argv. */ | 592 This requires inserting a new element into argv. */ |
847 | 854 |
848 if (!initialized) | 855 if (!initialized) |
849 { | 856 { |
850 char *file; | 857 char *file; |
851 /* Handle -l loadup-and-dump, args passed by Makefile. */ | 858 /* Handle -l loadup-and-dump, args passed by Makefile. */ |
852 if (argmatch (argv, "-l", "--load", 3, &file, &skip_args)) | 859 if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args)) |
853 Vtop_level = Fcons (intern ("load"), | 860 Vtop_level = Fcons (intern ("load"), |
854 Fcons (build_string (file), Qnil)); | 861 Fcons (build_string (file), Qnil)); |
855 #ifdef CANNOT_DUMP | 862 #ifdef CANNOT_DUMP |
856 /* Unless next switch is -nl, load "loadup.el" first thing. */ | 863 /* Unless next switch is -nl, load "loadup.el" first thing. */ |
857 if (!argmatch (argv, "-nl", "--no-loadup", 6, NULL, &skip_args)) | 864 if (!argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args)) |
858 Vtop_level = Fcons (intern ("load"), | 865 Vtop_level = Fcons (intern ("load"), |
859 Fcons (build_string ("loadup.el"), Qnil)); | 866 Fcons (build_string ("loadup.el"), Qnil)); |
860 #endif /* CANNOT_DUMP */ | 867 #endif /* CANNOT_DUMP */ |
861 } | 868 } |
862 | 869 |
870 This flushes the new TZ value into localtime. */ | 877 This flushes the new TZ value into localtime. */ |
871 tzset (); | 878 tzset (); |
872 #endif /* defined (sun) || defined (LOCALTIME_CACHE) */ | 879 #endif /* defined (sun) || defined (LOCALTIME_CACHE) */ |
873 | 880 |
874 /* Handle the GNU standard option --version. */ | 881 /* Handle the GNU standard option --version. */ |
875 if (argmatch (argv, "-version", "--version", 3, NULL, &skip_args)) | 882 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)) |
876 { | 883 { |
877 Lisp_Object ver; | 884 Lisp_Object ver; |
878 ver = call0 (intern ("emacs-version")); | 885 ver = call0 (intern ("emacs-version")); |
879 if (STRINGP (ver)) | 886 if (STRINGP (ver)) |
880 printf ("%s\n", XSTRING (ver)->data); | 887 printf ("%s\n", XSTRING (ver)->data); |