Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 May 2001 23:34:00 -0400
From:      Mike Heffner <mheffner@cowpie.acm.vt.edu>
To:        freebsd-audit@freebsd.org
Subject:   col(1) patch
Message-ID:  <20010527233400.B85869@cowpie.acm.vt.edu>

next in thread | raw e-mail | index | archive | help
From NetBSD add -p option to pass unknown control sequences instead of
the default of dropping them.

Also, use err(3) and style(9) cleanup.

Please review.

Index: col.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/col/col.1,v
retrieving revision 1.7
diff -u -r1.7 col.1
--- col.1	2001/05/11 23:53:46	1.7
+++ col.1	2001/05/27 04:55:41
@@ -43,7 +43,7 @@
 .Nd filter reverse line feeds from input
 .Sh SYNOPSIS
 .Nm
-.Op Fl bfhx
+.Op Fl bfhpx
 .Op Fl l Ar num
 .Sh DESCRIPTION
 .Nm Col
@@ -69,6 +69,12 @@
 on the following line.
 .It Fl h
 Don't output multiple spaces instead of tabs (default).
+.It Fl p
+Force unknown control sequences to be passed through unchanged.
+Normally,
+.Nm
+will filter out any control sequences from the input other than those
+recognized and interpreted by itself, which are listed below.
 .It Fl x
 Output multiple spaces instead of tabs.
 .It Fl l Ar num
Index: col.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/col/col.c,v
retrieving revision 1.9
diff -u -r1.9 col.c
--- col.c	2001/05/26 22:45:14	1.9
+++ col.c	2001/05/27 04:55:42
@@ -101,7 +101,6 @@
 void	free_line __P((LINE *));
 int	main __P((int, char **));
 void	usage __P((void));
-void	wrerr __P((void));
 void   *xmalloc __P((void *, size_t));
 
 CSET	last_set;		/* char_set of last char printed */
@@ -111,11 +110,12 @@
 int	max_bufd_lines;		/* max # lines to keep in memory */
 int	nblank_lines;		/* # blanks after last flushed line */
 int	no_backspaces;		/* if not to output any backspaces */
+int	pass_unknown_seqs;	/* pass unknown control sequences */
 
 #define	PUTC(ch) \
-	do {				\
-		if (putchar(ch) == EOF) \
-			wrerr();	\
+	do {					\
+		if (putchar(ch) == EOF)		\
+			errx(1, "write error");	\
 	} while (0)
 
 int
@@ -135,11 +135,11 @@
 	int nflushd_lines;		/* number of lines that were flushed */
 	int adjust, opt, warned;
 
-	(void) setlocale(LC_CTYPE, "");
+	(void)setlocale(LC_CTYPE, "");
 
 	max_bufd_lines = 128;
 	compress_spaces = 1;		/* compress spaces into tabs */
-	while ((opt = getopt(argc, argv, "bfhl:x")) != -1)
+	while ((opt = getopt(argc, argv, "bfhl:px")) != -1)
 		switch (opt) {
 		case 'b':		/* do not output backspaces */
 			no_backspaces = 1;
@@ -154,6 +154,9 @@
 			if ((max_bufd_lines = atoi(optarg)) <= 0)
 				errx(1, "bad -l argument %s", optarg);
 			break;
+		case 'p':		/* pass unknown control sequences */
+			pass_unknown_seqs = 1;
+			break;
 		case 'x':		/* do not compress spaces into tabs */
 			compress_spaces = 0;
 			break;
@@ -221,7 +224,8 @@
 				cur_line -= 2;
 				continue;
 			}
-			continue;
+			if (!pass_unknown_seqs)
+				continue;
 		}
 
 		/* Must stuff ch in a line - are we at the right one? */
@@ -284,8 +288,8 @@
 			int need;
 
 			need = l->l_lsize ? l->l_lsize * 2 : 90;
-			l->l_line = (CHAR *)xmalloc((void *) l->l_line,
-			    (unsigned) need * sizeof(CHAR));
+			l->l_line = xmalloc(l->l_line,
+			    (unsigned)need * sizeof(CHAR));
 			l->l_lsize = need;
 		}
 		c = &l->l_line[l->l_line_len++];
@@ -340,7 +344,7 @@
 		}
 		nblank_lines++;
 		if (l->l_line)
-			(void)free((void *)l->l_line);
+			(void)free(l->l_line);
 		free_line(l);
 	}
 	if (lines)
@@ -401,15 +405,15 @@
 		 */
 		if (l->l_lsize > sorted_size) {
 			sorted_size = l->l_lsize;
-			sorted = (CHAR *)xmalloc((void *)sorted,
+			sorted = xmalloc(sorted,
 			    (unsigned)sizeof(CHAR) * sorted_size);
 		}
 		if (l->l_max_col >= count_size) {
 			count_size = l->l_max_col + 1;
-			count = (int *)xmalloc((void *)count,
+			count = xmalloc(count,
 			    (unsigned)sizeof(int) * count_size);
 		}
-		memset((char *)count, 0, sizeof(int) * l->l_max_col + 1);
+		memset(count, 0, sizeof(int) * l->l_max_col + 1);
 		for (i = nchars, c = l->l_line; --i >= 0; c++)
 			count[c->c_column]++;
 
@@ -494,7 +498,7 @@
 	int i;
 
 	if (!line_freelist) {
-		l = (LINE *)xmalloc((void *)NULL, sizeof(LINE) * NALLOC);
+		l = xmalloc(NULL, sizeof(LINE) * NALLOC);
 		line_freelist = l;
 		for (i = 1; i < NALLOC; i++, l++)
 			l->l_next = l + 1;
@@ -522,8 +526,8 @@
 	size_t size;
 {
 
-	if (!(p = (void *)realloc(p, size)))
-		err(1, NULL);
+	if (!(p = realloc(p, size)))
+		err(1, (char *)NULL);
 	return (p);
 }
 
@@ -531,15 +535,8 @@
 usage()
 {
 
-	(void)fprintf(stderr, "usage: col [-bfhx] [-l nline]\n");
+	(void)fprintf(stderr, "usage: col [-bfhpx] [-l nline]\n");
 	exit(1);
-}
-
-void
-wrerr()
-{
-
-	errx(1, "write error");
 }
 
 void

Also at: http://people.freebsd.org/~mikeh/diffs/col.diff

Mike

-- 

  Mike Heffner               <mheffner@vt.edu>
  Fredericksburg, VA       <mikeh@FreeBSD.org>
      http://filebox.vt.edu/users/mheffner

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




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