ww: resolve root argv0 and retire stale help paths

This commit is contained in:
2026-08-09 03:56:37 +09:00
parent 5f829399ea
commit 00d0ed502d
3 changed files with 83 additions and 18 deletions

View File

@@ -96,17 +96,18 @@ fn cstrseal(dst: *u8, off: u64) void = {
fn selfdirinto(dst: *u8, dstsz: u64, argv0: *u8) void = {
let n: u64 = cstrlen(argv0);
let cut: u64 = 0u64;
let cut: u64 = n;
let i: u64 = 0u64;
for (i < n) {
if (argv0[i] == 47u8) { cut = i; }; // '/'
if (argv0[i] == 47u8) { cut = i; };
i += 1u64;
};
if (cut == 0u64) {
dst[0u64] = 46u8; // '.'
if (cut == n) {
dst[0u64] = 46u8;
dst[1u64] = 0u8;
return;
};
if (cut == 0u64) { cut = 1u64; };
if (cut + 1u64 >= dstsz) { cut = dstsz - 2u64; };
bytecpy(dst, argv0, cut);
dst[cut] = 0u8;
@@ -2000,7 +2001,7 @@ fn resolvemodule(selfdir: *u8, name: *u8, incs: *u8, isdir: *i32) *u8 = {
};
fn writeusage(fd: i32) void = {
let s: str = "usage: ww [-V] <subcommand> [args...]\n -V print version and exit\n build [-S] [-w DIR] [-o FILE] [path] compile module; -S stops after package asm\n run [path] ... build then exec, passing extra args to the program\n test [-S -o STEM] [-w DIR] [options] [path] build/run tests; -S emits package asm\n version print version and exit\n\n path forms:\n foo.ww literal file\n foo search cwd, -I dirs, then $WW_LIB-equiv for foo.ww or foo/foo.ww\n lib/foo directory: build lib/foo/foo.ww\n lib/... every package under lib, recursively (test only)\n . build the cwd's <basename>.ww\n";
let s: str = "usage: ww [-V] <subcommand> [args...]\n -V print version and exit\n build [-S] [-w DIR] [-o FILE] [path] compile module; -S stops after package asm\n run [path] ... build then exec, passing extra args to the program\n test [-S -o STEM] [-w DIR] [options] [path] build/run tests; -S emits package asm\n version print version and exit\n\n path forms:\n foo.ww literal file\n foo search cwd, -I dirs, then the source library for foo.ww or foo/\n lib/foo directory: build its package sources\n lib/... every package under lib, recursively (test only)\n . build the cwd's <basename>.ww\n";
os.write(fd, s.ptr, s.len: u64);
};
@@ -2733,7 +2734,9 @@ export fn main(argc: i32, argv: **u8) i32 = {
if (cstreqlit(cmd, "test")) {
return dotest(selfdir.ptr, argv, argc, 2);
};
cerr("ww: unknown subcommand\n");
cerr("ww: unknown subcommand: ");
os.write(2, cmd, cstrlen(cmd));
cerr("\n");
writeusage(2);
return 2;
};