From owner-freebsd-current@FreeBSD.ORG Sat Sep 2 03:12:53 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AE62616A4DE for ; Sat, 2 Sep 2006 03:12:53 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from mail27.syd.optusnet.com.au (mail27.syd.optusnet.com.au [211.29.133.168]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6BE9D43D4C for ; Sat, 2 Sep 2006 03:12:52 +0000 (GMT) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (c220-239-19-236.belrs4.nsw.optusnet.com.au [220.239.19.236]) by mail27.syd.optusnet.com.au (8.12.11/8.12.11) with ESMTP id k823Cn1Z017603 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Sat, 2 Sep 2006 13:12:50 +1000 Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by turion.vk2pj.dyndns.org (8.13.6/8.13.6) with ESMTP id k823CnYb010653; Sat, 2 Sep 2006 13:12:49 +1000 (EST) (envelope-from peter@turion.vk2pj.dyndns.org) Received: (from peter@localhost) by turion.vk2pj.dyndns.org (8.13.6/8.13.6/Submit) id k823CmBe010652; Sat, 2 Sep 2006 13:12:48 +1000 (EST) (envelope-from peter) Date: Sat, 2 Sep 2006 13:12:48 +1000 From: Peter Jeremy To: Lucas James Message-ID: <20060902031247.GE749@turion.vk2pj.dyndns.org> References: <200608281545.k7SFjn6l063922@lurza.secnetix.de> <200609020956.54008.Lucas.James@ldjcs.com.au> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DO5DiztRLs659m5i" Content-Disposition: inline In-Reply-To: <200609020956.54008.Lucas.James@ldjcs.com.au> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.12-2006-07-14 Cc: freebsd-current@freebsd.org Subject: Re: suggested addition to 'date' X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Sep 2006 03:12:53 -0000 --DO5DiztRLs659m5i Content-Type: multipart/mixed; boundary="fWddYNRDgTk9wQGZ" Content-Disposition: inline --fWddYNRDgTk9wQGZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, 2006-Sep-02 09:56:53 +1000, Lucas James wrote: >On Saturday 02 September 2006 03:53, Garance A Drosehn wrote:> >> mode. Not ever. Date is a command to set or display dates. >> It is not a command to filter files. 'cat' would be a more > appropriate place to add this option. I tend to agree. >or add an option to cat to prepend each line with an arbitrary string ala: > >cat -p `date` file Firstly, we already have this: sed "s=3D^=3D$(date)=3D" file And secondly, this pre-pends a fixed string. What's wanted is a filter to prepend a time/date stamp (which varies) to the input stream. The justification for extending date(1) is that it already has the code to handle date/time stamps. In reality, this code is all in strftime(3) and cat(1) already has hooks to insert a string at the beginning of a line so I believe that the attached patch is more appropriate. (Man page update on request). --=20 Peter Jeremy --fWddYNRDgTk9wQGZ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="cat.diff" Content-Transfer-Encoding: quoted-printable Index: cat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/ncvs/src/bin/cat/cat.c,v retrieving revision 1.32 diff -u -r1.32 cat.c --- cat.c 10 Jan 2005 08:39:20 -0000 1.32 +++ cat.c 2 Sep 2006 03:08:58 -0000 @@ -67,6 +67,7 @@ int bflag, eflag, nflag, sflag, tflag, vflag; int rval; const char *filename; +const char *datefmt; =20 static void usage(void); static void scanfiles(char *argv[], int cooked); @@ -84,7 +85,7 @@ =20 setlocale(LC_CTYPE, ""); =20 - while ((ch =3D getopt(argc, argv, "benstuv")) !=3D -1) + while ((ch =3D getopt(argc, argv, "benp:stuv")) !=3D -1) switch (ch) { case 'b': bflag =3D nflag =3D 1; /* -b implies -n */ @@ -95,6 +96,8 @@ case 'n': nflag =3D 1; break; + case 'p': + datefmt =3D optarg; case 's': sflag =3D 1; break; @@ -177,6 +180,8 @@ cook_cat(FILE *fp) { int ch, gobble, line, prev; + char datebuf[1024]; + time_t now; =20 /* Reset EOF condition on stdin. */ if (fp =3D=3D stdin && feof(stdin)) @@ -198,6 +203,14 @@ if (ferror(stdout)) break; } + if (datefmt !=3D NULL) { + time(&now); + strftime(datebuf, sizeof(datebuf), datefmt, + localtime(&now)); + (void)fputs(datebuf, stdout); + if (ferror(stdout)) + break; + } } if (ch =3D=3D '\n') { if (eflag && putchar('$') =3D=3D EOF) --fWddYNRDgTk9wQGZ-- --DO5DiztRLs659m5i Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFE+Pav/opHv/APuIcRAgx+AJ9UYNtTRokP1HApqU/yDDC8qvdQwwCgkXmu g4VSbq595reHFR8FnQssMaM= =8JLy -----END PGP SIGNATURE----- --DO5DiztRLs659m5i--