diff options
author | tjr <tjr@FreeBSD.org> | 2004-07-16 06:21:40 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2004-07-16 06:21:40 +0000 |
commit | 8d7b06e962e09616053a76adecccae3bb9954190 (patch) | |
tree | e76326f4d4f4966b7f8c4658b910163a1524bd0e /usr.bin/rev/rev.c | |
parent | 9ff80f3e79f9930822ff4ff965d0845033e88843 (diff) | |
download | FreeBSD-src-8d7b06e962e09616053a76adecccae3bb9954190.zip FreeBSD-src-8d7b06e962e09616053a76adecccae3bb9954190.tar.gz |
Add support for multibyte characters.
Diffstat (limited to 'usr.bin/rev/rev.c')
-rw-r--r-- | usr.bin/rev/rev.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/rev/rev.c b/usr.bin/rev/rev.c index 6a48d5e..87c8587 100644 --- a/usr.bin/rev/rev.c +++ b/usr.bin/rev/rev.c @@ -50,21 +50,26 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <errno.h> +#include <locale.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <wchar.h> 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); |