diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-08-01 21:57:13 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-08-01 21:57:13 +0200 |
commit | 8e07a4c9a52a0c9203f52e9d835e6da114f8a659 (patch) | |
tree | 0e871132fbe9d5a0a97c40a27077222703c94fb2 /sys | |
parent | 9b5b68a3022a6503aab296986fec1b463f9e6b1e (diff) |
cb: import updates from sources
Diffstat (limited to 'sys')
-rw-r--r-- | sys/man/1/cb | 2 | ||||
-rw-r--r-- | sys/src/cmd/cb/cb.c | 55 |
2 files changed, 28 insertions, 29 deletions
diff --git a/sys/man/1/cb b/sys/man/1/cb index b5eed691e..2789249bc 100644 --- a/sys/man/1/cb +++ b/sys/man/1/cb @@ -32,7 +32,7 @@ Join split lines. Print code in the so-called K&R style used in .IR "The C Programming Language" . .TP -.B -l length +.B -l Split lines that are longer than .IR length . .PD diff --git a/sys/src/cmd/cb/cb.c b/sys/src/cmd/cb/cb.c index d9c2bf584..92de903fa 100644 --- a/sys/src/cmd/cb/cb.c +++ b/sys/src/cmd/cb/cb.c @@ -4,48 +4,47 @@ #include "cb.h" #include "cbtype.h" +static void +usage(void) +{ + fprint(2, "usage: cb [-sj] [-l width]\n"); + exits("usage"); +} + void main(int argc, char *argv[]) { Biobuf stdin, stdout; - while (--argc > 0 && (*++argv)[0] == '-'){ - switch ((*argv)[1]){ - case 's': - strict = 1; - continue; - case 'j': - join = 1; - continue; - case 'l': - if((*argv)[2] != '\0'){ - maxleng = atoi( &((*argv)[2]) ); - } - else{ - maxleng = atoi(*++argv); - argc--; - } - maxtabs = maxleng/TABLENG - 2; - maxleng -= (maxleng + 5)/10; - continue; - default: - fprint(2, "cb: illegal option %c\n", *argv[1]); - exits("boom"); - } - } + ARGBEGIN{ + case 'j': + join = 1; + break; + case 'l': + maxleng = atoi(EARGF(usage())); + maxtabs = maxleng/TABLENG - 2; + maxleng -= (maxleng + 5)/10; + break; + case 's': + strict = 1; + break; + default: + usage(); + }ARGEND + Binit(&stdout, 1, OWRITE); output = &stdout; if (argc <= 0){ Binit(&stdin, 0, OREAD); input = &stdin; work(); + Bterm(input); } else { while (argc-- > 0){ - if ((input = Bopen( *argv, OREAD)) == 0){ - fprint(2, "cb: cannot open input file %s\n", *argv); - exits("boom"); - } + if ((input = Bopen(*argv, OREAD)) == 0) + sysfatal("can't open input file %s: %r", *argv); work(); + Bterm(input); argv++; } } |