Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Oct 2001 23:07:34 +0200 (CEST)
From:      Maxime Henrion <mux@qualys.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/31205: [PATCH] WARNSify and add a new option to script(1)
Message-ID:  <200110102107.f9AL7YQ07781@noos.fr>

next in thread | raw e-mail | index | archive | help

>Number:         31205
>Category:       bin
>Synopsis:       [PATCH] WARNSify and add a new option to script(1)
>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:   Wed Oct 10 14:10:07 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Maxime Henrion
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
None.
>Environment:
System: FreeBSD nebula 5.0-CURRENT FreeBSD 5.0-CURRENT #120: Wed Oct 10 17:46:49 CEST 2001 mux@nebula.cybercable.fr:/usr/src/sys/i386/compile/NEBULA i386

>Description:
	This patch WARNSify the script(1) command and add a new option
(-A) to rip ascii characters 13 out.  Since the WARNS changes are just
two `const' to add, I didn't separate the two patches.  I can send them
separate on demand.

>How-To-Repeat:
>Fix:

--- script.diff begins here ---
Index: Makefile
===================================================================
RCS file: /home/ncvs/src/usr.bin/script/Makefile,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Makefile
--- Makefile	27 May 1994 12:32:38 -0000	1.1.1.1
+++ Makefile	10 Oct 2001 20:53:52 -0000
@@ -4,4 +4,6 @@
 LDADD=	-lutil
 DPADD=	${LIBUTIL}
 
+WARNS?=	2
+
 .include <bsd.prog.mk>
Index: script.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/script/script.1,v
retrieving revision 1.15
diff -u -r1.15 script.1
--- script.1	15 Jul 2001 08:01:34 -0000	1.15
+++ script.1	10 Oct 2001 21:00:46 -0000
@@ -41,6 +41,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl a
+.Op Fl A
 .Op Fl k
 .Op Fl q
 .Op Fl t Ar time
@@ -77,6 +78,8 @@
 or
 .Pa typescript ,
 retaining the prior contents.
+.It Fl A
+Skip the ASCII 13 characters from the script output file.
 .It Fl k
 Log keys sent to program as well as output.
 .It Fl q
@@ -141,7 +144,8 @@
 .Nm Script
 places
 .Sy everything
-in the log file, including linefeeds and backspaces.
+(except if you use the -A option), in the log file,
+including linefeeds and backspaces.
 This is not what the naive user expects.
 .Pp
 It is not possible to specify a command without also naming the script file
Index: script.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/script/script.c,v
retrieving revision 1.15
diff -u -r1.15 script.c
--- script.c	26 Jul 2001 11:02:35 -0000	1.15
+++ script.c	10 Oct 2001 01:08:04 -0000
@@ -66,8 +66,8 @@
 FILE	*fscript;
 int	master, slave;
 int	child;
-char	*fname;
-int	qflg;
+const char	*fname;
+int	Aflg, qflg;
 
 struct	termios tt;
 
@@ -76,6 +76,7 @@
 void	doshell __P((char **));
 void	fail __P((void));
 void	finish __P((void));
+void	log_write __P((const char *, int));
 static void usage __P((void));
 
 int
@@ -95,11 +96,14 @@
 	int flushtime = 30;
 
 	aflg = kflg = 0;
-	while ((ch = getopt(argc, argv, "aqkt:")) != -1)
+	while ((ch = getopt(argc, argv, "aAqkt:")) != -1)
 		switch(ch) {
 		case 'a':
 			aflg = 1;
 			break;
+		case 'A':
+			Aflg = 1;
+			break;
 		case 'q':
 			qflg = 1;
 			break;
@@ -177,7 +181,7 @@
 				(void)write(master, ibuf, cc);
 				if (kflg && tcgetattr(master, &stt) >= 0 &&
 				    ((stt.c_lflag & ECHO) == 0)) {
-					(void)fwrite(ibuf, 1, cc, fscript);
+					log_write(ibuf, cc);
 				}
 			}
 		}
@@ -186,7 +190,7 @@
 			if (cc <= 0)
 				break;
 			(void)write(STDOUT_FILENO, obuf, cc);
-			(void)fwrite(obuf, 1, cc, fscript);
+			log_write(obuf, cc);
 		}
 		tvec = time(0);
 		if (tvec - start >= flushtime) {
@@ -202,7 +206,7 @@
 usage()
 {
 	(void)fprintf(stderr,
-	    "usage: script [-a] [-q] [-k] [-t time] [file] [command]\n");
+	    "usage: script [-a] [-A] [-q] [-k] [-t time] [file] [command]\n");
 	exit(1);
 }
 
@@ -232,7 +236,7 @@
 doshell(av)
 	char **av;
 {
-	char *shell;
+	const char *shell;
 
 	shell = getenv("SHELL");
 	if (shell == NULL)
@@ -273,4 +277,24 @@
 	(void)fclose(fscript);
 	(void)close(master);
 	exit(eno);
+}
+
+void
+log_write(const char *buf, int size)
+{
+	int off, i;
+
+	if (!Aflg) {
+		(void)fwrite(buf, 1, size, fscript);
+		return;
+	}
+	off = 0;
+	do {
+		i = 0;
+		while ((off + i < size) && (buf[off + i] != '\r'))
+			i++;
+		if (i > 0)
+			(void)fwrite(buf + off, 1, i, fscript);
+		off += i + 1;
+	} while (off < size);
 }
--- script.diff ends here ---


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

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110102107.f9AL7YQ07781>