From jimmy@jamesbailie.com  Fri Mar  3 17:37:56 2006
Return-Path: <jimmy@jamesbailie.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0219916A428
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  3 Mar 2006 17:37:56 +0000 (GMT)
	(envelope-from jimmy@jamesbailie.com)
Received: from smtp103.rog.mail.re2.yahoo.com (smtp103.rog.mail.re2.yahoo.com [206.190.36.81])
	by mx1.FreeBSD.org (Postfix) with SMTP id 869F243D45
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  3 Mar 2006 17:37:55 +0000 (GMT)
	(envelope-from jimmy@jamesbailie.com)
Received: (qmail 79580 invoked from network); 3 Mar 2006 17:37:54 -0000
Received: from unknown (HELO ?HOSTNAME?) (jazzturk@rogers.com@70.29.126.205 with login)
  by smtp103.rog.mail.re2.yahoo.com with SMTP; 3 Mar 2006 17:37:54 -0000
Received: by _HOSTNAME_ (sSMTP sendmail emulation); Fri,  3 Mar 2006 12:37:54 -0500
Message-Id: <20060303173755.869F243D45@mx1.FreeBSD.org>
Date: Fri,  3 Mar 2006 12:37:54 -0500
From: James Bailie <jimmy@jamesbailie.com>
Reply-To: James Bailie <jimmy@jamesbailie.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH]: Adds option to script(1) to suppress carriage-returns in log file.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         94052
>Category:       bin
>Synopsis:       [patch] Adds option to script(1) to suppress carriage-returns in log file.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 03 17:40:03 GMT 2006
>Closed-Date:    
>Last-Modified:  Mon Dec 29 18:15:43 UTC 2008
>Originator:     James Bailie <jimmy@jamesbailie.com>
>Release:        all
>Organization:
>Environment:
System: FreeBSD localhost 5.4-RELEASE-p8 FreeBSD 5.4-RELEASE-p8 #10: Tue Nov 22 11:55:20 EST 2005 jbailie@localhost:/usr/src/sys/i386/compile/LOCAL i386


	
>Description:
	
>How-To-Repeat:
	
>Fix:

	

--- diff.txt begins here ---
diff -ruN /usr/src/usr.bin/script/script.1 script/script.1
--- /usr/src/usr.bin/script/script.1	Fri Jul  2 20:24:43 2004
+++ script/script.1	Fri Mar  3 12:14:48 2006
@@ -80,6 +80,9 @@
 Log keys sent to program as well as output.
 .It Fl q
 Run in quiet mode, omit the start and stop status messages.
+.It Fl c
+Collape carriage-return/newline sequences into single newlines when writing
+data to log file.
 .It Fl t Ar time
 Specify time interval between flushing script output file.
 A value of 0
diff -ruN /usr/src/usr.bin/script/script.c script/script.c
--- /usr/src/usr.bin/script/script.c	Sun Feb 15 12:30:13 2004
+++ script/script.c	Fri Mar  3 12:18:58 2006
@@ -81,19 +81,20 @@
 int
 main(int argc, char *argv[])
 {
-	int cc;
+	int cc, ccount;
 	struct termios rtt, stt;
 	struct winsize win;
-	int aflg, kflg, ch, n;
+	int aflg, kflg, cflg, ch, n;
 	struct timeval tv, *tvp;
 	time_t tvec, start;
+	char *ptr;
 	char obuf[BUFSIZ];
 	char ibuf[BUFSIZ];
 	fd_set rfd;
 	int flushtime = 30;
 
-	aflg = kflg = 0;
-	while ((ch = getopt(argc, argv, "aqkt:")) != -1)
+	aflg = kflg = cflg = 0;
+	while ((ch = getopt(argc, argv, "aqkct:")) != -1)
 		switch(ch) {
 		case 'a':
 			aflg = 1;
@@ -104,6 +105,9 @@
 		case 'k':
 			kflg = 1;
 			break;
+		case 'c':
+			cflg = 1;
+			break;
 		case 't':
 			flushtime = atoi(optarg);
 			if (flushtime < 0)
@@ -195,6 +199,17 @@
 			if (cc <= 0)
 				break;
 			(void)write(STDOUT_FILENO, obuf, cc);
+
+			/* 
+			* Suppress carriage-returns if cflg set.
+			*/
+
+			if ( cflg ) {
+				for ( ptr = strnstr( obuf, "\r\n", cc ); ptr != NULL; 
+				      ptr = strnstr( ptr, "\r\n", ccount ))
+					bcopy( ptr + 1, ptr, ccount = --cc - ( ptr - obuf ));
+			}
+
 			(void)fwrite(obuf, 1, cc, fscript);
 		}
 		tvec = time(0);
--- diff.txt ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:
