Commit f4cdc368 by Zack Weinberg Committed by Zack Weinberg

cpplib.h (struct cpp_reader): Add help_only field.

	* cpplib.h (struct cpp_reader): Add help_only field.
	* cppinit.c (COMMAND_LINE_OPTIONS): Add OPT_version.
	(cpp_handle_option): Set pfile->help_only if we see -h,
	--help, -target-help, or --version.  Print version string but
	do not set help_only if we see -v or -version.  Make text
	printed by -v match that printed by (-)-version.

	* cppmain.c (main): Exit after option parsing if
	pfile->help_only is true.

	* toplev.c (independent_decode_option): Call print_version,
	then exit, if we see --version (but not -version).
	(print_version): Split lengthy message into two lines.

From-SVN: r38733
parent 3326b760
2001-01-05 Zack Weinberg <zack@wolery.stanford.edu>
* cpplib.h (struct cpp_reader): Add help_only field.
* cppinit.c (COMMAND_LINE_OPTIONS): Add OPT_version.
(cpp_handle_option): Set pfile->help_only if we see -h,
--help, -target-help, or --version. Print version string but
do not set help_only if we see -v or -version. Make text
printed by -v match that printed by (-)-version.
* cppmain.c (main): Exit after option parsing if
pfile->help_only is true.
* toplev.c (independent_decode_option): Call print_version,
then exit, if we see --version (but not -version).
(print_version): Split lengthy message into two lines.
2001-01-05 Nick Clifton <nickc@redhat.com> 2001-01-05 Nick Clifton <nickc@redhat.com>
* config/v850/v850.c (v850_encode_data_area): Use alloca to create * config/v850/v850.c (v850_encode_data_area): Use alloca to create
......
...@@ -1130,6 +1130,7 @@ new_pending_directive (pend, text, handler) ...@@ -1130,6 +1130,7 @@ new_pending_directive (pend, text, handler)
DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \ DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
DEF_OPT("trigraphs", 0, OPT_trigraphs) \ DEF_OPT("trigraphs", 0, OPT_trigraphs) \
DEF_OPT("v", 0, OPT_v) \ DEF_OPT("v", 0, OPT_v) \
DEF_OPT("version", 0, OPT_version) \
DEF_OPT("w", 0, OPT_w) DEF_OPT("w", 0, OPT_w)
#define DEF_OPT(text, msg, code) code, #define DEF_OPT(text, msg, code) code,
...@@ -1322,16 +1323,32 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1322,16 +1323,32 @@ cpp_handle_option (pfile, argc, argv)
case OPT_h: case OPT_h:
case OPT__help: case OPT__help:
print_help (); print_help ();
exit (0); /* XXX */ pfile->help_only = 1;
break; break;
case OPT_target__help: case OPT_target__help:
/* Print if any target specific options. */ /* Print if any target specific options. cpplib has none, but
exit (0); make sure help_only gets set. */
pfile->help_only = 1;
break; break;
/* --version inhibits compilation, -version doesn't. -v means
verbose and -version. Historical reasons, don't ask. */
case OPT__version: case OPT__version:
fprintf (stderr, _("GNU CPP version %s (cpplib)\n"), version_string); pfile->help_only = 1;
exit (0); /* XXX */ goto version;
case OPT_v:
CPP_OPTION (pfile, verbose) = 1;
goto version;
case OPT_version:
version:
fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
#ifdef TARGET_VERSION
TARGET_VERSION;
#endif
fputc ('\n', stderr);
break; break;
case OPT_C: case OPT_C:
CPP_OPTION (pfile, discard_comments) = 0; CPP_OPTION (pfile, discard_comments) = 0;
break; break;
...@@ -1425,14 +1442,6 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1425,14 +1442,6 @@ cpp_handle_option (pfile, argc, argv)
if (!strcmp (CPP_OPTION (pfile, out_fname), "-")) if (!strcmp (CPP_OPTION (pfile, out_fname), "-"))
CPP_OPTION (pfile, out_fname) = ""; CPP_OPTION (pfile, out_fname) = "";
break; break;
case OPT_v:
fprintf (stderr, _("GNU CPP version %s (cpplib)"), version_string);
#ifdef TARGET_VERSION
TARGET_VERSION;
#endif
fputc ('\n', stderr);
CPP_OPTION (pfile, verbose) = 1;
break;
case OPT_stdin_stdout: case OPT_stdin_stdout:
/* JF handle '-' as file name meaning stdin or stdout. */ /* JF handle '-' as file name meaning stdin or stdout. */
if (CPP_OPTION (pfile, in_fname) == NULL) if (CPP_OPTION (pfile, in_fname) == NULL)
......
...@@ -616,6 +616,10 @@ struct cpp_reader ...@@ -616,6 +616,10 @@ struct cpp_reader
/* True if we are skipping a failed conditional group. */ /* True if we are skipping a failed conditional group. */
unsigned char skipping; unsigned char skipping;
/* True if --help appeared in the options. Caller should then bail
out after option parsing and printing its own help. See cppmain.c. */
unsigned char help_only;
}; };
#define CPP_FATAL_LIMIT 1000 #define CPP_FATAL_LIMIT 1000
......
...@@ -82,6 +82,13 @@ main (argc, argv) ...@@ -82,6 +82,13 @@ main (argc, argv)
if (CPP_FATAL_ERRORS (pfile)) if (CPP_FATAL_ERRORS (pfile))
return (FATAL_EXIT_CODE); return (FATAL_EXIT_CODE);
/* If cpp_handle_options saw --help or --version on the command
line, it will have set pfile->help_only to indicate this. Exit
successfully. [The library does not exit itself, because
e.g. cc1 needs to print its own --help message at this point.] */
if (pfile->help_only)
return (SUCCESS_EXIT_CODE);
/* Open the output now. We must do so even if no_output is on, /* Open the output now. We must do so even if no_output is on,
because there may be other output than from the actual because there may be other output than from the actual
preprocessing (e.g. from -dM). */ preprocessing (e.g. from -dM). */
......
...@@ -4340,6 +4340,12 @@ independent_decode_option (argc, argv) ...@@ -4340,6 +4340,12 @@ independent_decode_option (argc, argv)
exit (0); exit (0);
} }
if (!strcmp (arg, "-version"))
{
print_version (stderr, "");
exit (0);
}
if (*arg == 'Y') if (*arg == 'Y')
arg++; arg++;
...@@ -4934,12 +4940,13 @@ print_version (file, indent) ...@@ -4934,12 +4940,13 @@ print_version (file, indent)
#endif #endif
fnotice (file, fnotice (file,
#ifdef __GNUC__ #ifdef __GNUC__
"%s%s%s version %s (%s) compiled by GNU C version %s.\n" "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
#else #else
"%s%s%s version %s (%s) compiled by CC.\n" "%s%s%s version %s (%s) compiled by CC.\n"
#endif #endif
, indent, *indent != 0 ? " " : "", , indent, *indent != 0 ? " " : "",
language_string, version_string, TARGET_NAME, __VERSION__); language_string, version_string, TARGET_NAME,
indent, __VERSION__);
} }
/* Print an option value and return the adjusted position in the line. /* Print an option value and return the adjusted position in the line.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment