add fs.home
This commit is contained in:
parent
4498e11516
commit
9281e8c0a8
3 changed files with 19 additions and 2 deletions
|
|
@ -60,7 +60,7 @@ for(var i = 1; i < ARGV.length; i++) {
|
|||
console.log("Error: invalid value '" + args[1] + "' for option '" + args[0] + "'");
|
||||
process.exit(1);
|
||||
} else if(opts || opt) {
|
||||
pmake.options[args[0]].action(args[1]);
|
||||
pmake.options[args[0]].action(args[1].replace(/^~(\/?)/, fs.home + "$1"));
|
||||
} else {
|
||||
pmake.options[args[0]].action();
|
||||
}
|
||||
|
|
|
|||
16
src/js_fs.c
16
src/js_fs.c
|
|
@ -107,6 +107,19 @@ static duk_ret_t js_fs_cwd(duk_context* self) {
|
|||
void js_fs_init(void) {
|
||||
int obj;
|
||||
char started_cwd[1024];
|
||||
char home[1024];
|
||||
#ifndef _WIN32
|
||||
struct passwd* p;
|
||||
#endif
|
||||
|
||||
home[0] = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
strcpy(home, getenv("USERPROFILE"));
|
||||
#else
|
||||
p = getpwuid(getuid());
|
||||
strcpy(home, p->pw_dir);
|
||||
#endif
|
||||
|
||||
getcwd(started_cwd, 1024);
|
||||
|
||||
|
|
@ -130,5 +143,8 @@ void js_fs_init(void) {
|
|||
duk_push_string(js_ctx, started_cwd);
|
||||
duk_put_prop_string(js_ctx, obj, "startedCwd");
|
||||
|
||||
duk_push_string(js_ctx, home);
|
||||
duk_put_prop_string(js_ctx, obj, "home");
|
||||
|
||||
duk_put_prop_string(js_ctx, 0, "fs");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <direct.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <duktape.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue