Mercurial > hg > xemacs-beta
comparison src/emacs.c @ 16:0293115a14e9 r19-15b91
Import from CVS: tag r19-15b91
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:49:20 +0200 |
parents | 9ee227acff29 |
children | 859a2309aef8 |
comparison
equal
deleted
inserted
replaced
15:ad457d5f7d04 | 16:0293115a14e9 |
---|---|
137 int noninteractive1; | 137 int noninteractive1; |
138 | 138 |
139 /* Save argv and argc. */ | 139 /* Save argv and argc. */ |
140 char **initial_argv; | 140 char **initial_argv; |
141 int initial_argc; | 141 int initial_argc; |
142 | |
143 static void sort_args (int argc, char **argv); | |
142 | 144 |
143 extern int always_gc; /* hack */ | 145 extern int always_gc; /* hack */ |
144 | 146 |
145 Lisp_Object Qkill_emacs_hook; | 147 Lisp_Object Qkill_emacs_hook; |
146 Lisp_Object Qsave_buffers_kill_emacs; | 148 Lisp_Object Qsave_buffers_kill_emacs; |
277 REGISTER int i; | 279 REGISTER int i; |
278 | 280 |
279 for (i = argc - 1; i >= 0; i--) | 281 for (i = argc - 1; i >= 0; i--) |
280 { | 282 { |
281 if (i == 0 || i > skip_args) | 283 if (i == 0 || i > skip_args) |
282 result = Fcons (build_ext_string (argv [i], FORMAT_OS), result); | 284 result = Fcons (build_ext_string (argv [i], FORMAT_FILENAME), result); |
283 } | 285 } |
284 return result; | 286 return result; |
285 } | 287 } |
286 | 288 |
287 Lisp_Object | 289 Lisp_Object |
339 Any directory names are omitted. | 341 Any directory names are omitted. |
340 */ ) | 342 */ ) |
341 () | 343 () |
342 { | 344 { |
343 return Fcopy_sequence (Vinvocation_name); | 345 return Fcopy_sequence (Vinvocation_name); |
346 } | |
347 | |
348 DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory, 0, 0, 0 /* | |
349 Return the directory name in which the Emacs executable was located. | |
350 */ ) | |
351 () | |
352 { | |
353 return Fcopy_sequence (Vinvocation_directory); | |
344 } | 354 } |
345 | 355 |
346 | 356 |
347 #ifdef I18N4 | 357 #ifdef I18N4 |
348 /* #### - don't know why I18N4 on SunOS/JLE | 358 /* #### - don't know why I18N4 on SunOS/JLE |
349 can't deal with this. It's a potential | 359 can't deal with this. It's a potential |
350 bug that needs to be looked at. */ | 360 bug that needs to be looked at. */ |
351 # undef RUN_TIME_REMAP | 361 # undef RUN_TIME_REMAP |
352 #endif | 362 #endif |
353 | 363 |
364 /* Test whether the next argument in ARGV matches SSTR or a prefix of | |
365 LSTR (at least MINLEN characters). If so, then if VALPTR is non-null | |
366 (the argument is supposed to have a value) store in *VALPTR either | |
367 the next argument or the portion of this one after the equal sign. | |
368 ARGV is read starting at position *SKIPPTR; this index is advanced | |
369 by the number of arguments used. | |
370 | |
371 Too bad we can't just use getopt for all of this, but we don't have | |
372 enough information to do it right. */ | |
373 | |
374 static int | |
375 argmatch (char **argv, int argc, char *sstr, char *lstr, | |
376 int minlen, char **valptr, int *skipptr) | |
377 { | |
378 char *p; | |
379 int arglen; | |
380 char *arg; | |
381 | |
382 /* Don't access argv[argc]; give up in advance. */ | |
383 if (argc <= *skipptr + 1) | |
384 return 0; | |
385 | |
386 arg = argv[*skipptr+1]; | |
387 if (arg == NULL) | |
388 return 0; | |
389 if (strcmp (arg, sstr) == 0) | |
390 { | |
391 if (valptr != NULL) | |
392 { | |
393 *valptr = argv[*skipptr+2]; | |
394 *skipptr += 2; | |
395 } | |
396 else | |
397 *skipptr += 1; | |
398 return 1; | |
399 } | |
400 arglen = (valptr != NULL && (p = strchr (arg, '=')) != NULL | |
401 ? p - arg : strlen (arg)); | |
402 if (lstr == 0 || arglen < minlen || strncmp (arg, lstr, arglen) != 0) | |
403 return 0; | |
404 else if (valptr == NULL) | |
405 { | |
406 *skipptr += 1; | |
407 return 1; | |
408 } | |
409 else if (p != NULL) | |
410 { | |
411 *valptr = p+1; | |
412 *skipptr += 1; | |
413 return 1; | |
414 } | |
415 else if (argv[*skipptr+2] != NULL) | |
416 { | |
417 *valptr = argv[*skipptr+2]; | |
418 *skipptr += 2; | |
419 return 1; | |
420 } | |
421 else | |
422 { | |
423 return 0; | |
424 } | |
425 } | |
426 | |
354 static DOESNT_RETURN | 427 static DOESNT_RETURN |
355 main_1 (int argc, char **argv, char **envp) | 428 main_1 (int argc, char **argv, char **envp) |
356 { | 429 { |
357 char stack_bottom_variable; | 430 char stack_bottom_variable; |
358 int skip_args = 0; | 431 int skip_args = 0; |
359 Lisp_Object load_me; | 432 Lisp_Object load_me; |
360 int inhibit_window_system; | 433 int inhibit_window_system; |
434 | |
435 noninteractive = 0; | |
361 | 436 |
362 #ifdef NeXT | 437 #ifdef NeXT |
363 extern int malloc_cookie; | 438 extern int malloc_cookie; |
364 | 439 |
365 /* 19-Jun-1995 -baw | 440 /* 19-Jun-1995 -baw |
367 * <cedman@princeton.edu>. Note that even Carl doesn't know what this | 442 * <cedman@princeton.edu>. Note that even Carl doesn't know what this |
368 * does; it was provided by NeXT, and it presumable makes NS's mallocator | 443 * does; it was provided by NeXT, and it presumable makes NS's mallocator |
369 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in | 444 * work with dumping. But malloc_jumpstart() and malloc_freezedry() in |
370 * unexnext.c are both completely undocumented, even in NS header files! | 445 * unexnext.c are both completely undocumented, even in NS header files! |
371 * But hey, it solves all NS related memory problems, so who's | 446 * But hey, it solves all NS related memory problems, so who's |
372 * complaining? | 447 * complaining? */ |
373 */ | |
374 if (initialized) | 448 if (initialized) |
375 if (malloc_jumpstart (malloc_cookie) != 0) | 449 if (malloc_jumpstart (malloc_cookie) != 0) |
376 printf ("malloc jumpstart failed!\n"); | 450 printf ("malloc jumpstart failed!\n"); |
377 #endif /* NeXT */ | 451 #endif /* NeXT */ |
378 | 452 |
381 if (!initialized) | 455 if (!initialized) |
382 init_free_hook (); | 456 init_free_hook (); |
383 #endif | 457 #endif |
384 #endif | 458 #endif |
385 | 459 |
460 sort_args (argc, argv); | |
461 | |
386 /* Map in shared memory, if we are using that. */ | 462 /* Map in shared memory, if we are using that. */ |
387 #ifdef HAVE_SHM | 463 #ifdef HAVE_SHM |
388 if (argc > 1 && !strcmp (argv[1], "-nl")) | 464 if (argmatch (argv, argc, "-nl", "--no-shared-memory", 6, NULL, &skip_args)) |
389 { | 465 { |
390 map_in_data (0); | 466 map_in_data (0); |
391 /* The shared memory was just restored, which clobbered this. */ | 467 /* The shared memory was just restored, which clobbered this. */ |
392 skip_args = 1; | 468 skip_args = 1; |
393 } | 469 } |
395 { | 471 { |
396 map_in_data (1); | 472 map_in_data (1); |
397 /* The shared memory was just restored, which clobbered this. */ | 473 /* The shared memory was just restored, which clobbered this. */ |
398 skip_args = 0; | 474 skip_args = 0; |
399 } | 475 } |
400 #endif | 476 #endif /* HAVE_SHM */ |
401 | 477 |
402 #ifdef VMS | 478 #ifdef VMS |
403 /* If -map specified, map the data file in */ | 479 /* If -map specified, map the data file in */ |
404 if (argc > 2 && ! strcmp (argv[1], "-map")) | 480 if (argc > 2 && ! strcmp (argv[1], "-map")) |
405 { | 481 { |
454 if (initialized) | 530 if (initialized) |
455 SOCKSinit (argv[0]); | 531 SOCKSinit (argv[0]); |
456 #endif /* HAVE_SOCKS */ | 532 #endif /* HAVE_SOCKS */ |
457 | 533 |
458 #ifndef SYSTEM_MALLOC | 534 #ifndef SYSTEM_MALLOC |
459 | |
460 if (!initialized) | 535 if (!initialized) |
461 { | 536 /* Arrange to get warning messages as memory fills up. */ |
462 /* Arrange to get warning messages as memory fills up. */ | 537 memory_warnings (0, malloc_warning); |
463 memory_warnings (0, malloc_warning); | |
464 } | |
465 #endif /* not SYSTEM_MALLOC */ | 538 #endif /* not SYSTEM_MALLOC */ |
466 | 539 |
467 #ifdef MSDOS | 540 #ifdef MSDOS |
468 /* We do all file input/output as binary files. When we need to translate | 541 /* We do all file input/output as binary files. When we need to translate |
469 newlines, we do that manually. */ | 542 newlines, we do that manually. */ |
470 _fmode = O_BINARY; | 543 _fmode = O_BINARY; |
471 (stdin)->_flag &= ~_IOTEXT; | 544 (stdin) ->_flag &= ~_IOTEXT; |
472 (stdout)->_flag &= ~_IOTEXT; | 545 (stdout)->_flag &= ~_IOTEXT; |
473 (stderr)->_flag &= ~_IOTEXT; | 546 (stderr)->_flag &= ~_IOTEXT; |
474 #endif /* MSDOS */ | 547 #endif /* MSDOS */ |
475 | 548 |
476 #ifdef SET_EMACS_PRIORITY | 549 #ifdef SET_EMACS_PRIORITY |
488 #else | 561 #else |
489 inhibit_window_system = 1; | 562 inhibit_window_system = 1; |
490 #endif | 563 #endif |
491 | 564 |
492 /* Handle the -t switch, which specifies filename to use as terminal */ | 565 /* Handle the -t switch, which specifies filename to use as terminal */ |
493 if (skip_args + 2 < argc && !strcmp (argv[skip_args + 1], "-t")) | 566 { |
494 { | 567 char *term; |
495 int result; | 568 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) |
496 | 569 { |
497 skip_args += 2; | 570 close (0); |
498 close (0); | 571 close (1); |
499 close (1); | 572 if (open (term, O_RDWR, 2) < 0) |
500 result = open (argv[skip_args], O_RDWR, 2 ); | 573 fatal ("%s: %s", term, strerror (errno)); |
501 if (result < 0) | 574 dup (0); |
502 { | 575 if (! isatty (0)) |
503 fatal ("%s: %s", argv[skip_args], strerror (errno)); | 576 fatal ("%s: not a tty", term); |
504 } | 577 |
505 dup (0); | 578 stderr_out ("Using %s", ttyname (0)); |
506 if (! isatty (0)) | 579 inhibit_window_system = 1; /* -t => -nw */ |
507 fatal ("%s: not a tty", argv[skip_args]); | 580 } |
508 | 581 } |
509 stderr_out ("Using %s", ttyname (0)); | 582 |
510 #if 0 | 583 /* Handle -nw switch */ |
511 stderr_out ("Using %s", argv[skip_args]); | 584 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) |
512 #endif | 585 inhibit_window_system = 1; |
513 inhibit_window_system = 1; /* -t => -nw */ | |
514 } | |
515 | |
516 if (skip_args + 1 < argc | |
517 && (!strcmp (argv[skip_args + 1], "-nw"))) | |
518 { | |
519 skip_args += 1; | |
520 inhibit_window_system = 1; | |
521 } | |
522 | 586 |
523 /* Handle the -batch switch, which means don't do interactive display. */ | 587 /* Handle the -batch switch, which means don't do interactive display. */ |
524 noninteractive = 0; | 588 if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) |
525 if (skip_args + 1 < argc && | 589 noninteractive = 1; |
526 (!strcmp (argv[skip_args + 1], "-batch") || | 590 |
527 !strcmp (argv[skip_args + 1], "--batch"))) | |
528 { | |
529 skip_args += 1; | |
530 noninteractive = 1; | |
531 } | |
532 | |
533 /* Partially handle the -version and -help switches: they imply -batch, | 591 /* Partially handle the -version and -help switches: they imply -batch, |
534 but are not removed from the list. | 592 but are not removed from the list. */ |
535 */ | 593 if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args) || |
536 if (skip_args + 1 < argc && | 594 argmatch (argv, argc, "-?", 0, 2, NULL, &skip_args) || |
537 (!strcmp (argv[skip_args + 1], "-version") || | 595 argmatch (argv, argc, "-flags", "--flags", 6, NULL, &skip_args)) |
538 !strcmp (argv[skip_args + 1], "--version") || | 596 noninteractive = 1, skip_args--; |
539 !strcmp (argv[skip_args + 1], "-help") || | 597 |
540 !strcmp (argv[skip_args + 1], "--help"))) | 598 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args) || |
541 noninteractive = 1; | 599 argmatch (argv, argc, "-V", 0, 2, NULL, &skip_args)) |
542 | 600 noninteractive = 1, skip_args--; |
601 | |
543 /* Now, figure out which type of console is our first console. */ | 602 /* Now, figure out which type of console is our first console. */ |
544 | 603 |
545 display_arg = 0; | 604 display_arg = 0; |
546 | 605 |
547 if (noninteractive) | 606 if (noninteractive) |
554 fatal ("Sorry, this XEmacs was not compiled with TTY support"); | 613 fatal ("Sorry, this XEmacs was not compiled with TTY support"); |
555 #endif | 614 #endif |
556 | 615 |
557 #ifdef HAVE_WINDOW_SYSTEM | 616 #ifdef HAVE_WINDOW_SYSTEM |
558 /* Stupid kludge to catch command-line display spec. We can't | 617 /* Stupid kludge to catch command-line display spec. We can't |
559 handle this argument entirely in window system dependent code | 618 handle this argument entirely in window-system-dependent code |
560 because we don't even know which window system dependent code | 619 because we don't even know which window-system-dependent code |
561 to run until we've recognized this argument. */ | 620 to run until we've recognized this argument. */ |
562 if (!inhibit_window_system && !noninteractive) | 621 if (!inhibit_window_system && !noninteractive) |
563 { | 622 { |
564 int i; | 623 #ifdef HAVE_X_WINDOWS |
565 char *disp; | 624 char *dpy = 0; |
625 int count_before = skip_args; | |
566 | 626 |
567 for (i = 1; (i < argc && !display_arg); i++) | 627 if (argmatch (argv, argc, "-d", "--display", 3, &dpy, &skip_args) || |
628 argmatch (argv, argc, "-display", 0, 3, &dpy, &skip_args)) | |
568 { | 629 { |
569 #ifdef HAVE_X_WINDOWS | 630 display_arg = 1; |
570 if (!strcmp (argv[i], "-d") || !strcmp (argv[i], "-display")) | 631 display_use = "x"; |
571 { | 632 } |
572 display_arg = 1; | 633 /* If we have the form --display=NAME, |
573 display_use = "x"; | 634 convert it into -d name. |
574 } | 635 This requires inserting a new element into argv. */ |
636 if (dpy != 0 && skip_args - count_before == 1) | |
637 { | |
638 char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); | |
639 int j; | |
640 | |
641 for (j = 0; j < count_before + 1; j++) | |
642 new[j] = argv[j]; | |
643 new[count_before + 1] = "-d"; | |
644 new[count_before + 2] = dpy; | |
645 for (j = count_before + 2; j <argc; j++) | |
646 new[j + 1] = argv[j]; | |
647 argv = new; | |
648 argc++; | |
649 } | |
650 /* Change --display to -d, when its arg is separate. */ | |
651 else if (dpy != 0 && skip_args > count_before | |
652 && argv[count_before + 1][1] == '-') | |
653 argv[count_before + 1] = "-d"; | |
654 | |
655 /* Don't actually discard this arg. */ | |
656 skip_args = count_before; | |
657 | |
658 /* If there is a non-empty environment var DISPLAY, set | |
659 `display_use', but not `display_arg', which is only to be set | |
660 if the display was specified on the command line. */ | |
661 if ((dpy = getenv ("DISPLAY")) && dpy[0]) | |
662 display_use = "x"; | |
663 | |
575 #endif /* HAVE_X_WINDOWS */ | 664 #endif /* HAVE_X_WINDOWS */ |
665 | |
576 #ifdef HAVE_NEXTSTEP | 666 #ifdef HAVE_NEXTSTEP |
577 if (!strcmp (argv[i], "-NXHost") || !strcmp (argv[i], "-MachLaunch")) | 667 if (argmatch (argv, argc, "-NXHost", 0, 6, 0, &skip_args) || |
578 { | 668 argmatch (argv, argc, "-MachLaunch", 0, 9, 0, &skip_args)) |
579 display_arg = 1; | 669 { |
580 display_use = "ns"; | 670 display_arg = 1; |
581 } | 671 display_use = "ns"; |
672 } | |
582 #endif /* HAVE_NEXTSTEP */ | 673 #endif /* HAVE_NEXTSTEP */ |
583 } | |
584 | |
585 #ifdef HAVE_X_WINDOWS | |
586 disp = getenv ("DISPLAY"); | |
587 | |
588 /* null string doesn't count as a display */ | |
589 if (disp && disp[0]) | |
590 display_use = "x"; | |
591 | |
592 /* Do not set display_arg here. It is only to be set if the display | |
593 was specified on the command line. */ | |
594 #endif | |
595 } | 674 } |
596 #endif /* HAVE_WINDOW_SYSTEM */ | 675 #endif /* HAVE_WINDOW_SYSTEM */ |
597 | 676 |
598 noninteractive1 = noninteractive; | 677 noninteractive1 = noninteractive; |
599 | 678 |
646 | 725 |
647 The *only* thing that the syms_of_*() functions are allowed to do | 726 The *only* thing that the syms_of_*() functions are allowed to do |
648 is call one of the following three functions: | 727 is call one of the following three functions: |
649 | 728 |
650 defsymbol() | 729 defsymbol() |
651 defsubr() | 730 defsubr() (i.e. DEFSUBR) |
652 deferror() | 731 deferror() |
653 defkeyword() | 732 defkeyword() |
654 | 733 |
655 Order does not matter in these functions. | 734 Order does not matter in these functions. |
656 */ | 735 */ |
1291 load_me = Qnil; | 1370 load_me = Qnil; |
1292 if (!initialized) | 1371 if (!initialized) |
1293 { | 1372 { |
1294 /* Handle -l loadup-and-dump, args passed by Makefile. */ | 1373 /* Handle -l loadup-and-dump, args passed by Makefile. */ |
1295 if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l")) | 1374 if (argc > 2 + skip_args && !strcmp (argv[1 + skip_args], "-l")) |
1296 load_me = build_string (argv[2 + skip_args]); | 1375 load_me = build_string (argv[2 + skip_args]); |
1297 #ifdef CANNOT_DUMP | 1376 #ifdef CANNOT_DUMP |
1298 /* Unless next switch is -nl, load "loadup.el" first thing. */ | 1377 /* Unless next switch is -nl, load "loadup.el" first thing. */ |
1299 if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl"))) | 1378 if (!(argc > 1 + skip_args && !strcmp (argv[1 + skip_args], "-nl"))) |
1300 load_me = build_string ("loadup.el"); | 1379 load_me = build_string ("loadup.el"); |
1301 #endif /* CANNOT_DUMP */ | 1380 #endif /* CANNOT_DUMP */ |
1309 initialized = 1; | 1388 initialized = 1; |
1310 | 1389 |
1311 /* This never returns. */ | 1390 /* This never returns. */ |
1312 initial_command_loop (load_me); | 1391 initial_command_loop (load_me); |
1313 /* NOTREACHED */ | 1392 /* NOTREACHED */ |
1393 } | |
1394 | |
1395 | |
1396 /* Sort the args so we can find the most important ones | |
1397 at the beginning of argv. */ | |
1398 | |
1399 /* First, here's a table of all the standard options. */ | |
1400 | |
1401 struct standard_args | |
1402 { | |
1403 CONST char * CONST name; | |
1404 CONST char * CONST longname; | |
1405 int priority; | |
1406 int nargs; | |
1407 }; | |
1408 | |
1409 static struct standard_args standard_args[] = | |
1410 { | |
1411 /* Handled by main_1 above: */ | |
1412 { "-nl", "--no-shared-memory", 100, 0 }, | |
1413 #ifdef VMS | |
1414 { "-map", "--map-data", 100, 0 }, | |
1415 #endif | |
1416 { "-t", "--terminal", 95, 1 }, | |
1417 { "-nw", "--no-windows", 90, 0 }, | |
1418 { "-batch", "--batch", 85, 0 }, | |
1419 { "-help", "--help", 80, 0 }, | |
1420 { "-flags", "--flags", 80, 0 }, | |
1421 { "-h", 0, 80, 0 }, | |
1422 { "-?", 0, 80, 0 }, | |
1423 { "-version", "--version", 75, 0 }, | |
1424 { "-V", 0, 75, 0 }, | |
1425 { "-d", "--display", 80, 1 }, | |
1426 { "-display", 0, 80, 1 }, | |
1427 { "-NXHost", 0, 79, 0 }, | |
1428 { "-MachLaunch", 0, 79, 0}, | |
1429 | |
1430 /* Handled by command-line-early in startup.el: */ | |
1431 { "-q", "--no-init-file", 50, 0 }, | |
1432 { "-unmapped", 0, 50, 0 }, | |
1433 { "-no-init-file", 0, 50, 0 }, | |
1434 { "-no-site-file", "--no-site-file", 40, 0 }, | |
1435 { "-u", "--user", 30, 1 }, | |
1436 { "-user", 0, 30, 1 }, | |
1437 { "-debug-init", "--debug-init", 20, 0 }, | |
1438 | |
1439 /* Xt options: */ | |
1440 { "-i", "--icon-type", 15, 0 }, | |
1441 { "-itype", 0, 15, 0 }, | |
1442 { "-iconic", "--iconic", 15, 0 }, | |
1443 { "-bg", "--background-color", 10, 1 }, | |
1444 { "-background", 0, 10, 1 }, | |
1445 { "-fg", "--foreground-color", 10, 1 }, | |
1446 { "-foreground", 0, 10, 1 }, | |
1447 { "-bd", "--border-color", 10, 1 }, | |
1448 { "-bw", "--border-width", 10, 1 }, | |
1449 { "-ib", "--internal-border", 10, 1 }, | |
1450 { "-ms", "--mouse-color", 10, 1 }, | |
1451 { "-cr", "--cursor-color", 10, 1 }, | |
1452 { "-fn", "--font", 10, 1 }, | |
1453 { "-font", 0, 10, 1 }, | |
1454 { "-g", "--geometry", 10, 1 }, | |
1455 { "-geometry", 0, 10, 1 }, | |
1456 { "-T", "--title", 10, 1 }, | |
1457 { "-title", 0, 10, 1 }, | |
1458 { "-name", "--name", 10, 1 }, | |
1459 { "-xrm", "--xrm", 10, 1 }, | |
1460 { "-r", "--reverse-video", 5, 0 }, | |
1461 { "-rv", 0, 5, 0 }, | |
1462 { "-reverse", 0, 5, 0 }, | |
1463 { "-hb", "--horizontal-scroll-bars", 5, 0 }, | |
1464 { "-vb", "--vertical-scroll-bars", 5, 0 }, | |
1465 | |
1466 /* These have the same priority as ordinary file name args, | |
1467 so they are not reordered with respect to those. */ | |
1468 { "-L", "--directory", 0, 1 }, | |
1469 { "-directory", 0, 0, 1 }, | |
1470 { "-l", "--load", 0, 1 }, | |
1471 { "-load", 0, 0, 1 }, | |
1472 { "-f", "--funcall", 0, 1 }, | |
1473 { "-funcall", 0, 0, 1 }, | |
1474 { "-eval", "--eval", 0, 1 }, | |
1475 { "-insert", "--insert", 0, 1 }, | |
1476 /* This should be processed after ordinary file name args and the like. */ | |
1477 { "-kill", "--kill", -10, 0 }, | |
1478 }; | |
1479 | |
1480 /* Reorder the elements of ARGV (assumed to have ARGC elements) | |
1481 so that the highest priority ones come first. | |
1482 Do not change the order of elements of equal priority. | |
1483 If an option takes an argument, keep it and its argument together. */ | |
1484 | |
1485 static void | |
1486 sort_args (int argc, char **argv) | |
1487 { | |
1488 char **new = (char **) xmalloc (sizeof (char *) * argc); | |
1489 /* For each element of argv, | |
1490 the corresponding element of options is: | |
1491 0 for an option that takes no arguments, | |
1492 1 for an option that takes one argument, etc. | |
1493 -1 for an ordinary non-option argument. */ | |
1494 int *options = (int *) xmalloc (sizeof (int) * argc); | |
1495 int *priority = (int *) xmalloc (sizeof (int) * argc); | |
1496 int to = 1; | |
1497 int from; | |
1498 int i; | |
1499 int end_of_options_p = 0; | |
1500 | |
1501 /* Categorize all the options, | |
1502 and figure out which argv elts are option arguments. */ | |
1503 for (from = 1; from < argc; from++) | |
1504 { | |
1505 options[from] = -1; | |
1506 priority[from] = 0; | |
1507 /* Pseudo options "--" and "run-temacs" indicate end of options */ | |
1508 if (!strcmp (argv[from], "--") || | |
1509 !strcmp (argv[from], "run-temacs")) | |
1510 end_of_options_p = 1; | |
1511 if (!end_of_options_p && argv[from][0] == '-') | |
1512 { | |
1513 int match, thislen; | |
1514 char *equals; | |
1515 | |
1516 /* Look for a match with a known old-fashioned option. */ | |
1517 for (i = 0; i < countof (standard_args); i++) | |
1518 if (!strcmp (argv[from], standard_args[i].name)) | |
1519 { | |
1520 options[from] = standard_args[i].nargs; | |
1521 priority[from] = standard_args[i].priority; | |
1522 if (from + standard_args[i].nargs >= argc) | |
1523 fatal ("Option `%s' requires an argument\n", argv[from]); | |
1524 from += standard_args[i].nargs; | |
1525 goto done; | |
1526 } | |
1527 | |
1528 /* Look for a match with a known long option. | |
1529 MATCH is -1 if no match so far, -2 if two or more matches so far, | |
1530 >= 0 (the table index of the match) if just one match so far. */ | |
1531 if (argv[from][1] == '-') | |
1532 { | |
1533 match = -1; | |
1534 thislen = strlen (argv[from]); | |
1535 equals = strchr (argv[from], '='); | |
1536 if (equals != 0) | |
1537 thislen = equals - argv[from]; | |
1538 | |
1539 for (i = 0; i < countof (standard_args); i++) | |
1540 if (standard_args[i].longname | |
1541 && !strncmp (argv[from], standard_args[i].longname, | |
1542 thislen)) | |
1543 { | |
1544 if (match == -1) | |
1545 match = i; | |
1546 else | |
1547 match = -2; | |
1548 } | |
1549 | |
1550 /* If we found exactly one match, use that. */ | |
1551 if (match >= 0) | |
1552 { | |
1553 options[from] = standard_args[match].nargs; | |
1554 priority[from] = standard_args[match].priority; | |
1555 /* If --OPTION=VALUE syntax is used, | |
1556 this option uses just one argv element. */ | |
1557 if (equals != 0) | |
1558 options[from] = 0; | |
1559 if (from + options[from] >= argc) | |
1560 fatal ("Option `%s' requires an argument\n", argv[from]); | |
1561 from += options[from]; | |
1562 } | |
1563 } | |
1564 done: ; | |
1565 } | |
1566 } | |
1567 | |
1568 /* Copy the arguments, in order of decreasing priority, to NEW. */ | |
1569 new[0] = argv[0]; | |
1570 while (to < argc) | |
1571 { | |
1572 int best = -1; | |
1573 int best_priority = -9999; | |
1574 | |
1575 /* Find the highest priority remaining option. | |
1576 If several have equal priority, take the first of them. */ | |
1577 for (from = 1; from < argc; from++) | |
1578 { | |
1579 if (argv[from] != 0 && priority[from] > best_priority) | |
1580 { | |
1581 best_priority = priority[from]; | |
1582 best = from; | |
1583 } | |
1584 /* Skip option arguments--they are tied to the options. */ | |
1585 if (options[from] > 0) | |
1586 from += options[from]; | |
1587 } | |
1588 | |
1589 if (best < 0) | |
1590 abort (); | |
1591 | |
1592 /* Copy the highest priority remaining option, with its args, to NEW. */ | |
1593 new[to++] = argv[best]; | |
1594 for (i = 0; i < options[best]; i++) | |
1595 new[to++] = argv[best + i + 1]; | |
1596 | |
1597 /* Clear out this option in ARGV. */ | |
1598 argv[best] = 0; | |
1599 for (i = 0; i < options[best]; i++) | |
1600 argv[best + i + 1] = 0; | |
1601 } | |
1602 | |
1603 memcpy (argv, new, sizeof (char *) * argc); | |
1314 } | 1604 } |
1315 | 1605 |
1316 static JMP_BUF run_temacs_catch; | 1606 static JMP_BUF run_temacs_catch; |
1317 | 1607 |
1318 static int run_temacs_argc; | 1608 static int run_temacs_argc; |
1405 | 1695 |
1406 /* ARGSUSED */ | 1696 /* ARGSUSED */ |
1407 DOESNT_RETURN | 1697 DOESNT_RETURN |
1408 main (int argc, char **argv, char **envp) | 1698 main (int argc, char **argv, char **envp) |
1409 { | 1699 { |
1700 int volatile vol_argc = argc; | |
1701 char ** volatile vol_argv = argv; | |
1702 char ** volatile vol_envp = envp; | |
1410 #ifdef QUANTIFY | 1703 #ifdef QUANTIFY |
1411 quantify_stop_recording_data (); | 1704 quantify_stop_recording_data (); |
1412 quantify_clear_data (); | 1705 quantify_clear_data (); |
1413 #endif /* QUANTIFY */ | 1706 #endif /* QUANTIFY */ |
1414 | 1707 |
1415 suppress_early_backtrace = 0; | 1708 suppress_early_backtrace = 0; |
1416 lim_data = 0; /* force reinitialization of this variable */ | 1709 lim_data = 0; /* force reinitialization of this variable */ |
1417 | 1710 |
1418 if (sizeof (Lisp_Object) != sizeof (void *)) | 1711 /* Lisp_Object must fit in a word; check VALBITS and GCTYPEBITS */ |
1419 abort (); /* Lisp_Object must fit in a word; | 1712 assert (sizeof (Lisp_Object) == sizeof (void *)); |
1420 check VALBITS and GCTYPEBITS */ | 1713 |
1421 if (!initialized) | 1714 if (!initialized) |
1422 { | 1715 { |
1423 run_temacs_argc = 0; | 1716 run_temacs_argc = 0; |
1424 if (! SETJMP (run_temacs_catch)) | 1717 if (! SETJMP (run_temacs_catch)) |
1425 main_1 (argc, argv, envp); | 1718 main_1 (vol_argc, vol_argv, vol_envp); |
1426 /* run-emacs-from-temacs called */ | 1719 /* run-emacs-from-temacs called */ |
1427 argc = run_temacs_argc; | 1720 vol_argc = run_temacs_argc; |
1428 run_temacs_argc = 0; | 1721 vol_argv = run_temacs_argv; |
1429 argv = run_temacs_argv; | |
1430 #ifdef _SCO_DS | 1722 #ifdef _SCO_DS |
1431 /* | 1723 /* This makes absolutely no sense to anyone involved. There are |
1432 This makes absolutely no sense to anyone involved. | 1724 several people using this stuff. We've compared versions on |
1433 There are several people using this stuff. We've | 1725 everything we can think of. We can find no difference. |
1434 compared versions on everything we can think of. We | 1726 However, on both my systems environ is a plain old global |
1435 can find no difference. However, on both my systems | 1727 variable initialized to zero. _environ is the one that |
1436 environ is a plain old global variable initialized to | 1728 contains pointers to the actual environment. |
1437 zero. _environ is the one that contains pointers to | 1729 |
1438 the actual environment. | 1730 Since we can't figure out the difference (and we're hours |
1439 Since we can't figure out the difference (and we're | 1731 away from a release), this takes a very cowardly approach and |
1440 hours away from a release), this takes a very cowardly | 1732 is bracketed with both a system specific preprocessor test |
1441 approach and is bracketed with both a system specific | 1733 and a runtime "do you have this problem" test |
1442 preprocessor test and a runtime "do you have this | 1734 |
1443 problem" test | 1735 06/20/96 robertl@dgii.com */ |
1444 06/20/96 robertl@dgii.com | 1736 { |
1445 */ | 1737 extern char *_environ; |
1446 { | 1738 if ((unsigned) environ == 0) |
1447 extern char *_environ ; | 1739 environ=_environ; |
1448 if ((unsigned) environ == 0) | 1740 } |
1449 environ=_environ; | 1741 #endif /* _SCO_DS */ |
1450 } | 1742 vol_envp = environ; |
1451 #endif | 1743 } |
1452 envp = environ; | |
1453 } | |
1454 run_temacs_argc = -1; | 1744 run_temacs_argc = -1; |
1455 | 1745 |
1456 main_1 (argc, argv, envp); | 1746 main_1 (vol_argc, vol_argv, vol_envp); |
1457 } | 1747 } |
1458 | 1748 |
1459 | 1749 |
1460 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P" /* | 1750 DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P" /* |
1461 Exit the XEmacs job and kill it. Ask for confirmation, without argument. | 1751 Exit the XEmacs job and kill it. Ask for confirmation, without argument. |
1881 #endif /* !CANNOT_DUMP */ | 2171 #endif /* !CANNOT_DUMP */ |
1882 | 2172 |
1883 defsubr (&Srun_emacs_from_temacs); | 2173 defsubr (&Srun_emacs_from_temacs); |
1884 defsubr (&Srunning_temacs_p); | 2174 defsubr (&Srunning_temacs_p); |
1885 defsubr (&Sinvocation_name); | 2175 defsubr (&Sinvocation_name); |
2176 defsubr (&Sinvocation_directory); | |
1886 defsubr (&Skill_emacs); | 2177 defsubr (&Skill_emacs); |
1887 defsubr (&Snoninteractive); | 2178 defsubr (&Snoninteractive); |
1888 | 2179 |
1889 #ifdef QUANTIFY | 2180 #ifdef QUANTIFY |
1890 defsubr (&Squantify_start_recording_data); | 2181 defsubr (&Squantify_start_recording_data); |