bin/94052: [PATCH]: Adds option to script(1) to suppress
carriage-returns in log file.
James Bailie
jimmy at jamesbailie.com
Fri Mar 3 09:40:05 PST 2006
>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:
>Originator: James Bailie <jimmy at 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 at 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:
More information about the freebsd-bugs
mailing list