modified: nasm.1 to add newer command line options

modified:   nasm.c to fully parse command line before redirecting stderr.
This commit is contained in:
Charles Crayne 2007-09-30 22:15:36 -07:00
parent b001e89859
commit fcce07f171
2 changed files with 112 additions and 88 deletions

178
nasm.1
View File

@ -4,23 +4,29 @@ nasm \- the Netwide Assembler, a portable 80x86 assembler
.SH SYNOPSIS .SH SYNOPSIS
.B nasm .B nasm
[ [
.B \-@
response file
] [
.B \-f .B \-f
format format
] [ ] [
.B \-o .B \-o
outfile outfile
] [ ] [
.B \-l
listfile
] [
.IR options ... .IR options ...
] infile ] filename
.br .br
.B nasm \-h .B nasm \-h
.br .br
.B nasm \-r .B nasm \-v
.SH DESCRIPTION .SH DESCRIPTION
The The
.B nasm .B nasm
command assembles the file command assembles the file
.I infile .I filename
and directs output to the file and directs output to the file
.I outfile .I outfile
if specified. If if specified. If
@ -33,11 +39,12 @@ extensions for a raw binary file. Failing that, the output file name
will be `nasm.out'. will be `nasm.out'.
.SS OPTIONS .SS OPTIONS
.TP .TP
.B \-h .BI \-@ " filename"
Causes Causes
.B nasm .B nasm
to exit immediately, after giving a summary of its invocation to process options from
options, and listing all its supported output file formats. .I filename
as if they were included on the command line.
.TP .TP
.B \-a .B \-a
Causes Causes
@ -45,6 +52,14 @@ Causes
to assemble the given input file without first applying the macro to assemble the given input file without first applying the macro
preprocessor. preprocessor.
.TP .TP
.BI \-D " macro[=value]"
Pre-defines a single-line macro.
.TP
.BI \-d " macro[=value]"
Same as the
.B \-D
option.
.TP
.B \-e .B \-e
Causes Causes
.B nasm .B nasm
@ -53,70 +68,27 @@ to preprocess the given input file, and write the output to
(or the specified output file name), and not actually assemble (or the specified output file name), and not actually assemble
anything. anything.
.TP .TP
.B \-M
Causes
.B nasm
to output Makefile-style dependencies to stdout; normal output is
suppressed.
.TP
.BI \-E " filename"
Causes
.B nasm
to redirect error messages to
.IR filename .
This option exists to support operating systems on which stderr is not
easily redirected.
.TP
.BI \-r
Causes
.B nasm
to exit immediately, after displaying its version number.
.I (obsolete)
.TP
.BI \-v
Causes
.B nasm
to exit immediately, after displaying its version number.
.TP
.BI \-f " format" .BI \-f " format"
Specifies the output file format. Formats include Specifies the output file format. To see a list of valid output
.IR bin , formats, use the
to produce flat-form binary files, and .B -hf
.I aout option.
and
.I elf
to produce Linux a.out and ELF object files, respectively.
.TP .TP
.BI \-o " outfile" .B \-g
Specifies a precise name for the output file, overriding
.BR nasm 's
default means of determining it.
.TP
.BI \-l " listfile"
Causes an assembly listing to be directed to the given file, in
which the original source is displayed on the right hand side (plus
the source for included files and the expansions of multi-line
macros) and the generated code is shown in hex on the left.
.TP
.B \-s
Causes Causes
.B nasm .B nasm
to send its error messages and/or help text to to generate debug information in selected format
.I stdout
instead of
.IR stderr .
.TP .TP
.BI \-w [+-]foo .B \-h
Causes Causes
.B nasm .B nasm
to enable or disable certain classes of warning messages, for to exit immediately, after giving a summary of its invocation
example options.
.B \-w+orphan-labels .TP
or .B \-hf
.B \-w-macro-params Same as
to, respectively, enable warnings about labels alone on lines or .B -h
disable warnings about incorrect numbers of parameters in macro , but also lists all valid output formats.
calls.
.TP .TP
.BI \-I " directory" .BI \-I " directory"
Adds a directory to the search path for include files. The directory Adds a directory to the search path for include files. The directory
@ -128,6 +100,26 @@ Same as the
.B \-I .B \-I
option. option.
.TP .TP
.BI \-l " listfile"
Causes an assembly listing to be directed to the given file, in
which the original source is displayed on the right hand side (plus
the source for included files and the expansions of multi-line
macros) and the generated code is shown in hex on the left.
.TP
.B \-M
Causes
.B nasm
to output Makefile-style dependencies to stdout; normal output is
suppressed.
.TP
.BI \-O " number"
optimize branch offsets (-O0 disables, default).
.TP
.BI \-o " outfile"
Specifies a precise name for the output file, overriding
.BR nasm 's
default means of determining it.
.TP
.BI \-P " file" .BI \-P " file"
Specifies a file to be pre-included, before the main source file Specifies a file to be pre-included, before the main source file
starts to be processed. starts to be processed.
@ -137,13 +129,24 @@ Same as the
.B \-P .B \-P
option. option.
.TP .TP
.BI \-D " macro[=value]" .BI \-r
Pre-defines a single-line macro. Causes
.B nasm
to exit immediately, after displaying its version number.
.I (obsolete)
.TP .TP
.BI \-d " macro[=value]" .B \-s
Same as the Causes
.B \-D .B nasm
option. to send its error messages and/or help text to
.I stdout
instead of
.IR stderr .
.TP
.B \-t
Causes
.B nasm
to assemble in SciTech TASM compatible mode
.TP .TP
.BI \-U " macro" .BI \-U " macro"
Undefines a single-line macro. Undefines a single-line macro.
@ -152,6 +155,31 @@ Undefines a single-line macro.
Same as the Same as the
.B \-U .B \-U
option. option.
.TP
.BI \-v
Causes
.B nasm
to exit immediately, after displaying its version number.
.TP
.BI \-w [+-]foo
Causes
.B nasm
to enable or disable certain classes of warning messages, for
example
.B \-w+orphan-labels
or
.B \-w-macro-params
.TP
.BI \-X " format"
specifies error reporting format (gnu or vc).
.TP
.BI \-Z " filename"
Causes
.B nasm
to redirect error messages to
.IR filename .
This option exists to support operating systems on which stderr is not
easily redirected.
.PP .PP
.RE .RE
.SS SYNTAX .SS SYNTAX
@ -452,17 +480,7 @@ and
.IR %elifnctx .IR %elifnctx
are also supported. are also supported.
.SH BUGS .SH BUGS
There is a reported seg-fault on some (Linux) systems with some Please report bugs through the bug tracker function at http://nasm.sourceforge.org.
large source files. This appears to be very hard to reproduce. All
other
.I known
bugs have been fixed...
.SH RESTRICTIONS
There is no support for listing files, symbol maps, or debugging
object-file records. The advanced features of the ELF and Win32
object file formats are not supported, and there is no means for
warning the programmer against using an instruction beyond the
capability of the target processor.
.SH SEE ALSO .SH SEE ALSO
.BR as "(" 1 ")," .BR as "(" 1 "),"
.BR ld "(" 1 ")." .BR ld "(" 1 ")."

