add fs.home

This commit is contained in:
Nishi 2026-05-10 02:42:55 +09:00
commit 9281e8c0a8
Signed by: nishi
GPG key ID: 27EF69B208EB9343
3 changed files with 19 additions and 2 deletions

View file

@ -47,7 +47,7 @@ for(var i = 1; i < ARGV.length; i++) {
if(pmake.options[args[0]]) {
var opts = pmake.options[args[0]].options;
var opt = pmake.options[args[0]].option;
var opt = pmake.options[args[0]].option;
if(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] + "'");
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();
}

View file

@ -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");
}

View file

@ -11,6 +11,7 @@
#include <direct.h>
#else
#include <unistd.h>
#include <pwd.h>
#endif
#include <duktape.h>