summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Kotler <fbkotler@users.sourceforge.net>2003-08-27 11:33:56 +0000
committerFrank Kotler <fbkotler@users.sourceforge.net>2003-08-27 11:33:56 +0000
commitd0ed6fd30dad0591f735f576ecf473e5243ed766 (patch)
tree3ec94f899a9b5868a79e339c1c71e22034e99ee2
parent1d392362ef3d158b14f251321e7caf815ce35d0f (diff)
downloadnasm-d0ed6fd30dad0591f735f576ecf473e5243ed766.tar.gz
Alexei's patch to allow "-I" paths to be searched for "incbin"ed files
-rw-r--r--AUTHORS8
-rw-r--r--CHANGES2
-rw-r--r--assemble.c48
-rw-r--r--doc/nasmdoc.src7
-rw-r--r--preproc.c66
-rw-r--r--preproc.h1
6 files changed, 124 insertions, 8 deletions
diff --git a/AUTHORS b/AUTHORS
index 967fafa5..a82f85e0 100644
--- a/AUTHORS
+++ b/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
diff --git a/CHANGES b/CHANGES
index 39a79c60..35576179 100644
--- a/CHANGES
+++ b/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
diff --git a/assemble.c b/assemble.c
index 6da584a5..160e6713 100644
--- a/assemble.c
+++ b/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'",
diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src
index 795cf53f..60bd694b 100644
--- a/doc/nasmdoc.src
+++ b/doc/nasmdoc.src
@@ -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
diff --git a/preproc.c b/preproc.c
index 2492df68..89749453 100644
--- a/preproc.c
+++ b/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)
diff --git a/preproc.h b/preproc.h
index 0b7df114..e196d38e 100644
--- a/preproc.h
+++ b/preproc.h
@@ -10,6 +10,7 @@
#define NASM_PREPROC_H
void pp_include_path (char *);
+char** pp_get_include_path_ptr (char **pPrevPath);
void pp_pre_include (char *);
void pp_pre_define (char *);
void pp_pre_undefine (char *);