22
nasm.c
View File

@ -53,6 +53,7 @@ int globalrel = 0;
static char inname[FILENAME_MAX]; static char inname[FILENAME_MAX];
static char outname[FILENAME_MAX]; static char outname[FILENAME_MAX];
static char listname[FILENAME_MAX]; static char listname[FILENAME_MAX];
static char errname[FILENAME_MAX];
static int globallineno; /* for forward-reference tracking */ static int globallineno; /* for forward-reference tracking */
/* static int pass = 0; */ /* static int pass = 0; */
static struct ofmt *ofmt = NULL; static struct ofmt *ofmt = NULL;
@ -442,13 +443,7 @@ static int process_arg(char *p, char *q)
} else if (p[1] == 'l') { /* listing file */ } else if (p[1] == 'l') { /* listing file */
strcpy(listname, param); strcpy(listname, param);
} else if (p[1] == 'Z') { /* error messages file */ } else if (p[1] == 'Z') { /* error messages file */
error_file = fopen(param, "w"); strcpy(errname, param);
if (!error_file) {
error_file = stderr; /* Revert to default! */
report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
"cannot open file `%s' for error messages",
param);
}
} else if (p[1] == 'F') { /* specify debug format */ } else if (p[1] == 'F') { /* specify debug format */
ofmt->current_dfmt = dfmt_find(ofmt, param); ofmt->current_dfmt = dfmt_find(ofmt, param);
if (!ofmt->current_dfmt) { if (!ofmt->current_dfmt) {
@ -724,7 +719,7 @@ static void parse_cmdline(int argc, char **argv)
FILE *rfile; FILE *rfile;
char *envreal, *envcopy = NULL, *p, *arg; char *envreal, *envcopy = NULL, *p, *arg;
*inname = *outname = *listname = '\0'; *inname = *outname = *listname = *errname = '\0';
/* /*
* First, process the NASMENV environment variable. * First, process the NASMENV environment variable.
@ -785,6 +780,17 @@ static void parse_cmdline(int argc, char **argv)
if (!*inname) if (!*inname)
report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE, report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
"no input file specified"); "no input file specified");
else {
if (*errname) {
error_file = fopen(errname, "w");
if (!error_file) {
error_file = stderr; /* Revert to default! */
report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
"cannot open file `%s' for error messages",
errname);
}
}
}
} }
/* List of directives */ /* List of directives */