static constcharparam_head preproc_options;
static int
-do_preproc_only(FILE *in)
+do_preproc_only()
{
yasm_linemap *linemap;
char *preproc_buf = yasm_xmalloc(PREPROC_BUF_SIZE);
/* determine the object filename if not specified, but we need a
file name for the makefile rule */
if (generate_make_dependencies && !obj_filename) {
- if (in == stdin)
+ if (in_filename == NULL)
/* Default to yasm.out if no obj filename specified */
obj_filename = yasm__xstrdup("yasm.out");
else {
}
/* Pre-process until done */
- cur_preproc = yasm_preproc_create(cur_preproc_module, in, in_filename,
+ cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename,
linemap, errwarns);
apply_preproc_builtins();
fwrite(preproc_buf, got, 1, out);
}
- if (in != stdin)
- fclose(in);
-
if (out != stdout)
fclose(out);
}
static int
-do_assemble(FILE *in)
+do_assemble()
{
yasm_object *object;
const char *base_filename;
/* determine the object filename if not specified */
if (!obj_filename) {
- if (in == stdin)
+ if (in_filename == NULL)
/* Default to yasm.out if no obj filename specified */
obj_filename = yasm__xstrdup("yasm.out");
else {
yasm_xfree(estr);
yasm_xfree(xrefstr);
- if (in != stdin)
- fclose(in);
cleanup(object);
return EXIT_FAILURE;
}
print_error(_("%s: `%s' is not a valid %s for %s `%s'"), _("FATAL"),
cur_preproc_module->keyword, _("preprocessor"),
_("parser"), cur_parser_module->keyword);
- if (in != stdin)
- fclose(in);
cleanup(object);
return EXIT_FAILURE;
}
- cur_preproc = yasm_preproc_create(cur_preproc_module, in, in_filename,
+ cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename,
linemap, errwarns);
apply_preproc_builtins();
cur_parser_module->do_parse(object, cur_preproc, list_filename != NULL,
linemap, errwarns);
- /* Close input file */
- if (in != stdin)
- fclose(in);
-
check_errors(errwarns, object, linemap);
/* Finalize parse */
if (!in_filename) {
print_error(_("No input files specified"));
return EXIT_FAILURE;
- } else if (strcmp(in_filename, "-") != 0) {
- /* Open the input file (if not standard input) */
- in = fopen(in_filename, "rt");
- if (!in) {
- print_error(_("%s: could not open file `%s'"), _("FATAL"),
- in_filename);
- yasm_xfree(in_filename);
- if (obj_filename)
- yasm_xfree(obj_filename);
- return EXIT_FAILURE;
- }
- } else {
- /* Filename was "-", read stdin */
- in = stdin;
}
/* handle preproc-only case here */
* Module-level implementation of yasm_preproc_create().
* Call yasm_preproc_create() instead of calling this function.
*
- * \param f initial starting file
- * \param in_filename initial starting filename
+ * \param in_filename initial starting filename, or NULL to read from
+ * stdin
* \param lm line mapping repository
* \param errwarns error/warnning set.
* \return New preprocessor.
*
* \note Any preprocessor errors and warnings are stored into errwarns.
*/
- /*@only@*/ yasm_preproc * (*create) (FILE *f, const char *in_filename,
+ /*@only@*/ yasm_preproc * (*create) (const char *in_filename,
yasm_linemap *lm,
yasm_errwarns *errwarns);
* The preprocessor needs access to the object format module to find out
* any output format specific macros.
* \param module preprocessor module
- * \param f initial starting file
- * \param in_filename initial starting file filename
+ * \param in_filename initial starting filename, or NULL to read from stdin
* \param lm line mapping repository
* \param errwarns error/warning set
* \return New preprocessor.
* \note Errors/warnings are stored into errwarns.
*/
/*@only@*/ yasm_preproc *yasm_preproc_create
- (yasm_preproc_module *module, FILE *f, const char *in_filename,
+ (yasm_preproc_module *module, const char *in_filename,
yasm_linemap *lm, yasm_errwarns *errwarns);
/** Cleans up any allocated preproc memory.
/* Inline macro implementations for preproc functions */
-#define yasm_preproc_create(module, f, in_filename, lm, ews) \
- module->create(f, in_filename, lm, ews)
+#define yasm_preproc_create(module, in_filename, lm, ews) \
+ module->create(in_filename, lm, ews)
#define yasm_preproc_destroy(preproc) \
((yasm_preproc_base *)preproc)->module->destroy(preproc)
/* TODO: Use autoconf to get the limit on the command line length. */
#define CMDLINE_SIZE 32770
-extern int isatty(int);
-
/* Pre-declare the preprocessor module object. */
yasm_preproc_module yasm_cpp_LTX_preproc;
Interface functions.
*******************************************************************************/
static yasm_preproc *
-cpp_preproc_create(FILE *f, const char *in, yasm_linemap *lm,
- yasm_errwarns *errwarns)
+cpp_preproc_create(const char *in, yasm_linemap *lm, yasm_errwarns *errwarns)
{
yasm_preproc_cpp *pp = yasm_xmalloc(sizeof(yasm_preproc_cpp));
TAILQ_INIT(&pp->cpp_args);
- /* We can't handle reading from a tty yet. */
- if (isatty(fileno(f)) > 0)
- yasm__fatal("incapable of reading from a tty");
-
- /*
- We don't need the FILE* given by yasm since we will simply pass the
- filename to cpp, but closing it causes a segfault.
-
- TODO: Change the preprocessor interface, so no FILE* is given.
- */
-
return (yasm_preproc *)pp;
}
}
static yasm_preproc *
-nasm_preproc_create(FILE *f, const char *in_filename, yasm_linemap *lm,
+nasm_preproc_create(const char *in_filename, yasm_linemap *lm,
yasm_errwarns *errwarns)
{
+ FILE *f;
yasm_preproc_nasm *preproc_nasm = yasm_xmalloc(sizeof(yasm_preproc_nasm));
preproc_nasm->preproc.module = &yasm_nasm_LTX_preproc;
+ if (strcmp(in_filename, "-") != 0) {
+ f = fopen(in_filename, "r");
+ if (!f)
+ yasm__fatal("Could not open input file");
+ }
+ else
+ f = stdin;
+
preproc_nasm->in = f;
cur_lm = lm;
cur_errwarns = errwarns;
int isatty(int);
static yasm_preproc *
-raw_preproc_create(FILE *f, const char *in_filename, yasm_linemap *lm,
+raw_preproc_create(const char *in_filename, yasm_linemap *lm,
yasm_errwarns *errwarns)
{
+ FILE *f;
yasm_preproc_raw *preproc_raw = yasm_xmalloc(sizeof(yasm_preproc_raw));
+ if (strcmp(in_filename, "-") != 0) {
+ f = fopen(in_filename, "r");
+ if (!f)
+ yasm__fatal("Could not open input file");
+ }
+ else
+ f = stdin;
+
preproc_raw->preproc.module = &yasm_raw_LTX_preproc;
preproc_raw->in = f;
preproc_raw->cur_lm = lm;
expand_token_list(struct source_head *paramexp, struct source_head *to_head, source **to_tail);
static yasm_preproc *
-yapp_preproc_create(FILE *f, const char *in_filename, yasm_linemap *lm,
+yapp_preproc_create(const char *in_filename, yasm_linemap *lm,
yasm_errwarns *errwarns)
{
+ FILE *f;
yasm_preproc_yapp *preproc_yapp = yasm_xmalloc(sizeof(yasm_preproc_yapp));
+ if (strcmp(in_filename, "-") != 0) {
+ f = fopen(in_filename, "r");
+ if (!f)
+ yasm__fatal("Could not open input file");
+ }
+ else
+ f = stdin;
+
preproc_yapp->preproc.module = &yasm_yapp_LTX_preproc;
yapp_preproc_linemap = lm;
return 0;
append_token(token, to_head, to_tail);
token = yapp_preproc_lex();
- }
+ }
return '\n';
}