From owner-freebsd-current@FreeBSD.ORG Sun Sep 3 06:33:07 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 B8D6516A4DE for ; Sun, 3 Sep 2006 06:33:07 +0000 (UTC) (envelope-from prvs=julian=39403106a@elischer.org) Received: from a50.ironport.com (a50.ironport.com [63.251.108.112]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6821543D45 for ; Sun, 3 Sep 2006 06:33:07 +0000 (GMT) (envelope-from prvs=julian=39403106a@elischer.org) Received: from unknown (HELO [192.168.2.6]) ([10.251.60.39]) by a50.ironport.com with ESMTP; 02 Sep 2006 23:33:06 -0700 Message-ID: <44FA7720.5040304@elischer.org> Date: Sat, 02 Sep 2006 23:33:04 -0700 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.13) Gecko/20060414 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Peter Jeremy References: <200608281545.k7SFjn6l063922@lurza.secnetix.de> <200609020956.54008.Lucas.James@ldjcs.com.au> <20060902031247.GE749@turion.vk2pj.dyndns.org> In-Reply-To: <20060902031247.GE749@turion.vk2pj.dyndns.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: Lucas James , 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: Sun, 03 Sep 2006 06:33:07 -0000 Peter Jeremy wrote: >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=^=$(date)=" 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). > > I look forward to this commit.. (I don't care where I get the capacity from as long as I can datestamp files) puting it in 'tee' is also an option.. timestamping the 'file' output. > > >------------------------------------------------------------------------ > >Index: cat.c >=================================================================== >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; > > static void usage(void); > static void scanfiles(char *argv[], int cooked); >@@ -84,7 +85,7 @@ > > setlocale(LC_CTYPE, ""); > >- while ((ch = getopt(argc, argv, "benstuv")) != -1) >+ while ((ch = getopt(argc, argv, "benp:stuv")) != -1) > switch (ch) { > case 'b': > bflag = nflag = 1; /* -b implies -n */ >@@ -95,6 +96,8 @@ > case 'n': > nflag = 1; > break; >+ case 'p': >+ datefmt = optarg; > case 's': > sflag = 1; > break; >@@ -177,6 +180,8 @@ > cook_cat(FILE *fp) > { > int ch, gobble, line, prev; >+ char datebuf[1024]; >+ time_t now; > > /* Reset EOF condition on stdin. */ > if (fp == stdin && feof(stdin)) >@@ -198,6 +203,14 @@ > if (ferror(stdout)) > break; > } >+ if (datefmt != NULL) { >+ time(&now); >+ strftime(datebuf, sizeof(datebuf), datefmt, >+ localtime(&now)); >+ (void)fputs(datebuf, stdout); >+ if (ferror(stdout)) >+ break; >+ } > } > if (ch == '\n') { > if (eflag && putchar('$') == EOF) > >