Add support for multibyte characters. The output is questionable when a
character straddles the "start" or "stop" columns, but this should be quite uncommon.
This commit is contained in:
parent
866b1c7484
commit
d10ab05ebd
@ -32,7 +32,7 @@
|
||||
.\" @(#)colrm.1 8.1 (Berkeley) 6/6/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd July 15, 2004
|
||||
.Dd July 29, 2004
|
||||
.Dt COLRM 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -78,7 +78,3 @@ The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
||||
.Sh BUGS
|
||||
The
|
||||
.Nm
|
||||
utility does not recognize multibyte characters.
|
||||
|
@ -50,10 +50,12 @@ __FBSDID("$FreeBSD$");
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#define TAB 8
|
||||
|
||||
@ -64,9 +66,11 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
u_long column, start, stop;
|
||||
int ch;
|
||||
int ch, width;
|
||||
char *p;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
switch(ch) {
|
||||
case '?':
|
||||
@ -98,8 +102,8 @@ main(int argc, char *argv[])
|
||||
errx(1, "illegal start and stop columns");
|
||||
|
||||
for (column = 0;;) {
|
||||
switch (ch = getchar()) {
|
||||
case EOF:
|
||||
switch (ch = getwchar()) {
|
||||
case WEOF:
|
||||
check(stdin);
|
||||
break;
|
||||
case '\b':
|
||||
@ -113,12 +117,13 @@ main(int argc, char *argv[])
|
||||
column = (column + TAB) & ~(TAB - 1);
|
||||
break;
|
||||
default:
|
||||
++column;
|
||||
if ((width = wcwidth(ch)) > 0)
|
||||
column += width;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((!start || column < start || (stop && column > stop)) &&
|
||||
putchar(ch) == EOF)
|
||||
putwchar(ch) == WEOF)
|
||||
check(stdout);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user