This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Cosmetic tweaks: cpplib, toplev.c


If you do gcc -v with current sources (branch or mainline), that winds
up being "cc1 -v -version", which produces this rather silly-looking
report:

GNU CPP version 3.1 20010219 (experimental) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/work/inst/i686-pc-linux-gnu/bin/include"
ignoring nonexistent directory "/work/inst/i686-pc-linux-gnu/include"
GNU CPP version 3.1 20010219 (experimental) (cpplib) (i386 Linux/ELF)
GNU C version 3.1 20010219 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 3.1 20010219 (experimental).
ignoring nonexistent directory "../lib/gcc-lib/i686-pc-linux-gnu/3.1/include"
[etc]

cc1 --version, on the other hand, doesn't print the cpplib version
string at all.  (Yes, -version is not the same thing as --version.)

The appended patch rearranges things such that you cannot get cpplib's
version string printed twice, and you will get cpplib's version string
with --version (they come out in the opposite order, which I can live
with).  I thought about also moving all the "ignoring..."  messages
below the banner, but that got into too much hairy linked list
mangling for 2AM last night.

I'll hold off on the cpplib changes until I get an OK on the toplev.c
changes.  Also, is this reasonable for the branch?  It is low-risk,
and the double message looks really lame.

Note there's also a tweak for append_include_chain, which is never
called with a fourth argument of QUOTE.

zw
	* cpphash.h (struct cpp_reader): Add print_version field.
	* cppinit.c (cpp_handle_option): For -v, -version, and --version,
	just set print_version and other flags as appropriate.
	(cpp_post_options): Print version here if print_version is set.

	* toplev.c (exit_after_options): New flag.
	(independent_decode_option): Don't exit here; just set
	exit_after_options.
	(main): Exit after calling lang_hooks.post_options if
	exit_after_options is true.

	* cppinit.c (append_include_chain): Drop never-used case QUOTE.
	(merge_include_chains): Adjust comment to match code.

===================================================================
Index: cpphash.h
--- cpphash.h	2001/02/07 23:13:46	1.97
+++ cpphash.h	2001/02/20 06:02:46
@@ -343,6 +343,10 @@ struct cpp_reader
 
   /* True if we are skipping a failed conditional group.  */
   unsigned char skipping;
+
+  /* Whether to print our version number.  Done this way so
+     we don't get it twice for -v -version.  */
+  unsigned char print_version;
 };
 
 /* Character classes.  Based on the more primitive macros in safe-ctype.h.
===================================================================
Index: cppinit.c
--- cppinit.c	2001/02/07 18:32:41	1.147
+++ cppinit.c	2001/02/20 06:02:49
@@ -117,8 +117,9 @@ static void new_pending_directive	PARAMS
 static void output_deps			PARAMS ((cpp_reader *));
 static int parse_option			PARAMS ((const char *));
 
-/* Fourth argument to append_include_chain: chain to use.  */
-enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
+/* Fourth argument to append_include_chain: chain to use.
+   Note it's never asked to append to the quote chain.  */
+enum { BRACKET = 0, SYSTEM, AFTER };
 
 /* If we have designated initializers (GCC >2.7) these tables can be
    initialized, constant data.  Otherwise, they have to be filled in at
@@ -250,7 +251,6 @@ append_include_chain (pfile, dir, path, 
 
   switch (path)
     {
-    case QUOTE:		APPEND (pend, quote, new); break;
     case BRACKET:	APPEND (pend, brack, new); break;
     case SYSTEM:	APPEND (pend, systm, new); break;
     case AFTER:		APPEND (pend, after, new); break;
@@ -338,7 +338,7 @@ merge_include_chains (pfile)
   /* This is a bit tricky.  First we drop dupes from the quote-include
      list.  Then we drop dupes from the bracket-include list.
      Finally, if qtail and brack are the same directory, we cut out
-     brack.
+     brack and move brack up to point to qtail.
 
      We can't just merge the lists and then uniquify them because
      then we may lose directories from the <> search path that should
@@ -1313,18 +1313,14 @@ cpp_handle_option (pfile, argc, argv)
 	     verbose and -version.  Historical reasons, don't ask.  */
 	case OPT__version:
 	  CPP_OPTION (pfile, help_only) = 1;
-	  goto version;
+	  pfile->print_version = 1;
+	  break;
 	case OPT_v:
 	  CPP_OPTION (pfile, verbose) = 1;
-	  goto version;
-
+	  pfile->print_version = 1;
+	  break;
 	case OPT_version:
-	version:
-	  fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
-#ifdef TARGET_VERSION
-	  TARGET_VERSION;
-#endif
-	  fputc ('\n', stderr);
+	  pfile->print_version = 1;
 	  break;
 
 	case OPT_C:
@@ -1689,6 +1685,16 @@ void
 cpp_post_options (pfile)
      cpp_reader *pfile;
 {
+
+  if (pfile->print_version)
+    {
+      fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
+#ifdef TARGET_VERSION
+      TARGET_VERSION;
+#endif
+      fputc ('\n', stderr);
+    }
+
   /* -Wtraditional is not useful in C++ mode.  */
   if (CPP_OPTION (pfile, cplusplus))
     CPP_OPTION (pfile, warn_traditional) = 0;
===================================================================
Index: toplev.c
--- toplev.c	2001/02/19 00:09:28	1.425
+++ toplev.c	2001/02/20 06:02:53
@@ -391,6 +391,9 @@ int errorcount = 0;
 int warningcount = 0;
 int sorrycount = 0;
 
+/* Nonzero if we should exit after parsing options.  */
+int exit_after_options = 0;
+
 /* The FUNCTION_DECL for the function currently being compiled,
    or 0 if between functions.  */
 tree current_function_decl;
@@ -4360,19 +4363,19 @@ independent_decode_option (argc, argv)
   if (!strcmp (arg, "-help"))
     {
       display_help ();
-      exit (0);
+      exit_after_options = 1;
     }
 
   if (!strcmp (arg, "-target-help"))
     {
       display_target_options ();
-      exit (0);
+      exit_after_options = 1;
     }
 
   if (!strcmp (arg, "-version"))
     {
       print_version (stderr, "");
-      exit (0);
+      exit_after_options = 1;
     }
 
   /* Handle '--param <name>=<value>'.  */
@@ -4821,6 +4824,9 @@ main (argc, argv)
   /* All command line options have been processed.  */
   if (lang_hooks.post_options)
     (*lang_hooks.post_options) ();
+
+  if (exit_after_options)
+    exit (0);
 
   /* Reflect any language-specific diagnostic option setting.  */
   reshape_diagnostic_buffer ();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]