comparison src/emacs.c @ 22553:b071f874301e

(sort_args): Discard duplicate options with no args. (main): With duplicate -d options, use the last one. Likewise for -t. Check -d last, by checking for -nl earlier on.
author Richard M. Stallman <rms@gnu.org>
date Tue, 23 Jun 1998 14:42:40 +0000
parents d9eac134a41b
children 2ba6f9b60ee6
comparison
equal deleted inserted replaced
22552:c9dbdcb10fdf 22553:b071f874301e
555 extern int errno; 555 extern int errno;
556 extern int sys_nerr; 556 extern int sys_nerr;
557 #ifdef HAVE_SETRLIMIT 557 #ifdef HAVE_SETRLIMIT
558 struct rlimit rlim; 558 struct rlimit rlim;
559 #endif 559 #endif
560 int no_loadup = 0;
560 561
561 #ifdef LINUX_SBRK_BUG 562 #ifdef LINUX_SBRK_BUG
562 __sbrk (1); 563 __sbrk (1);
563 #endif 564 #endif
564 565
576 if (initialized) 577 if (initialized)
577 run_time_remap (argv[0]); 578 run_time_remap (argv[0]);
578 #endif 579 #endif
579 580
580 sort_args (argc, argv); 581 sort_args (argc, argv);
582 argc = 0;
583 while (argv[argc]) argc++;
581 584
582 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args) 585 if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args)
583 /* We don't know the version number unless this is a dumped Emacs. 586 /* We don't know the version number unless this is a dumped Emacs.
584 So ignore --version otherwise. */ 587 So ignore --version otherwise. */
585 && initialized) 588 && initialized)
746 #endif 749 #endif
747 750
748 inhibit_window_system = 0; 751 inhibit_window_system = 0;
749 752
750 /* Handle the -t switch, which specifies filename to use as terminal */ 753 /* Handle the -t switch, which specifies filename to use as terminal */
751 { 754 while (1)
752 char *term; 755 {
753 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) 756 char *term;
754 { 757 if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
755 int result; 758 {
756 close (0); 759 int result;
757 close (1); 760 close (0);
758 result = open (term, O_RDWR, 2 ); 761 close (1);
759 if (result < 0) 762 result = open (term, O_RDWR, 2 );
760 { 763 if (result < 0)
761 char *errstring = strerror (errno); 764 {
762 fprintf (stderr, "emacs: %s: %s\n", term, errstring); 765 char *errstring = strerror (errno);
763 exit (1); 766 fprintf (stderr, "emacs: %s: %s\n", term, errstring);
764 } 767 exit (1);
765 dup (0); 768 }
766 if (! isatty (0)) 769 dup (0);
767 { 770 if (! isatty (0))
768 fprintf (stderr, "emacs: %s: not a tty\n", term); 771 {
769 exit (1); 772 fprintf (stderr, "emacs: %s: not a tty\n", term);
770 } 773 exit (1);
771 fprintf (stderr, "Using %s\n", term); 774 }
775 fprintf (stderr, "Using %s\n", term);
772 #ifdef HAVE_WINDOW_SYSTEM 776 #ifdef HAVE_WINDOW_SYSTEM
773 inhibit_window_system = 1; /* -t => -nw */ 777 inhibit_window_system = 1; /* -t => -nw */
774 #endif 778 #endif
775 } 779 }
776 } 780 else
781 break;
782 }
783
777 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args)) 784 if (argmatch (argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
778 inhibit_window_system = 1; 785 inhibit_window_system = 1;
779 786
780 /* Handle the -batch switch, which means don't do interactive display. */ 787 /* Handle the -batch switch, which means don't do interactive display. */
781 noninteractive = 0; 788 noninteractive = 0;
794 Report bugs to bug-gnu-emacs@gnu.org. First, please see\n\ 801 Report bugs to bug-gnu-emacs@gnu.org. First, please see\n\
795 the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]); 802 the Bugs section of the Emacs manual or the file BUGS.\n", argv[0]);
796 exit (0); 803 exit (0);
797 } 804 }
798 805
806 if (! noninteractive)
807 {
808 #ifdef BSD_PGRPS
809 if (initialized)
810 {
811 inherited_pgroup = EMACS_GETPGRP (0);
812 setpgrp (0, getpid ());
813 }
814 #else
815 #if defined (USG5) && defined (INTERRUPT_INPUT)
816 setpgrp ();
817 #endif
818 #endif
819 }
820
821 #ifdef POSIX_SIGNALS
822 init_signals ();
823 #endif
824
825 /* Don't catch SIGHUP if dumping. */
826 if (1
827 #ifndef CANNOT_DUMP
828 && initialized
829 #endif
830 )
831 {
832 sigblock (sigmask (SIGHUP));
833 /* In --batch mode, don't catch SIGHUP if already ignored.
834 That makes nohup work. */
835 if (! noninteractive
836 || signal (SIGHUP, SIG_IGN) != SIG_IGN)
837 signal (SIGHUP, fatal_error_signal);
838 sigunblock (sigmask (SIGHUP));
839 }
840
841 if (
842 #ifndef CANNOT_DUMP
843 ! noninteractive || initialized
844 #else
845 1
846 #endif
847 )
848 {
849 /* Don't catch these signals in batch mode if dumping.
850 On some machines, this sets static data that would make
851 signal fail to work right when the dumped Emacs is run. */
852 signal (SIGQUIT, fatal_error_signal);
853 signal (SIGILL, fatal_error_signal);
854 signal (SIGTRAP, fatal_error_signal);
855 #ifdef SIGUSR1
856 signal (SIGUSR1, handle_USR1_signal);
857 #ifdef SIGUSR2
858 signal (SIGUSR2, handle_USR2_signal);
859 #endif
860 #endif
861 #ifdef SIGABRT
862 signal (SIGABRT, fatal_error_signal);
863 #endif
864 #ifdef SIGHWE
865 signal (SIGHWE, fatal_error_signal);
866 #endif
867 #ifdef SIGPRE
868 signal (SIGPRE, fatal_error_signal);
869 #endif
870 #ifdef SIGORE
871 signal (SIGORE, fatal_error_signal);
872 #endif
873 #ifdef SIGUME
874 signal (SIGUME, fatal_error_signal);
875 #endif
876 #ifdef SIGDLK
877 signal (SIGDLK, fatal_error_signal);
878 #endif
879 #ifdef SIGCPULIM
880 signal (SIGCPULIM, fatal_error_signal);
881 #endif
882 #ifdef SIGIOT
883 /* This is missing on some systems - OS/2, for example. */
884 signal (SIGIOT, fatal_error_signal);
885 #endif
886 #ifdef SIGEMT
887 signal (SIGEMT, fatal_error_signal);
888 #endif
889 signal (SIGFPE, fatal_error_signal);
890 #ifdef SIGBUS
891 signal (SIGBUS, fatal_error_signal);
892 #endif
893 signal (SIGSEGV, fatal_error_signal);
894 #ifdef SIGSYS
895 signal (SIGSYS, fatal_error_signal);
896 #endif
897 signal (SIGTERM, fatal_error_signal);
898 #ifdef SIGXCPU
899 signal (SIGXCPU, fatal_error_signal);
900 #endif
901 #ifdef SIGXFSZ
902 signal (SIGXFSZ, fatal_error_signal);
903 #endif /* SIGXFSZ */
904
905 #ifdef SIGDANGER
906 /* This just means available memory is getting low. */
907 signal (SIGDANGER, memory_warning_signal);
908 #endif
909
910 #ifdef AIX
911 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
912 signal (SIGXCPU, fatal_error_signal);
913 #ifndef _I386
914 signal (SIGIOINT, fatal_error_signal);
915 #endif
916 signal (SIGGRANT, fatal_error_signal);
917 signal (SIGRETRACT, fatal_error_signal);
918 signal (SIGSOUND, fatal_error_signal);
919 signal (SIGMSG, fatal_error_signal);
920 #endif /* AIX */
921 }
922
923 noninteractive1 = noninteractive;
924
925 /* Perform basic initializations (not merely interning symbols) */
926
927 if (!initialized)
928 {
929 init_alloc_once ();
930 init_obarray ();
931 init_eval_once ();
932 init_charset_once ();
933 init_coding_once ();
934 init_syntax_once (); /* Create standard syntax table. */
935 init_category_once (); /* Create standard category table. */
936 /* Must be done before init_buffer */
937 init_casetab_once ();
938 init_buffer_once (); /* Create buffer table and some buffers */
939 init_minibuf_once (); /* Create list of minibuffers */
940 /* Must precede init_window_once */
941 init_window_once (); /* Init the window system */
942 }
943
944 init_alloc ();
945 init_eval ();
946 init_data ();
947 running_asynch_code = 0;
948
949 /* Handle --unibyte and the EMACS_UNIBYTE envvar,
950 but not while dumping. */
951 if (
952 #ifndef CANNOT_DUMP
953 ! noninteractive || initialized
954 #else
955 1
956 #endif
957 )
958 {
959 int inhibit_unibyte = 0;
960
961 /* --multibyte overrides EMACS_UNIBYTE. */
962 if (argmatch (argv, argc, "-no-unibyte", "--no-unibyte", 4, NULL, &skip_args)
963 || argmatch (argv, argc, "-multibyte", "--multibyte", 4, NULL, &skip_args))
964 inhibit_unibyte = 1;
965
966 /* --unibyte requests that we set up to do everything with single-byte
967 buffers and strings. We need to handle this before calling
968 init_lread, init_editfns and other places that generate Lisp strings
969 from text in the environment. */
970 if (argmatch (argv, argc, "-unibyte", "--unibyte", 4, NULL, &skip_args)
971 || argmatch (argv, argc, "-no-multibyte", "--no-multibyte", 4, NULL, &skip_args)
972 || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte))
973 {
974 Lisp_Object old_log_max;
975 Lisp_Object symbol, tail;
976
977 symbol = intern ("default-enable-multibyte-characters");
978 Fset (symbol, Qnil);
979
980 if (initialized)
981 {
982 /* Erase pre-dump messages in *Messages* now so no abort. */
983 old_log_max = Vmessage_log_max;
984 XSETFASTINT (Vmessage_log_max, 0);
985 message_dolog ("", 0, 1, 0);
986 Vmessage_log_max = old_log_max;
987 }
988
989 for (tail = Vbuffer_alist; CONSP (tail);
990 tail = XCONS (tail)->cdr)
991 {
992 Lisp_Object buffer;
993
994 buffer = Fcdr (XCONS (tail)->car);
995 /* Verify that all buffers are empty now, as they
996 ought to be. */
997 if (BUF_Z (XBUFFER (buffer)) > BUF_BEG (XBUFFER (buffer)))
998 abort ();
999 /* It is safe to do this crudely in an empty buffer. */
1000 XBUFFER (buffer)->enable_multibyte_characters = Qnil;
1001 }
1002 }
1003 }
1004
1005 no_loadup
1006 = !argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args);
1007
1008
799 #ifdef HAVE_X_WINDOWS 1009 #ifdef HAVE_X_WINDOWS
800 /* Stupid kludge to catch command-line display spec. We can't 1010 /* Stupid kludge to catch command-line display spec. We can't
801 handle this argument entirely in window system dependent code 1011 handle this argument entirely in window system dependent code
802 because we don't even know which window system dependent code 1012 because we don't even know which window system dependent code
803 to run until we've recognized this argument. */ 1013 to run until we've recognized this argument. */
804 { 1014 {
805 char *displayname = 0; 1015 char *displayname = 0;
806 int i; 1016 int i;
807 int count_before = skip_args; 1017 int count_before = skip_args;
808 1018
809 if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args)) 1019 /* Skip any number of -d options, but only use the last one. */
810 display_arg = 1; 1020 while (1)
811 else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args)) 1021 {
812 display_arg = 1; 1022 int count_before_this = skip_args;
1023
1024 if (argmatch (argv, argc, "-d", "--display", 3, &displayname, &skip_args))
1025 display_arg = 1;
1026 else if (argmatch (argv, argc, "-display", 0, 3, &displayname, &skip_args))
1027 display_arg = 1;
1028 else
1029 break;
1030
1031 count_before = count_before_this;
1032 }
813 1033
814 /* If we have the form --display=NAME, 1034 /* If we have the form --display=NAME,
815 convert it into -d name. 1035 convert it into -d name.
816 This requires inserting a new element into argv. */ 1036 This requires inserting a new element into argv. */
817 if (displayname != 0 && skip_args - count_before == 1) 1037 if (displayname != 0 && skip_args - count_before == 1)
836 /* Don't actually discard this arg. */ 1056 /* Don't actually discard this arg. */
837 skip_args = count_before; 1057 skip_args = count_before;
838 } 1058 }
839 #endif 1059 #endif
840 1060
841 if (! noninteractive) 1061 /* argmatch must not be used after here,
842 { 1062 except when bulding temacs
843 #ifdef BSD_PGRPS 1063 because the -d argument has not been skipped in skip_args. */
844 if (initialized)
845 {
846 inherited_pgroup = EMACS_GETPGRP (0);
847 setpgrp (0, getpid ());
848 }
849 #else
850 #if defined (USG5) && defined (INTERRUPT_INPUT)
851 setpgrp ();
852 #endif
853 #endif
854 }
855
856 #ifdef POSIX_SIGNALS
857 init_signals ();
858 #endif
859
860 /* Don't catch SIGHUP if dumping. */
861 if (1
862 #ifndef CANNOT_DUMP
863 && initialized
864 #endif
865 )
866 {
867 sigblock (sigmask (SIGHUP));
868 /* In --batch mode, don't catch SIGHUP if already ignored.
869 That makes nohup work. */
870 if (! noninteractive
871 || signal (SIGHUP, SIG_IGN) != SIG_IGN)
872 signal (SIGHUP, fatal_error_signal);
873 sigunblock (sigmask (SIGHUP));
874 }
875
876 if (
877 #ifndef CANNOT_DUMP
878 ! noninteractive || initialized
879 #else
880 1
881 #endif
882 )
883 {
884 /* Don't catch these signals in batch mode if dumping.
885 On some machines, this sets static data that would make
886 signal fail to work right when the dumped Emacs is run. */
887 signal (SIGQUIT, fatal_error_signal);
888 signal (SIGILL, fatal_error_signal);
889 signal (SIGTRAP, fatal_error_signal);
890 #ifdef SIGUSR1
891 signal (SIGUSR1, handle_USR1_signal);
892 #ifdef SIGUSR2
893 signal (SIGUSR2, handle_USR2_signal);
894 #endif
895 #endif
896 #ifdef SIGABRT
897 signal (SIGABRT, fatal_error_signal);
898 #endif
899 #ifdef SIGHWE
900 signal (SIGHWE, fatal_error_signal);
901 #endif
902 #ifdef SIGPRE
903 signal (SIGPRE, fatal_error_signal);
904 #endif
905 #ifdef SIGORE
906 signal (SIGORE, fatal_error_signal);
907 #endif
908 #ifdef SIGUME
909 signal (SIGUME, fatal_error_signal);
910 #endif
911 #ifdef SIGDLK
912 signal (SIGDLK, fatal_error_signal);
913 #endif
914 #ifdef SIGCPULIM
915 signal (SIGCPULIM, fatal_error_signal);
916 #endif
917 #ifdef SIGIOT
918 /* This is missing on some systems - OS/2, for example. */
919 signal (SIGIOT, fatal_error_signal);
920 #endif
921 #ifdef SIGEMT
922 signal (SIGEMT, fatal_error_signal);
923 #endif
924 signal (SIGFPE, fatal_error_signal);
925 #ifdef SIGBUS
926 signal (SIGBUS, fatal_error_signal);
927 #endif
928 signal (SIGSEGV, fatal_error_signal);
929 #ifdef SIGSYS
930 signal (SIGSYS, fatal_error_signal);
931 #endif
932 signal (SIGTERM, fatal_error_signal);
933 #ifdef SIGXCPU
934 signal (SIGXCPU, fatal_error_signal);
935 #endif
936 #ifdef SIGXFSZ
937 signal (SIGXFSZ, fatal_error_signal);
938 #endif /* SIGXFSZ */
939
940 #ifdef SIGDANGER
941 /* This just means available memory is getting low. */
942 signal (SIGDANGER, memory_warning_signal);
943 #endif
944
945 #ifdef AIX
946 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
947 signal (SIGXCPU, fatal_error_signal);
948 #ifndef _I386
949 signal (SIGIOINT, fatal_error_signal);
950 #endif
951 signal (SIGGRANT, fatal_error_signal);
952 signal (SIGRETRACT, fatal_error_signal);
953 signal (SIGSOUND, fatal_error_signal);
954 signal (SIGMSG, fatal_error_signal);
955 #endif /* AIX */
956 }
957
958 noninteractive1 = noninteractive;
959
960 /* Perform basic initializations (not merely interning symbols) */
961
962 if (!initialized)
963 {
964 init_alloc_once ();
965 init_obarray ();
966 init_eval_once ();
967 init_charset_once ();
968 init_coding_once ();
969 init_syntax_once (); /* Create standard syntax table. */
970 init_category_once (); /* Create standard category table. */
971 /* Must be done before init_buffer */
972 init_casetab_once ();
973 init_buffer_once (); /* Create buffer table and some buffers */
974 init_minibuf_once (); /* Create list of minibuffers */
975 /* Must precede init_window_once */
976 init_window_once (); /* Init the window system */
977 }
978
979 init_alloc ();
980 init_eval ();
981 init_data ();
982 running_asynch_code = 0;
983
984 /* Handle --unibyte and the EMACS_UNIBYTE envvar,
985 but not while dumping. */
986 if (
987 #ifndef CANNOT_DUMP
988 ! noninteractive || initialized
989 #else
990 1
991 #endif
992 )
993 {
994 int inhibit_unibyte = 0;
995
996 /* --multibyte overrides EMACS_UNIBYTE. */
997 if (argmatch (argv, argc, "-no-unibyte", "--no-unibyte", 4, NULL, &skip_args)
998 || argmatch (argv, argc, "-multibyte", "--multibyte", 4, NULL, &skip_args))
999 inhibit_unibyte = 1;
1000
1001 /* --unibyte requests that we set up to do everything with single-byte
1002 buffers and strings. We need to handle this before calling
1003 init_lread, init_editfns and other places that generate Lisp strings
1004 from text in the environment. */
1005 if (argmatch (argv, argc, "-unibyte", "--unibyte", 4, NULL, &skip_args)
1006 || argmatch (argv, argc, "-no-multibyte", "--no-multibyte", 4, NULL, &skip_args)
1007 || (getenv ("EMACS_UNIBYTE") && !inhibit_unibyte))
1008 {
1009 Lisp_Object old_log_max;
1010 Lisp_Object symbol, tail;
1011
1012 symbol = intern ("default-enable-multibyte-characters");
1013 Fset (symbol, Qnil);
1014
1015 if (initialized)
1016 {
1017 /* Erase pre-dump messages in *Messages* now so no abort. */
1018 old_log_max = Vmessage_log_max;
1019 XSETFASTINT (Vmessage_log_max, 0);
1020 message_dolog ("", 0, 1, 0);
1021 Vmessage_log_max = old_log_max;
1022 }
1023
1024 for (tail = Vbuffer_alist; CONSP (tail);
1025 tail = XCONS (tail)->cdr)
1026 {
1027 Lisp_Object buffer;
1028
1029 buffer = Fcdr (XCONS (tail)->car);
1030 /* Verify that all buffers are empty now, as they
1031 ought to be. */
1032 if (BUF_Z (XBUFFER (buffer)) > BUF_BEG (XBUFFER (buffer)))
1033 abort ();
1034 /* It is safe to do this crudely in an empty buffer. */
1035 XBUFFER (buffer)->enable_multibyte_characters = Qnil;
1036 }
1037 }
1038 }
1039 1064
1040 #ifdef MSDOS 1065 #ifdef MSDOS
1041 /* Call early 'cause init_environment needs it. */ 1066 /* Call early 'cause init_environment needs it. */
1042 init_dosfns (); 1067 init_dosfns ();
1043 /* Set defaults for several environment variables. */ 1068 /* Set defaults for several environment variables. */
1217 if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args)) 1242 if (argmatch (argv, argc, "-l", "--load", 3, &file, &skip_args))
1218 Vtop_level = Fcons (intern ("load"), 1243 Vtop_level = Fcons (intern ("load"),
1219 Fcons (build_string (file), Qnil)); 1244 Fcons (build_string (file), Qnil));
1220 #ifdef CANNOT_DUMP 1245 #ifdef CANNOT_DUMP
1221 /* Unless next switch is -nl, load "loadup.el" first thing. */ 1246 /* Unless next switch is -nl, load "loadup.el" first thing. */
1222 if (!argmatch (argv, argc, "-nl", "--no-loadup", 6, NULL, &skip_args)) 1247 if (! no_loadup)
1223 Vtop_level = Fcons (intern ("load"), 1248 Vtop_level = Fcons (intern ("load"),
1224 Fcons (build_string ("loadup.el"), Qnil)); 1249 Fcons (build_string ("loadup.el"), Qnil));
1225 #endif /* CANNOT_DUMP */ 1250 #endif /* CANNOT_DUMP */
1226 } 1251 }
1227 1252
1308 #endif 1333 #endif
1309 { "-t", "--terminal", 120, 1 }, 1334 { "-t", "--terminal", 120, 1 },
1310 { "-nw", "--no-windows", 110, 0 }, 1335 { "-nw", "--no-windows", 110, 0 },
1311 { "-batch", "--batch", 100, 0 }, 1336 { "-batch", "--batch", 100, 0 },
1312 { "-help", "--help", 90, 0 }, 1337 { "-help", "--help", 90, 0 },
1313 { "-d", "--display", 80, 1 }, 1338 { "-no-unibyte", "--no-unibyte", 83, 0 },
1314 { "-display", 0, 80, 1 }, 1339 { "-multibyte", "--multibyte", 82, 0 },
1315 { "-no-unibyte", "--no-unibyte", 71, 0 }, 1340 { "-unibyte", "--unibyte", 81, 0 },
1316 { "-multibyte", "--multibyte", 71, 0 }, 1341 { "-no-multibyte", "--no-multibyte", 80, 0 },
1317 { "-unibyte", "--unibyte", 70, 0 },
1318 { "-no-multibyte", "--no-multibyte", 70, 0 },
1319 #ifdef CANNOT_DUMP 1342 #ifdef CANNOT_DUMP
1320 { "-nl", "--no-loadup", 60, 0 }, 1343 { "-nl", "--no-loadup", 70, 0 },
1321 #endif 1344 #endif
1345 /* -d must come last before the options handled in startup.el. */
1346 { "-d", "--display", 60, 1 },
1347 { "-display", 0, 60, 1 },
1322 /* Now for the options handled in startup.el. */ 1348 /* Now for the options handled in startup.el. */
1323 { "-q", "--no-init-file", 50, 0 }, 1349 { "-q", "--no-init-file", 50, 0 },
1324 { "-no-init-file", 0, 50, 0 }, 1350 { "-no-init-file", 0, 50, 0 },
1325 { "-no-site-file", "--no-site-file", 40, 0 }, 1351 { "-no-site-file", "--no-site-file", 40, 0 },
1326 { "-u", "--user", 30, 1 }, 1352 { "-u", "--user", 30, 1 },
1368 }; 1394 };
1369 1395
1370 /* Reorder the elements of ARGV (assumed to have ARGC elements) 1396 /* Reorder the elements of ARGV (assumed to have ARGC elements)
1371 so that the highest priority ones come first. 1397 so that the highest priority ones come first.
1372 Do not change the order of elements of equal priority. 1398 Do not change the order of elements of equal priority.
1373 If an option takes an argument, keep it and its argument together. */ 1399 If an option takes an argument, keep it and its argument together.
1400
1401 If an option that takes no argument appears more
1402 than once, eliminate all but one copy of it. */
1374 1403
1375 static void 1404 static void
1376 sort_args (argc, argv) 1405 sort_args (argc, argv)
1377 int argc; 1406 int argc;
1378 char **argv; 1407 char **argv;
1384 1 for an option that takes one argument, etc. 1413 1 for an option that takes one argument, etc.
1385 -1 for an ordinary non-option argument. */ 1414 -1 for an ordinary non-option argument. */
1386 int *options = (int *) xmalloc (sizeof (int) * argc); 1415 int *options = (int *) xmalloc (sizeof (int) * argc);
1387 int *priority = (int *) xmalloc (sizeof (int) * argc); 1416 int *priority = (int *) xmalloc (sizeof (int) * argc);
1388 int to = 1; 1417 int to = 1;
1418 int incoming_used = 1;
1389 int from; 1419 int from;
1390 int i; 1420 int i;
1391 int end_of_options = argc; 1421 int end_of_options = argc;
1392 1422
1393 /* Categorize all the options, 1423 /* Categorize all the options,
1467 } 1497 }
1468 } 1498 }
1469 1499
1470 /* Copy the arguments, in order of decreasing priority, to NEW. */ 1500 /* Copy the arguments, in order of decreasing priority, to NEW. */
1471 new[0] = argv[0]; 1501 new[0] = argv[0];
1472 while (to < argc) 1502 while (incoming_used < argc)
1473 { 1503 {
1474 int best = -1; 1504 int best = -1;
1475 int best_priority = -9999; 1505 int best_priority = -9999;
1476 1506
1477 /* Find the highest priority remaining option. 1507 /* Find the highest priority remaining option.
1489 } 1519 }
1490 1520
1491 if (best < 0) 1521 if (best < 0)
1492 abort (); 1522 abort ();
1493 1523
1494 /* Copy the highest priority remaining option, with its args, to NEW. */ 1524 /* Copy the highest priority remaining option, with its args, to NEW.
1495 new[to++] = argv[best]; 1525 Unless it is a duplicate of the previous one. */
1496 for (i = 0; i < options[best]; i++) 1526 if (! (options[best] == 0
1497 new[to++] = argv[best + i + 1]; 1527 && ! strcmp (new[to - 1], argv[best])))
1528 {
1529 new[to++] = argv[best];
1530 for (i = 0; i < options[best]; i++)
1531 new[to++] = argv[best + i + 1];
1532 }
1533
1534 incoming_used += 1 + (options[best] > 0 ? options[best] : 0);
1498 1535
1499 /* Clear out this option in ARGV. */ 1536 /* Clear out this option in ARGV. */
1500 argv[best] = 0; 1537 argv[best] = 0;
1501 for (i = 0; i < options[best]; i++) 1538 for (i = 0; i < options[best]; i++)
1502 argv[best + i + 1] = 0; 1539 argv[best + i + 1] = 0;