From 507e8f1644e1cedddcd381cb9fa2fffa13c95bc1 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Fri, 16 Jul 2004 06:21:40 +0000 Subject: [PATCH] Add support for multibyte characters. --- usr.bin/rev/rev.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr.bin/rev/rev.c b/usr.bin/rev/rev.c index 6a48d5e7e35e..87c858712ff8 100644 --- a/usr.bin/rev/rev.c +++ b/usr.bin/rev/rev.c @@ -50,21 +50,26 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include #include +#include void usage(void); int main(int argc, char *argv[]) { - const char *filename, *p, *t; + const char *filename; + wchar_t *p, *t; FILE *fp; size_t len; int ch, rval; + setlocale(LC_ALL, ""); + while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': @@ -88,13 +93,13 @@ main(int argc, char *argv[]) } filename = *argv++; } - while ((p = fgetln(fp, &len)) != NULL) { + while ((p = fgetwln(fp, &len)) != NULL) { if (p[len - 1] == '\n') --len; t = p + len - 1; for (t = p + len - 1; t >= p; --t) - putchar(*t); - putchar('\n'); + putwchar(*t); + putwchar('\n'); } if (ferror(fp)) { warn("%s", filename);