[Midnightbsd-cvs] src [11341] trunk/bin/cat: sync cat
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Thu Jul 5 15:04:53 EDT 2018
Revision: 11341
http://svnweb.midnightbsd.org/src/?rev=11341
Author: laffer1
Date: 2018-07-05 15:04:52 -0400 (Thu, 05 Jul 2018)
Log Message:
-----------
sync cat
Modified Paths:
--------------
trunk/bin/cat/Makefile
trunk/bin/cat/cat.1
trunk/bin/cat/cat.c
Added Paths:
-----------
trunk/bin/cat/tests/
trunk/bin/cat/tests/Makefile
Property Changed:
----------------
trunk/bin/cat/cat.1
Modified: trunk/bin/cat/Makefile
===================================================================
--- trunk/bin/cat/Makefile 2018-07-05 17:58:21 UTC (rev 11340)
+++ trunk/bin/cat/Makefile 2018-07-05 19:04:52 UTC (rev 11341)
@@ -1,7 +1,13 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 5/31/93
-# $FreeBSD: src/bin/cat/Makefile,v 1.7 2001/12/04 01:57:37 obrien Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/bin/cat/Makefile 292282 2015-12-15 18:09:03Z ngie $
+.include <bsd.own.mk>
+
PROG= cat
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
Modified: trunk/bin/cat/cat.1
===================================================================
--- trunk/bin/cat/cat.1 2018-07-05 17:58:21 UTC (rev 11340)
+++ trunk/bin/cat/cat.1 2018-07-05 19:04:52 UTC (rev 11341)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"-
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -30,8 +31,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)cat.1 8.3 (Berkeley) 5/2/95
-.\" $FreeBSD: src/bin/cat/cat.1,v 1.25 2005/01/16 16:41:55 ru Exp $
-.\" $MidnightBSD: src/bin/cat/cat.1,v 1.4 2006/09/09 13:48:40 laffer1 Exp $
+.\" $FreeBSD: stable/10/bin/cat/cat.1 246090 2013-01-29 20:01:47Z joel $
.\"
.Dd January 29, 2013
.Dt CAT 1
@@ -42,7 +42,6 @@
.Sh SYNOPSIS
.Nm
.Op Fl belnstuv
-.Op Fl D Ar date_fmt
.Op Ar
.Sh DESCRIPTION
The
@@ -96,13 +95,6 @@
.It Fl s
Squeeze multiple adjacent empty lines, causing the output to be
single spaced.
-.It Fl D
-Prepends a date and/or time on each line of output, in the format date_fmt at the time the line was read by the
-.Nm
-utility. Follows
-.Xr strftime 3
-formatting rules. If a seperator is desired, it must be included using %t or
-including a space character. Any text may be included in the format.
.It Fl t
Display non-printing characters (see the
.Fl v
@@ -171,14 +163,6 @@
when it encountered the first
.Sq Fl
operand.
-.Pp
-The command:
-.Pp
-.Dl "cat -D '%F %T ' file1"
-.Pp
-will print the contents of
-.Ar file1
-with the current date prepended to each line in the form YYYY-MM-DD HH:MM:SS followed by a space. This is useful for timestamping output.
.Sh SEE ALSO
.Xr head 1 ,
.Xr more 1 ,
@@ -187,8 +171,8 @@
.Xr tail 1 ,
.Xr vis 1 ,
.Xr zcat 1 ,
-.Xr setbuf 3 ,
-.Xr strftime 3
+.Xr fcntl 2 ,
+.Xr setbuf 3
.Rs
.%A Rob Pike
.%T "UNIX Style, or cat -v Considered Harmful"
@@ -203,7 +187,7 @@
specification.
.Pp
The flags
-.Op Fl belnstvD
+.Op Fl belnstv
are extensions to the specification.
.Sh HISTORY
A
Property changes on: trunk/bin/cat/cat.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/bin/cat/cat.c
===================================================================
--- trunk/bin/cat/cat.c 2018-07-05 17:58:21 UTC (rev 11340)
+++ trunk/bin/cat/cat.c 2018-07-05 19:04:52 UTC (rev 11341)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -28,9 +29,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $MidnightBSD$
- * $FreeBSD: src/bin/cat/cat.c,v 1.32 2005/01/10 08:39:20 imp Exp $
*/
#if 0
@@ -47,6 +45,7 @@
#endif
#endif /* not lint */
#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/bin/cat/cat.c 306200 2016-09-22 16:46:59Z ache $");
#include <sys/param.h>
#include <sys/stat.h>
@@ -60,26 +59,22 @@
#include <err.h>
#include <fcntl.h>
#include <locale.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stddef.h>
+#include <wchar.h>
+#include <wctype.h>
-#define DATEPFX_MAXLEN 1024
-
static int bflag, eflag, lflag, nflag, sflag, tflag, vflag;
static int rval;
-static time_t prev_time;
-static const char *datefmt;
-static char *datepfx;
-const char *filename;
+static const char *filename;
-static void usage(void);
+static void usage(void) __dead2;
static void scanfiles(char *argv[], int cooked);
static void cook_cat(FILE *);
static void raw_cat(int);
-static void set_datepfx(void);
#ifndef NO_UDOM_SUPPORT
static int udom_open(const char *path, int flags);
@@ -108,7 +103,7 @@
setlocale(LC_CTYPE, "");
- while ((ch = getopt(argc, argv, "bD:elnstuv")) != -1)
+ while ((ch = getopt(argc, argv, "belnstuv")) != -1)
switch (ch) {
case 'b':
bflag = nflag = 1; /* -b implies -n */
@@ -122,9 +117,6 @@
case 'n':
nflag = 1;
break;
- case 'D':
- datefmt = optarg;
- break;
case 's':
sflag = 1;
break;
@@ -151,15 +143,7 @@
err(EXIT_FAILURE, "stdout");
}
- /*
- * Test date format so the user will get an error sooner
- * rather than later
- */
- if (datefmt != NULL)
- set_datepfx();
-
- if (bflag || eflag || nflag || sflag || tflag || vflag ||
- datefmt != NULL)
+ if (bflag || eflag || nflag || sflag || tflag || vflag)
scanfiles(argv, 1);
else
scanfiles(argv, 0);
@@ -172,7 +156,8 @@
static void
usage(void)
{
- fprintf(stderr, "usage: cat [-belnstuv] [-D datefmt] [file ...]\n");
+
+ fprintf(stderr, "usage: cat [-belnstuv] [file ...]\n");
exit(1);
/* NOTREACHED */
}
@@ -223,6 +208,7 @@
cook_cat(FILE *fp)
{
int ch, gobble, line, prev;
+ wint_t wch;
/* Reset EOF condition on stdin. */
if (fp == stdin && feof(stdin))
@@ -244,12 +230,6 @@
if (ferror(stdout))
break;
}
- if (datefmt != NULL) {
- set_datepfx();
- (void)fputs(datepfx, stdout);
- if (ferror(stdout))
- break;
- }
}
if (ch == '\n') {
if (eflag && putchar('$') == EOF)
@@ -261,18 +241,40 @@
continue;
}
} else if (vflag) {
- if (!isascii(ch) && !isprint(ch)) {
+ (void)ungetc(ch, fp);
+ /*
+ * Our getwc(3) doesn't change file position
+ * on error.
+ */
+ if ((wch = getwc(fp)) == WEOF) {
+ if (ferror(fp) && errno == EILSEQ) {
+ clearerr(fp);
+ /* Resync attempt. */
+ memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+ if ((ch = getc(fp)) == EOF)
+ break;
+ wch = ch;
+ goto ilseq;
+ } else
+ break;
+ }
+ if (!iswascii(wch) && !iswprint(wch)) {
+ilseq:
if (putchar('M') == EOF || putchar('-') == EOF)
break;
- ch = toascii(ch);
+ wch = toascii(wch);
}
- if (iscntrl(ch)) {
- if (putchar('^') == EOF ||
- putchar(ch == '\177' ? '?' :
- ch | 0100) == EOF)
+ if (iswcntrl(wch)) {
+ ch = toascii(wch);
+ ch = (ch == '\177') ? '?' : (ch | 0100);
+ if (putchar('^') == EOF || putchar(ch) == EOF)
break;
continue;
}
+ if (putwchar(wch) == WEOF)
+ break;
+ ch = -1;
+ continue;
}
if (putchar(ch) == EOF)
break;
@@ -321,31 +323,6 @@
}
}
-static void
-set_datepfx(void)
-{
- int reslen;
- time_t now;
-
- if (datepfx == NULL)
- datepfx = malloc(DATEPFX_MAXLEN);
-
- /*
- * Avoid the calls to localtime and strftime if
- * the current second is the same as the last
- * read in value.
- */
- now = time(NULL);
- if (now == prev_time)
- return;
-
- reslen = strftime(datepfx, DATEPFX_MAXLEN, datefmt,
- localtime(&now));
- if (reslen == 0)
- errx(1, "Format specified by -D results in prefix > %d bytes.",
- DATEPFX_MAXLEN);
-}
-
#ifndef NO_UDOM_SUPPORT
static int
Added: trunk/bin/cat/tests/Makefile
===================================================================
--- trunk/bin/cat/tests/Makefile (rev 0)
+++ trunk/bin/cat/tests/Makefile 2018-07-05 19:04:52 UTC (rev 11341)
@@ -0,0 +1,27 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/bin/cat/tests/Makefile 320710 2017-07-06 05:26:27Z ngie $
+
+NETBSD_ATF_TESTS_SH= cat_test
+
+FILESDIR= ${TESTSDIR}
+
+FILES+= d_align.in
+FILES+= d_align.out
+FILES+= d_b_output.in
+FILES+= d_b_output.out
+FILES+= d_se_output.in
+FILES+= d_se_output.out
+FILES+= d_s_output.in
+FILES+= d_s_output.out
+FILES+= d_vt_output.in
+FILES+= d_vt_output.out
+
+.include <netbsd-tests.test.mk>
+
+d_align.out: ${TESTSRC}/d_align.out
+ sed -E -e 's,^[[:space:]]{7}\$$$$,\$$,' < ${.ALLSRC} > ${.TARGET}.tmp
+ mv ${.TARGET}.tmp ${.TARGET}
+
+CLEANFILES+= d_align.out d_align.out.tmp
+
+.include <bsd.test.mk>
Property changes on: trunk/bin/cat/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the Midnightbsd-cvs
mailing list