Allow <blank>s to be used to separate tab stop positions with the -t

argument, not just ASCII space characters and commas. Don't count
non-printing characters when determining column position.
This commit is contained in:
Tim J. Robbins 2002-06-15 10:16:39 +00:00
parent 3ba0209ecf
commit ec85e6a06c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=98251
3 changed files with 27 additions and 5 deletions

View File

@ -95,6 +95,18 @@ are reconverted to maximal strings of tabs. If the
option is given, then tabs are inserted whenever they would compress the option is given, then tabs are inserted whenever they would compress the
resultant file by replacing two or more characters. resultant file by replacing two or more characters.
.El .El
.Sh ENVIRONMENT
The
.Ev LANG ,
.Ev LC_ALL
and
.Ev LC_CTYPE
environment variables affect the execution of
.Nm expand
and
.Nm unexpand
as described in
.Xr environ 7 .
.Sh STANDARDS .Sh STANDARDS
The The
.Nm expand .Nm expand

View File

@ -47,6 +47,7 @@ static const char rcsid[] =
#include <ctype.h> #include <ctype.h>
#include <err.h> #include <err.h>
#include <locale.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -69,8 +70,11 @@ main(argc, argv)
register int n; register int n;
int rval; int rval;
setlocale(LC_CTYPE, "");
/* handle obsolete syntax */ /* handle obsolete syntax */
while (argc > 1 && argv[1][0] == '-' && isdigit(argv[1][1])) { while (argc > 1 && argv[1][0] == '-' &&
isdigit((unsigned char)argv[1][1])) {
getstops(&argv[1][1]); getstops(&argv[1][1]);
argc--; argv++; argc--; argv++;
} }
@ -140,7 +144,8 @@ main(argc, argv)
default: default:
putchar(c); putchar(c);
column++; if (isprint(c))
column++;
continue; continue;
case '\n': case '\n':
@ -173,7 +178,7 @@ getstops(cp)
tabstops[nstops++] = i; tabstops[nstops++] = i;
if (*cp == 0) if (*cp == 0)
break; break;
if (*cp != ',' && *cp != ' ') if (*cp != ',' && !isblank((unsigned char)*cp))
errx(1, "bad tab stop spec"); errx(1, "bad tab stop spec");
cp++; cp++;
} }

View File

@ -48,8 +48,10 @@ static const char sccsid[] = "@(#)unexpand.c 8.1 (Berkeley) 6/6/93";
/* /*
* unexpand - put tabs into a file replacing blanks * unexpand - put tabs into a file replacing blanks
*/ */
#include <ctype.h>
#include <err.h> #include <err.h>
#include <limits.h> #include <limits.h>
#include <locale.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -71,6 +73,8 @@ main(argc, argv)
int ch, failed; int ch, failed;
char *filename; char *filename;
setlocale(LC_CTYPE, "");
nstops = 1; nstops = 1;
tabstops[0] = 8; tabstops[0] = 8;
while ((ch = getopt(argc, argv, "at:")) != -1) { while ((ch = getopt(argc, argv, "at:")) != -1) {
@ -176,7 +180,8 @@ tabify()
doneline = ocol = dcol = 0; doneline = ocol = dcol = 0;
} else if (ch != ' ' || dcol > limit) { } else if (ch != ' ' || dcol > limit) {
putchar(ch); putchar(ch);
ocol++, dcol++; if (isprint(ch))
ocol++, dcol++;
} }
/* /*
@ -213,7 +218,7 @@ getstops(cp)
tabstops[nstops++] = i; tabstops[nstops++] = i;
if (*cp == 0) if (*cp == 0)
break; break;
if (*cp != ',' && *cp != ' ') if (*cp != ',' && !isblank((unsigned char)*cp))
errx(1, "bad tab stop spec"); errx(1, "bad tab stop spec");
cp++; cp++;
} }