[Midnightbsd-cvs] src [11264] trunk/usr.bin/ul/ul.c: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Jul 3 19:54:09 EDT 2018


Revision: 11264
          http://svnweb.midnightbsd.org/src/?rev=11264
Author:   laffer1
Date:     2018-07-03 19:54:09 -0400 (Tue, 03 Jul 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/usr.bin/ul/Makefile
    trunk/usr.bin/ul/ul.1
    trunk/usr.bin/ul/ul.c

Property Changed:
----------------
    trunk/usr.bin/ul/ul.1

Modified: trunk/usr.bin/ul/Makefile
===================================================================
--- trunk/usr.bin/ul/Makefile	2018-07-03 23:53:17 UTC (rev 11263)
+++ trunk/usr.bin/ul/Makefile	2018-07-03 23:54:09 UTC (rev 11264)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/ul/Makefile 87700 2001-12-11 23:27:23Z markm $
 
 PROG=	ul
 

Modified: trunk/usr.bin/ul/ul.1
===================================================================
--- trunk/usr.bin/ul/ul.1	2018-07-03 23:53:17 UTC (rev 11263)
+++ trunk/usr.bin/ul/ul.1	2018-07-03 23:54:09 UTC (rev 11264)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -26,7 +27,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)ul.1	8.1 (Berkeley) 6/6/93
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/ul/ul.1 216370 2010-12-11 08:32:16Z joel $
 .\"
 .Dd August 4, 2004
 .Dt UL 1


Property changes on: trunk/usr.bin/ul/ul.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/ul/ul.c
===================================================================
--- trunk/usr.bin/ul/ul.c	2018-07-03 23:53:17 UTC (rev 11263)
+++ trunk/usr.bin/ul/ul.c	2018-07-03 23:54:09 UTC (rev 11264)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1980, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -38,7 +39,7 @@
 static char sccsid[] = "@(#)ul.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$MidnightBSD$";
+  "$FreeBSD: stable/10/usr.bin/ul/ul.c 303075 2016-07-20 07:33:48Z gahr $";
 #endif /* not lint */
 
 #include <err.h>
@@ -66,8 +67,8 @@
 #define	UNDERL	010	/* Ul */
 #define	BOLD	020	/* Bold */
 
-int	must_use_uc, must_overstrike;
-const char
+static int	must_use_uc, must_overstrike;
+static const char
 	*CURS_UP, *CURS_RIGHT, *CURS_LEFT,
 	*ENTER_STANDOUT, *EXIT_STANDOUT, *ENTER_UNDERLINE, *EXIT_UNDERLINE,
 	*ENTER_DIM, *ENTER_BOLD, *ENTER_REVERSE, *UNDER_CHAR, *EXIT_ATTRIBUTES;
@@ -78,25 +79,27 @@
 	int	c_width;	/* width or -1 if multi-column char. filler */
 } ;
 
-struct	CHAR	obuf[MAXBUF];
-int	col, maxcol;
-int	mode;
-int	halfpos;
-int	upln;
-int	iflag;
+static struct	CHAR	sobuf[MAXBUF]; /* static output buffer */
+static struct	CHAR	*obuf = sobuf;
+static int	buflen = MAXBUF;
+static int	col, maxcol;
+static int	mode;
+static int	halfpos;
+static int	upln;
+static int	iflag;
 
 static void usage(void);
-void setnewmode(int);
-void initcap(void);
-void reverse(void);
-int outchar(int);
-void fwd(void);
-void initbuf(void);
-void iattr(void);
-void overstrike(void);
-void flushln(void);
-void filter(FILE *);
-void outc(wint_t, int);
+static void setnewmode(int);
+static void initcap(void);
+static void reverse(void);
+static int outchar(int);
+static void fwd(void);
+static void initbuf(void);
+static void iattr(void);
+static void overstrike(void);
+static void flushln(void);
+static void filter(FILE *);
+static void outc(wint_t, int);
 
 #define	PRINT(s)	if (s == NULL) /* void */; else tputs(s, 1, outchar)
 
@@ -155,6 +158,9 @@
 		else
 			filter(f);
 	}
+	if (obuf != sobuf) {
+		free(obuf);
+	}
 	exit(0);
 }
 
@@ -165,133 +171,153 @@
 	exit(1);
 }
 
