@@ -1,4 +1,4 @@
-.\" $NetBSD: rev.1,v 1.7 2008/11/28 20:30:05 reed Exp $
+.\" $NetBSD: rev.1,v 1.8 2009/07/21 01:12:55 ahoka Exp $
.\"
.\" Copyright (c) 1985, 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)rev.1 8.1 (Berkeley) 6/9/93
.\"
-.Dd January 21, 2001
+.Dd July 21, 2009
.Dt REV 1
.Os
.Sh NAME
@@ -44,3 +44,7 @@
utility copies the specified files to the standard output, reversing the
order of characters in every line.
If no files are specified, the standard input is read.
+.Sh ENVIRONMENT
+.Bl -tag -width indent
+.It Ev LC_ALL
+.El
@@ -1,4 +1,4 @@
-/* $NetBSD: rev.c,v 1.9 2009/04/13 04:36:34 lukem Exp $ */
+/* $NetBSD: rev.c,v 1.10 2009/07/21 01:12:55 ahoka Exp $ */
/*-
* Copyright (c) 1987, 1992, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)rev.c 8.3 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: rev.c,v 1.9 2009/04/13 04:36:34 lukem Exp $");
+__RCSID("$NetBSD: rev.c,v 1.10 2009/07/21 01:12:55 ahoka Exp $");
#endif
#endif /* not lint */
@@ -47,10 +47,11 @@
#include <err.h>
#include <errno.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
+#include <wchar.h>
int main __P((int, char **));
void usage __P((void));
@@ -61,11 +62,13 @@
char *argv[];
{
const char *filename;
- char *p, *t;
+ wchar_t *p, *t;
FILE *fp;
size_t len;
int ch, rval;
+ setlocale(LC_ALL, "");
+
while ((ch = getopt(argc, argv, "")) != -1)
switch(ch) {
case '?':
@@ -89,13 +92,13 @@
}
filename = *argv++;
}
- while ((p = fgetln(fp, &len)) != NULL) {
- if (p[len - 1] == '\n')
+ while ((p = fgetwln(fp, &len)) != NULL) {
+ if (p[len - 1] == L'\n')
--len;
t = p + len - 1;
for (t = p + len - 1; t >= p; --t)
- putchar(*t);
- putchar('\n');
+ putwchar(*t);
+ putwchar(L'\n');
}
if (ferror(fp)) {
warn("%s", filename);