forked from pyrite-dev/pmake
add fs.home
This commit is contained in:
parent
4498e11516
commit
9281e8c0a8
3 changed files with 19 additions and 2 deletions
|
|
@ -47,7 +47,7 @@ for(var i = 1; i < ARGV.length; i++) {
|
||||||
|
|
||||||
if(pmake.options[args[0]]) {
|
if(pmake.options[args[0]]) {
|
||||||
var opts = pmake.options[args[0]].options;
|
var opts = pmake.options[args[0]].options;
|
||||||
var opt = pmake.options[args[0]].option;
|
var opt = pmake.options[args[0]].option;
|
||||||
|
|
||||||
if(opts) {
|
if(opts) {
|
||||||
if((typeof opts) == "function") opts = opts();
|
if((typeof opts) == "function") opts = opts();
|
||||||
|
|
@ -60,7 +60,7 @@ for(var i = 1; i < ARGV.length; i++) {
|
||||||
console.log("Error: invalid value '" + args[1] + "' for option '" + args[0] + "'");
|
console.log("Error: invalid value '" + args[1] + "' for option '" + args[0] + "'");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else if(opts || opt) {
|
} else if(opts || opt) {
|
||||||
pmake.options[args[0]].action(args[1]);
|
pmake.options[args[0]].action(args[1].replace(/^~(\/?)/, fs.home + "$1"));
|
||||||
} else {
|
} else {
|
||||||
pmake.options[args[0]].action();
|
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) {
|
void js_fs_init(void) {
|
||||||
int obj;
|
int obj;
|
||||||
char started_cwd[1024];
|
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);
|
getcwd(started_cwd, 1024);
|
||||||
|
|
||||||
|
|
@ -130,5 +143,8 @@ void js_fs_init(void) {
|
||||||
duk_push_string(js_ctx, started_cwd);
|
duk_push_string(js_ctx, started_cwd);
|
||||||
duk_put_prop_string(js_ctx, obj, "startedCwd");
|
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");
|
duk_put_prop_string(js_ctx, 0, "fs");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <duktape.h>
|
#include <duktape.h>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue