| | @@ -35,6 +35,8 @@ |
| 35 | 35 | (* What read makes of a word or a letter. *) |
| 36 | 36 | const read1 = 1; readEnd = 0; readSkip = -1; |
| 37 | 37 | |
| 38 | +const largest = 9223372036854775807; (* the largest I64, a number with no top *) |
| 39 | + |
| 38 | 40 | (* b written whole to fd, then freed. *) |
| 39 | 41 | proc say(fd: INT; b: ^Buf.Buf); |
| 40 | 42 | var s: []U8; n: INT; |
| | @@ -367,12 +369,17 @@ |
| 367 | 369 | end; |
| 368 | 370 | |
| 369 | 371 | (* The value of the option just read, as a whole number from lo to hi; |
| 370 | | - anything else is a mistake. *) |
| 372 | + anything else is a mistake. A number with no top is given the |
| 373 | + largest I64 for hi, and the mistake says "from lo up". *) |
| 371 | 374 | proc number*(p: ^Parser; lo, hi: I64): I64; |
| 372 | 375 | var n: I64; ok: BOOL; |
| 373 | 376 | begin |
| 374 | 377 | n, ok := Str.toInt(p^.value); |
| 375 | 378 | if not ok or (n < lo) or (n > hi) then |
| 379 | + if hi = largest then |
| 380 | + refuse(p, "{}{} wants a number from {} up, not '{}'", |
| 381 | + [Fmt.str(dashes(p)), Fmt.str(p^.spelt), Fmt.int(lo), Fmt.str(p^.value)]); |
| 382 | + end; |
| 376 | 383 | refuse(p, "{}{} wants a number from {} to {}, not '{}'", |
| 377 | 384 | [Fmt.str(dashes(p)), Fmt.str(p^.spelt), Fmt.int(lo), Fmt.int(hi), Fmt.str(p^.value)]); |
| 378 | 385 | end; |
| | @@ -395,7 +402,7 @@ |
| 395 | 402 | program of getopt's page, or a program with a bad table, or one with |
| 396 | 403 | no synopsis lines; and holds each to what it writes, and its status. *) |
| 397 | 404 | proc keep; |
| 398 | | -const wait = 1; |
| 405 | +const wait = 1; jobs = 2; |
| 399 | 406 | var p: Parser; verbose, ok: BOOL; secs: I64; bar, job, w: []U8; b: Buf.Buf; i: INT; |
| 400 | 407 | begin |
| 401 | 408 | secs := 10; |
| | @@ -404,11 +411,13 @@ |
| 404 | 411 | sub("", "start", "start a job"), |
| 405 | 412 | option("", 'v', "verbose", "", "say more"), |
| 406 | 413 | option("", wait, "wait", "secs", "give the job secs to start"), |
| 414 | + option("", jobs, "jobs", "n", "keep n jobs at most"), |
| 407 | 415 | usage("start", "keep start [-b label] name command [argument ...]"), |
| 408 | 416 | option("start", 'b', "bar", "label", "show the job in the bar as label")]); |
| 409 | 417 | while next(ADR(p)) do |
| 410 | 418 | if p.letter = 'v' then verbose := true; |
| 411 | 419 | elsif p.letter = wait then secs := number(ADR(p), 1, 600); |
| 420 | + elsif p.letter = jobs then _ := number(ADR(p), 1, largest); |
| 412 | 421 | end; |
| 413 | 422 | end; |
| 414 | 423 | w, ok := operand(ADR(p)); |
| | @@ -499,7 +508,7 @@ |
| 499 | 508 | |
| 500 | 509 | proc main*; |
| 501 | 510 | const |
| 502 | | - keepHelp = "usage: keep [-v] [--wait secs] start ...\n\n start start a job\n -v, --verbose say more\n --wait secs give the job secs to start\n -h, --help print this and exit\n"; |
| 511 | + keepHelp = "usage: keep [-v] [--wait secs] start ...\n\n start start a job\n -v, --verbose say more\n --wait secs give the job secs to start\n --jobs n keep n jobs at most\n -h, --help print this and exit\n"; |
| 503 | 512 | startHelp = "usage: keep start [-b label] name command [argument ...]\n\n -b, --bar label show the job in the bar as label\n -h, --help print this and exit\n"; |
| 504 | 513 | k = "OPTTEST=keep"; |
| 505 | 514 | var cases: []Case; i: INT; mode: []U8; |
| | @@ -536,6 +545,8 @@ |
| 536 | 545 | {mode: k, args: ["keep", "--wait", "0", "start", "a", "b"], |
| 537 | 546 | err: "keep: --wait wants a number from 1 to 600, not '0'\nusage: keep [-v] [--wait secs] start ...\n", status: 2}, |
| 538 | 547 | {mode: k, args: ["keep", "--wait=9x", "start"], err: "keep: --wait wants a number from 1 to 600, not '9x'\nusage: keep [-v] [--wait secs] start ...\n", status: 2}, |
| 548 | + {mode: k, args: ["keep", "--jobs=0", "start"], err: "keep: --jobs wants a number from 1 up, not '0'\nusage: keep [-v] [--wait secs] start ...\n", status: 2}, |
| 549 | + {mode: k, args: ["keep", "--jobs", "9223372036854775807", "start", "n", "c"], out: "job n: c\n"}, |
| 539 | 550 | {mode: "OPTTEST=bad", args: ["bad", "-v"], err: "bad: option table, row 2: the option is in the scope already\n", status: 1}, |
| 540 | 551 | {mode: "OPTTEST=plain", args: ["plain", "remote", "add", "-f", "--force"], out: "f\nf\n"}, |
| 541 | 552 | {mode: "OPTTEST=plain", args: ["plain", "remote", "add", "-x"], err: "plain: unknown option -x\nusage: plain remote add\n", status: 2}, |