diff options
author | Keith Kanios <keith@kanios.net> | 2011-06-05 04:11:01 -0500 |
---|---|---|
committer | Keith Kanios <keith@kanios.net> | 2011-06-05 04:11:01 -0500 |
commit | 622a7e2f1dc7c53e5fdc73ba6a6bf59808ef701c (patch) | |
tree | 789dfbedb8b41a7c60b5e81602a79d734b883ead | |
parent | 20306b2b8ccff6eb9c175086d4d8f430edfc0463 (diff) | |
download | nasm-path.tar.gz |
Add __PATH__ supportpath
-rw-r--r-- | compiler.h | 39 | ||||
-rw-r--r-- | nasmlib.c | 21 | ||||
-rw-r--r-- | nasmlib.h | 2 | ||||
-rw-r--r-- | preproc.c | 20 | ||||
-rw-r--r-- | standard.mac | 3 |
5 files changed, 82 insertions, 3 deletions
@@ -183,4 +183,43 @@ char *strsep(char **, const char *); # define no_return void #endif +/* + * Detect DOS Host/Target + */ +#ifndef __DOS__ +# ifdef DOS +# define __DOS__ +# endif +# ifdef MSDOS +# define __DOS__ +# endif +# ifdef __MSDOS__ +# define __DOS__ +# endif +# ifdef _MSDOS +# define __DOS__ +# endif +#endif + +/* + * Detect Windows Host/Target + */ +#ifndef __WINDOWS__ +# ifdef _WIN32 +# define __WINDOWS__ +# endif +# ifdef __WIN32__ +# define __WINDOWS__ +# endif +# ifdef _WIN64 +# define __WINDOWS__ +# endif +# ifdef _MSC_VER +# define __WINDOWS__ +# endif +# ifdef __TOS_WIN__ +# define __WINDOWS__ +# endif +#endif + #endif /* NASM_COMPILER_H */ @@ -649,6 +649,27 @@ int src_get(int32_t *xline, char **xname) return 0; } +int src_get_path(char **xname) +{ + const char *path = NULL; + + if (!file_name) { + return -1; + } + + path = strrchr(file_name, '/'); +#if defined(__DOS__) || defined(__WINDOWS__) + if (!path) + path = strrchr(file_name, '\\'); +#endif + + if (path != NULL) { + *xname = nasm_strndup(file_name, (path - file_name + 1)); + } + + return 0; +} + char *nasm_strcat(const char *one, const char *two) { char *rslt; @@ -386,6 +386,8 @@ int32_t src_get_linnum(void); */ int src_get(int32_t *xline, char **xname); +int src_get_path(char **xname); + char *nasm_strcat(const char *one, const char *two); char *nasm_skip_spaces(const char *p); @@ -4403,13 +4403,29 @@ again: * expansion back on the to-do stack. */ if (!m->expansion) { + if (!strcmp("__PATH__", m->name)) { + char *path = NULL; + src_get_path(&path); + if (path != NULL) { + tline->text = nasm_quote(path, strlen(path)); + nasm_free(path); + } else { + tline->text = nasm_quote("", 0); + } + tline->type = TOK_STRING; + continue; + } if (!strcmp("__FILE__", m->name)) { int32_t num = 0; char *file = NULL; src_get(&num, &file); - tline->text = nasm_quote(file, strlen(file)); + if (file != NULL) { + tline->text = nasm_quote(file, strlen(file)); + nasm_free(file); + } else { + tline->text = nasm_quote("", 0); + } tline->type = TOK_STRING; - nasm_free(file); continue; } if (!strcmp("__LINE__", m->name)) { diff --git a/standard.mac b/standard.mac index b2dff8d6..0c27fe2b 100644 --- a/standard.mac +++ b/standard.mac @@ -50,8 +50,9 @@ ; here, not all of them are: the user-level form of a format-specific ; directive should be defined in the module for that directive. -; These three need to be defined, though the actual definitions will +; These need to be defined, though the actual definitions will ; be constantly updated during preprocessing. +%define __PATH__ %define __FILE__ %define __LINE__ %define __BITS__ |