ref: a0f7caa3c4f858f1c29869eccca1da1090281275
parent: 9c8931bd4218132e5d6de8f00b0555ef0f42d8e1
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Wed Aug 1 17:57:13 EDT 2012
cb: import updates from sources
--- a/sys/man/1/cb
+++ b/sys/man/1/cb
@@ -32,7 +32,7 @@
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
--- a/sys/src/cmd/cb/cb.c
+++ b/sys/src/cmd/cb/cb.c
@@ -4,35 +4,34 @@
#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){@@ -39,13 +38,13 @@
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++;
}
}
--
⑨