diff options
Diffstat (limited to 'libstd')
-rw-r--r-- | libstd/dial+posixy.myr | 1 | ||||
-rw-r--r-- | libstd/fmt2.myr | 15 | ||||
-rw-r--r-- | libstd/optparse.myr | 20 |
3 files changed, 25 insertions, 11 deletions
diff --git a/libstd/dial+posixy.myr b/libstd/dial+posixy.myr index 1554cdb..77920b6 100644 --- a/libstd/dial+posixy.myr +++ b/libstd/dial+posixy.myr @@ -56,7 +56,6 @@ const dial = {str var err err = sys.connect(sock, (&sa) castto(sys.sockaddr#), sizeof(sys.sockaddr_in)) if err < 0 - put("Errno %i\n", -err) sys.close(sock) -> `Fail "Failed to bind socket" ;; diff --git a/libstd/fmt2.myr b/libstd/fmt2.myr index 5d3511f..bc1de45 100644 --- a/libstd/fmt2.myr +++ b/libstd/fmt2.myr @@ -42,6 +42,21 @@ pkg std = $noret const f2fatalv : (fmt : byte[:], ap : valist# -> void) ;; +/* same as 'put', but exits the program after printing */ +const f2fatal = {fmt, args + var ap + + ap = vastart(&args) + f2putv(fmt, &ap) + exit(1) +} + +/* same as 'putv', but exits the program after printing */ +const f2fatalv = {fmt, ap + f2putv(fmt, ap) + exit(1) +} + var fmtmapinited : bool = false var fmtmap : htab(byte[:], (sb : strbuf#, ap : valist#, opts : byte[:] -> void))# diff --git a/libstd/optparse.myr b/libstd/optparse.myr index 4f454b5..888b72f 100644 --- a/libstd/optparse.myr +++ b/libstd/optparse.myr @@ -1,7 +1,7 @@ use "alloc.use" use "die.use" use "extremum.use" -use "fmt.use" +use "fmt2.use" use "option.use" use "sleq.use" use "slpush.use" @@ -62,7 +62,7 @@ const optparse = {args, def parsed.opts = slpush(parsed.opts, optnext(&ctx)) ;; if ctx.args.len < def.minargs - put("error: expected at least %z args, got %i\n", def.minargs, ctx.args.len) + f2put("error: expected at least {} args, got {}\n", def.minargs, ctx.args.len) optusage(ctx.optargs[0], ctx.optdef) exit(1) ;; @@ -97,7 +97,7 @@ const optnext = {ctx optusage(ctx.optargs[0], ctx.optdef) exit(0) else - fatal("unexpected argument '%c'\n", c) + f2fatal("unexpected argument '{}'\n", c) ;; | `Some (true, needed): /* -arg => '-a' 'rg' */ @@ -111,7 +111,7 @@ const optnext = {ctx ctx.argidx++ next(ctx) elif needed - put("Expected argument for %c\n", c) + f2put("Expected argument for {}\n", c) exit(1) ;; | `Some (false, _): @@ -162,15 +162,15 @@ const next = {ctx } const optusage = {prog, def - std.put("usage: %s [-h?] ", prog) + std.f2put("usage: {} [-h?] ", prog) for o in def.opts - std.put("[-%c%s%s] ", o.opt, sep(o.arg), o.arg) + std.f2put("[-{}{}{}] ", o.opt, sep(o.arg), o.arg) ;; - std.put("%s\n", def.argdesc) - std.put("\t-h\tprint this help message\n") - std.put("\t-?\tprint this help message\n") + std.f2put("{}\n", def.argdesc) + std.f2put("\t-h\tprint this help message\n") + std.f2put("\t-?\tprint this help message\n") for o in def.opts - std.put("\t-%c%s%s\t%s\n", o.opt, sep(o.arg), o.arg, o.desc) + std.f2put("\t-{}{}{}\t{}\n", o.opt, sep(o.arg), o.arg, o.desc) ;; } |