diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index ffb095cc..d7db7939 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -1,4 +1,4 @@ -/* $Id: yasm.c,v 1.4 2001/07/11 23:16:50 peter Exp $ +/* $Id: yasm.c,v 1.5 2001/08/18 22:15:12 peter Exp $ * Program entry point, command line parsing * * Copyright (C) 2001 Peter Johnson @@ -21,19 +21,39 @@ */ #include #include +#include extern int yydebug; +extern FILE *yyin; extern int yyparse(void); +char *filename = (char *)NULL; unsigned int line_number = 1; unsigned int mode_bits = 32; int -main (void) +main (int argc, char *argv[]) { + FILE *in; + yydebug = 1; + + if(argc==2) { + in = fopen(argv[1], "rt"); + if(!in) { + fprintf(stderr, "could not open file `%s'\n", argv[1]); + return EXIT_FAILURE; + } + filename = strdup(argv[1]); + yyin = in; + } else + filename = strdup(""); + yyparse(); + + if(filename) + free(filename); return EXIT_SUCCESS; } diff --git a/libyasm/bytecode.c b/libyasm/bytecode.c index 9af7ad0d..54c7c8e4 100644 --- a/libyasm/bytecode.c +++ b/libyasm/bytecode.c @@ -1,4 +1,4 @@ -/* $Id: bytecode.c,v 1.14 2001/07/25 00:33:10 peter Exp $ +/* $Id: bytecode.c,v 1.15 2001/08/18 22:15:12 peter Exp $ * Bytecode utility functions * * Copyright (C) 2001 Peter Johnson @@ -21,6 +21,7 @@ */ #include #include +#include #include "globals.h" #include "bytecode.h" #include "errwarn.h" @@ -232,7 +233,7 @@ BuildBC_Common (bytecode *bc) { bc->len = 0; - bc->filename = (char *)NULL; + bc->filename = strdup(filename); bc->lineno = line_number; bc->offset = 0; diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index b6c4e263..eaf6292a 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -1,4 +1,4 @@ -/* $Id: errwarn.c,v 1.17 2001/07/25 00:33:10 peter Exp $ +/* $Id: errwarn.c,v 1.18 2001/08/18 22:15:12 peter Exp $ * Error and warning reporting and related functions. * * Copyright (C) 2001 Peter Johnson @@ -72,7 +72,8 @@ static char *err_msgs[] = { "unexpected end of file in string", "expression syntax error", "floating-point constant encountered in `%s'", - "non-floating-point value encountered in `%s'" + "non-floating-point value encountered in `%s'", + "could not open file `%s'" }; /* Warning messages. Match up with warn_num enum in errwarn.h. */ @@ -275,7 +276,7 @@ void OutputError (void) { if(last_err_num != ERR_NONE) - fprintf(stderr, "filename:%u: %s\n", line_number, last_err); + fprintf(stderr, "%s:%u: %s\n", filename, line_number, last_err); last_err_num = ERR_NONE; } @@ -284,7 +285,8 @@ void OutputWarning (void) { if(last_warn_num != WARN_NONE) - fprintf(stderr, "filename:%u: warning: %s\n", line_number, last_warn); + fprintf(stderr, "%s:%u: warning: %s\n", filename, line_number, + last_warn); last_warn_num = WARN_NONE; } diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index 51bf7175..5c76a17b 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -1,4 +1,4 @@ -/* $Id: errwarn.h,v 1.11 2001/07/25 00:33:10 peter Exp $ +/* $Id: errwarn.h,v 1.12 2001/08/18 22:15:12 peter Exp $ * Error and warning reporting and related functions header file. * * Copyright (C) 2001 Peter Johnson @@ -50,7 +50,8 @@ typedef enum { ERR_STRING_EOF, ERR_EXPR_SYNTAX, ERR_DECLDATA_FLOAT, - ERR_DECLDATA_EXPR + ERR_DECLDATA_EXPR, + ERR_FILE_OPEN } err_num; /* Warning constants. Match up with warn_msgs in errwarn.c. */ diff --git a/libyasm/linemgr.h b/libyasm/linemgr.h index 30153d4f..e33463c8 100644 --- a/libyasm/linemgr.h +++ b/libyasm/linemgr.h @@ -1,4 +1,4 @@ -/* $Id: linemgr.h,v 1.3 2001/06/28 21:22:01 peter Exp $ +/* $Id: linemgr.h,v 1.4 2001/08/18 22:15:12 peter Exp $ * Globals header file * * Copyright (C) 2001 Peter Johnson @@ -22,6 +22,7 @@ #ifndef YASM_GLOBALS_H #define YASM_GLOBALS_H +extern char *filename; extern unsigned int line_number; extern unsigned int mode_bits; extern struct symrec_s *locallabel_base; diff --git a/src/bytecode.c b/src/bytecode.c index 9af7ad0d..54c7c8e4 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -1,4 +1,4 @@ -/* $Id: bytecode.c,v 1.14 2001/07/25 00:33:10 peter Exp $ +/* $Id: bytecode.c,v 1.15 2001/08/18 22:15:12 peter Exp $ * Bytecode utility functions * * Copyright (C) 2001 Peter Johnson @@ -21,6 +21,7 @@ */ #include #include +#include #include "globals.h" #include "bytecode.h" #include "errwarn.h" @@ -232,7 +233,7 @@ BuildBC_Common (bytecode *bc) { bc->len = 0; - bc->filename = (char *)NULL; + bc->filename = strdup(filename); bc->lineno = line_number; bc->offset = 0; diff --git a/src/errwarn.c b/src/errwarn.c index b6c4e263..eaf6292a 100644 --- a/src/errwarn.c +++ b/src/errwarn.c @@ -1,4 +1,4 @@ -/* $Id: errwarn.c,v 1.17 2001/07/25 00:33:10 peter Exp $ +/* $Id: errwarn.c,v 1.18 2001/08/18 22:15:12 peter Exp $ * Error and warning reporting and related functions. * * Copyright (C) 2001 Peter Johnson @@ -72,7 +72,8 @@ static char *err_msgs[] = { "unexpected end of file in string", "expression syntax error", "floating-point constant encountered in `%s'", - "non-floating-point value encountered in `%s'" + "non-floating-point value encountered in `%s'", + "could not open file `%s'" }; /* Warning messages. Match up with warn_num enum in errwarn.h. */ @@ -275,7 +276,7 @@ void OutputError (void) { if(last_err_num != ERR_NONE) - fprintf(stderr, "filename:%u: %s\n", line_number, last_err); + fprintf(stderr, "%s:%u: %s\n", filename, line_number, last_err); last_err_num = ERR_NONE; } @@ -284,7 +285,8 @@ void OutputWarning (void) { if(last_warn_num != WARN_NONE) - fprintf(stderr, "filename:%u: warning: %s\n", line_number, last_warn); + fprintf(stderr, "%s:%u: warning: %s\n", filename, line_number, + last_warn); last_warn_num = WARN_NONE; } diff --git a/src/errwarn.h b/src/errwarn.h index 51bf7175..5c76a17b 100644 --- a/src/errwarn.h +++ b/src/errwarn.h @@ -1,4 +1,4 @@ -/* $Id: errwarn.h,v 1.11 2001/07/25 00:33:10 peter Exp $ +/* $Id: errwarn.h,v 1.12 2001/08/18 22:15:12 peter Exp $ * Error and warning reporting and related functions header file. * * Copyright (C) 2001 Peter Johnson @@ -50,7 +50,8 @@ typedef enum { ERR_STRING_EOF, ERR_EXPR_SYNTAX, ERR_DECLDATA_FLOAT, - ERR_DECLDATA_EXPR + ERR_DECLDATA_EXPR, + ERR_FILE_OPEN } err_num; /* Warning constants. Match up with warn_msgs in errwarn.c. */ diff --git a/src/globals.h b/src/globals.h index a5fe788f..5083ebdc 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,4 +1,4 @@ -/* $Id: globals.h,v 1.3 2001/06/28 21:22:01 peter Exp $ +/* $Id: globals.h,v 1.4 2001/08/18 22:15:12 peter Exp $ * Globals header file * * Copyright (C) 2001 Peter Johnson @@ -22,6 +22,7 @@ #ifndef YASM_GLOBALS_H #define YASM_GLOBALS_H +extern char *filename; extern unsigned int line_number; extern unsigned int mode_bits; extern struct symrec_s *locallabel_base; diff --git a/src/linemgr.h b/src/linemgr.h index 30153d4f..e33463c8 100644 --- a/src/linemgr.h +++ b/src/linemgr.h @@ -1,4 +1,4 @@ -/* $Id: linemgr.h,v 1.3 2001/06/28 21:22:01 peter Exp $ +/* $Id: linemgr.h,v 1.4 2001/08/18 22:15:12 peter Exp $ * Globals header file * * Copyright (C) 2001 Peter Johnson @@ -22,6 +22,7 @@ #ifndef YASM_GLOBALS_H #define YASM_GLOBALS_H +extern char *filename; extern unsigned int line_number; extern unsigned int mode_bits; extern struct symrec_s *locallabel_base; diff --git a/src/main.c b/src/main.c index 28bee46f..68cbcaea 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.4 2001/07/11 23:16:50 peter Exp $ +/* $Id: main.c,v 1.5 2001/08/18 22:15:12 peter Exp $ * Program entry point, command line parsing * * Copyright (C) 2001 Peter Johnson @@ -21,19 +21,39 @@ */ #include #include +#include extern int yydebug; +extern FILE *yyin; extern int yyparse(void); +char *filename = (char *)NULL; unsigned int line_number = 1; unsigned int mode_bits = 32; int -main (void) +main (int argc, char *argv[]) { + FILE *in; + yydebug = 1; + + if(argc==2) { + in = fopen(argv[1], "rt"); + if(!in) { + fprintf(stderr, "could not open file `%s'\n", argv[1]); + return EXIT_FAILURE; + } + filename = strdup(argv[1]); + yyin = in; + } else + filename = strdup(""); + yyparse(); + + if(filename) + free(filename); return EXIT_SUCCESS; }