cb: import updates from sources

This commit is contained in:
cinap_lenrek 2012-08-01 21:57:13 +02:00
parent 9b5b68a302
commit 8e07a4c9a5
2 changed files with 28 additions and 29 deletions

View file

@ -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

View file

@ -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++;
}
}