#define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
#endif
-/* The original file name, before changing "-" to "stdin". */
-static const char *orig_filename;
+/* The input filename as understood by CPP, where "" represents stdin. */
+static const char *cpp_filename;
/* We may keep statistics about how long which files took to compile. */
static int header_time, body_time;
struct cpp_callbacks *cb;
struct c_fileinfo *toplevel;
- orig_filename = filename;
-
/* Set up filename timing. Must happen before cpp_start_read. */
file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
0,
cb->undef = cb_undef;
}
+
if (filename == 0 || !strcmp (filename, "-"))
- filename = "stdin";
+ filename = "stdin", cpp_filename = "";
+ else
+ cpp_filename = filename;
/* Start it at 0. */
lineno = 0;
int
yyparse()
{
- if (! cpp_start_read (parse_in, orig_filename))
+ if (! cpp_start_read (parse_in, cpp_filename))
return 1; /* cpplib has emitted an error. */
return yyparse_1();
create one with a non-NULL value (regardless of success in opening
the file). If the file doesn't exist or is inaccessible, this
entry is flagged so we don't attempt to open it again in the
- future. If the file isn't open, open it.
+ future. If the file isn't open, open it. The empty string is
+ interpreted as stdin.
Returns an include_file structure with an open file descriptor on
success, or NULL on failure. */
/* Push an input buffer and load it up with the contents of FNAME.
- If FNAME is "" or NULL, read standard input. */
+ If FNAME is "", read standard input. */
int
_cpp_read_file (pfile, fname)
cpp_reader *pfile;
const char *fname;
{
- struct include_file *f;
-
- if (fname == NULL)
- fname = "";
-
- f = open_file (pfile, fname);
+ struct include_file *f = open_file (pfile, fname);
if (f == NULL)
{
}
/* This is called after options have been processed. Setup for
- processing input from the file named FNAME. (Use standard input if
- FNAME == NULL.) Return 1 on success, 0 on failure. */
-
+ processing input from the file named FNAME, or stdin if it is the
+ empty string. Return 1 on success, 0 on failure. */
int
cpp_start_read (pfile, fname)
cpp_reader *pfile;
fprintf (stderr, _("End of search list.\n"));
}
- if (CPP_OPTION (pfile, in_fname) == NULL
- || *CPP_OPTION (pfile, in_fname) == 0)
- {
- CPP_OPTION (pfile, in_fname) = fname;
- if (CPP_OPTION (pfile, in_fname) == NULL)
- CPP_OPTION (pfile, in_fname) = "";
- }
- if (CPP_OPTION (pfile, out_fname) == NULL)
- CPP_OPTION (pfile, out_fname) = "";
-
if (CPP_OPTION (pfile, print_deps))
/* Set the default target (if there is none already). */
- deps_add_default_target (pfile->deps, CPP_OPTION (pfile, in_fname));
+ deps_add_default_target (pfile->deps, fname);
/* Open the main input file. This must be done early, so we have a
buffer to stand on. */
/* This is the list of all command line options, with the leading
"-" removed. It must be sorted in ASCII collating order. */
#define COMMAND_LINE_OPTIONS \
- DEF_OPT("", 0, OPT_stdin_stdout) \
DEF_OPT("$", 0, OPT_dollar) \
DEF_OPT("+", 0, OPT_plus) \
DEF_OPT("-help", 0, OPT__help) \
int i = 0;
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
- if (argv[i][0] != '-')
+ /* Interpret "-" or a non-option as a file name. */
+ if (argv[i][0] != '-' || argv[i][1] == '\0')
{
- if (CPP_OPTION (pfile, out_fname) != NULL)
- cpp_fatal (pfile, "Too many arguments. Type %s --help for usage info",
- progname);
- else if (CPP_OPTION (pfile, in_fname) != NULL)
+ if (CPP_OPTION (pfile, in_fname) == NULL)
+ CPP_OPTION (pfile, in_fname) = argv[i];
+ else if (CPP_OPTION (pfile, out_fname) == NULL)
CPP_OPTION (pfile, out_fname) = argv[i];
else
- CPP_OPTION (pfile, in_fname) = argv[i];
+ cpp_fatal (pfile, "Too many filenames. Type %s --help for usage info",
+ progname);
}
else
{
CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
break;
case OPT_o:
- if (CPP_OPTION (pfile, out_fname) != NULL)
+ if (CPP_OPTION (pfile, out_fname) == NULL)
+ CPP_OPTION (pfile, out_fname) = arg;
+ else
{
cpp_fatal (pfile, "Output filename specified twice");
return argc;
}
- CPP_OPTION (pfile, out_fname) = arg;
- if (!strcmp (CPP_OPTION (pfile, out_fname), "-"))
- CPP_OPTION (pfile, out_fname) = "";
- break;
- case OPT_stdin_stdout:
- /* JF handle '-' as file name meaning stdin or stdout. */
- if (CPP_OPTION (pfile, in_fname) == NULL)
- CPP_OPTION (pfile, in_fname) = "";
- else if (CPP_OPTION (pfile, out_fname) == NULL)
- CPP_OPTION (pfile, out_fname) = "";
break;
case OPT_d:
/* Args to -d specify what parts of macros to dump.
cpp_post_options (pfile)
cpp_reader *pfile;
{
+ /* Canonicalize in_fname and out_fname. We guarantee they are not
+ NULL, and that the empty string represents stdin / stdout. */
+ if (CPP_OPTION (pfile, in_fname) == NULL
+ || !strcmp (CPP_OPTION (pfile, in_fname), "-"))
+ CPP_OPTION (pfile, in_fname) = "";
+
+ if (CPP_OPTION (pfile, out_fname) == NULL
+ || !strcmp (CPP_OPTION (pfile, out_fname), "-"))
+ CPP_OPTION (pfile, out_fname) = "";
+
/* -Wtraditional is not useful in C++ mode. */
if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0;