cppinit.c (cpp_handle_option): help_only is now part of the cpp_options structure.

* cppinit.c (cpp_handle_option): help_only is now part of the
        cpp_options structure.
        * cpplib.c (cpp_errors, cpp_get_options, cpp_get_callbacks,
        cpp_set_callbacks): New functions.
        * cpplib.h (cpp_callbacks): Break out as a named structure.
        (cpp_options): Move help_only here from cpp_reader.
        (CPP_FATAL_ERRORS): Update to use cpp_errors.
        (cpp_errors, cpp_get_options, cpp_get_callbacks,
        cpp_set_callbacks): New prototypes.
        * cppmain.c (main): Update for help_only.

From-SVN: r38971
This commit is contained in:
Neil Booth 2001-01-13 01:00:01 +00:00 committed by Neil Booth
parent 23de1fbfd0
commit 7e96d768fe
5 changed files with 83 additions and 19 deletions

View File

@ -1,3 +1,16 @@
2001-01-13 Neil Booth <neil@daikokuya.demon.co.uk>
* cppinit.c (cpp_handle_option): help_only is now part of the
cpp_options structure.
* cpplib.c (cpp_errors, cpp_get_options, cpp_get_callbacks,
cpp_set_callbacks): New functions.
* cpplib.h (cpp_callbacks): Break out as a named structure.
(cpp_options): Move help_only here from cpp_reader.
(CPP_FATAL_ERRORS): Update to use cpp_errors.
(cpp_errors, cpp_get_options, cpp_get_callbacks,
cpp_set_callbacks): New prototypes.
* cppmain.c (main): Update for help_only.
2001-01-13 Joseph S. Myers <jsm28@cam.ac.uk>
* Makefile.in (info, maintainer-clean, install-info, uninstall):

View File

@ -1290,18 +1290,18 @@ cpp_handle_option (pfile, argc, argv)
case OPT_h:
case OPT__help:
print_help ();
pfile->help_only = 1;
CPP_OPTION (pfile, help_only) = 1;
break;
case OPT_target__help:
/* Print if any target specific options. cpplib has none, but
make sure help_only gets set. */
pfile->help_only = 1;
CPP_OPTION (pfile, help_only) = 1;
break;
/* --version inhibits compilation, -version doesn't. -v means
verbose and -version. Historical reasons, don't ask. */
case OPT__version:
pfile->help_only = 1;
CPP_OPTION (pfile, help_only) = 1;
goto version;
case OPT_v:
CPP_OPTION (pfile, verbose) = 1;

View File

@ -1714,6 +1714,39 @@ handle_assertion (pfile, str, type)
run_directive (pfile, type, BUF_CL_OPTION, str, count);
}
/* The number of errors for a given reader. */
unsigned int
cpp_errors (pfile)
cpp_reader *pfile;
{
return pfile->errors;
}
/* The options structure. */
cpp_options *
cpp_get_options (pfile)
cpp_reader *pfile;
{
return &pfile->opts;
}
/* The callbacks structure. */
cpp_callbacks *
cpp_get_callbacks (pfile)
cpp_reader *pfile;
{
return &pfile->cb;
}
/* Copy the given callbacks structure to our own. */
void
cpp_set_callbacks (pfile, cb)
cpp_reader *pfile;
cpp_callbacks *cb;
{
pfile->cb = *cb;
}
/* Push a new buffer on the buffer stack. Returns the new buffer; it
doesn't fail. It does not generate a file change call back; that
is the responsibility of the caller. */

View File

@ -42,6 +42,7 @@ typedef struct cpp_pool cpp_pool;
typedef struct cpp_macro cpp_macro;
typedef struct cpp_lexer_pos cpp_lexer_pos;
typedef struct cpp_lookahead cpp_lookahead;
typedef struct cpp_callbacks cpp_callbacks;
struct directive; /* These are deliberately incomplete. */
struct answer;
@ -419,6 +420,11 @@ struct cpp_options
/* Treat C++ alternate operator names special. */
unsigned char operator_names;
/* True if --help, --version or --target-help appeared in the
options. Stand-alone CPP should then bail out after option
parsing; drivers might want to continue printing help. */
unsigned char help_only;
};
struct lexer_state
@ -485,6 +491,19 @@ struct cpp_file_change
unsigned char externc; /* Nonzero if wrapper needed. */
};
/* Call backs. */
struct cpp_callbacks
{
void (*file_change) PARAMS ((cpp_reader *, const cpp_file_change *));
void (*include) PARAMS ((cpp_reader *, const unsigned char *,
const cpp_token *));
void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*undef) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*poison) PARAMS ((cpp_reader *));
void (*ident) PARAMS ((cpp_reader *, const cpp_string *));
void (*def_pragma) PARAMS ((cpp_reader *));
};
/* A cpp_reader encapsulates the "state" of a pre-processor run.
Applying cpp_get_token repeatedly yields a stream of pre-processor
tokens. Usually, there is only one cpp_reader object active. */
@ -581,16 +600,7 @@ struct cpp_reader
struct pragma_entry *pragmas;
/* Call backs. */
struct {
void (*file_change) PARAMS ((cpp_reader *, const cpp_file_change *));
void (*include) PARAMS ((cpp_reader *, const unsigned char *,
const cpp_token *));
void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*undef) PARAMS ((cpp_reader *, cpp_hashnode *));
void (*poison) PARAMS ((cpp_reader *));
void (*ident) PARAMS ((cpp_reader *, const cpp_string *));
void (*def_pragma) PARAMS ((cpp_reader *));
} cb;
struct cpp_callbacks cb;
/* User visible options. */
struct cpp_options opts;
@ -608,15 +618,11 @@ struct cpp_reader
/* True if we are skipping a failed conditional group. */
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
/* True if we have seen a "fatal" error. */
#define CPP_FATAL_ERRORS(READER) ((READER)->errors >= CPP_FATAL_LIMIT)
#define CPP_FATAL_ERRORS(PFILE) (cpp_errors (PFILE) >= CPP_FATAL_LIMIT)
#define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
#define CPP_BUFFER(PFILE) ((PFILE)->buffer)
@ -699,6 +705,15 @@ struct cpp_hashnode
/* Call this first to get a handle to pass to other functions. */
extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
/* Call these to get pointers to the options and callback structures
for a given reader. These pointers are good until you call
cpp_finish on that reader. You can either edit the callbacks
through the pointer returned from cpp_get_callbacks, or set them
with cpp_set_callbacks. */
extern cpp_options *cpp_get_options PARAMS ((cpp_reader *));
extern cpp_callbacks *cpp_get_callbacks PARAMS ((cpp_reader *));
extern void cpp_set_callbacks PARAMS ((cpp_reader *, cpp_callbacks *));
/* Now call cpp_handle_option[s] to handle 1[or more] switches. The
return value is the number of arguments used. If
cpp_handle_options returns without using all arguments, it couldn't
@ -710,6 +725,9 @@ extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
extern void cpp_post_options PARAMS ((cpp_reader *));
/* Error count. */
extern unsigned int cpp_errors PARAMS ((cpp_reader *));
extern unsigned int cpp_token_len PARAMS ((const cpp_token *));
extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *,
const cpp_token *));

View File

@ -87,7 +87,7 @@ main (argc, argv)
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)
if (CPP_OPTION (pfile, help_only))
return (SUCCESS_EXIT_CODE);
/* Open the output now. We must do so even if no_output is on,