emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 835ce688e2 1/2: ; * src/emacs.c (main): Move -version output afte


From: Eli Zaretskii
Subject: master 835ce688e2 1/2: ; * src/emacs.c (main): Move -version output after initialization.
Date: Thu, 2 Jun 2022 03:52:18 -0400 (EDT)

branch: master
commit 835ce688e24ae599b8834fa5160e4b1559d0c172
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    ; * src/emacs.c (main): Move -version output after initialization.
---
 src/emacs.c | 176 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 97 insertions(+), 79 deletions(-)

diff --git a/src/emacs.c b/src/emacs.c
index e4257a66b4..43b9901e08 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1415,77 +1415,19 @@ main (int argc, char **argv)
      should be explicitly recognized, ignored, and removed from
      'command-line-args-left' in 'command-line-1'.  */
 
+  bool only_version = false;
   sort_args (argc, argv);
   argc = 0;
   while (argv[argc]) argc++;
 
   skip_args = 0;
   if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
-    {
-      Lisp_Object rversion, rbranch, rtime;
-      const char *version, *copyright;
-
-      if (initialized)
-       {
-         Lisp_Object tem, tem2;
-
-         /* Fformat_time_string below manipulates bignums, so we need
-            this initialization.  */
-         init_bignum ();
-
-         tem = Fsymbol_value (intern_c_string ("emacs-version"));
-         tem2 = Fsymbol_value (intern_c_string ("emacs-copyright"));
-         if (!STRINGP (tem))
-           {
-             fputs ("Invalid value of 'emacs-version'\n", stderr);
-             exit (1);
-           }
-         if (!STRINGP (tem2))
-           {
-             fputs ("Invalid value of 'emacs-copyright'\n", stderr);
-             exit (1);
-           }
-         else
-           {
-             version = SSDATA (tem);
-             copyright = SSDATA (tem2);
-           }
-       }
-      else
-       {
-         version = emacs_version;
-         copyright = emacs_copyright;
-       }
-      printf ("%s %s\n", PACKAGE_NAME, version);
-
-      rversion
-       = Fsymbol_value (intern_c_string ("emacs-repository-version"));
-      rbranch
-       = Fsymbol_value (intern_c_string ("emacs-repository-branch"));
-      rtime
-       = Fsymbol_value (intern_c_string ("emacs-build-time"));
-
-      if (!NILP (rversion) && !NILP (rbranch) && !NILP (rtime))
-       printf ("Development version %s on %s branch; build date %s.\n",
-               SSDATA (Fsubstring (rversion, make_fixnum (0),
-                                   make_fixnum (12))),
-               SSDATA (rbranch),
-               SSDATA (Fformat_time_string (build_string ("%Y-%m-%d"),
-                                            rtime, Qnil)));
-
-      printf (("%s\n"
-              "%s comes with ABSOLUTELY NO WARRANTY.\n"
-              "You may redistribute copies of %s\n"
-              "under the terms of the GNU General Public License.\n"
-              "For more information about these matters, "
-              "see the file named COPYING.\n"),
-             copyright, PACKAGE_NAME, PACKAGE_NAME);
-      exit (0);
-    }
+    only_version = true;
 
 #ifdef HAVE_PDUMPER
   if (argmatch (argv, argc, "-fingerprint", "--fingerprint", 4,
-               NULL, &skip_args))
+               NULL, &skip_args)
+      && !only_version)
     {
       if (initialized)
         {
@@ -1510,7 +1452,8 @@ main (int argc, char **argv)
     pdumper_record_wd (emacs_wd);
 #endif
 
-  if (argmatch (argv, argc, "-chdir", "--chdir", 4, &ch_to_dir, &skip_args))
+  if (argmatch (argv, argc, "-chdir", "--chdir", 4, &ch_to_dir, &skip_args)
+      && !only_version)
     {
 #ifdef WINDOWSNT
       /* argv[] array is kept in its original ANSI codepage encoding,
@@ -1636,7 +1579,7 @@ main (int argc, char **argv)
   inhibit_window_system = 0;
 
   /* Handle the -t switch, which specifies filename to use as terminal.  */
-  while (1)
+  while (!only_version)
     {
       char *term;
       if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args))
@@ -1674,7 +1617,8 @@ main (int argc, char **argv)
 
   /* Handle the -batch switch, which means don't do interactive display.  */
   noninteractive = 0;
-  if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args))
+  if (argmatch (argv, argc, "-batch", "--batch", 5, NULL, &skip_args)
+      || only_version)
     {
       noninteractive = 1;
       Vundo_outer_limit = Qnil;
@@ -1691,7 +1635,8 @@ main (int argc, char **argv)
     }
 
   /* Handle the --help option, which gives a usage message.  */
-  if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
+  if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args)
+      && !only_version)
     {
       int i;
       printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]);
