mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-12-15 09:09:58 +08:00
Alexei's patch to allow "-I" paths to be searched for "incbin"ed files
This commit is contained in:
parent
1d392362ef
commit
d0ed6fd30d
8
AUTHORS
8
AUTHORS
@ -109,3 +109,11 @@ N: Michael K. Ter Louw
|
||||
E: mterlo1 "at" uic "dot" edu
|
||||
D: Multisection support for "-f bin"
|
||||
|
||||
N: Martin Wawro
|
||||
E: FIXME
|
||||
D: stabs debug support for "-f elf"
|
||||
|
||||
N: Alexei Frounze
|
||||
E: alexfru@users.sourceforge.net
|
||||
D: "-I" paths searched for "incbined" files
|
||||
D: bugswatting
|
||||
|
2
CHANGES
2
CHANGES
@ -1,5 +1,7 @@
|
||||
0.98.37
|
||||
-------
|
||||
* Paths given in "-I" switch searched for "incbin"ed as
|
||||
well as "%include"ed files.
|
||||
* Added stabs debugging for the ELF output format, patch from
|
||||
Martin Wawro.
|
||||
* Fix output/outbin.c to allow origin > 80000000h
|
||||
|
48
assemble.c
48
assemble.c
@ -74,6 +74,7 @@
|
||||
#include "nasmlib.h"
|
||||
#include "assemble.h"
|
||||
#include "insns.h"
|
||||
#include "preproc.h"
|
||||
|
||||
extern struct itemplate *nasm_instructions[];
|
||||
|
||||
@ -267,6 +268,8 @@ long assemble (long segment, long offset, int bits, unsigned long cp,
|
||||
static char fname[FILENAME_MAX];
|
||||
FILE * fp;
|
||||
long len;
|
||||
char *prefix = "", *combine;
|
||||
char** pPrevPath = NULL;
|
||||
|
||||
len = FILENAME_MAX-1;
|
||||
if (len > instruction->eops->stringlen)
|
||||
@ -274,7 +277,26 @@ long assemble (long segment, long offset, int bits, unsigned long cp,
|
||||
strncpy (fname, instruction->eops->stringval, len);
|
||||
fname[len] = '\0';
|
||||
|
||||
if ( (fp = fopen(fname, "rb")) == NULL)
|
||||
while (1) /* added by alexfru: 'incbin' uses include paths */
|
||||
{
|
||||
combine = nasm_malloc(strlen(prefix) + len + 1);
|
||||
strcpy(combine, prefix);
|
||||
strcat(combine, fname);
|
||||
|
||||
if ( (fp = fopen(combine, "rb")) != NULL)
|
||||
{
|
||||
nasm_free(combine);
|
||||
break;
|
||||
}
|
||||
|
||||
nasm_free(combine);
|
||||
pPrevPath = pp_get_include_path_ptr (pPrevPath);
|
||||
if (pPrevPath == NULL)
|
||||
break;
|
||||
prefix = *pPrevPath;
|
||||
}
|
||||
|
||||
if (fp == NULL)
|
||||
error (ERR_NONFATAL, "`incbin': unable to open file `%s'", fname);
|
||||
else if (fseek(fp, 0L, SEEK_END) < 0)
|
||||
error (ERR_NONFATAL, "`incbin': unable to seek on file `%s'",
|
||||
@ -489,13 +511,35 @@ long insn_size (long segment, long offset, int bits, unsigned long cp,
|
||||
char fname[FILENAME_MAX];
|
||||
FILE * fp;
|
||||
long len;
|
||||
char *prefix = "", *combine;
|
||||
char** pPrevPath = NULL;
|
||||
|
||||
len = FILENAME_MAX-1;
|
||||
if (len > instruction->eops->stringlen)
|
||||
len = instruction->eops->stringlen;
|
||||
strncpy (fname, instruction->eops->stringval, len);
|
||||
fname[len] = '\0';
|
||||
if ( (fp = fopen(fname, "rb")) == NULL )
|
||||
|
||||
while (1) /* added by alexfru: 'incbin' uses include paths */
|
||||
{
|
||||
combine = nasm_malloc(strlen(prefix) + len + 1);
|
||||
strcpy(combine, prefix);
|
||||
strcat(combine, fname);
|
||||
|
||||
if ( (fp = fopen(combine, "rb")) != NULL)
|
||||
{
|
||||
nasm_free(combine);
|
||||
break;
|
||||
}
|
||||
|
||||
nasm_free(combine);
|
||||
pPrevPath = pp_get_include_path_ptr (pPrevPath);
|
||||
if (pPrevPath == NULL)
|
||||
break;
|
||||
prefix = *pPrevPath;
|
||||
}
|
||||
|
||||
if (fp == NULL)
|
||||
error (ERR_NONFATAL, "`incbin': unable to open file `%s'", fname);
|
||||
else if (fseek(fp, 0L, SEEK_END) < 0)
|
||||
error (ERR_NONFATAL, "`incbin': unable to seek on file `%s'",
|
||||
|
@ -599,8 +599,9 @@ See also the \c{-E} option, \k{opt-E}.
|
||||
|
||||
\S{opt-i} The \i\c{-i}\I\c{-I} Option: Include File Search Directories
|
||||
|
||||
When NASM sees the \i\c{%include} directive in a source file (see
|
||||
\k{include}), it will search for the given file not only in the
|
||||
When NASM sees the \i\c{%include} or \i\c{incbin} directive in
|
||||
a source file (see \k{include} or \k{incbin}),
|
||||
it will search for the given file not only in the
|
||||
current directory, but also in any directories specified on the
|
||||
command line by the use of the \c{-i} option. Therefore you can
|
||||
include files from a \i{macro library}, for example, by typing
|
||||
@ -621,8 +622,6 @@ Under Unix, a trailing forward slash is similarly necessary.
|
||||
by noting that the option \c{-ifoo} will cause \c{%include "bar.i"}
|
||||
to search for the file \c{foobar.i}...)
|
||||
|
||||
\#FIXME - the above is not true - see the "backslash()" function
|
||||
|
||||
If you want to define a \e{standard} \i{include search path},
|
||||
similar to \c{/usr/include} on Unix systems, you should place one or
|
||||
more \c{-i} directives in the \c{NASMENV} environment variable (see
|
||||
|
66
preproc.c
66
preproc.c
@ -4358,12 +4358,74 @@ void
|
||||
pp_include_path(char *path)
|
||||
{
|
||||
IncPath *i;
|
||||
|
||||
/* by alexfru: order of path inclusion fixed (was reverse order) */
|
||||
i = nasm_malloc(sizeof(IncPath));
|
||||
i->path = nasm_strdup(path);
|
||||
i->next = ipath;
|
||||
i->next = NULL;
|
||||
|
||||
if (ipath != NULL)
|
||||
{
|
||||
IncPath *j = ipath;
|
||||
while (j->next != NULL)
|
||||
j = j->next;
|
||||
j->next = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
ipath = i;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* added by alexfru:
|
||||
*
|
||||
* This function is used to "export" the include paths, e.g.
|
||||
* the paths specified in the '-I' command switch.
|
||||
* The need for such exporting is due to the 'incbin' directive,
|
||||
* which includes raw binary files (unlike '%include', which
|
||||
* includes text source files). It would be real nice to be
|
||||
* able to specify paths to search for incbin'ned files also.
|
||||
* So, this is a simple workaround.
|
||||
*
|
||||
* The function use is simple:
|
||||
*
|
||||
* The 1st call (with NULL argument) returns a pointer to the 1st path
|
||||
* (char** type) or NULL if none include paths available.
|
||||
*
|
||||
* All subsequent calls take as argument the value returned by this
|
||||
* function last. The return value is either the next path
|
||||
* (char** type) or NULL if the end of the paths list is reached.
|
||||
*
|
||||
* It is maybe not the best way to do things, but I didn't want
|
||||
* to export too much, just one or two functions and no types or
|
||||
* variables exported.
|
||||
*
|
||||
* Can't say I like the current situation with e.g. this path list either,
|
||||
* it seems to be never deallocated after creation...
|
||||
*/
|
||||
char**
|
||||
pp_get_include_path_ptr (char **pPrevPath)
|
||||
{
|
||||
/* This macro returns offset of a member of a structure */
|
||||
#define GetMemberOffset(StructType,MemberName)\
|
||||
((size_t)&((StructType*)0)->MemberName)
|
||||
IncPath *i;
|
||||
|
||||
if (pPrevPath == NULL)
|
||||
{
|
||||
if(ipath != NULL)
|
||||
return &ipath->path;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
i = (IncPath*) ((char*)pPrevPath - GetMemberOffset(IncPath,path));
|
||||
i = i->next;
|
||||
if (i != NULL)
|
||||
return &i->path;
|
||||
else
|
||||
return NULL;
|
||||
#undef GetMemberOffset
|
||||
}
|
||||
|
||||
void
|
||||
pp_pre_include(char *fname)
|
||||
|
Loading…
Reference in New Issue
Block a user