-void
+static void
 filter(FILE *f)
 {
 	wint_t c;
 	int i, w;
+	int copy;
+	
+	copy = 0;
 
-	while ((c = getwc(f)) != WEOF && col < MAXBUF) switch(c) {
+	while ((c = getwc(f)) != WEOF) {
+		if (col == buflen) {
+			if (obuf == sobuf) {
+				obuf = NULL;
+				copy = 1;
+			}
+			obuf = realloc(obuf, sizeof(*obuf) * 2 * buflen);
+			if (obuf == NULL) {
+				obuf = sobuf;
+				break;
+			} else if (copy) {
+				memcpy(obuf, sobuf, sizeof(*obuf) * buflen);
+				copy = 0;
+			}
+			bzero((char *)(obuf + buflen), sizeof(*obuf) * buflen);
+			buflen *= 2;
+		}
+		switch(c) {
+		case '\b':
+			if (col > 0)
+				col--;
+			continue;
 
-	case '\b':
-		if (col > 0)
-			col--;
-		continue;
+		case '\t':
+			col = (col+8) & ~07;
+			if (col > maxcol)
+				maxcol = col;
+			continue;
 
-	case '\t':
-		col = (col+8) & ~07;
-		if (col > maxcol)
-			maxcol = col;
-		continue;
+		case '\r':
+			col = 0;
+			continue;
 
-	case '\r':
-		col = 0;
-		continue;
+		case SO:
+			mode |= ALTSET;
+			continue;
 
-	case SO:
-		mode |= ALTSET;
-		continue;
+		case SI:
+			mode &= ~ALTSET;
+			continue;
 
-	case SI:
-		mode &= ~ALTSET;
-		continue;
+		case IESC:
+			switch (c = getwc(f)) {
 
-	case IESC:
-		switch (c = getwc(f)) {
+			case HREV:
+				if (halfpos == 0) {
+					mode |= SUPERSC;
+					halfpos--;
+				} else if (halfpos > 0) {
+					mode &= ~SUBSC;
+					halfpos--;
+				} else {
+					halfpos = 0;
+					reverse();
+				}
+				continue;
 
-		case HREV:
-			if (halfpos == 0) {
-				mode |= SUPERSC;
-				halfpos--;
-			} else if (halfpos > 0) {
-				mode &= ~SUBSC;
-				halfpos--;
-			} else {
-				halfpos = 0;
+			case HFWD:
+				if (halfpos == 0) {
+					mode |= SUBSC;
+					halfpos++;
+				} else if (halfpos < 0) {
+					mode &= ~SUPERSC;
+					halfpos++;
+				} else {
+					halfpos = 0;
+					fwd();
+				}
+				continue;
+
+			case FREV:
 				reverse();
+				continue;
+
+			default:
+				errx(1, "unknown escape sequence in input: %o, %o", IESC, c);
 			}
 			continue;
 
-		case HFWD:
-			if (halfpos == 0) {
-				mode |= SUBSC;
-				halfpos++;
-			} else if (halfpos < 0) {
-				mode &= ~SUPERSC;
-				halfpos++;
-			} else {
-				halfpos = 0;
-				fwd();
+		case '_':
+			if (obuf[col].c_char || obuf[col].c_width < 0) {
+				while (col > 0 && obuf[col].c_width < 0)
+					col--;
+				w = obuf[col].c_width;
+				for (i = 0; i < w; i++)
+					obuf[col++].c_mode |= UNDERL | mode;
+				if (col > maxcol)
+					maxcol = col;
+				continue;
 			}
+			obuf[col].c_char = '_';
+			obuf[col].c_width = 1;
+			/* FALLTHROUGH */
+		case ' ':
+			col++;
+			if (col > maxcol)
+				maxcol = col;
 			continue;
 
-		case FREV:
-			reverse();
+		case '\n':
+			flushln();
 			continue;
 
+		case '\f':
+			flushln();
+			putwchar('\f');
+			continue;
+
 		default:
-			errx(1, "unknown escape sequence in input: %o, %o", IESC, c);
-		}
-		continue;
-
-	case '_':
-		if (obuf[col].c_char || obuf[col].c_width < 0) {
-			while (col > 0 && obuf[col].c_width < 0)
-				col--;
-			w = obuf[col].c_width;
-			for (i = 0; i < w; i++)
-				obuf[col++].c_mode |= UNDERL | mode;
+			if ((w = wcwidth(c)) <= 0)	/* non printing */
+				continue;
+			if (obuf[col].c_char == '\0') {
+				obuf[col].c_char = c;
+				for (i = 0; i < w; i++)
+					obuf[col + i].c_mode = mode;
+				obuf[col].c_width = w;
+				for (i = 1; i < w; i++)
+					obuf[col + i].c_width = -1;
+			} else if (obuf[col].c_char == '_') {
+				obuf[col].c_char = c;
+				for (i = 0; i < w; i++)
+					obuf[col + i].c_mode |= UNDERL|mode;
+				obuf[col].c_width = w;
+				for (i = 1; i < w; i++)
+					obuf[col + i].c_width = -1;
+			} else if ((wint_t)obuf[col].c_char == c) {
+				for (i = 0; i < w; i++)
+					obuf[col + i].c_mode |= BOLD|mode;
+			} else {
+				w = obuf[col].c_width;
+				for (i = 0; i < w; i++)
+					obuf[col + i].c_mode = mode;
+			}
+			col += w;
 			if (col > maxcol)
 				maxcol = col;
 			continue;
 		}
-		obuf[col].c_char = '_';
-		obuf[col].c_width = 1;
-		/* FALLTHROUGH */
-	case ' ':
-		col++;
-		if (col > maxcol)
-			maxcol = col;
-		continue;
-
-	case '\n':
-		flushln();
-		continue;
-
-	case '\f':
-		flushln();
-		putwchar('\f');
-		continue;
-
-	default:
-		if ((w = wcwidth(c)) <= 0)	/* non printing */
-			continue;
-		if (obuf[col].c_char == '\0') {
-			obuf[col].c_char = c;
-			for (i = 0; i < w; i++)
-				obuf[col + i].c_mode = mode;
-			obuf[col].c_width = w;
-			for (i = 1; i < w; i++)
-				obuf[col + i].c_width = -1;
-		} else if (obuf[col].c_char == '_') {
-			obuf[col].c_char = c;
-			for (i = 0; i < w; i++)
-				obuf[col + i].c_mode |= UNDERL|mode;
-			obuf[col].c_width = w;
-			for (i = 1; i < w; i++)
-				obuf[col + i].c_width = -1;
-		} else if (obuf[col].c_char == c) {
-			for (i = 0; i < w; i++)
-				obuf[col + i].c_mode |= BOLD|mode;
-		} else {
-			w = obuf[col].c_width;
-			for (i = 0; i < w; i++)
-				obuf[col + i].c_mode = mode;
-		}
-		col += w;
-		if (col > maxcol)
-			maxcol = col;
-		continue;
 	}
 	if (ferror(f))
 		err(1, NULL);
@@ -299,7 +325,7 @@
 		flushln();
 }
 
-void
+static void
 flushln(void)
 {
 	int lastmode;
@@ -341,7 +367,7 @@
  * For terminals that can overstrike, overstrike underlines and bolds.
  * We don't do anything with halfline ups and downs, or Greek.
  */
-void
+static void
 overstrike(void)
 {
 	int i;
@@ -381,7 +407,7 @@
 	}
 }
 
-void
+static void
 iattr(void)
 {
 	int i;
@@ -405,17 +431,17 @@
 	putwchar('\n');
 }
 
-void
+static void
 initbuf(void)
 {
 
-	bzero((char *)obuf, sizeof (obuf));	/* depends on NORMAL == 0 */
+	bzero((char *)obuf, buflen * sizeof(*obuf)); /* depends on NORMAL == 0 */
 	col = 0;
 	maxcol = 0;
 	mode &= ALTSET;
 }
 
-void
+static void
 fwd(void)
 {
 	int oldcol, oldmax;
@@ -427,7 +453,7 @@
 	maxcol = oldmax;
 }
 
-void
+static void
 reverse(void)
 {
 	upln++;
@@ -437,7 +463,7 @@
 	upln++;
 }
 
-void
+static void
 initcap(void)
 {
 	static char tcapbuf[512];
@@ -490,7 +516,7 @@
 	must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
 }
 
-int
+static int
 outchar(int c)
 {
 	return (putwchar(c) != WEOF ? c : EOF);
@@ -498,7 +524,7 @@
 
 static int curmode = 0;
 
-void
+static void
 outc(wint_t c, int width)
 {
 	int i;
@@ -512,7 +538,7 @@
 	}
 }
 
-void
+static void
 setnewmode(int newmode)
 {
 	if (!iflag) {



More information about the Midnightbsd-cvs mailing list