@@ -1712,20 +1657,27 @@ main (int argc, char **argv)
 
   int sockfd = -1;
 
-  if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL, &skip_args)
-      || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg, 
&skip_args))
+  if (!only_version)
     {
-      daemon_type = 1;           /* foreground */
-    }
-  else if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
-      || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, 
&skip_args)
-      || argmatch (argv, argc, "-bg-daemon", "--bg-daemon", 10, NULL, 
&skip_args)
-      || argmatch (argv, argc, "-bg-daemon", "--bg-daemon", 10, &dname_arg, 
&skip_args))
-    {
-      daemon_type = 2;          /* background */
+      if (argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, NULL,
+                   &skip_args)
+         || argmatch (argv, argc, "-fg-daemon", "--fg-daemon", 10, &dname_arg,
+                      &skip_args))
+       {
+         daemon_type = 1;           /* foreground */
+       }
+      else if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, 
&skip_args)
+              || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg,
+                           &skip_args)
+              || argmatch (argv, argc, "-bg-daemon", "--bg-daemon", 10, NULL,
+                           &skip_args)
+              || argmatch (argv, argc, "-bg-daemon", "--bg-daemon", 10,
+                           &dname_arg, &skip_args))
+       {
+         daemon_type = 2;          /* background */
+       }
     }
 
-
   if (daemon_type > 0)
     {
 #ifndef DOS_NT
@@ -2001,7 +1953,7 @@ Using an Emacs configured with --with-x-toolkit=lucid 
does not have this problem
   bool module_assertions
     = argmatch (argv, argc, "-module-assertions", "--module-assertions", 15,
                 NULL, &skip_args);
-  if (will_dump_p () && module_assertions)
+  if (will_dump_p () && module_assertions && !only_version)
     {
       fputs ("Module assertions are not supported during dumping\n", stderr);
       exit (1);
@@ -2049,7 +2001,7 @@ Using an Emacs configured with --with-x-toolkit=lucid 
does not have this problem
     int count_before = skip_args;
 
     /* Skip any number of -d options, but only use the last one.  */
-    while (1)
+    while (!only_version)
       {
        int count_before_this = skip_args;
 
@@ -2191,6 +2143,72 @@ Using an Emacs configured with --with-x-toolkit=lucid 
does not have this problem
   init_callproc ();    /* Must follow init_cmdargs but not init_sys_modes.  */
   init_fileio ();
   init_lread ();
+
+  /* If "-version" was specified, produce version information and
+     exit.  We do it here because the code below needs to call Lisp
+     primitives, which cannot be done safely before we call all the
+     init_FOO initialization functions above.  */
+  if (only_version)
+    {
+      const char *version, *copyright;
+
+      if (initialized)
+       {
+         Lisp_Object tem = Fsymbol_value (intern_c_string ("emacs-version"));
+         Lisp_Object tem2 = Fsymbol_value (intern_c_string 
("emacs-copyright"));
+         if (!STRINGP (tem))
+           {
+             fputs ("Invalid value of 'emacs-version'\n", stderr);
+             exit (1);
+           }
+         if (!STRINGP (tem2))
+           {
+             fputs ("Invalid value of 'emacs-copyright'\n", stderr);
+             exit (1);
+           }
+         else
+           {
+             version = SSDATA (tem);
+             copyright = SSDATA (tem2);
+           }
+       }
+      else
+       {
+         version = emacs_version;
+         copyright = emacs_copyright;
+       }
+      printf ("%s %s\n", PACKAGE_NAME, version);
+
+      if (initialized)
+       {
+         Lisp_Object rversion, rbranch, rtime;
+
+         rversion
+           = Fsymbol_value (intern_c_string ("emacs-repository-version"));
+         rbranch
+           = Fsymbol_value (intern_c_string ("emacs-repository-branch"));
+         rtime
+           = Fsymbol_value (intern_c_string ("emacs-build-time"));
+
+         if (!NILP (rversion) && !NILP (rbranch) && !NILP (rtime))
+           printf ("Development version %s on %s branch; build date %s.\n",
+                   SSDATA (Fsubstring (rversion, make_fixnum (0),
+                                       make_fixnum (12))),
+                   SSDATA (rbranch),
+                   SSDATA (Fformat_time_string (build_string ("%Y-%m-%d"),
+                                                rtime, Qnil)));
+       }
+
+      printf (("%s\n"
+              "%s comes with ABSOLUTELY NO WARRANTY.\n"
+              "You may redistribute copies of %s\n"
+              "under the terms of the GNU General Public License.\n"
+              "For more information about these matters, "
+              "see the file named COPYING.\n"),
+             copyright, PACKAGE_NAME, PACKAGE_NAME);
+      exit (0);
+    }
+
 #ifdef WINDOWSNT
   /* Check to see if Emacs has been installed correctly.  */
   check_windows_init_file ();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]