command line (no real command-line parsing yet).
svn path=/trunk/yasm/; revision=130
-/* $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
*/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
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("<UNKNOWN>");
+
yyparse();
+
+ if(filename)
+ free(filename);
return EXIT_SUCCESS;
}
-/* $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
*/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "globals.h"
#include "bytecode.h"
#include "errwarn.h"
{
bc->len = 0;
- bc->filename = (char *)NULL;
+ bc->filename = strdup(filename);
bc->lineno = line_number;
bc->offset = 0;
-/* $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
"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. */
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;
}
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;
}
-/* $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
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. */
-/* $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
#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;
-/* $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
*/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "globals.h"
#include "bytecode.h"
#include "errwarn.h"
{
bc->len = 0;
- bc->filename = (char *)NULL;
+ bc->filename = strdup(filename);
bc->lineno = line_number;
bc->offset = 0;
-/* $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
"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. */
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;
}
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;
}
-/* $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
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. */
-/* $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
#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;
-/* $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
#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;
-/* $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
*/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
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("<UNKNOWN>");
+
yyparse();
+
+ if(filename)
+ free(filename);
return EXIT_SUCCESS;
}