diff --git a/src/engine/Jamfile b/src/engine/Jamfile index 5aee1ffbc..426876c9d 100644 --- a/src/engine/Jamfile +++ b/src/engine/Jamfile @@ -117,7 +117,7 @@ Library libjam.a : hash.c headers.c hdrmacro.c lists.c make.c make1.c newstr.c option.c parse.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c - builtins.c ; + builtins.c pwd.c ; if $(BINDIR) { InstallBin $(BINDIR) : jam ; } @@ -138,7 +138,7 @@ ALLSOURCE = parse.h patchlevel.h pathmac.c pathunix.c pathvms.c regexp.c regexp.h rules.c rules.h scan.c scan.h search.c search.h subst.c timestamp.c timestamp.h variable.c variable.h yyacc strings.c modules.h - frames.h filesys.c strings.h + frames.h filesys.c strings.h pwd.c pwd.h INSTALL common.mk builds/win32-visualc.mk diff --git a/src/engine/builtins.c b/src/engine/builtins.c index 9c7cef8a4..38d58eea4 100644 --- a/src/engine/builtins.c +++ b/src/engine/builtins.c @@ -15,6 +15,7 @@ # include "frames.h" # include "hash.h" # include "strings.h" +# include "pwd.h" /* * builtins.c - builtin jam rules @@ -170,6 +171,12 @@ load_builtins() bind_builtin( "BACKTRACE" , builtin_backtrace, 0, args ); } + + { + char * args[] = { 0 }; + bind_builtin( "PWD" , + builtin_pwd, 0, args ); + } } /* @@ -569,6 +576,17 @@ LIST *builtin_caller_module( PARSE *parse, FRAME *frame ) } } +/* + * Return the current working directory. + * + * Usage: pwd = [ PWD ] ; + */ +LIST* +builtin_pwd( PARSE *parse, FRAME *frame ) +{ + return pwd(); +} + static void lol_build( LOL* lol, char** elements ) { LIST* l = L0; diff --git a/src/engine/builtins.h b/src/engine/builtins.h index 8d71fe815..8a57ad850 100644 --- a/src/engine/builtins.h +++ b/src/engine/builtins.h @@ -27,5 +27,6 @@ LIST *builtin_import( PARSE *parse, FRAME *args ); LIST *builtin_export( PARSE *parse, FRAME *args ); LIST *builtin_caller_module( PARSE *parse, FRAME *args ); LIST *builtin_backtrace( PARSE *parse, FRAME *args ); +LIST *builtin_pwd( PARSE *parse, FRAME *args ); #endif diff --git a/src/engine/common.mk b/src/engine/common.mk index 5d55eb001..d37fa9f3c 100644 --- a/src/engine/common.mk +++ b/src/engine/common.mk @@ -9,7 +9,7 @@ SOURCES = \ hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c \ newstr.c option.c parse.c pathunix.c pathvms.c regexp.c \ rules.c scan.c search.c subst.c timestamp.c variable.c modules.c \ - strings.c filesys.c builtins.c + strings.c filesys.c builtins.c pwd.c # the bootstrap "jam0" build tool # diff --git a/src/engine/pwd.c b/src/engine/pwd.c new file mode 100644 index 000000000..fb60bed52 --- /dev/null +++ b/src/engine/pwd.c @@ -0,0 +1,28 @@ +#include "jam.h" +#include "lists.h" +#include "newstr.h" + +#ifdef NT +#include +#define PATH_MAX _MAX_PATH +#else +#include +#endif + +#include + +LIST* +pwd(void) +{ + char buffer[PATH_MAX]; + if (getcwd(buffer, sizeof(buffer)) == NULL) + { + perror("can not get current directory"); + return L0; + } + else + { + return list_new(L0, newstr(buffer)); + } +} + diff --git a/src/engine/pwd.h b/src/engine/pwd.h new file mode 100644 index 000000000..506eace50 --- /dev/null +++ b/src/engine/pwd.h @@ -0,0 +1,6 @@ +#ifndef PWD_H +#define PWD_H + +LIST* pwd(void); + +#endif