[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Wed Jul 25 14:36:07 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/49f3e3227aef
changeset: 491:49f3e3227aef
user:      Aleksandr Rybalko <ray at ddteam.net>
date:      Wed Jul 25 16:31:11 2012 +0300
description:
Lazy update

diffstat:

 head/usr.bin/Makefile                            |    36 +-
 head/usr.bin/ar/Makefile                         |     6 +-
 head/usr.bin/ar/acpyacc.y                        |     3 +-
 head/usr.bin/bc/bc.y                             |     3 +-
 head/usr.bin/calendar/calendar.1                 |     4 +-
 head/usr.bin/calendar/calendars/calendar.freebsd |     6 +-
 head/usr.bin/chat/chat.c                         |     4 +-
 head/usr.bin/clang/clang/Makefile                |     3 +-
 head/usr.bin/clang/clang/clang.1                 |     4 +-
 head/usr.bin/clang/tblgen/tblgen.1               |     4 +-
 head/usr.bin/csup/csup.1                         |     6 +-
 head/usr.bin/ctlstat/ctlstat.8                   |     6 +-
 head/usr.bin/cut/cut.1                           |    12 +-
 head/usr.bin/cut/cut.c                           |     8 +-
 head/usr.bin/dc/dc.1                             |     8 +-
 head/usr.bin/du/du.1                             |    16 +-
 head/usr.bin/du/du.c                             |     8 +-
 head/usr.bin/fetch/fetch.1                       |    13 +-
 head/usr.bin/find/find.1                         |    66 +-
 head/usr.bin/find/getdate.y                      |     4 +-
 head/usr.bin/fstat/Makefile                      |     4 +-
 head/usr.bin/fstat/fstat.c                       |     4 +-
 head/usr.bin/gprof/gprof.1                       |     4 +-
 head/usr.bin/gprof/lookup.c                      |     8 +-
 head/usr.bin/gzip/zmore.1                        |     4 +-
 head/usr.bin/ipcrm/ipcrm.1                       |     4 +-
 head/usr.bin/join/join.1                         |     2 +-
 head/usr.bin/kdump/kdump.1                       |     8 +-
 head/usr.bin/kdump/kdump.c                       |     8 +-
 head/usr.bin/kdump/mkioctls                      |     4 +-
 head/usr.bin/killall/killall.1                   |     8 +-
 head/usr.bin/killall/killall.c                   |    42 +-
 head/usr.bin/ktrace/ktrace.1                     |     6 +-
 head/usr.bin/ktrace/ktrace.h                     |     8 +-
 head/usr.bin/lastcomm/lastcomm.1                 |    15 +-
 head/usr.bin/lastcomm/lastcomm.c                 |    30 +-
 head/usr.bin/less/defines.h                      |    14 +-
 head/usr.bin/lex/lex.1                           |     5 +-
 head/usr.bin/limits/limits.1                     |     6 +-
 head/usr.bin/login/login.1                       |     4 +-
 head/usr.bin/m4/parser.y                         |     7 +-
 head/usr.bin/mail/popen.c                        |     6 +-
 head/usr.bin/make/Makefile                       |     8 +-
 head/usr.bin/make/make.1                         |    30 +-
 head/usr.bin/make/var.c                          |    31 +-
 head/usr.bin/makewhatis/makewhatis.c             |     4 +-
 head/usr.bin/man/man.conf.5                      |     9 +-
 head/usr.bin/minigzip/Makefile                   |     4 +-
 head/usr.bin/minigzip/minigzip.1                 |     6 +-
 head/usr.bin/mkcsmapper/ldef.h                   |     3 +-
 head/usr.bin/mkcsmapper/lex.l                    |     4 +-
 head/usr.bin/mkesdb/ldef.h                       |     3 +-
 head/usr.bin/mkesdb/lex.l                        |     4 +-
 head/usr.bin/mklocale/extern.h                   |     3 +-
 head/usr.bin/mklocale/mklocale.1                 |     4 +-
 head/usr.bin/ncplogin/ncplogout.1                |     4 +-
 head/usr.bin/netstat/Makefile                    |     6 +-
 head/usr.bin/netstat/inet.c                      |     7 +-
 head/usr.bin/netstat/sctp.c                      |     6 +-
 head/usr.bin/nfsstat/nfsstat.c                   |     5 +-
 head/usr.bin/pamtest/Makefile                    |    11 +
 head/usr.bin/passwd/passwd.1                     |     4 +-
 head/usr.bin/procstat/Makefile                   |     4 +-
 head/usr.bin/procstat/procstat.1                 |     8 +-
 head/usr.bin/procstat/procstat_rlimit.c          |     6 +-
 head/usr.bin/procstat/procstat_vm.c              |     8 +-
 head/usr.bin/rctl/rctl.8                         |     4 +-
 head/usr.bin/rlogin/rlogin.1                     |     4 +-
 head/usr.bin/rsh/rsh.1                           |     4 +-
 head/usr.bin/sockstat/sockstat.1                 |     7 +-
 head/usr.bin/sockstat/sockstat.c                 |    37 +-
 head/usr.bin/sort/Makefile                       |    45 +
 head/usr.bin/sort/bwstring.c                     |  1154 +++++++++++++
 head/usr.bin/sort/bwstring.h                     |   142 +
 head/usr.bin/sort/coll.c                         |  1301 ++++++++++++++
 head/usr.bin/sort/coll.h                         |   167 +
 head/usr.bin/sort/file.c                         |  1632 ++++++++++++++++++
 head/usr.bin/sort/file.h                         |   138 +
 head/usr.bin/sort/mem.c                          |    82 +
 head/usr.bin/sort/mem.h                          |    45 +
 head/usr.bin/sort/nls/C.msg                      |    16 +
 head/usr.bin/sort/nls/hu_HU.ISO8859-2.msg        |    16 +
 head/usr.bin/sort/radixsort.c                    |   691 +++++++
 head/usr.bin/sort/radixsort.h                    |    38 +
 head/usr.bin/sort/sort.1.in                      |   638 +++++++
 head/usr.bin/sort/sort.c                         |  1335 +++++++++++++++
 head/usr.bin/sort/sort.h                         |   128 +
 head/usr.bin/sort/vsort.c                        |   265 +++
 head/usr.bin/sort/vsort.h                        |    37 +
 head/usr.bin/stat/stat.1                         |     8 +-
 head/usr.bin/stdbuf/Makefile                     |     8 +
 head/usr.bin/stdbuf/stdbuf.1                     |   116 +
 head/usr.bin/stdbuf/stdbuf.c                     |   110 +
 head/usr.bin/tftp/tftp.1                         |     6 +-
 head/usr.bin/top/machine.c                       |    86 +-
 head/usr.bin/top/top.local.1                     |    27 +-
 head/usr.bin/touch/touch.1                       |    44 +-
 head/usr.bin/touch/touch.c                       |    60 +-
 head/usr.bin/unzip/unzip.1                       |    14 +-
 head/usr.bin/unzip/unzip.c                       |    17 +-
 head/usr.bin/usbhidctl/usbhid.c                  |     8 +-
 head/usr.bin/usbhidctl/usbhidctl.1               |    11 +-
 head/usr.bin/who/who.1                           |     4 +-
 head/usr.bin/whois/whois.1                       |     4 +-
 head/usr.bin/xinstall/xinstall.c                 |    27 +-
 head/usr.bin/yacc/ACKNOWLEDGEMENTS               |    25 -
 head/usr.bin/yacc/Makefile                       |    17 +-
 head/usr.bin/yacc/NEW_FEATURES                   |    48 -
 head/usr.bin/yacc/NOTES                          |     9 -
 head/usr.bin/yacc/README                         |    23 -
 head/usr.bin/yacc/closure.c                      |   306 ---
 head/usr.bin/yacc/defs.h                         |   348 ---
 head/usr.bin/yacc/error.c                        |   341 ---
 head/usr.bin/yacc/lalr.c                         |   701 --------
 head/usr.bin/yacc/lr0.c                          |   671 -------
 head/usr.bin/yacc/main.c                         |   438 -----
 head/usr.bin/yacc/mkpar.c                        |   404 ----
 head/usr.bin/yacc/output.c                       |  1342 ---------------
 head/usr.bin/yacc/reader.c                       |  1924 ----------------------
 head/usr.bin/yacc/skeleton.c                     |   426 ----
 head/usr.bin/yacc/symtab.c                       |   162 -
 head/usr.bin/yacc/test/error.output              |    27 -
 head/usr.bin/yacc/test/error.tab.c               |   317 ---
 head/usr.bin/yacc/test/error.y                   |     6 -
 head/usr.bin/yacc/test/ftp.output                |  1625 ------------------
 head/usr.bin/yacc/test/ftp.tab.c                 |  1785 --------------------
 head/usr.bin/yacc/test/ftp.tab.h                 |    63 -
 head/usr.bin/yacc/test/ftp.y                     |  1180 -------------
 head/usr.bin/yacc/verbose.c                      |   381 ----
 head/usr.bin/yacc/warshall.c                     |   123 -
 head/usr.bin/yacc/yacc.1                         |   169 -
 head/usr.bin/yacc/yyfix.1                        |   110 -
 head/usr.bin/yacc/yyfix.sh                       |    74 -
 133 files changed, 8771 insertions(+), 13353 deletions(-)

diffs (24393 lines):

diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/Makefile
--- a/head/usr.bin/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,5 +1,5 @@
 #	From: @(#)Makefile	8.3 (Berkeley) 1/7/94
-# $FreeBSD: head/usr.bin/Makefile 233337 2012-03-23 03:16:35Z stas $
+# $FreeBSD: head/usr.bin/Makefile 238564 2012-07-18 07:07:54Z obrien $
 
 .include <bsd.own.mk>
 
@@ -105,6 +105,7 @@
 	mkfifo \
 	mklocale \
 	mktemp \
+	mkulzma \
 	mkuzip \
 	mt \
 	ncal \
@@ -141,8 +142,10 @@
 	shar \
 	showmount \
 	sockstat \
+	sort \
 	split \
 	stat \
+	stdbuf \
 	su \
 	systat \
 	tabs \
@@ -205,10 +208,6 @@
 SUBDIR+=	atm
 .endif
 
-.if ${MK_MAN_UTILS} != "no"
-SUBDIR+=	catman
-.endif
-
 .if ${MK_BIND_UTILS} != "no"
 SUBDIR+=	dig
 SUBDIR+=	host
@@ -232,6 +231,10 @@
 _clang=		clang
 .endif
 
+.if ${MK_GROFF} != "no"
+SUBDIR+=	vgrind
+.endif
+
 .if ${MK_HESIOD} != "no"
 SUBDIR+=	hesinfo
 .endif
@@ -242,15 +245,8 @@
 _mkesdb=	mkesdb
 .endif
 
-.if ${MK_GROFF} != "no"
-SUBDIR+=	vgrind
-.endif
-
-.if ${MK_OPENSSL} != "no"
-SUBDIR+=	bc
-SUBDIR+=	chkey
-SUBDIR+=	dc
-SUBDIR+=	newkey
+.if ${MK_KERBEROS_SUPPORT} != "no"
+SUBDIR+=	compile_et
 .endif
 
 .if ${MK_LIBTHR} != "no"
@@ -261,10 +257,6 @@
 SUBDIR+=	locate
 .endif
 
-.if ${MK_KERBEROS_SUPPORT} != "no"
-SUBDIR+=	compile_et
-.endif
-
 # XXX msgs?
 .if ${MK_MAIL} != "no"
 SUBDIR+=	biff
@@ -278,6 +270,7 @@
 .endif
 
 .if ${MK_MAN_UTILS} != "no"
+SUBDIR+=	catman
 _makewhatis=	makewhatis
 _man=		man
 .endif
@@ -292,6 +285,13 @@
 SUBDIR+=	ypwhich
 .endif
 
+.if ${MK_OPENSSL} != "no"
+SUBDIR+=	bc
+SUBDIR+=	chkey
+SUBDIR+=	dc
+SUBDIR+=	newkey
+.endif
+
 .if ${MK_QUOTAS} != "no"
 SUBDIR+=	quota
 .endif
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ar/Makefile
--- a/head/usr.bin/ar/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ar/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,6 @@
-# $FreeBSD$
+# $FreeBSD: head/usr.bin/ar/Makefile 234782 2012-04-29 09:32:44Z kib $
+
+.include <bsd.own.mk>
 
 PROG=	ar
 SRCS=	ar.c acplex.l acpyacc.y read.c util.c write.c y.tab.h
@@ -8,7 +10,9 @@
 
 CFLAGS+=-I. -I${.CURDIR}
 
+.if ${MK_SHARED_TOOLCHAIN} == "no"
 NO_SHARED?=	yes
+.endif
 LINKS=	${BINDIR}/ar ${BINDIR}/ranlib
 MLINKS= ar.1 ranlib.1
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ar/acpyacc.y
--- a/head/usr.bin/ar/acpyacc.y	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ar/acpyacc.y	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/ar/acpyacc.y 222122 2011-05-20 11:29:09Z bcr $");
+__FBSDID("$FreeBSD: head/usr.bin/ar/acpyacc.y 235789 2012-05-22 16:33:10Z bapt $");
 
 #include <sys/mman.h>
 #include <sys/param.h>
@@ -54,7 +54,6 @@
 
 
 extern int	yylex(void);
-extern int	yyparse(void);
 
 static void	yyerror(const char *);
 static void	arscp_addlib(char *archive, struct list *list);
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/bc/bc.y
--- a/head/usr.bin/bc/bc.y	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/bc/bc.y	Wed Jul 25 16:31:11 2012 +0300
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/bc/bc.y 232994 2012-03-15 01:43:44Z kevlo $");
+__FBSDID("$FreeBSD: head/usr.bin/bc/bc.y 235789 2012-05-22 16:33:10Z bapt $");
 
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -69,7 +69,6 @@
 	ssize_t			index;
 };
 
-int			 yyparse(void);
 int			 yywrap(void);
 
 int			 fileindex;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/calendar/calendar.1
--- a/head/usr.bin/calendar/calendar.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/calendar/calendar.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)calendar.1  8.1 (Berkeley) 6/29/93
-.\" $FreeBSD: head/usr.bin/calendar/calendar.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/calendar/calendar.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
 .Dd June 13, 2002
 .Dt CALENDAR 1
@@ -218,7 +218,7 @@
 .Sh FILES
 .Bl -tag -width calendar.christian -compact
 .It Pa calendar
-file in current directory
+file in current directory.
 .It Pa ~/.calendar
 .Pa calendar
 HOME directory.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/calendar/calendars/calendar.freebsd
--- a/head/usr.bin/calendar/calendars/calendar.freebsd	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/calendar/calendars/calendar.freebsd	Wed Jul 25 16:31:11 2012 +0300
@@ -1,7 +1,7 @@
 /*
  * FreeBSD
  *
- * $FreeBSD: head/usr.bin/calendar/calendars/calendar.freebsd 234446 2012-04-18 22:56:46Z dteske $
+ * $FreeBSD: head/usr.bin/calendar/calendars/calendar.freebsd 238058 2012-07-03 07:28:57Z zeising $
  */
 
 #ifndef _calendar_freebsd_
@@ -144,6 +144,7 @@
 05/08	Sean Kelly <smkelly at FreeBSD.org> born in Walnut Creek, California, United States, 1982
 05/09	Daniel Eischen <deischen at FreeBSD.org> born in Syracuse, New York, United States, 1963
 05/09	Aaron Dalton <aaron at FreeBSD.org> born in Boise, Idaho, United States, 1973
+05/09	Jase Thew <jase at FreeBSD.org> born in Abergavenny, Gwent, United Kingdom, 1974
 05/10	Markus Brueffer <markus at FreeBSD.org> born in Gronau, Nordrhein-Westfalen, Germany, 1977
 05/11	Jesus Rodriguez <jesusr at FreeBSD.org> born in Barcelona, Spain, 1972
 05/11	Roman Kurakin <rik at FreeBSD.org> born in Moscow, USSR, 1979
@@ -309,6 +310,7 @@
 10/23	Mario Sergio Fujikawa Ferreira <lioux at FreeBSD.org> born in Brasilia, Distrito Federal, Brazil, 1976
 10/25	Eric Melville <eric at FreeBSD.org> born in Los Gatos, California, United States, 1980
 10/25	Julien Laffaye <jlaffaye at FreeBSD.org> born in Toulouse, France, 1988
+10/25	Ashish SHUKLA <ashish at FreeBSD.org> born in Kanpur, India, 1985
 10/26	Philip M. Gollucci <pgollucci at FreeBSD.org> born in Silver Spring, Maryland, United States, 1979
 10/27	Takanori Watanabe <takawata at FreeBSD.org> born in Numazu, Shizuoka, Japan, 1972
 11/05	M. Warner Losh <imp at FreeBSD.org> born in Kansas City, Kansas, United States, 1966
@@ -316,6 +318,7 @@
 11/09	Antoine Brodin <antoine at FreeBSD.org> born in Bagnolet, France, 1981
 11/10	Gregory Neil Shapiro <gshapiro at FreeBSD.org> born in Providence, Rhode Island, United States, 1970
 11/13	John Baldwin <jhb at FreeBSD.org> born in Stuart, Virginia, United States, 1977
+11/14	Jeremie Le Hen <jlh at FreeBSD.org> born in Nancy, France, 1980
 11/15	Lars Engels <lme at FreeBSD.org> born in Hilden, Nordrhein-Westfalen, Germany, 1980
 11/15	Tijl Coosemans <tijl at FreeBSD.org> born in Duffel, Belgium, 1983
 11/16	Jose Maria Alcaide Salinas <jmas at FreeBSD.org> born in Madrid, Spain, 1962
@@ -347,6 +350,7 @@
 12/23	Sean Chittenden <seanc at FreeBSD.org> born in Seattle, Washington, United States, 1979
 12/23	Alejandro Pulver <alepulver at FreeBSD.org> born in Buenos Aires, Argentina, 1989
 12/24	Guido Falsi <madpilot at FreeBSD.org> born in Firenze, Italy, 1978
+12/25	Niclas Zeising <zeising at FreeBSD.org> born in Stockholm, Sweden, 1986
 12/28	Soren Schmidt <sos at FreeBSD.org> born in Maribo, Denmark, 1960
 12/28	Ade Lovett <ade at FreeBSD.org> born in London, England, 1969
 12/28	Marius Strobl <marius at FreeBSD.org> born in Cham, Bavaria, Germany, 1978
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/chat/chat.c
--- a/head/usr.bin/chat/chat.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/chat/chat.c	Wed Jul 25 16:31:11 2012 +0300
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/chat/chat.c 236213 2012-05-29 01:48:06Z kevlo $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -408,6 +408,7 @@
 
     va_start(args, fmt);
     vfmtmsg(line, sizeof(line), fmt, args);
+    va_end(args);
     if (to_log)
 	syslog(LOG_INFO, "%s", line);
     if (to_stderr)
@@ -425,6 +426,7 @@
 
     va_start(args, fmt);
     vfmtmsg(line, sizeof(line), fmt, args);
+    va_end(args);
     if (to_log)
 	syslog(LOG_ERR, "%s", line);
     if (to_stderr)
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/clang/clang/Makefile
--- a/head/usr.bin/clang/clang/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/clang/clang/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/usr.bin/clang/clang/Makefile 234353 2012-04-16 21:23:25Z dim $
+# $FreeBSD: head/usr.bin/clang/clang/Makefile 234982 2012-05-03 20:41:21Z dim $
 
 .include <bsd.own.mk>
 
@@ -41,7 +41,6 @@
 	clangstaticanalyzercheckers \
 	clangstaticanalyzercore \
 	clanganalysis \
-	clangindex \
 	clangarcmigrate \
 	clangrewrite \
 	clangedit \
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/clang/clang/clang.1
--- a/head/usr.bin/clang/clang/clang.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/clang/clang/clang.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-.\" $FreeBSD: head/usr.bin/clang/clang/clang.1 234353 2012-04-16 21:23:25Z dim $
+.\" $FreeBSD: head/usr.bin/clang/clang/clang.1 235211 2012-05-10 02:07:00Z gjb $
 .\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
 .\"
 .\" Standard preamble:
@@ -475,7 +475,7 @@
 .IX Item "CPATH"
 If this environment variable is present, it is treated as a delimited
 list of paths to be added to the default system include path list. The
-delimiter is the platform dependent delimitor, as used in the \fI\s-1PATH\s0\fR
+delimiter is the platform dependent delimiter, as used in the \fI\s-1PATH\s0\fR
 environment variable.
 .Sp
 Empty components in the environment variable are ignored.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/clang/tblgen/tblgen.1
--- a/head/usr.bin/clang/tblgen/tblgen.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/clang/tblgen/tblgen.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-.\" $FreeBSD: head/usr.bin/clang/tblgen/tblgen.1 234353 2012-04-16 21:23:25Z dim $
+.\" $FreeBSD: head/usr.bin/clang/tblgen/tblgen.1 235211 2012-05-10 02:07:00Z gjb $
 .\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14)
 .\"
 .\" Standard preamble:
@@ -175,7 +175,7 @@
 Print all records to standard output (default).
 .IP "\fB\-print\-enums\fR" 4
 .IX Item "-print-enums"
-Print enumeration values for a class
+Print enumeration values for a class.
 .IP "\fB\-print\-sets\fR" 4
 .IX Item "-print-sets"
 Print expanded sets for testing \s-1DAG\s0 exprs.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/csup/csup.1
--- a/head/usr.bin/csup/csup.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/csup/csup.1	Wed Jul 25 16:31:11 2012 +0300
@@ -22,7 +22,7 @@
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" $Id: cvsup.1,v 1.70 2003/03/04 18:23:46 jdp Exp $
-.\" $FreeBSD: head/usr.bin/csup/csup.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/csup/csup.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
 .Dd February 1, 2006
 .Dt CSUP 1
@@ -311,7 +311,7 @@
 The default
 .Ar base
 directory is
-.Pa /usr/local/etc/csup .
+.Pa /usr/local/etc/cvsup .
 .It Cm prefix= Ns Ar prefix
 This is the directory under which updated files will be placed.
 By default, it is the same as
@@ -656,7 +656,7 @@
 .El
 .Pp
 will not work because the file on the server is called
-.Ql Makefile,v.
+.Ql Makefile,v .
 A better solution would be
 .Pp
 .Bl -item -compact -offset indent
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ctlstat/ctlstat.8
--- a/head/usr.bin/ctlstat/ctlstat.8	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ctlstat/ctlstat.8	Wed Jul 25 16:31:11 2012 +0300
@@ -32,7 +32,7 @@
 .\" Author: Ken Merry <ken at FreeBSD.org>
 .\"
 .\" $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.8#2 $
-.\" $FreeBSD: head/usr.bin/ctlstat/ctlstat.8 229997 2012-01-12 00:34:33Z ken $
+.\" $FreeBSD: head/usr.bin/ctlstat/ctlstat.8 235873 2012-05-24 02:24:03Z wblock $
 .\"
 .Dd June 4, 2010
 .Dt CTLSTAT 8
@@ -86,8 +86,8 @@
 No statistics are computed in this mode, only raw numbers are displayed.
 .It Fl l Ar lun
 Request statistics for the specified LUN.
-This option is incompatible with total (
-.Fl t )
+This option is incompatible with total
+.Fl ( t )
 mode.
 .It Fl n Ar numdevs
 Display statistics for this many devices.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/cut/cut.1
--- a/head/usr.bin/cut/cut.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/cut/cut.1	Wed Jul 25 16:31:11 2012 +0300
@@ -29,7 +29,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)cut.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/cut/cut.1 236867 2012-06-11 03:10:15Z kevlo $
 .\"
 .Dd December 21, 2006
 .Dt CUT 1
@@ -68,7 +68,7 @@
 .Ar list
 can be in terms of column position or in terms of fields delimited
 by a special character.
-Column numbering starts from 1.
+Column and field numbering start from 1.
 .Pp
 The
 .Ar list
@@ -78,14 +78,14 @@
 Number ranges consist of a number, a dash
 .Pq Sq \- ,
 and a second number
-and select the fields or columns from the first number to the second,
+and select the columns or fields from the first number to the second,
 inclusive.
 Numbers or number ranges may be preceded by a dash, which selects all
-fields or columns from 1 to the last number.
+columns or fields from 1 to the last number.
 Numbers or number ranges may be followed by a dash, which selects all
-fields or columns from the last number to the end of the line.
+columns or fields from the last number to the end of the line.
 Numbers and number ranges may be repeated, overlapping, and in any order.
-It is not an error to select fields or columns not present in the
+It is not an error to select columns or fields not present in the
 input line.
 .Pp
 The options are as follows:
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/cut/cut.c
--- a/head/usr.bin/cut/cut.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/cut/cut.c	Wed Jul 25 16:31:11 2012 +0300
@@ -37,7 +37,7 @@
 static const char sccsid[] = "@(#)cut.c	8.3 (Berkeley) 5/4/95";
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/cut/cut.c 227162 2011-11-06 08:14:51Z ed $");
+__FBSDID("$FreeBSD: head/usr.bin/cut/cut.c 236866 2012-06-11 03:02:40Z kevlo $");
 
 #include <ctype.h>
 #include <err.h>
@@ -164,7 +164,7 @@
 	 * set a byte in the positions array to indicate if a field or
 	 * column is to be selected; use +1, it's 1-based, not 0-based.
 	 * Numbers and number ranges may be overlapping, repeated, and in
-	 * any order. We handle "-3-5" although there's no real reason too.
+	 * any order. We handle "-3-5" although there's no real reason to.
 	 */
 	for (; (p = strsep(&list, ", \t")) != NULL;) {
 		setautostart = start = stop = 0;
@@ -187,9 +187,9 @@
 			}
 		}
 		if (*p)
-			errx(1, "[-cf] list: illegal list value");
+			errx(1, "[-bcf] list: illegal list value");
 		if (!stop || !start)
-			errx(1, "[-cf] list: values may not include zero");
+			errx(1, "[-bcf] list: values may not include zero");
 		if (maxval < stop) {
 			maxval = stop;
 			needpos(maxval + 1);
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/dc/dc.1
--- a/head/usr.bin/dc/dc.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/dc/dc.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-.\"	$FreeBSD$
+.\"	$FreeBSD: head/usr.bin/dc/dc.1 235400 2012-05-13 14:16:04Z joel $
 .\"	$OpenBSD: dc.1,v 1.24 2010/01/02 19:48:56 schwarze Exp $
 .\"
 .\" Copyright (C) Caldera International Inc.  2001-2002.
@@ -315,7 +315,7 @@
 and decimal point.
 .It Ic z
 The stack level is pushed onto the stack.
-.It Cm [ Ns ... Ns Cm ]
+.It Cm \&[ Ns ... Ns Cm \&]
 Puts the bracketed
 .Tn ASCII
 string onto the top of the stack.
@@ -375,12 +375,12 @@
 .It Ic \&?
 A line of input is taken from the input source (usually the terminal)
 and executed.
-.It Ic : Ns Ar r
+.It Ic \&: Ns Ar r
 Pop two values from the stack.
 The second value on the stack is stored into the array
 .Ar r
 indexed by the top of stack.
-.It Ic ; Ns Ar r
+.It Ic \&; Ns Ar r
 Pop a value from the stack.
 The value is used as an index into register
 .Ar r .
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/du/du.1
--- a/head/usr.bin/du/du.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/du/du.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)du.1	8.2 (Berkeley) 4/1/94
-.\" $FreeBSD: head/usr.bin/du/du.1 228669 2011-12-17 23:18:14Z jilles $
+.\" $FreeBSD: head/usr.bin/du/du.1 238602 2012-07-18 19:28:22Z des $
 .\"
-.Dd December 17, 2011
+.Dd July 18, 2012
 .Dt DU 1
 .Os
 .Sh NAME
@@ -38,7 +38,7 @@
 .Nm
 .Op Fl Aclnx
 .Op Fl H | L | P
-.Op Fl h | k | m
+.Op Fl g | h | k | m
 .Op Fl a | s | d Ar depth
 .Op Fl B Ar blocksize
 .Op Fl I Ar mask
@@ -63,9 +63,9 @@
 .Ar blocksize
 byte blocks.
 This is different from the
-.Fl h, k
+.Fl h, k, m
 and
-.Fl  m
+.Fl  g
 options or setting
 .Ev BLOCKSIZE
 and gives an estimate of how much space the examined file hierarchy would
@@ -95,13 +95,15 @@
 Display an entry for all files and directories
 .Ar depth
 directories deep.
+.It Fl g
+Display block counts in 1073741824-byte (1 GiB) blocks.
 .It Fl h
 .Dq Human-readable
 output.
 Use unit suffixes: Byte, Kilobyte, Megabyte,
 Gigabyte, Terabyte and Petabyte.
 .It Fl k
-Display block counts in 1024-byte (1-Kbyte) blocks.
+Display block counts in 1024-byte (1 kiB) blocks.
 .It Fl l
 If a file has multiple hard links, count its size multiple times.
 The default behavior of
@@ -112,7 +114,7 @@
 option is specified, the hard link checks are disabled, and these files
 are counted (and displayed) as many times as they are found.
 .It Fl m
-Display block counts in 1048576-byte (1-Mbyte) blocks.
+Display block counts in 1048576-byte (1 MiB) blocks.
 .It Fl n
 Ignore files and directories with user
 .Dq nodump
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/du/du.c
--- a/head/usr.bin/du/du.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/du/du.c	Wed Jul 25 16:31:11 2012 +0300
@@ -42,7 +42,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/du/du.c 228669 2011-12-17 23:18:14Z jilles $");
+__FBSDID("$FreeBSD: head/usr.bin/du/du.c 238602 2012-07-18 19:28:22Z des $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -109,7 +109,7 @@
 	depth = INT_MAX;
 	SLIST_INIT(&ignores);
 
-	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrt:x")) != -1)
+	while ((ch = getopt(argc, argv, "AB:HI:LPasd:cghklmnrt:x")) != -1)
 		switch (ch) {
 		case 'A':
 			Aflag = 1;
@@ -156,6 +156,10 @@
 		case 'c':
 			cflag = 1;
 			break;
+		case 'g':
+			hflag = 0;
+			blocksize = 1073741824;
+			break;
 		case 'h':
 			hflag = 1;
 			break;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/fetch/fetch.1
--- a/head/usr.bin/fetch/fetch.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/fetch/fetch.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,5 +1,5 @@
 .\"-
-.\" Copyright (c) 2000-2012 Dag-Erling Smørgrav
+.\" Copyright (c) 2000-2011 Dag-Erling Smørgrav
 .\" All rights reserved.
 .\" Portions Copyright (c) 1999 Massachusetts Institute of Technology; used
 .\" by permission.
@@ -27,9 +27,9 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/fetch/fetch.1 232274 2012-02-28 22:15:46Z obrien $
+.\" $FreeBSD: head/usr.bin/fetch/fetch.1 236110 2012-05-26 17:19:41Z des $
 .\"
-.Dd February 28, 2012
+.Dd September 27, 2011
 .Dt FETCH 1
 .Os
 .Sh NAME
@@ -214,11 +214,6 @@
 flag is specified, wait this many seconds between successive retries.
 .El
 .Pp
-.Ar URL
-.Bd -literal
-    <scheme>:(//(<user>(:<pwd>)[email protected])?<host>(:<port>)?)?/(<document>)?
-.Ed
-.Pp
 If
 .Nm
 receives a
@@ -254,7 +249,7 @@
 .Ev HTTP_REFERER ,
 .Ev HTTP_USER_AGENT ,
 .Ev NETRC ,
-.Ev NO_PROXY and
+.Ev NO_PROXY No and
 .Ev no_proxy .
 .Sh EXIT STATUS
 The
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/find/find.1
--- a/head/usr.bin/find/find.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/find/find.1	Wed Jul 25 16:31:11 2012 +0300
@@ -29,9 +29,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)find.1	8.7 (Berkeley) 5/9/95
-.\" $FreeBSD: head/usr.bin/find/find.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/find/find.1 237035 2012-06-13 21:53:40Z jilles $
 .\"
-.Dd September 28, 2011
+.Dd June 13, 2012
 .Dt FIND 1
 .Os
 .Sh NAME
@@ -126,36 +126,15 @@
 .It Fl d
 Cause
 .Nm
-to perform a depth-first traversal, i.e., directories
-are visited in post-order and all entries in a directory will be acted
-on before the directory itself.
-By default,
-.Nm
-visits directories in pre-order, i.e., before their contents.
-Note, the default is
-.Em not
-a breadth-first traversal.
+to perform a depth-first traversal.
 .Pp
-This option is equivalent to the
+This option is a BSD-specific equivalent of the
 .Ic -depth
-primary of
+primary specified by
 .St -p1003.1-2001 .
-The
-.Fl d
-option
-can be useful when
-.Nm
-is used with
-.Xr cpio 1
-to process files that are contained in directories with unusual permissions.
-It ensures that you have write permission while you are placing files in a
-directory, then sets the directory's permissions as the last thing.
-.It Fl f
-Specify a file hierarchy for
-.Nm
-to traverse.
-File hierarchies may also be specified as the operands immediately
-following the options.
+Refer to its description under
+.Sx PRIMARIES
+for more information.
 .It Fl s
 Cause
 .Nm
@@ -301,7 +280,7 @@
 .Ic -atime
 primary description for information on supported time units.
 .It Ic -d
-Same as
+Non-portable, BSD-specific version of
 .Ic depth .
 GNU find implements this as a primary in mistaken emulation of
 .Fx
@@ -319,12 +298,37 @@
 .Dq Pa \&.
 for security reasons.
 Depth-first traversal processing is implied by this option.
+The
+.Ic -delete
+primary will fail to delete a directory if it is not empty.
 Following symlinks is incompatible with this option.
 .It Ic -depth
 Always true;
-same as the
+same as the non-portable
 .Fl d
 option.
+Cause
+.Nm
+to perform a depth-first traversal, i.e., directories
+are visited in post-order and all entries in a directory will be acted
+on before the directory itself.
+By default,
+.Nm
+visits directories in pre-order, i.e., before their contents.
+Note, the default is
+.Em not
+a breadth-first traversal.
+.Pp
+The
+.Ic -depth
+primary
+can be useful when
+.Nm
+is used with
+.Xr cpio 1
+to process files that are contained in directories with unusual permissions.
+It ensures that you have write permission while you are placing files in a
+directory, then sets the directory's permissions as the last thing.
 .It Ic -depth Ar n
 True if the depth of the file relative to the starting point of the traversal
 is
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/find/getdate.y
--- a/head/usr.bin/find/getdate.y	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/find/getdate.y	Wed Jul 25 16:31:11 2012 +0300
@@ -13,7 +13,7 @@
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/find/getdate.y 235789 2012-05-22 16:33:10Z bapt $");
 
 #include <stdio.h>
 #include <ctype.h>
@@ -60,11 +60,9 @@
 
 #include <time.h>
 
-#define yyparse getdate_yyparse
 #define yylex getdate_yylex
 #define yyerror getdate_yyerror
 
-static int yyparse(void);
 static int yylex(void);
 static int yyerror(const char *);
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/fstat/Makefile
--- a/head/usr.bin/fstat/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/fstat/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,10 +1,10 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $FreeBSD: head/usr.bin/fstat/Makefile 221807 2011-05-12 10:11:39Z stas $
+# $FreeBSD: head/usr.bin/fstat/Makefile 235642 2012-05-19 05:07:03Z marcel $
 
 PROG=	fstat
 SRCS=	fstat.c fuser.c main.c
 LINKS=	${BINDIR}/fstat ${BINDIR}/fuser
-DPADD=	${LIBKVM}
+DPADD=	${LIBKVM} ${LIBUTIL} ${LIBPROCSTAT}
 LDADD=	-lkvm -lutil -lprocstat
 
 MAN1=	fuser.1 fstat.1
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/fstat/fstat.c
--- a/head/usr.bin/fstat/fstat.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/fstat/fstat.c	Wed Jul 25 16:31:11 2012 +0300
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/fstat/fstat.c 233760 2012-04-01 18:22:48Z jhb $");
+__FBSDID("$FreeBSD: head/usr.bin/fstat/fstat.c 235602 2012-05-18 10:15:46Z gleb $");
 
 #include <sys/param.h>
 #include <sys/user.h>
@@ -244,7 +244,7 @@
 		for (d = devs; d != NULL; d = d->next)
 			if (d->fsid == vn.vn_fsid) {
 				fsmatch = 1;
-				if ((unsigned)d->ino == vn.vn_fileid) {
+				if (d->ino == vn.vn_fileid) {
 					filename = d->name;
 					break;
 				}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/gprof/gprof.1
--- a/head/usr.bin/gprof/gprof.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/gprof/gprof.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)gprof.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/gprof/gprof.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
 .Dd December 25, 2008
 .Dt GPROF 1
@@ -73,7 +73,7 @@
 instead of
 .Fl l Ns Ar c .
 Read the given object file (the default is
-.Pa a.out)
+.Pa a.out )
 and establishes the relation between its symbol table
 and the call graph profile.
 The default graph profile file name is the name
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/gprof/lookup.c
--- a/head/usr.bin/gprof/lookup.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/gprof/lookup.c	Wed Jul 25 16:31:11 2012 +0300
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/gprof/lookup.c 235975 2012-05-25 06:48:42Z gber $");
 
 #include "gprof.h"
 
@@ -66,6 +66,12 @@
 		    printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 );
 		}
 #	    endif /* DEBUG */
+#if defined(__arm__)
+	if (nl[middle].name[0] == '$' &&
+	    nl[middle-1].value == nl[middle].value)
+		middle--;
+#endif
+
 	    return &nl[ middle ];
 	}
 	if ( nl[ middle ].value > address ) {
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/gzip/zmore.1
--- a/head/usr.bin/gzip/zmore.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/gzip/zmore.1	Wed Jul 25 16:31:11 2012 +0300
@@ -19,8 +19,8 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.\" $FreeBSD$
-.Dd February 06, 2011
+.\" $FreeBSD: head/usr.bin/gzip/zmore.1 236596 2012-06-05 03:14:39Z eadler $
+.Dd February 6, 2011
 .Dt ZMORE 1
 .Os
 .Sh NAME
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ipcrm/ipcrm.1
--- a/head/usr.bin/ipcrm/ipcrm.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ipcrm/ipcrm.1	Wed Jul 25 16:31:11 2012 +0300
@@ -21,7 +21,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/ipcrm/ipcrm.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/ipcrm/ipcrm.1 235211 2012-05-10 02:07:00Z gjb $
 .\""
 .Dd December 12, 2007
 .Dt IPCRM 1
@@ -112,7 +112,7 @@
 .Xr ipcs 1
 .Sh HISTORY
 The wiping of all System V IPC objects was first implemented in
-.Fx 6.4 and 7.1.
+.Fx 6.4 No and 7.1.
 .Sh AUTHORS
 The original author was Adam Glass.
 The wiping of all System V IPC objects was thought up by Callum
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/join/join.1
--- a/head/usr.bin/join/join.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/join/join.1	Wed Jul 25 16:31:11 2012 +0300
@@ -29,7 +29,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)join.1	8.3 (Berkeley) 4/28/95
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/join/join.1 235597 2012-05-18 03:30:50Z gjb $
 .\"
 .Dd July 5, 2004
 .Dt JOIN 1
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/kdump/kdump.1
--- a/head/usr.bin/kdump/kdump.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/kdump/kdump.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)kdump.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD: head/usr.bin/kdump/kdump.1 234494 2012-04-20 15:32:36Z jhb $
+.\" $FreeBSD: head/usr.bin/kdump/kdump.1 236577 2012-06-04 19:09:14Z jhb $
 .\"
-.Dd April 20, 2012
+.Dd June 4, 2012
 .Dt KDUMP 1
 .Os
 .Sh NAME
@@ -86,9 +86,9 @@
 Suppressing this feature yields a more consistent output format and is
 easily amenable to further processing.
 .It Fl p Ar pid
-Display only trace events that correspond to the process
+Display only trace events that correspond to the process or thread
 .Ar pid .
-This may be useful when there are multiple processes recorded in the
+This may be useful when there are multiple processes or threads recorded in the
 same trace file.
 .It Fl R
 Display relative timestamps (time since previous entry).
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/kdump/kdump.c
--- a/head/usr.bin/kdump/kdump.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/kdump/kdump.c	Wed Jul 25 16:31:11 2012 +0300
@@ -39,7 +39,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/kdump/kdump.c 234494 2012-04-20 15:32:36Z jhb $");
+__FBSDID("$FreeBSD: head/usr.bin/kdump/kdump.c 236577 2012-06-04 19:09:14Z jhb $");
 
 #define _KERNEL
 extern int errno;
@@ -251,7 +251,8 @@
 			}
 		}
 		if (trpoints & (1<<ktr_header.ktr_type))
-			if (pid == 0 || ktr_header.ktr_pid == pid)
+			if (pid == 0 || ktr_header.ktr_pid == pid ||
+			    ktr_header.ktr_tid == pid)
 				dumpheader(&ktr_header);
 		if ((ktrlen = ktr_header.ktr_len) < 0)
 			errx(1, "bogus length 0x%x", ktrlen);
@@ -266,7 +267,8 @@
 		if (fetchprocinfo(&ktr_header, (u_int *)m) != 0)
 			continue;
 		sv_flags = abidump(&ktr_header);
-		if (pid && ktr_header.ktr_pid != pid)
+		if (pid && ktr_header.ktr_pid != pid &&
+		    ktr_header.ktr_tid != pid)
 			continue;
 		if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
 			continue;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/kdump/mkioctls
--- a/head/usr.bin/kdump/mkioctls	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/kdump/mkioctls	Wed Jul 25 16:31:11 2012 +0300
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $FreeBSD: head/usr.bin/kdump/mkioctls 234058 2012-04-09 14:47:18Z dim $
+# $FreeBSD: head/usr.bin/kdump/mkioctls 235911 2012-05-24 14:07:44Z mav $
 #
 # When editing this script, keep in mind that truss also uses it.
 #
@@ -63,6 +63,8 @@
 	print "#include <netinet6/ip6_mroute.h>"
 	print "#include <stdio.h>"
 	print "#include <cam/cam.h>"
+	print "#include <stddef.h>"
+	print "#include <stdint.h>"
 	print ""
 	print ioctl_includes
 	print ""
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/killall/killall.1
--- a/head/usr.bin/killall/killall.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/killall/killall.1	Wed Jul 25 16:31:11 2012 +0300
@@ -22,9 +22,9 @@
 .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/killall/killall.1 233510 2012-03-26 15:18:14Z joel $
+.\" $FreeBSD: head/usr.bin/killall/killall.1 237618 2012-06-27 00:50:25Z delphij $
 .\"
-.Dd December 25, 2009
+.Dd June 27, 2012
 .Dt KILLALL 1
 .Os
 .Sh NAME
@@ -34,6 +34,7 @@
 .Nm
 .Op Fl delmsvz
 .Op Fl help
+.Op Fl I
 .Op Fl j Ar jail
 .Op Fl u Ar user
 .Op Fl t Ar tty
@@ -71,6 +72,9 @@
 option.
 .It Fl help
 Give a help on the command usage and exit.
+.It Fl I
+Request confirmation before attempting to signal each
+process.
 .It Fl l
 List the names of the available signals and exit, like in
 .Xr kill 1 .
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/killall/killall.c
--- a/head/usr.bin/killall/killall.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/killall/killall.c	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/killall/killall.c 237847 2012-06-30 16:36:22Z kib $");
 
 #include <sys/param.h>
 #include <sys/jail.h>
@@ -53,7 +53,7 @@
 usage(void)
 {
 
-	fprintf(stderr, "usage: killall [-delmsvz] [-help] [-j jail]\n");
+	fprintf(stderr, "usage: killall [-delmsvz] [-help] [-I] [-j jail]\n");
 	fprintf(stderr,
 	    "               [-u user] [-t tty] [-c cmd] [-SIGNAL] [cmd]...\n");
 	fprintf(stderr, "At least one option or argument to specify processes must be given.\n");
@@ -90,13 +90,14 @@
 int
 main(int ac, char **av)
 {
-	struct kinfo_proc *procs = NULL, *newprocs;
+	struct kinfo_proc *procs, *newprocs;
 	struct stat	sb;
 	struct passwd	*pw;
 	regex_t		rgx;
 	regmatch_t	pmatch;
-	int		i, j;
+	int		i, j, ch;
 	char		buf[256];
+	char		first;
 	char		*user = NULL;
 	char		*tty = NULL;
 	char		*cmd = NULL;
@@ -104,6 +105,7 @@
 	int		sflag = 0;
 	int		dflag = 0;
 	int		eflag = 0;
+	int		Iflag = 0;
 	int		jflag = 0;
 	int		mflag = 0;
 	int		zflag = 0;
@@ -141,6 +143,9 @@
 		if (**av == '-') {
 			++*av;
 			switch (**av) {
+			case 'I':
+				Iflag = 1;
+				break;
 			case 'j':
 				++*av;
 				if (**av == '\0') {
@@ -273,9 +278,6 @@
 	size = 0;
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_PROC;
-	mib[2] = KERN_PROC_PROC;
-	mib[3] = 0;
-	miblen = 3;
 
 	if (user) {
 		mib[2] = eflag ? KERN_PROC_UID : KERN_PROC_RUID;
@@ -285,16 +287,20 @@
 		mib[2] = KERN_PROC_TTY;
 		mib[3] = tdev;
 		miblen = 4;
+	} else {
+		mib[2] = KERN_PROC_PROC;
+		mib[3] = 0;
+		miblen = 3;
 	}
 
+	procs = NULL;
 	st = sysctl(mib, miblen, NULL, &size, NULL, 0);
 	do {
 		size += size / 10;
 		newprocs = realloc(procs, size);
-		if (newprocs == 0) {
-			if (procs)
-				free(procs);
-			errx(1, "could not reallocate memory");
+		if (newprocs == NULL) {
+			free(procs);
+			err(1, "could not reallocate memory");
 		}
 		procs = newprocs;
 		st = sysctl(mib, miblen, procs, &size, NULL, 0);
@@ -304,7 +310,7 @@
 	if (size % sizeof(struct kinfo_proc) != 0) {
 		fprintf(stderr, "proc size mismatch (%zu total, %zu chunks)\n",
 			size, sizeof(struct kinfo_proc));
-		fprintf(stderr, "userland out of sync with kernel, recompile libkvm etc\n");
+		fprintf(stderr, "userland out of sync with kernel\n");
 		exit(1);
 	}
 	nprocs = size / sizeof(struct kinfo_proc);
@@ -313,7 +319,7 @@
 	mypid = getpid();
 
 	for (i = 0; i < nprocs; i++) {
-		if ((procs[i].ki_stat & SZOMB) == SZOMB && !zflag)
+		if (procs[i].ki_stat == SZOMB && !zflag)
 			continue;
 		thispid = procs[i].ki_pid;
 		strlcpy(thiscmd, procs[i].ki_comm, sizeof(thiscmd));
@@ -382,6 +388,16 @@
 			if (matched)
 				break;
 		}
+		if (matched != 0 && Iflag) {
+			printf("Send signal %d to %s (pid %d uid %d)? ",
+				sig, thiscmd, thispid, thisuid);
+			fflush(stdout);
+			first = ch = getchar();
+			while (ch != '\n' && ch != EOF)
+				ch = getchar();
+			if (first != 'y' && first != 'Y')
+				matched = 0;
+		}
 		if (matched == 0)
 			continue;
 		if (dflag)
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ktrace/ktrace.1
--- a/head/usr.bin/ktrace/ktrace.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ktrace/ktrace.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)ktrace.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD: head/usr.bin/ktrace/ktrace.1 233925 2012-04-05 17:13:14Z jhb $
+.\" $FreeBSD: head/usr.bin/ktrace/ktrace.1 236357 2012-05-31 14:46:02Z jhb $
 .\"
-.Dd April 5, 2012
+.Dd May 31, 2012
 .Dt KTRACE 1
 .Os
 .Sh NAME
@@ -131,7 +131,7 @@
 requests
 .It Cm +
 trace the default set of trace points -
-.Cm c , f , i , n , p , s , t , u , y
+.Cm c , i , n , p , s , t , u , y
 .El
 .It Ar command
 Execute
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ktrace/ktrace.h
--- a/head/usr.bin/ktrace/ktrace.h	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ktrace/ktrace.h	Wed Jul 25 16:31:11 2012 +0300
@@ -27,17 +27,17 @@
  * SUCH DAMAGE.
  *
  *	@(#)ktrace.h	8.1 (Berkeley) 6/6/93
- * $FreeBSD: head/usr.bin/ktrace/ktrace.h 233925 2012-04-05 17:13:14Z jhb $
+ * $FreeBSD: head/usr.bin/ktrace/ktrace.h 236357 2012-05-31 14:46:02Z jhb $
  */
 
 #define DEF_POINTS (KTRFAC_SYSCALL | KTRFAC_SYSRET | KTRFAC_NAMEI | \
 		    KTRFAC_GENIO | KTRFAC_PSIG | KTRFAC_USER | \
-		    KTRFAC_STRUCT | KTRFAC_SYSCTL | KTRFAC_CAPFAIL | \
-		    KTRFAC_FAULT | KTRFAC_FAULTEND)
+		    KTRFAC_STRUCT | KTRFAC_SYSCTL | KTRFAC_CAPFAIL)
 
 #define PROC_ABI_POINTS (KTRFAC_PROCCTOR | KTRFAC_PROCDTOR)
 
-#define ALL_POINTS (DEF_POINTS | KTRFAC_CSW | PROC_ABI_POINTS)
+#define ALL_POINTS (DEF_POINTS | KTRFAC_CSW | PROC_ABI_POINTS | \
+		    KTRFAC_FAULT | KTRFAC_FAULTEND)
 
 #define DEF_TRACEFILE	"ktrace.out"
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/lastcomm/lastcomm.1
--- a/head/usr.bin/lastcomm/lastcomm.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/lastcomm/lastcomm.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	From: @(#)lastcomm.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/lastcomm/lastcomm.1 235541 2012-05-17 11:10:13Z kib $
 .\"
-.Dd May 14, 2007
+.Dd May 17, 2012
 .Dt LASTCOMM 1
 .Os
 .Sh NAME
@@ -38,6 +38,7 @@
 .Nm
 .Op Fl EScesu
 .Op Fl f Ar file
+.Op Cm + Ns Ar format
 .Op Ar command ...\&
 .Op Ar user ...\&
 .Op Ar terminal ...\&
@@ -77,6 +78,15 @@
 reads accounting entries from the standard input.
 .El
 .Pp
+An operand with a leading plus sign
+.Pq Sq +
+is followed a user-defined format string which specifies the format
+in which to display the process's start or exit date and time.
+The format string may contain any of the conversion specifications
+described in the
+.Xr strftime 3
+manual page, as well as arbitrary text.
+.Pp
 If no options are specified,
 .Fl cS
 is assumed.
@@ -165,6 +175,7 @@
 .Sh SEE ALSO
 .Xr last 1 ,
 .Xr sigaction 2 ,
+.Xr strftime 3 ,
 .Xr acct 5 ,
 .Xr core 5
 .Sh HISTORY
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/lastcomm/lastcomm.c
--- a/head/usr.bin/lastcomm/lastcomm.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/lastcomm/lastcomm.c	Wed Jul 25 16:31:11 2012 +0300
@@ -39,7 +39,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/lastcomm/lastcomm.c 223375 2011-06-21 20:36:10Z delphij $");
+__FBSDID("$FreeBSD: head/usr.bin/lastcomm/lastcomm.c 235541 2012-05-17 11:10:13Z kib $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -52,6 +52,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include "pathnames.h"
 
@@ -82,10 +83,12 @@
 	int (*readrec)(FILE *f, struct acctv2 *av2);
 	time_t t;
 	int ch, rv;
-	const char *acctfile;
+	const char *acctfile, *format;
+	char buf[1024];
 	int flags = 0;
 
 	acctfile = _PATH_ACCT;
+	format = NULL;
 	while ((ch = getopt(argc, argv, "f:usecSE")) != -1)
 		switch((char)ch) {
 		case 'f':
@@ -126,6 +129,12 @@
 	argc -= optind;
 	argv += optind;
 
+	if (argc > 0 && **argv == '+') {
+		format = *argv + 1; /* skip + */
+		argc--;
+		argv++;
+	}
+
 	if (strcmp(acctfile, "-") == 0) {
 		fp = stdin;
 		readrec = readrec_forward;
@@ -177,14 +186,24 @@
 		
 		/* starting time */
 		if (flags & AC_BTIME) {
-			(void)printf(" %.16s", ctime(&ab.ac_btime));
+			if (format != NULL) {
+				(void)strftime(buf, sizeof(buf), format,
+				    localtime(&ab.ac_btime));
+				(void)printf(" %s", buf);
+			} else
+				(void)printf(" %.16s", ctime(&ab.ac_btime));
 		}
 		
 		/* exit time (starting time + elapsed time )*/
 		if (flags & AC_FTIME) {
 			t = ab.ac_btime;
 			t += (time_t)(ab.ac_etime / 1000000);
-			(void)printf(" %.16s", ctime(&t));
+			if (format != NULL) {
+				(void)strftime(buf, sizeof(buf), format,
+				    localtime(&t));
+				(void)printf(" %s", buf);
+			} else
+				(void)printf(" %.16s", ctime(&t));
 		}
 		printf("\n");
  	}
@@ -250,6 +269,7 @@
 usage(void)
 {
 	(void)fprintf(stderr,
-"usage: lastcomm [-EScesu] [-f file] [command ...] [user ...] [terminal ...]\n");
+	    "usage: lastcomm [-EScesu] [-f file] [+format] [command ...] "
+	    "[user ...] [terminal ...]\n");
 	exit(1);
 }
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/less/defines.h
--- a/head/usr.bin/less/defines.h	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/less/defines.h	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/usr.bin/less/defines.h 221718 2011-05-10 01:05:41Z delphij $ */
+/* $FreeBSD: head/usr.bin/less/defines.h 237613 2012-06-26 23:17:33Z delphij $ */
 /* defines.h.  Generated from defines.h.in by configure.  */
 /* defines.h.in.  Generated from configure.ac by autoheader.  */
 
@@ -227,18 +227,12 @@
 /* Define to 1 if you have the `fsync' function. */
 #define HAVE_FSYNC 1
 
+/* GNU regex library */
+/* #undef HAVE_GNU_REGEX */
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #define HAVE_INTTYPES_H 1
 
-/* Define to 1 if you have the `gen' library (-lgen). */
-/* #undef HAVE_LIBGEN */
-
-/* Define to 1 if you have the `intl' library (-lintl). */
-/* #undef HAVE_LIBINTL */
-
-/* Define to 1 if you have the `PW' library (-lPW). */
-/* #undef HAVE_LIBPW */
-
 /* Define to 1 if you have the <limits.h> header file. */
 #define HAVE_LIMITS_H 1
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/lex/lex.1
--- a/head/usr.bin/lex/lex.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/lex/lex.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/lex/lex.1 235853 2012-05-23 18:41:45Z joel $
 .\"
 .TH FLEX 1 "April 1995" "Version 2.5"
 .SH NAME
@@ -2247,8 +2247,7 @@
 .TP
 .B \-F
 specifies that the
-.ul
-fast
+.I fast
 scanner table representation should be used (and stdio
 bypassed).  This representation is
 about as fast as the full table representation
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/limits/limits.1
--- a/head/usr.bin/limits/limits.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/limits/limits.1	Wed Jul 25 16:31:11 2012 +0300
@@ -17,9 +17,9 @@
 .\" 5. Modifications may be freely made to this file providing the above
 .\"    conditions are met.
 .\"
-.\" $FreeBSD: head/usr.bin/limits/limits.1 230549 2012-01-25 20:14:41Z trociny $
+.\" $FreeBSD: head/usr.bin/limits/limits.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
-.Dd January 23, 2011
+.Dd January 23, 2012
 .Dt LIMITS 1
 .Os
 .Sh NAME
@@ -179,7 +179,7 @@
 or
 .Fl H
 options.
-.Fl e
+.It Fl e
 Select
 .Dq "eval mode"
 formatting for output.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/login/login.1
--- a/head/usr.bin/login/login.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/login/login.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)login.1	8.2 (Berkeley) 5/5/94
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/login/login.1 236892 2012-06-11 16:18:39Z des $
 .\"
 .Dd September 13, 2006
 .Dt LOGIN 1
@@ -137,8 +137,6 @@
 system mailboxes
 .It Pa \&.hushlogin
 makes login quieter
-.It Pa /etc/auth.conf
-configure authentication services
 .It Pa /etc/pam.d/login
 .Xr pam 8
 configuration file
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/m4/parser.y
--- a/head/usr.bin/m4/parser.y	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/m4/parser.y	Wed Jul 25 16:31:11 2012 +0300
@@ -15,15 +15,14 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * $FreeBSD: head/usr.bin/m4/parser.y 228697 2011-12-18 22:04:55Z bapt $
+ * $FreeBSD: head/usr.bin/m4/parser.y 235789 2012-05-22 16:33:10Z bapt $
  */
+#include <math.h>
 #include <stdint.h>
-#include <math.h>
 #define YYSTYPE	int32_t
 extern int32_t end_result;
 extern int yylex(void);
 extern int yyerror(const char *);
-extern int yyparse(void);
 %}
 %token NUMBER
 %token ERROR
@@ -35,9 +34,9 @@
 %left EQ NE
 %left '<' LE '>' GE
 %left LSHIFT RSHIFT
-%right EXPONENT
 %left '+' '-'
 %left '*' '/' '%'
+%right EXPONENT
 %right UMINUS UPLUS '!' '~'
 
 %%
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mail/popen.c
--- a/head/usr.bin/mail/popen.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mail/popen.c	Wed Jul 25 16:31:11 2012 +0300
@@ -33,7 +33,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/mail/popen.c 236286 2012-05-30 03:55:44Z eadler $");
 
 #include "rcv.h"
 #include <sys/wait.h>
@@ -336,12 +336,14 @@
 wait_child(int pid)
 {
 	sigset_t nset, oset;
-	struct child *cp = findchild(pid);
+	struct child *cp;
 
 	(void)sigemptyset(&nset);
 	(void)sigaddset(&nset, SIGCHLD);
 	(void)sigprocmask(SIG_BLOCK, &nset, &oset);	
 
+	cp = findchild(pid);
+
 	while (!cp->done)
 		(void)sigsuspend(&oset);
 	wait_status = cp->status;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/make/Makefile
--- a/head/usr.bin/make/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/make/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,6 +1,8 @@
 #	@(#)Makefile	5.2 (Berkeley) 12/28/90
 #	$Id: Makefile,v 1.6 1994/06/30 05:33:39 cgd Exp $
-# $FreeBSD: head/usr.bin/make/Makefile 228525 2011-12-15 06:25:19Z fjoe $
+# $FreeBSD: head/usr.bin/make/Makefile 237282 2012-06-20 00:37:00Z obrien $
+
+.include <bsd.own.mk>
 
 PROG=	make
 CFLAGS+=-I${.CURDIR}
@@ -8,10 +10,12 @@
 	lst.c main.c make.c parse.c proc.c shell.c str.c suff.c targ.c	\
 	util.c var.c
 
+.if !defined(MK_SHARED_TOOLCHAIN) || ${MK_SHARED_TOOLCHAIN} == "no"
 NO_SHARED?=	YES
+.endif
 
 # Version has the RYYYYMMDDX format, where R is from RELENG_<R>
-CFLAGS+=-DMAKE_VERSION=\"5201111300\"
+CFLAGS+=-DMAKE_VERSION=\"10201205300\"
 
 # There is no obvious performance improvement currently.
 # CFLAGS+=-DUSE_KQUEUE
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/make/make.1
--- a/head/usr.bin/make/make.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/make/make.1	Wed Jul 25 16:31:11 2012 +0300
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)make.1	8.8 (Berkeley) 6/13/95
-.\" $FreeBSD: head/usr.bin/make/make.1 227121 2011-11-05 21:32:17Z jilles $
+.\" $FreeBSD: head/usr.bin/make/make.1 236365 2012-05-31 20:13:44Z obrien $
 .\"
-.Dd November 5, 2011
+.Dd May 30, 2012
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -320,6 +320,11 @@
 Multiple instances of this option may be specified;
 the variables will be printed one per line,
 with a blank line for each null or undefined variable.
+If
+.Ar variable
+contains a
+.Sq Ic $
+then the value will be expanded before printing.
 .It Fl v
 Be extra verbose.
 Print any extra information.
@@ -902,6 +907,7 @@
 Replaces each word in the variable with everything but the last component.
 .It Cm :L
 Converts variable to lower-case letters.
+(deprecated)
 .It Cm :M Ns Ar pattern
 Select only those words that match the rest of the modifier.
 The standard shell wildcard characters
@@ -993,8 +999,13 @@
 .Ar new_string .
 .It Cm :T
 Replaces each word in the variable with its last component.
+.It Cm :tl
+Converts variable to lower-case letters.
+.It Cm :tu
+Converts variable to upper-case letters.
 .It Cm :U
 Converts variable to upper-case letters.
+(deprecated)
 .It Cm :u
 Remove adjacent duplicate words (like
 .Xr uniq 1 ) .
@@ -1661,7 +1672,7 @@
 .Ic ::
 targets that have no prerequisites
 .It
-.Ic !
+.Ic \&!
 targets
 .It
 targets that have
@@ -1742,6 +1753,19 @@
 .Va .MAKE ;
 support for this may be removed in the future.
 .Pp
+The use of the
+.Cm :L
+and
+.Cm :U
+modifiers are deprecated
+in
+.Fx 10.0
+and the more portable (among Pmake decedents)
+.Cm :tl
+and
+.Cm :tu
+should be used instead.
+.Pp
 Most of the more esoteric features of
 .Nm
 should probably be avoided for greater compatibility.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/make/var.c
--- a/head/usr.bin/make/var.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/make/var.c	Wed Jul 25 16:31:11 2012 +0300
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/make/var.c 228992 2011-12-30 11:02:40Z uqs $");
+__FBSDID("$FreeBSD: head/usr.bin/make/var.c 236346 2012-05-31 00:36:56Z obrien $");
 
 /**
  * var.c --
@@ -1746,6 +1746,19 @@
 		case 'C':
 			newStr = modifier_C(vp, value, v);
 			break;
+		case 't':
+			/* :tl :tu for OSF ODE & NetBSD make compatibility */
+			switch (vp->ptr[1]) {
+			case 'l':
+				vp->ptr++;
+				goto mod_lower;
+				break;
+			case 'u':
+				vp->ptr++;
+				goto mod_upper;
+				break;
+			}
+			/* FALLTHROUGH */
 		default:
 			if (vp->ptr[1] != endc && vp->ptr[1] != ':') {
 #ifdef SUNSHCMD
@@ -1774,6 +1787,7 @@
 
 			switch (vp->ptr[0]) {
 			case 'L':
+			mod_lower:
 				{
 				const char	*cp;
 				Buffer		*buf;
@@ -1799,6 +1813,7 @@
 				vp->ptr++;
 				break;
 			case 'U':
+			mod_upper:
 				{
 				const char	*cp;
 				Buffer		*buf;
@@ -2578,7 +2593,7 @@
 Var_Print(Lst *vlist, Boolean expandVars)
 {
 	LstNode		*n;
-	const char	*name;
+	char		*name;
 
 	LST_FOREACH(n, vlist) {
 		name = Lst_Datum(n);
@@ -2586,13 +2601,17 @@
 			char *value;
 			char *v;
 
-			v = emalloc(strlen(name) + 1 + 3);
-			sprintf(v, "${%s}", name);
-
+			if (*name == '$') {
+				v = name;
+			} else {
+				v = emalloc(strlen(name) + 1 + 3);
+				sprintf(v, "${%s}", name);
+			}
 			value = Buf_Peel(Var_Subst(v, VAR_GLOBAL, FALSE));
 			printf("%s\n", value);
 
-			free(v);
+			if (v != name)
+				free(v);
 			free(value);
 		} else {
 			const char *value = Var_Value(name, VAR_GLOBAL);
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/makewhatis/makewhatis.c
--- a/head/usr.bin/makewhatis/makewhatis.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/makewhatis/makewhatis.c	Wed Jul 25 16:31:11 2012 +0300
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/makewhatis/makewhatis.c 237348 2012-06-20 23:53:36Z delphij $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -693,7 +693,7 @@
 static void
 process_page(struct page_info *page, char *section_dir)
 {
-	gzFile *in;
+	gzFile in;
 	char buffer[4096];
 	char *line;
 	StringList *names;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/man/man.conf.5
--- a/head/usr.bin/man/man.conf.5	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/man/man.conf.5	Wed Jul 25 16:31:11 2012 +0300
@@ -23,7 +23,7 @@
 .\"  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\"  SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/man/man.conf.5 233520 2012-03-26 19:23:57Z joel $
+.\" $FreeBSD: head/usr.bin/man/man.conf.5 236508 2012-06-03 11:09:51Z joel $
 .\"
 .Dd June 3, 2011
 .Dt MAN.CONF 5
@@ -57,7 +57,7 @@
 is intended to be used by the local administrator to set additional policy.
 .Pp
 Currently supported configuration variables include:
-.Bl -tag -offset indent
+.Bl -tag -width 12n -offset indent
 .It MANCONFIG
 Overrides the default location to import additional manual configuration files.
 Defaults to
@@ -70,7 +70,8 @@
 .Pp
 For pages in a given language, overriding the default toolset for
 display is supported via the following definitions:
-.Bl -tag -offset indent -compact
+.Pp
+.Bl -tag -width 12n -offset indent -compact
 .It EQN Ns _ Ns Va LANG
 .It NROFF Ns _ Ns Va LANG
 .It PIC Ns _ Ns Va LANG
@@ -87,7 +88,7 @@
 The parser used for this utility is very basic and only supports comment
 characters (#) at the beginning of a line.
 .Sh FILES
-.Bl -tag -compact
+.Bl -tag -width "Pa /usr/local/etc/man.d/*.conf" -compact
 .It Pa /etc/man.conf
 System configuration file.
 .It Pa /usr/local/etc/man.d/*.conf
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/minigzip/Makefile
--- a/head/usr.bin/minigzip/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/minigzip/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,6 +1,6 @@
-# $FreeBSD$
+# $FreeBSD: head/usr.bin/minigzip/Makefile 237410 2012-06-21 21:47:08Z delphij $
 
-SRCDIR=	${.CURDIR}/../../lib/libz
+SRCDIR=	${.CURDIR}/../../lib/libz/test
 .PATH:	${SRCDIR}
 
 PROG=	minigzip
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/minigzip/minigzip.1
--- a/head/usr.bin/minigzip/minigzip.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/minigzip/minigzip.1	Wed Jul 25 16:31:11 2012 +0300
@@ -22,9 +22,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/minigzip/minigzip.1 235802 2012-05-22 19:40:54Z delphij $
 .\"
-.Dd October 3, 2002
+.Dd May 22, 2012
 .Dt MINIGZIP 1
 .Os
 .Sh NAME
@@ -48,7 +48,7 @@
 The default operation is compression, decompression can be
 selected by supplying the
 .Fl d
-flag on the commandline.
+flag on the command line.
 .Pp
 If any
 .Ar file
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mkcsmapper/ldef.h
--- a/head/usr.bin/mkcsmapper/ldef.h	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mkcsmapper/ldef.h	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $FreeBSD: head/usr.bin/mkcsmapper/ldef.h 235789 2012-05-22 16:33:10Z bapt $ */
 /* $NetBSD: ldef.h,v 1.2 2006/09/09 14:35:17 tnozaki Exp $	*/
 
 /*-
@@ -39,4 +39,3 @@
 extern int	 line_number;
 extern int	 yyerror(const char *);
 extern int	 yylex(void);
-extern int	 yyparse(void);
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mkcsmapper/lex.l
--- a/head/usr.bin/mkcsmapper/lex.l	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mkcsmapper/lex.l	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $FreeBSD: head/usr.bin/mkcsmapper/lex.l 238197 2012-07-07 17:05:55Z eadler $ */
 /* $NetBSD: lex.l,v 1.4 2006/02/09 22:03:15 dogcow Exp $	*/
 
 %{
@@ -57,7 +57,7 @@
 <COMMENT>[\n]	{ line_number++; }
 <COMMENT>.	{ }
 <COMMENT><<EOF>>	{
-		yyerror("unexpected file end (unterminate comment)\n");
+		yyerror("unexpected file end (unterminated comment)\n");
 		exit(1);
 	}
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mkesdb/ldef.h
--- a/head/usr.bin/mkesdb/ldef.h	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mkesdb/ldef.h	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $FreeBSD: head/usr.bin/mkesdb/ldef.h 238185 2012-07-07 04:14:28Z kientzle $ */
 /* $NetBSD: ldef.h,v 1.2 2005/06/27 01:23:59 fvdl Exp $	*/
 
 /*-
@@ -30,7 +30,6 @@
 extern int	 line_number;
 extern int	 yyerror(const char *);
 extern int	 yylex(void);
-extern int	 yyparse(void);
 
 struct named_csid {
 	STAILQ_ENTRY(named_csid)	 ci_entry;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mkesdb/lex.l
--- a/head/usr.bin/mkesdb/lex.l	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mkesdb/lex.l	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $FreeBSD: head/usr.bin/mkesdb/lex.l 238197 2012-07-07 17:05:55Z eadler $ */
 /* $NetBSD: lex.l,v 1.3 2006/02/09 22:03:15 dogcow Exp $	*/
 
 %{
@@ -59,7 +59,7 @@
 <COMMENT>[\n]	{ line_number++; }
 <COMMENT>.	{ }
 <COMMENT><<EOF>>	{
-		yyerror("unexpected file end (unterminate comment)\n");
+		yyerror("unexpected file end (unterminated comment)\n");
 		exit(1);
 	}
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mklocale/extern.h
--- a/head/usr.bin/mklocale/extern.h	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mklocale/extern.h	Wed Jul 25 16:31:11 2012 +0300
@@ -29,8 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/usr.bin/mklocale/extern.h 235789 2012-05-22 16:33:10Z bapt $
  */
 
 int yylex(void);
-int yyparse(void);
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/mklocale/mklocale.1
--- a/head/usr.bin/mklocale/mklocale.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/mklocale/mklocale.1	Wed Jul 25 16:31:11 2012 +0300
@@ -29,7 +29,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)mklocale.1	8.2 (Berkeley) 4/18/94
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/mklocale/mklocale.1 235400 2012-05-13 14:16:04Z joel $
 .\"
 .Dd October 17, 2004
 .Dt MKLOCALE 1
@@ -123,7 +123,7 @@
 .It Dv ">\|\^)\|]"
 Used to end a mapping.
 All are equivalent.
-.It Dv :
+.It Dv ":"
 Used as a delimiter in mappings.
 .El
 .El
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/ncplogin/ncplogout.1
--- a/head/usr.bin/ncplogin/ncplogout.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/ncplogin/ncplogout.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/ncplogin/ncplogout.1 235211 2012-05-10 02:07:00Z gjb $
 .Dd September 15, 1999
 .Dt NCPLOGOUT 1
 .Os
@@ -30,7 +30,7 @@
 .Bl -tag -width indent
 .It Fl S Ar server
 Specify the name of the
-.Tn Netware
+.Tn NetWare
 server to which the connection should be terminated.
 Can be omitted if there is only
 one connection active.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/netstat/Makefile
--- a/head/usr.bin/netstat/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/netstat/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,5 +1,5 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/12/93
-# $FreeBSD: head/usr.bin/netstat/Makefile 232748 2012-03-09 20:50:15Z dim $
+# $FreeBSD: head/usr.bin/netstat/Makefile 238514 2012-07-16 06:43:04Z tuexen $
 
 .include <bsd.own.mk>
 
@@ -13,6 +13,10 @@
 CFLAGS+=-DIPSEC
 CFLAGS+=-DSCTP
 
+.if ${MK_INET_SUPPORT} != "no"
+CFLAGS+=-DINET
+.endif
+
 .if ${MK_INET6_SUPPORT} != "no"
 SRCS+=	inet6.c
 CFLAGS+=-DINET6
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/netstat/inet.c
--- a/head/usr.bin/netstat/inet.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/netstat/inet.c	Wed Jul 25 16:31:11 2012 +0300
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/netstat/inet.c 234245 2012-04-13 22:35:53Z delphij $");
+__FBSDID("$FreeBSD: head/usr.bin/netstat/inet.c 237263 2012-06-19 07:34:13Z np $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -461,7 +461,10 @@
 #endif
 		vchar = ((inp->inp_vflag & INP_IPV4) != 0) ?
 		    "4 " : "  ";
-		printf("%-3.3s%-2.2s ", name, vchar);
+		if (istcp && (tp->t_flags & TF_TOE) != 0)
+			printf("%-3.3s%-2.2s ", "toe", vchar);
+		else
+			printf("%-3.3s%-2.2s ", name, vchar);
 		if (Lflag) {
 			char buf1[15];
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/netstat/sctp.c
--- a/head/usr.bin/netstat/sctp.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/netstat/sctp.c	Wed Jul 25 16:31:11 2012 +0300
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/netstat/sctp.c 230555 2012-01-25 21:49:48Z tuexen $");
+__FBSDID("$FreeBSD: head/usr.bin/netstat/sctp.c 238514 2012-07-16 06:43:04Z tuexen $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -107,6 +107,7 @@
  * If numeric_addr has been supplied, give
  * numeric value, otherwise try for symbolic name.
  */
+#ifdef INET
 static char *
 inetname(struct in_addr *inp)
 {
@@ -146,6 +147,7 @@
 	}
 	return (line);
 }
+#endif
 
 #ifdef INET6
 static char ntop_buf[INET6_ADDRSTRLEN];
@@ -197,9 +199,11 @@
 	int width;
 
 	switch (address->sa.sa_family) {
+#ifdef INET
 	case AF_INET:
 		sprintf(line, "%.*s.", Wflag ? 39 : 16, inetname(&address->sin.sin_addr));
 		break;
+#endif
 #ifdef INET6
 	case AF_INET6:
 		sprintf(line, "%.*s.", Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr));
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/nfsstat/nfsstat.c
--- a/head/usr.bin/nfsstat/nfsstat.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/nfsstat/nfsstat.c	Wed Jul 25 16:31:11 2012 +0300
@@ -41,7 +41,7 @@
 static char sccsid[] = "@(#)nfsstat.c	8.2 (Berkeley) 3/31/95";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: head/usr.bin/nfsstat/nfsstat.c 225113 2011-08-23 13:44:56Z rmacklem $";
+  "$FreeBSD: head/usr.bin/nfsstat/nfsstat.c 238701 2012-07-22 18:59:31Z hrs $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -995,7 +995,6 @@
 			    );
 		    }
 		    printf("\n");
-		    lastst = nfsstats;
 		}
 		if (serverOnly) {
 		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
@@ -1019,8 +1018,8 @@
 			(nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS] -
 			 lastst.srvrpccnt[NFSV4OP_READDIRPLUS]));
 		    printf("\n");
-		    lastst = nfsstats;
 		}
+		lastst = nfsstats;
 		fflush(stdout);
 		sleep(interval);
 	}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/pamtest/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/pamtest/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,11 @@
+# $FreeBSD: head/usr.bin/pamtest/Makefile 236109 2012-05-26 17:10:16Z des $
+
+OPENPAM=	${.CURDIR}/../../contrib/openpam
+.PATH: ${OPENPAM}/include ${OPENPAM}/bin/pamtest
+
+PROG= pamtest
+SRCS= pamtest.c
+DPADD= ${LIBPAM}
+LDADD= ${MINUSLPAM}
+
+.include <bsd.prog.mk>
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/passwd/passwd.1
--- a/head/usr.bin/passwd/passwd.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/passwd/passwd.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)passwd.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/passwd/passwd.1 236892 2012-06-11 16:18:39Z des $
 .\"
 .Dd June 6, 1993
 .Dt PASSWD 1
@@ -221,8 +221,6 @@
 temporary copy of the password file
 .It Pa /etc/login.conf
 login class capabilities database
-.It Pa /etc/auth.conf
-configure authentication services
 .El
 .Sh SEE ALSO
 .Xr chpass 1 ,
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/procstat/Makefile
--- a/head/usr.bin/procstat/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/procstat/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,4 +1,4 @@
-# $FreeBSD: head/usr.bin/procstat/Makefile 227956 2011-11-24 20:54:06Z trociny $
+# $FreeBSD: head/usr.bin/procstat/Makefile 235642 2012-05-19 05:07:03Z marcel $
 
 PROG=	procstat
 MAN=	procstat.1
@@ -16,6 +16,6 @@
 	procstat_vm.c
 
 LDADD+=	-lutil -lprocstat -lkvm
-DPADD+=	${LIBUTIL}
+DPADD+=	${LIBUTIL} ${LIBPROCSTAT} ${LIBKVM}
 
 .include <bsd.prog.mk>
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/procstat/procstat.1
--- a/head/usr.bin/procstat/procstat.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/procstat/procstat.1	Wed Jul 25 16:31:11 2012 +0300
@@ -23,9 +23,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/procstat/procstat.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/procstat/procstat.1 238527 2012-07-16 09:38:19Z pgj $
 .\"
-.Dd March 23, 2012
+.Dd July 11, 2012
 .Dt PROCSTAT 1
 .Os
 .Sh NAME
@@ -433,6 +433,10 @@
 needs copy
 .It S
 one or more superpage mappings are used
+.It D
+grows down (top-down stack)
+.It U
+grows up (bottom-up stack)
 .El
 .Sh EXIT STATUS
 .Ex -std
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/procstat/procstat_rlimit.c
--- a/head/usr.bin/procstat/procstat_rlimit.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/procstat/procstat_rlimit.c	Wed Jul 25 16:31:11 2012 +0300
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/usr.bin/procstat/procstat_rlimit.c 230548 2012-01-25 20:13:37Z trociny $
+ * $FreeBSD: head/usr.bin/procstat/procstat_rlimit.c 238086 2012-07-03 19:11:38Z trociny $
  */
 
 #include <sys/param.h>
@@ -66,8 +66,8 @@
 #error "Resource limits have grown. Add new entries to rlimit_param[]."
 #endif
 
-static
-const char *humanize_rlimit(int indx, rlim_t limit)
+static const char *
+humanize_rlimit(int indx, rlim_t limit)
 {
 	static char buf[14];
 	int scale;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/procstat/procstat_vm.c
--- a/head/usr.bin/procstat/procstat_vm.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/procstat/procstat_vm.c	Wed Jul 25 16:31:11 2012 +0300
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/usr.bin/procstat/procstat_vm.c 227317 2011-11-07 21:16:19Z trociny $
+ * $FreeBSD: head/usr.bin/procstat/procstat_vm.c 238753 2012-07-24 19:40:12Z trociny $
  */
 
 #include <sys/param.h>
@@ -50,7 +50,7 @@
 
 	ptrwidth = 2*sizeof(void *) + 2;
 	if (!hflag)
-		printf("%5s %*s %*s %3s %4s %4s %3s %3s %3s %-2s %-s\n",
+		printf("%5s %*s %*s %3s %4s %4s %3s %3s %4s %-2s %-s\n",
 		    "PID", ptrwidth, "START", ptrwidth, "END", "PRT", "RES",
 		    "PRES", "REF", "SHD", "FL", "TP", "PATH");
 
@@ -72,7 +72,9 @@
 		printf("%-1s", kve->kve_flags & KVME_FLAG_COW ? "C" : "-");
 		printf("%-1s", kve->kve_flags & KVME_FLAG_NEEDS_COPY ? "N" :
 		    "-");
-		printf("%-1s ", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
+		printf("%-1s", kve->kve_flags & KVME_FLAG_SUPER ? "S" : "-");
+		printf("%-1s ", kve->kve_flags & KVME_FLAG_GROWS_UP ? "U" :
+		    kve->kve_flags & KVME_FLAG_GROWS_DOWN ? "D" : "-");
 		switch (kve->kve_type) {
 		case KVME_TYPE_NONE:
 			str = "--";
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/rctl/rctl.8
--- a/head/usr.bin/rctl/rctl.8	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/rctl/rctl.8	Wed Jul 25 16:31:11 2012 +0300
@@ -23,7 +23,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/rctl/rctl.8 233667 2012-03-29 16:07:22Z joel $
+.\" $FreeBSD: head/usr.bin/rctl/rctl.8 234568 2012-04-22 07:55:56Z delphij $
 .\"
 .Dd March 1, 2012
 .Dt RCTL 8
@@ -186,7 +186,7 @@
 The
 .Nm
 command appeared in
-.Fx 9.0.
+.Fx 9.0 .
 .Sh AUTHORS
 .An -nosplit
 The
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/rlogin/rlogin.1
--- a/head/usr.bin/rlogin/rlogin.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/rlogin/rlogin.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)rlogin.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/rlogin/rlogin.1 236892 2012-06-11 16:18:39Z des $
 .\"
 .Dd September 26, 2003
 .Dt RLOGIN 1
@@ -128,7 +128,6 @@
 .Bl -tag -width /etc/hosts -compact
 .It Pa /etc/hosts
 .It Pa /etc/hosts.equiv
-.It Pa /etc/auth.conf
 .It Ev $HOME Ns Pa /.rhosts
 .El
 .Sh SEE ALSO
@@ -138,7 +137,6 @@
 .Xr setsockopt 2 ,
 .Xr ruserok 3 ,
 .Xr tty 4 ,
-.Xr auth.conf 5 ,
 .Xr hosts 5 ,
 .Xr hosts.equiv 5 ,
 .Xr rlogind 8 ,
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/rsh/rsh.1
--- a/head/usr.bin/rsh/rsh.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/rsh/rsh.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)rsh.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/rsh/rsh.1 236892 2012-06-11 16:18:39Z des $
 .\"
 .Dd October 16, 2002
 .Dt RSH 1
@@ -125,14 +125,12 @@
 .Sh FILES
 .Bl -tag -width /etc/hosts -compact
 .It Pa /etc/hosts
-.It Pa /etc/auth.conf
 .El
 .Sh SEE ALSO
 .Xr rlogin 1 ,
 .Xr setsockopt 2 ,
 .Xr rcmd 3 ,
 .Xr ruserok 3 ,
-.Xr auth.conf 5 ,
 .Xr hosts 5 ,
 .Xr hosts.equiv 5 ,
 .Xr rlogind 8 ,
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sockstat/sockstat.1
--- a/head/usr.bin/sockstat/sockstat.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/sockstat/sockstat.1	Wed Jul 25 16:31:11 2012 +0300
@@ -25,9 +25,9 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/sockstat/sockstat.1 230512 2012-01-24 21:33:34Z jilles $
+.\" $FreeBSD: head/usr.bin/sockstat/sockstat.1 235870 2012-05-24 01:31:10Z thompsa $
 .\"
-.Dd January 24, 2012
+.Dd May 16, 2012
 .Dt SOCKSTAT 1
 .Os
 .Sh NAME
@@ -36,6 +36,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl 46cLlu
+.Op Fl j Ar jid
 .Op Fl p Ar ports
 .Op Fl P Ar protocols
 .Sh DESCRIPTION
@@ -57,6 +58,8 @@
 (IPv6) sockets.
 .It Fl c
 Show connected sockets.
+.It Fl j Ar jid
+Show only sockets belonging to the specified jail ID.
 .It Fl L
 Only show Internet sockets if the local or foreign addresses are not
 in the loopback network prefix
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sockstat/sockstat.c
--- a/head/usr.bin/sockstat/sockstat.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/sockstat/sockstat.c	Wed Jul 25 16:31:11 2012 +0300
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/sockstat/sockstat.c 230874 2012-02-01 18:03:21Z trociny $");
+__FBSDID("$FreeBSD: head/usr.bin/sockstat/sockstat.c 237674 2012-06-27 23:26:32Z thompsa $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -62,6 +62,7 @@
 static int	 opt_4;		/* Show IPv4 sockets */
 static int	 opt_6;		/* Show IPv6 sockets */
 static int	 opt_c;		/* Show connected sockets */
+static int	 opt_j;		/* Show specified jail */
 static int	 opt_L;		/* Don't show IPv4 or IPv6 loopback sockets */
 static int	 opt_l;		/* Show listening sockets */
 static int	 opt_u;		/* Show Unix domain sockets */
@@ -324,6 +325,7 @@
 			}
 			inp = &xtp->xt_inp;
 			so = &xtp->xt_socket;
+			protoname = xtp->xt_tp.t_flags & TF_TOE ? "toe" : "tcp";
 			break;
 		case IPPROTO_UDP:
 		case IPPROTO_DIVERT:
@@ -549,6 +551,27 @@
 }
 
 static int
+getprocjid(pid_t pid)
+{
+	static struct kinfo_proc proc;
+	size_t len;
+	int mib[4];
+
+	mib[0] = CTL_KERN;
+	mib[1] = KERN_PROC;
+	mib[2] = KERN_PROC_PID;
+	mib[3] = (int)pid;
+	len = sizeof proc;
+	if (sysctl(mib, 4, &proc, &len, NULL, 0) == -1) {
+		/* Do not warn if the process exits before we get its jid. */
+		if (errno != ESRCH)
+			warn("sysctl()");
+		return (-1);
+	}
+	return (proc.ki_jid);
+}
+
+static int
 check_ports(struct sock *s)
 {
 	int port;
@@ -643,6 +666,8 @@
 	for (xf = xfiles, n = 0; n < nxfiles; ++n, ++xf) {
 		if (xf->xf_data == NULL)
 			continue;
+		if (opt_j >= 0 && opt_j != getprocjid(xf->xf_pid))
+			continue;
 		hash = (int)((uintptr_t)xf->xf_data % HASHSIZE);
 		for (s = sockhash[hash]; s != NULL; s = s->next)
 			if ((void *)s->socket == xf->xf_data)
@@ -668,6 +693,8 @@
 		pos += xprintf("%d ", xf->xf_fd);
 		displaysock(s, pos);
 	}
+	if (opt_j >= 0)
+		return;
 	for (hash = 0; hash < HASHSIZE; hash++) {
 		for (s = sockhash[hash]; s != NULL; s = s->next) {
 			if (s->shown)
@@ -706,7 +733,7 @@
 usage(void)
 {
 	fprintf(stderr,
-	    "Usage: sockstat [-46cLlu] [-p ports] [-P protocols]\n");
+	    "Usage: sockstat [-46cLlu] [-j jid] [-p ports] [-P protocols]\n");
 	exit(1);
 }
 
@@ -716,7 +743,8 @@
 	int protos_defined = -1;
 	int o, i;
 
-	while ((o = getopt(argc, argv, "46cLlp:P:uv")) != -1)
+	opt_j = -1;
+	while ((o = getopt(argc, argv, "46cj:Llp:P:uv")) != -1)
 		switch (o) {
 		case '4':
 			opt_4 = 1;
@@ -727,6 +755,9 @@
 		case 'c':
 			opt_c = 1;
 			break;
+		case 'j':
+			opt_j = atoi(optarg);
+			break;
 		case 'L':
 			opt_L = 1;
 			break;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,45 @@
+# $FreeBSD: head/usr.bin/sort/Makefile 237629 2012-06-27 05:59:01Z gabor $
+
+.include <bsd.own.mk>
+
+.if ${MK_GNU_SORT} != "yes"
+PROG=	sort
+.else
+PROG=	bsdsort
+CLEANFILES+= bsdsort.1
+
+bsdsort.1: sort.1
+	cp ${.ALLSRC} ${.TARGET}
+.endif
+
+SRCS=	bwstring.c coll.c file.c mem.c radixsort.c sort.c vsort.c
+
+WARNS=	6
+
+sort.1: sort.1.in
+	/usr/bin/sed ${MAN_SUB} ${.ALLSRC} >${.TARGET}
+
+CLEANFILES+= sort.1
+
+.if defined(WITH_THREADS)
+CFLAGS+= -DSORT_THREADS
+LDFLAGS+= -lpthread -lmd
+MAN_SUB+= -e 's|%%THREADS%%||g'
+.else
+LDFLAGS+= -lmd
+MAN_SUB+= -e 's|%%THREADS%%|\.\\"|g'
+.endif
+
+.if !defined(WITHOUT_NLS)
+NLS+=	hu_HU.ISO8859-2
+NLSSRCFILES= ${NLS:[email protected][email protected]@}
+MAN_SUB+= -e 's|%%NLS%%||g'
+.for lang in ${NLS}
+NLSSRCDIR_${lang}= ${.CURDIR}/nls
+.endfor
+.else
+CFLAGS+= -DWITHOUT_NLS
+MAN_SUB+= -e 's|%%NLS%%|\.\\"|g'
+.endif
+
+.include <bsd.prog.mk>
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/bwstring.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/bwstring.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,1154 @@
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/bwstring.c 235987 2012-05-25 09:30:16Z gabor $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <err.h>
+#include <langinfo.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "bwstring.h"
+#include "sort.h"
+
+bool byte_sort;
+
+static wchar_t **wmonths;
+static unsigned char **cmonths;
+
+/* initialise months */
+
+void
+initialise_months(void)
+{
+	const nl_item item[12] = { ABMON_1, ABMON_2, ABMON_3, ABMON_4,
+	    ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, ABMON_10,
+	    ABMON_11, ABMON_12 };
+	unsigned char *tmp;
+	size_t len;
+
+	if (MB_CUR_MAX == 1) {
+		if (cmonths == NULL) {
+			unsigned char *m;
+
+			cmonths = sort_malloc(sizeof(unsigned char*) * 12);
+			for (int i = 0; i < 12; i++) {
+				cmonths[i] = NULL;
+				tmp = (unsigned char *) nl_langinfo(item[i]);
+				if (tmp == NULL)
+					continue;
+				if (debug_sort)
+					printf("month[%d]=%s\n", i, tmp);
+				len = strlen(tmp);
+				if (len < 1)
+					continue;
+				while (isblank(*tmp))
+					++tmp;
+				m = sort_malloc(len + 1);
+				memcpy(m, tmp, len + 1);
+				m[len] = '\0';
+				for (unsigned int j = 0; j < len; j++)
+					m[j] = toupper(m[j]);
+				cmonths[i] = m;
+			}
+		}
+
+	} else {
+		if (wmonths == NULL) {
+			wchar_t *m;
+
+			wmonths = sort_malloc(sizeof(wchar_t *) * 12);
+			for (int i = 0; i < 12; i++) {
+				wmonths[i] = NULL;
+				tmp = (unsigned char *) nl_langinfo(item[i]);
+				if (tmp == NULL)
+					continue;
+				if (debug_sort)
+					printf("month[%d]=%s\n", i, tmp);
+				len = strlen(tmp);
+				if (len < 1)
+					continue;
+				while (isblank(*tmp))
+					++tmp;
+				m = sort_malloc(SIZEOF_WCHAR_STRING(len + 1));
+				if (mbstowcs(m, tmp, len) == ((size_t) -1))
+					continue;
+				m[len] = L'\0';
+				for (unsigned int j = 0; j < len; j++)
+					m[j] = towupper(m[j]);
+				wmonths[i] = m;
+			}
+		}
+	}
+}
+
+/*
+ * Compare two wide-character strings
+ */
+static int
+wide_str_coll(const wchar_t *s1, const wchar_t *s2)
+{
+	int ret = 0;
+
+	errno = 0;
+	ret = wcscoll(s1, s2);
+	if (errno == EILSEQ) {
+		errno = 0;
+		ret = wcscmp(s1, s2);
+		if (errno != 0) {
+			for (size_t i = 0; ; ++i) {
+				wchar_t c1 = s1[i];
+				wchar_t c2 = s2[i];
+				if (c1 == L'\0')
+					return ((c2 == L'\0') ? 0 : -1);
+				if (c2 == L'\0')
+					return (+1);
+				if (c1 == c2)
+					continue;
+				return ((int)(c1 - c2));
+			}
+		}
+	}
+	return (ret);
+}
+
+/* counterparts of wcs functions */
+
+void
+bwsprintf(FILE *f, struct bwstring *bws, const char *prefix, const char *suffix)
+{
+
+	if (MB_CUR_MAX == 1)
+		fprintf(f, "%s%s%s", prefix, bws->data.cstr, suffix);
+	else
+		fprintf(f, "%s%S%s", prefix, bws->data.wstr, suffix);
+}
+
+const void* bwsrawdata(const struct bwstring *bws)
+{
+
+	return (&(bws->data));
+}
+
+size_t bwsrawlen(const struct bwstring *bws)
+{
+
+	return ((MB_CUR_MAX == 1) ? bws->len : SIZEOF_WCHAR_STRING(bws->len));
+}
+
+size_t
+bws_memsize(const struct bwstring *bws)
+{
+
+	return ((MB_CUR_MAX == 1) ? (bws->len + 2 + sizeof(struct bwstring)) :
+	    (SIZEOF_WCHAR_STRING(bws->len + 1) + sizeof(struct bwstring)));
+}
+
+void
+bws_setlen(struct bwstring *bws, size_t newlen)
+{
+
+	if (bws && newlen != bws->len && newlen <= bws->len) {
+		bws->len = newlen;
+		if (MB_CUR_MAX == 1)
+			bws->data.cstr[newlen] = '\0';
+		else
+			bws->data.wstr[newlen] = L'\0';
+	}
+}
+
+/*
+ * Allocate a new binary string of specified size
+ */
+struct bwstring *
+bwsalloc(size_t sz)
+{
+	struct bwstring *ret;
+
+	if (MB_CUR_MAX == 1)
+		ret = sort_malloc(sizeof(struct bwstring) + 1 + sz);
+	else
+		ret = sort_malloc(sizeof(struct bwstring) +
+		    SIZEOF_WCHAR_STRING(sz + 1));
+	ret->len = sz;
+
+	if (MB_CUR_MAX == 1)
+		ret->data.cstr[ret->len] = '\0';
+	else
+		ret->data.wstr[ret->len] = L'\0';
+
+	return (ret);
+}
+
+/*
+ * Create a copy of binary string.
+ * New string size equals the length of the old string.
+ */
+struct bwstring *
+bwsdup(const struct bwstring *s)
+{
+
+	if (s == NULL)
+		return (NULL);
+	else {
+		struct bwstring *ret = bwsalloc(s->len);
+
+		if (MB_CUR_MAX == 1)
+			memcpy(ret->data.cstr, s->data.cstr, (s->len));
+		else
+			memcpy(ret->data.wstr, s->data.wstr,
+			    SIZEOF_WCHAR_STRING(s->len));
+
+		return (ret);
+	}
+}
+
+/*
+ * Create a new binary string from a raw binary buffer.
+ */
+struct bwstring *
+bwssbdup(const wchar_t *str, size_t len)
+{
+
+	if (str == NULL)
+		return ((len == 0) ? bwsalloc(0) : NULL);
+	else {
+		struct bwstring *ret;
+
+		ret = bwsalloc(len);
+
+		if (MB_CUR_MAX == 1)
+			for (size_t i = 0; i < len; ++i)
+				ret->data.cstr[i] = (unsigned char) str[i];
+		else
+			memcpy(ret->data.wstr, str, SIZEOF_WCHAR_STRING(len));
+
+		return (ret);
+	}
+}
+
+/*
+ * Create a new binary string from a raw binary buffer.
+ */
+struct bwstring *
+bwscsbdup(const unsigned char *str, size_t len)
+{
+	struct bwstring *ret;
+
+	ret = bwsalloc(len);
+
+	if (str) {
+		if (MB_CUR_MAX == 1)
+			memcpy(ret->data.cstr, str, len);
+		else {
+			mbstate_t mbs;
+			const char *s;
+			size_t charlen, chars, cptr;
+
+			charlen = chars = 0;
+			cptr = 0;
+			s = (const char *) str;
+
+			memset(&mbs, 0, sizeof(mbs));
+
+			while (cptr < len) {
+				size_t n = MB_CUR_MAX;
+
+				if (n > len - cptr)
+					n = len - cptr;
+				charlen = mbrlen(s + cptr, n, &mbs);
+				switch (charlen) {
+				case 0:
+					/* FALLTHROUGH */
+				case (size_t) -1:
+					/* FALLTHROUGH */
+				case (size_t) -2:
+					ret->data.wstr[chars++] =
+					    (unsigned char) s[cptr];
+					++cptr;
+					break;
+				default:
+					n = mbrtowc(ret->data.wstr + (chars++),
+					    s + cptr, charlen, &mbs);
+					if ((n == (size_t)-1) || (n == (size_t)-2))
+						/* NOTREACHED */
+						err(2, "mbrtowc error");
+					cptr += charlen;
+				};
+			}
+
+			ret->len = chars;
+			ret->data.wstr[ret->len] = L'\0';
+		}
+	}
+	return (ret);
+}
+
+/*
+ * De-allocate object memory
+ */
+void
+bwsfree(const struct bwstring *s)
+{
+
+	if (s)
+		sort_free(s);
+}
+
+/*
+ * Copy content of src binary string to dst.
+ * If the capacity of the dst string is not sufficient,
+ * then the data is truncated.
+ */
+size_t
+bwscpy(struct bwstring *dst, const struct bwstring *src)
+{
+	size_t nums = src->len;
+
+	if (nums > dst->len)
+		nums = dst->len;
+	dst->len = nums;
+
+	if (MB_CUR_MAX == 1) {
+		memcpy(dst->data.cstr, src->data.cstr, nums);
+		dst->data.cstr[dst->len] = '\0';
+	} else {
+		memcpy(dst->data.wstr, src->data.wstr,
+		    SIZEOF_WCHAR_STRING(nums + 1));
+		dst->data.wstr[dst->len] = L'\0';
+	}
+
+	return (nums);
+}
+
+/*
+ * Copy content of src binary string to dst,
+ * with specified number of symbols to be copied.
+ * If the capacity of the dst string is not sufficient,
+ * then the data is truncated.
+ */
+struct bwstring *
+bwsncpy(struct bwstring *dst, const struct bwstring *src, size_t size)
+{
+	size_t nums = src->len;
+
+	if (nums > dst->len)
+		nums = dst->len;
+	if (nums > size)
+		nums = size;
+	dst->len = nums;
+
+	if (MB_CUR_MAX == 1) {
+		memcpy(dst->data.cstr, src->data.cstr, nums);
+		dst->data.cstr[dst->len] = '\0';
+	} else {
+		memcpy(dst->data.wstr, src->data.wstr,
+		    SIZEOF_WCHAR_STRING(nums + 1));
+		dst->data.wstr[dst->len] = L'\0';
+	}
+
+	return (dst);
+}
+
+/*
+ * Copy content of src binary string to dst,
+ * with specified number of symbols to be copied.
+ * An offset value can be specified, from the start of src string.
+ * If the capacity of the dst string is not sufficient,
+ * then the data is truncated.
+ */
+struct bwstring *
+bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset,
+    size_t size)
+{
+
+	if (offset >= src->len) {
+		dst->data.wstr[0] = 0;
+		dst->len = 0;
+	} else {
+		size_t nums = src->len - offset;
+
+		if (nums > dst->len)
+			nums = dst->len;
+		if (nums > size)
+			nums = size;
+		dst->len = nums;
+		if (MB_CUR_MAX == 1) {
+			memcpy(dst->data.cstr, src->data.cstr + offset,
+			    (nums));
+			dst->data.cstr[dst->len] = '\0';
+		} else {
+			memcpy(dst->data.wstr, src->data.wstr + offset,
+			    SIZEOF_WCHAR_STRING(nums));
+			dst->data.wstr[dst->len] = L'\0';
+		}
+	}
+	return (dst);
+}
+
+/*
+ * Write binary string to the file.
+ * The output is ended either with '\n' (nl == true)
+ * or '\0' (nl == false).
+ */
+int
+bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended)
+{
+
+	if (MB_CUR_MAX == 1) {
+		size_t len = bws->len;
+
+		if (!zero_ended) {
+			bws->data.cstr[len] = '\n';
+
+			if (fwrite(bws->data.cstr, len + 1, 1, f) < 1)
+				err(2, NULL);
+
+			bws->data.cstr[len] = '\0';
+		} else if (fwrite(bws->data.cstr, len + 1, 1, f) < 1)
+			err(2, NULL);
+
+		return (len + 1);
+
+	} else {
+		wchar_t eols;
+		int printed = 0;
+
+		eols = zero_ended ? btowc('\0') : btowc('\n');
+
+		while (printed < (int) BWSLEN(bws)) {
+			const wchar_t *s = bws->data.wstr + printed;
+
+			if (*s == L'\0') {
+				int nums;
+
+				nums = fwprintf(f, L"%lc", *s);
+
+				if (nums != 1)
+					err(2, NULL);
+				++printed;
+			} else {
+				int nums;
+
+				nums = fwprintf(f, L"%ls", s);
+
+				if (nums < 1)
+					err(2, NULL);
+				printed += nums;
+			}
+		}
+		fwprintf(f, L"%lc", eols);
+		return (printed + 1);
+	}
+}
+
+/*
+ * Allocate and read a binary string from file.
+ * The strings are nl-ended or zero-ended, depending on the sort setting.
+ */
+struct bwstring *
+bwsfgetln(FILE *f, size_t *len, bool zero_ended, struct reader_buffer *rb)
+{
+	wchar_t eols;
+
+	eols = zero_ended ? btowc('\0') : btowc('\n');
+
+	if (!zero_ended && (MB_CUR_MAX > 1)) {
+		wchar_t *ret;
+
+		ret = fgetwln(f, len);
+
+		if (ret == NULL) {
+			if (!feof(f))
+				err(2, NULL);
+			return (NULL);
+		}
+		if (*len > 0) {
+			if (ret[*len - 1] == eols)
+				--(*len);
+		}
+		return (bwssbdup(ret, *len));
+
+	} else if (!zero_ended && (MB_CUR_MAX == 1)) {
+		char *ret;
+
+		ret = fgetln(f, len);
+
+		if (ret == NULL) {
+			if (!feof(f))
+				err(2, NULL);
+			return (NULL);
+		}
+		if (*len > 0) {
+			if (ret[*len - 1] == '\n')
+				--(*len);
+		}
+		return (bwscsbdup(ret, *len));
+
+	} else {
+		wchar_t c = 0;
+
+		*len = 0;
+
+		if (feof(f))
+			return (NULL);
+
+		if (2 >= rb->fgetwln_z_buffer_size) {
+			rb->fgetwln_z_buffer_size += 256;
+			rb->fgetwln_z_buffer = sort_realloc(rb->fgetwln_z_buffer,
+			    sizeof(wchar_t) * rb->fgetwln_z_buffer_size);
+		}
+		rb->fgetwln_z_buffer[*len] = 0;
+
+		if (MB_CUR_MAX == 1)
+			while (!feof(f)) {
+				c = fgetc(f);
+
+				if (c == EOF) {
+					if (*len == 0)
+						return (NULL);
+					goto line_read_done;
+				}
+				if (c == eols)
+					goto line_read_done;
+
+				if (*len + 1 >= rb->fgetwln_z_buffer_size) {
+					rb->fgetwln_z_buffer_size += 256;
+					rb->fgetwln_z_buffer = sort_realloc(rb->fgetwln_z_buffer,
+					    SIZEOF_WCHAR_STRING(rb->fgetwln_z_buffer_size));
+				}
+
+				rb->fgetwln_z_buffer[*len] = c;
+				rb->fgetwln_z_buffer[++(*len)] = 0;
+			}
+		else
+			while (!feof(f)) {
+				c = fgetwc(f);
+
+				if (c == WEOF) {
+					if (*len == 0)
+						return (NULL);
+					goto line_read_done;
+				}
+				if (c == eols)
+					goto line_read_done;
+
+				if (*len + 1 >= rb->fgetwln_z_buffer_size) {
+					rb->fgetwln_z_buffer_size += 256;
+					rb->fgetwln_z_buffer = sort_realloc(rb->fgetwln_z_buffer,
+					    SIZEOF_WCHAR_STRING(rb->fgetwln_z_buffer_size));
+				}
+
+				rb->fgetwln_z_buffer[*len] = c;
+				rb->fgetwln_z_buffer[++(*len)] = 0;
+			}
+
+line_read_done:
+		/* we do not count the last 0 */
+		return (bwssbdup(rb->fgetwln_z_buffer, *len));
+	}
+}
+
+int
+bwsncmp(const struct bwstring *bws1, const struct bwstring *bws2,
+    size_t offset, size_t len)
+{
+	size_t cmp_len, len1, len2;
+	int res = 0;
+
+	cmp_len = 0;
+	len1 = bws1->len;
+	len2 = bws2->len;
+
+	if (len1 <= offset) {
+		return ((len2 <= offset) ? 0 : -1);
+	} else {
+		if (len2 <= offset)
+			return (+1);
+		else {
+			len1 -= offset;
+			len2 -= offset;
+
+			cmp_len = len1;
+
+			if (len2 < cmp_len)
+				cmp_len = len2;
+
+			if (len < cmp_len)
+				cmp_len = len;
+
+			if (MB_CUR_MAX == 1) {
+				const unsigned char *s1, *s2;
+
+				s1 = bws1->data.cstr + offset;
+				s2 = bws2->data.cstr + offset;
+
+				res = memcmp(s1, s2, cmp_len);
+
+			} else {
+				const wchar_t *s1, *s2;
+
+				s1 = bws1->data.wstr + offset;
+				s2 = bws2->data.wstr + offset;
+
+				res = memcmp(s1, s2, SIZEOF_WCHAR_STRING(cmp_len));
+			}
+		}
+	}
+
+	if (res == 0) {
+		if (len1 < cmp_len && len1 < len2)
+			res = -1;
+		else if (len2 < cmp_len && len2 < len1)
+			res = +1;
+	}
+
+	return (res);
+}
+
+int
+bwscmp(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset)
+{
+	size_t len1, len2, cmp_len;
+	int res;
+
+	len1 = bws1->len;
+	len2 = bws2->len;
+
+	len1 -= offset;
+	len2 -= offset;
+
+	cmp_len = len1;
+
+	if (len2 < cmp_len)
+		cmp_len = len2;
+
+	res = bwsncmp(bws1, bws2, offset, cmp_len);
+
+	if (res == 0) {
+		if( len1 < len2)
+			res = -1;
+		else if (len2 < len1)
+			res = +1;
+	}
+
+	return (res);
+}
+
+int
+bws_iterator_cmp(bwstring_iterator iter1, bwstring_iterator iter2, size_t len)
+{
+	wchar_t c1, c2;
+	size_t i = 0;
+
+	for (i = 0; i < len; ++i) {
+		c1 = bws_get_iter_value(iter1);
+		c2 = bws_get_iter_value(iter2);
+		if (c1 != c2)
+			return (c1 - c2);
+		iter1 = bws_iterator_inc(iter1, 1);
+		iter2 = bws_iterator_inc(iter2, 1);
+	}
+
+	return (0);
+}
+
+int
+bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset)
+{
+	size_t len1, len2;
+
+	len1 = bws1->len;
+	len2 = bws2->len;
+
+	if (len1 <= offset)
+		return ((len2 <= offset) ? 0 : -1);
+	else {
+		if (len2 <= offset)
+			return (+1);
+		else {
+			len1 -= offset;
+			len2 -= offset;
+
+			if (MB_CUR_MAX == 1) {
+				const unsigned char *s1, *s2;
+
+				s1 = bws1->data.cstr + offset;
+				s2 = bws2->data.cstr + offset;
+
+				if (byte_sort) {
+					int res = 0;
+
+					if (len1 > len2) {
+						res = memcmp(s1, s2, len2);
+						if (!res)
+							res = +1;
+					} else if (len1 < len2) {
+						res = memcmp(s1, s2, len1);
+						if (!res)
+							res = -1;
+					} else
+						res = memcmp(s1, s2, len1);
+
+					return (res);
+
+				} else {
+					int res = 0;
+					size_t i, maxlen;
+
+					i = 0;
+					maxlen = len1;
+
+					if (maxlen > len2)
+						maxlen = len2;
+
+					while (i < maxlen) {
+						/* goto next non-zero part: */
+						while ((i < maxlen) &&
+						    !s1[i] && !s2[i])
+							++i;
+
+						if (i >= maxlen)
+							break;
+
+						if (s1[i] == 0) {
+							if (s2[i] == 0)
+								/* NOTREACHED */
+								err(2, "bwscoll error 01");
+							else
+								return (-1);
+						} else if (s2[i] == 0)
+							return (+1);
+
+						res = strcoll(s1 + i, s2 + i);
+						if (res)
+							return (res);
+
+						while ((i < maxlen) &&
+						    s1[i] && s2[i])
+							++i;
+
+						if (i >= maxlen)
+							break;
+
+						if (s1[i] == 0) {
+							if (s2[i] == 0) {
+								++i;
+								continue;
+							} else
+								return (-1);
+						} else if (s2[i] == 0)
+							return (+1);
+						else
+							/* NOTREACHED */
+							err(2, "bwscoll error 02");
+					}
+
+					if (len1 < len2)
+						return (-1);
+					else if (len1 > len2)
+						return (+1);
+
+					return (0);
+				}
+			} else {
+				const wchar_t *s1, *s2;
+				size_t i, maxlen;
+				int res = 0;
+
+				s1 = bws1->data.wstr + offset;
+				s2 = bws2->data.wstr + offset;
+
+				i = 0;
+				maxlen = len1;
+
+				if (maxlen > len2)
+					maxlen = len2;
+
+				while (i < maxlen) {
+
+					/* goto next non-zero part: */
+					while ((i < maxlen) &&
+					    !s1[i] && !s2[i])
+						++i;
+
+					if (i >= maxlen)
+						break;
+
+					if (s1[i] == 0) {
+						if (s2[i] == 0)
+							/* NOTREACHED */
+							err(2, "bwscoll error 1");
+						else
+							return (-1);
+					} else if (s2[i] == 0)
+						return (+1);
+
+					res = wide_str_coll(s1 + i, s2 + i);
+					if (res)
+						return (res);
+
+					while ((i < maxlen) && s1[i] && s2[i])
+						++i;
+
+					if (i >= maxlen)
+						break;
+
+					if (s1[i] == 0) {
+						if (s2[i] == 0) {
+							++i;
+							continue;
+						} else
+							return (-1);
+					} else if (s2[i] == 0)
+						return (+1);
+					else
+						/* NOTREACHED */
+						err(2, "bwscoll error 2");
+				}
+
+				if (len1 < len2)
+					return (-1);
+				else if (len1 > len2)
+					return (+1);
+
+				return (0);
+			}
+		}
+	}
+}
+
+/*
+ * Correction of the system API
+ */
+double
+bwstod(struct bwstring *s0, bool *empty)
+{
+	double ret = 0;
+
+	if (MB_CUR_MAX == 1) {
+		unsigned char *end, *s;
+		char *ep;
+
+		s = s0->data.cstr;
+		end = s + s0->len;
+		ep = NULL;
+
+		while (isblank(*s) && s < end)
+			++s;
+
+		if (!isprint(*s)) {
+			*empty = true;
+			return (0);
+		}
+
+		ret = strtod(s, &ep);
+		if ((unsigned char*) ep == s) {
+			*empty = true;
+			return (0);
+		}
+	} else {
+		wchar_t *end, *ep, *s;
+
+		s = s0->data.wstr;
+		end = s + s0->len;
+		ep = NULL;
+
+		while (iswblank(*s) && s < end)
+			++s;
+
+		if (!iswprint(*s)) {
+			*empty = true;
+			return (0);
+		}
+
+		ret = wcstod(s, &ep);
+		if (ep == s) {
+			*empty = true;
+			return (0);
+		}
+	}
+
+	*empty = false;
+	return (ret);
+}
+
+/*
+ * A helper function for monthcoll.  If a line matches
+ * a month name, it returns (number of the month - 1),
+ * while if there is no match, it just return -1.
+ */
+
+int
+bws_month_score(const struct bwstring *s0)
+{
+
+	if (MB_CUR_MAX == 1) {
+		const unsigned char *end, *s;
+		size_t len;
+
+		s = s0->data.cstr;
+		end = s + s0->len;
+
+		while (isblank(*s) && s < end)
+			++s;
+
+		len = strlen(s);
+
+		for (int i = 11; i >= 0; --i) {
+			if (cmonths[i] &&
+			    (s == (unsigned char*)strstr(s, cmonths[i])))
+				return (i);
+		}
+
+	} else {
+		const wchar_t *end, *s;
+		size_t len;
+
+		s = s0->data.wstr;
+		end = s + s0->len;
+
+		while (iswblank(*s) && s < end)
+			++s;
+
+		len = wcslen(s);
+
+		for (int i = 11; i >= 0; --i) {
+			if (wmonths[i] && (s == wcsstr(s, wmonths[i])))
+				return (i);
+		}
+	}
+
+	return (-1);
+}
+
+/*
+ * Rips out leading blanks (-b).
+ */
+struct bwstring *
+ignore_leading_blanks(struct bwstring *str)
+{
+
+	if (MB_CUR_MAX == 1) {
+		unsigned char *dst, *end, *src;
+
+		src = str->data.cstr;
+		dst = src;
+		end = src + str->len;
+
+		while (src < end && isblank(*src))
+			++src;
+
+		if (src != dst) {
+			size_t newlen;
+
+			newlen = BWSLEN(str) - (src - dst);
+
+			while (src < end) {
+				*dst = *src;
+				++dst;
+				++src;
+			}
+			bws_setlen(str, newlen);
+		}
+	} else {
+		wchar_t *dst, *end, *src;
+
+		src = str->data.wstr;
+		dst = src;
+		end = src + str->len;
+
+		while (src < end && iswblank(*src))
+			++src;
+
+		if (src != dst) {
+
+			size_t newlen = BWSLEN(str) - (src - dst);
+
+			while (src < end) {
+				*dst = *src;
+				++dst;
+				++src;
+			}
+			bws_setlen(str, newlen);
+
+		}
+	}
+	return (str);
+}
+
+/*
+ * Rips out nonprinting characters (-i).
+ */
+struct bwstring *
+ignore_nonprinting(struct bwstring *str)
+{
+	size_t newlen = str->len;
+
+	if (MB_CUR_MAX == 1) {
+		unsigned char *dst, *end, *src;
+		unsigned char c;
+
+		src = str->data.cstr;
+		dst = src;
+		end = src + str->len;
+
+		while (src < end) {
+			c = *src;
+			if (isprint(c)) {
+				*dst = c;
+				++dst;
+				++src;
+			} else {
+				++src;
+				--newlen;
+			}
+		}
+	} else {
+		wchar_t *dst, *end, *src;
+		wchar_t c;
+
+		src = str->data.wstr;
+		dst = src;
+		end = src + str->len;
+
+		while (src < end) {
+			c = *src;
+			if (iswprint(c)) {
+				*dst = c;
+				++dst;
+				++src;
+			} else {
+				++src;
+				--newlen;
+			}
+		}
+	}
+	bws_setlen(str, newlen);
+
+	return (str);
+}
+
+/*
+ * Rips out any characters that are not alphanumeric characters
+ * nor blanks (-d).
+ */
+struct bwstring *
+dictionary_order(struct bwstring *str)
+{
+	size_t newlen = str->len;
+
+	if (MB_CUR_MAX == 1) {
+		unsigned char *dst, *end, *src;
+		unsigned char c;
+
+		src = str->data.cstr;
+		dst = src;
+		end = src + str->len;
+
+		while (src < end) {
+			c = *src;
+			if (isalnum(c) || isblank(c)) {
+				*dst = c;
+				++dst;
+				++src;
+			} else {
+				++src;
+				--newlen;
+			}
+		}
+	} else {
+		wchar_t *dst, *end, *src;
+		wchar_t c;
+
+		src = str->data.wstr;
+		dst = src;
+		end = src + str->len;
+
+		while (src < end) {
+			c = *src;
+			if (iswalnum(c) || iswblank(c)) {
+				*dst = c;
+				++dst;
+				++src;
+			} else {
+				++src;
+				--newlen;
+			}
+		}
+	}
+	bws_setlen(str, newlen);
+
+	return (str);
+}
+
+/*
+ * Converts string to lower case(-f).
+ */
+struct bwstring *
+ignore_case(struct bwstring *str)
+{
+
+	if (MB_CUR_MAX == 1) {
+		unsigned char *end, *s;
+
+		s = str->data.cstr;
+		end = s + str->len;
+
+		while (s < end) {
+			*s = toupper(*s);
+			++s;
+		}
+	} else {
+		wchar_t *end, *s;
+
+		s = str->data.wstr;
+		end = s + str->len;
+
+		while (s < end) {
+			*s = towupper(*s);
+			++s;
+		}
+	}
+	return (str);
+}
+
+void
+bws_disorder_warnx(struct bwstring *s, const char *fn, size_t pos)
+{
+
+	if (MB_CUR_MAX == 1)
+		warnx("%s:%zu: disorder: %s", fn, pos + 1, s->data.cstr);
+	else
+		warnx("%s:%zu: disorder: %ls", fn, pos + 1, s->data.wstr);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/bwstring.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/bwstring.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,142 @@
+/*	$FreeBSD: head/usr.bin/sort/bwstring.h 235267 2012-05-11 12:37:16Z gabor $	*/
+
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__BWSTRING_H__)
+#define __BWSTRING_H__
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sysexits.h>
+#include <wchar.h>
+
+#include "mem.h"
+
+extern bool byte_sort;
+
+/* wchar_t is of 4 bytes: */
+#define SIZEOF_WCHAR_STRING(LEN) ((LEN)*sizeof(wchar_t))
+
+/*
+ * Binary "wide" string
+ */
+struct bwstring
+{
+	size_t				len;
+	union
+	{
+		wchar_t		wstr[0];
+		unsigned char	cstr[0];
+	}				data;
+};
+
+struct reader_buffer
+{
+	wchar_t			*fgetwln_z_buffer;
+	size_t			 fgetwln_z_buffer_size;
+};
+
+typedef void *bwstring_iterator;
+
+#define BWSLEN(s) ((s)->len)
+
+struct bwstring *bwsalloc(size_t sz);
+
+size_t bwsrawlen(const struct bwstring *bws);
+const void* bwsrawdata(const struct bwstring *bws);
+void bws_setlen(struct bwstring *bws, size_t newlen);
+size_t bws_memsize(const struct bwstring *bws);
+double bwstod(struct bwstring *s0, bool *empty);
+int bws_month_score(const struct bwstring *s0);
+
+struct bwstring *ignore_leading_blanks(struct bwstring *str);
+struct bwstring *ignore_nonprinting(struct bwstring *str);
+struct bwstring *dictionary_order(struct bwstring *str);
+struct bwstring *ignore_case(struct bwstring *str);
+
+void bwsprintf(FILE*, struct bwstring*, const char *prefix, const char *suffix);
+void bws_disorder_warnx(struct bwstring *s, const char *fn, size_t pos);
+
+struct bwstring *bwsdup(const struct bwstring *s);
+struct bwstring *bwssbdup(const wchar_t *str, size_t size);
+struct bwstring *bwscsbdup(const unsigned char *str, size_t size);
+void bwsfree(const struct bwstring *s);
+size_t bwscpy(struct bwstring *dst, const struct bwstring *src);
+struct bwstring *bwsncpy(struct bwstring *dst, const struct bwstring *src, size_t size);
+struct bwstring *bwsnocpy(struct bwstring *dst, const struct bwstring *src, size_t offset, size_t size);
+int bwscmp(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset);
+int bwsncmp(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset, size_t len);
+int bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset);
+int bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended);
+struct bwstring *bwsfgetln(FILE *file, size_t *len, bool zero_ended, struct reader_buffer *rb);
+
+static inline bwstring_iterator
+bws_begin(struct bwstring *bws)
+{
+
+	return (bwstring_iterator) (&(bws->data));
+}
+
+static inline bwstring_iterator
+bws_end(struct bwstring *bws)
+{
+
+	return ((MB_CUR_MAX == 1) ?
+	    (bwstring_iterator) (bws->data.cstr + bws->len) :
+	    (bwstring_iterator) (bws->data.wstr + bws->len));
+}
+
+static inline bwstring_iterator
+bws_iterator_inc(bwstring_iterator iter, size_t pos)
+{
+
+	if (MB_CUR_MAX == 1)
+		return ((unsigned char *) iter) + pos;
+	else
+		return ((wchar_t*) iter) + pos;
+}
+
+static inline wchar_t
+bws_get_iter_value(bwstring_iterator iter)
+{
+
+	if (MB_CUR_MAX == 1)
+		return *((unsigned char *) iter);
+	else
+		return *((wchar_t*) iter);
+}
+
+int
+bws_iterator_cmp(bwstring_iterator iter1, bwstring_iterator iter2, size_t len);
+
+#define BWS_GET(bws, pos) ((MB_CUR_MAX == 1) ? ((bws)->data.cstr[(pos)]) : (bws)->data.wstr[(pos)])
+
+void initialise_months(void);
+
+#endif /* __BWSTRING_H__ */
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/coll.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/coll.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,1301 @@
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/coll.c 236764 2012-06-08 19:21:49Z gabor $");
+
+#include <sys/types.h>
+
+#include <errno.h>
+#include <err.h>
+#include <langinfo.h>
+#include <limits.h>
+#include <math.h>
+#include <md5.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "coll.h"
+#include "vsort.h"
+
+struct key_specs *keys;
+size_t keys_num = 0;
+
+wchar_t symbol_decimal_point = L'.';
+/* there is no default thousands separator in collate rules: */
+wchar_t symbol_thousands_sep = 0;
+wchar_t symbol_negative_sign = L'-';
+wchar_t symbol_positive_sign = L'+';
+
+static int wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset);
+static int gnumcoll(struct key_value*, struct key_value *, size_t offset);
+static int monthcoll(struct key_value*, struct key_value *, size_t offset);
+static int numcoll(struct key_value*, struct key_value *, size_t offset);
+static int hnumcoll(struct key_value*, struct key_value *, size_t offset);
+static int randomcoll(struct key_value*, struct key_value *, size_t offset);
+static int versioncoll(struct key_value*, struct key_value *, size_t offset);
+
+/*
+ * Allocate keys array
+ */
+struct keys_array *
+keys_array_alloc(void)
+{
+	struct keys_array *ka;
+	size_t sz;
+
+	sz = keys_array_size();
+	ka = sort_malloc(sz);
+	memset(ka, 0, sz);
+
+	return (ka);
+}
+
+/*
+ * Calculate whether we need key hint space 
+ */
+static size_t
+key_hint_size(void)
+{
+
+	return (need_hint ? sizeof(struct key_hint) : 0);
+}
+
+/*
+ * Calculate keys array size
+ */
+size_t
+keys_array_size(void)
+{
+
+	return (keys_num * (sizeof(struct key_value) + key_hint_size()));
+}
+
+/*
+ * Clean data of keys array
+ */
+void
+clean_keys_array(const struct bwstring *s, struct keys_array *ka)
+{
+
+	if (ka) {
+		for (size_t i = 0; i < keys_num; ++i)
+			if (ka->key[i].k && ka->key[i].k != s)
+				bwsfree(ka->key[i].k);
+		memset(ka, 0, keys_array_size());
+	}
+}
+
+/*
+ * Set value of a key in the keys set
+ */
+void
+set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind)
+{
+
+	if (ka && keys_num > ind) {
+		struct key_value *kv;
+
+		kv = &(ka->key[ind]);
+
+		if (kv->k && kv->k != s)
+			bwsfree(kv->k);
+		kv->k = s;
+	}
+}
+
+/*
+ * Initialize a sort list item
+ */
+struct sort_list_item *
+sort_list_item_alloc(void)
+{
+	struct sort_list_item *si;
+	size_t sz;
+
+	sz = sizeof(struct sort_list_item) + keys_array_size();
+	si = sort_malloc(sz);
+	memset(si, 0, sz);
+
+	return (si);
+}
+
+size_t
+sort_list_item_size(struct sort_list_item *si)
+{
+	size_t ret = 0;
+
+	if (si) {
+		ret = sizeof(struct sort_list_item) + keys_array_size();
+		if (si->str)
+			ret += bws_memsize(si->str);
+		for (size_t i = 0; i < keys_num; ++i) {
+			struct key_value *kv;
+
+			kv = &(si->ka.key[i]);
+
+			if (kv->k != si->str)
+				ret += bws_memsize(kv->k);
+		}
+	}
+	return (ret);
+}
+
+/*
+ * Calculate key for a sort list item
+ */
+static void
+sort_list_item_make_key(struct sort_list_item *si)
+{
+
+	preproc(si->str, &(si->ka));
+}
+
+/*
+ * Set value of a sort list item.
+ * Return combined string and keys memory size.
+ */
+void
+sort_list_item_set(struct sort_list_item *si, struct bwstring *str)
+{
+
+	if (si) {
+		clean_keys_array(si->str, &(si->ka));
+		if (si->str) {
+			if (si->str == str) {
+				/* we are trying to reset the same string */
+				return;
+			} else {
+				bwsfree(si->str);
+				si->str = NULL;
+			}
+		}
+		si->str = str;
+		sort_list_item_make_key(si);
+	}
+}
+
+/*
+ * De-allocate a sort list item object memory
+ */
+void
+sort_list_item_clean(struct sort_list_item *si)
+{
+
+	if (si) {
+		clean_keys_array(si->str, &(si->ka));
+		if (si->str) {
+			bwsfree(si->str);
+			si->str = NULL;
+		}
+	}
+}
+
+/*
+ * Skip columns according to specs
+ */
+static size_t
+skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start,
+    bool skip_blanks, bool *empty_key)
+{
+	if (cols < 1)
+		return (BWSLEN(s) + 1);
+
+	if (skip_blanks)
+		while (start < BWSLEN(s) && iswblank(BWS_GET(s,start)))
+			++start;
+
+	while (start < BWSLEN(s) && cols > 1) {
+		--cols;
+		++start;
+	}
+
+	if (start >= BWSLEN(s))
+		*empty_key = true;
+
+	return (start);
+}
+
+/*
+ * Skip fields according to specs
+ */
+static size_t
+skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field)
+{
+
+	if (fields < 2) {
+		if (BWSLEN(s) == 0)
+			*empty_field = true;
+		return (0);
+	} else if (!(sort_opts_vals.tflag)) {
+		size_t cpos = 0;
+		bool pb = true;
+
+		while (cpos < BWSLEN(s)) {
+			bool isblank;
+
+			isblank = iswblank(BWS_GET(s,cpos));
+
+			if (isblank && !pb) {
+				--fields;
+				if (fields <= 1)
+					return (cpos);
+			}
+			pb = isblank;
+			++cpos;
+		}
+		if (fields > 1)
+			*empty_field = true;
+		return (cpos);
+	} else {
+		size_t cpos = 0;
+
+		while (cpos < BWSLEN(s)) {
+			if (BWS_GET(s,cpos) == sort_opts_vals.field_sep) {
+				--fields;
+				if (fields <= 1)
+					return (cpos + 1);
+			}
+			++cpos;
+		}
+		if (fields > 1)
+			*empty_field = true;
+		return (cpos);
+	}
+}
+
+/*
+ * Find fields start
+ */
+static void
+find_field_start(const struct bwstring *s, struct key_specs *ks,
+    size_t *field_start, size_t *key_start, bool *empty_field, bool *empty_key)
+{
+
+	*field_start = skip_fields_to_start(s, ks->f1, empty_field);
+	if (!*empty_field)
+		*key_start = skip_cols_to_start(s, ks->c1, *field_start,
+		    ks->pos1b, empty_key);
+	else
+		*empty_key = true;
+}
+
+/*
+ * Find end key position
+ */
+static size_t
+find_field_end(const struct bwstring *s, struct key_specs *ks)
+{
+	size_t f2, next_field_start, pos_end;
+	bool empty_field, empty_key;
+
+	pos_end = 0;
+	next_field_start = 0;
+	empty_field = false;
+	empty_key = false;
+	f2 = ks->f2;
+
+	if (f2 == 0)
+		return (BWSLEN(s) + 1);
+	else {
+		if (ks->c2 == 0) {
+			next_field_start = skip_fields_to_start(s, f2 + 1,
+			    &empty_field);
+			if ((next_field_start > 0) && sort_opts_vals.tflag &&
+			    (sort_opts_vals.field_sep == BWS_GET(s,
+			    next_field_start - 1)))
+				--next_field_start;
+		} else
+			next_field_start = skip_fields_to_start(s, f2,
+			    &empty_field);
+	}
+
+	if (empty_field || (next_field_start >= BWSLEN(s)))
+		return (BWSLEN(s) + 1);
+
+	if (ks->c2) {
+		pos_end = skip_cols_to_start(s, ks->c2, next_field_start,
+		    ks->pos2b, &empty_key);
+		if (pos_end < BWSLEN(s))
+			++pos_end;
+	} else
+		pos_end = next_field_start;
+
+	return (pos_end);
+}
+
+/*
+ * Cut a field according to the key specs
+ */
+static struct bwstring *
+cut_field(const struct bwstring *s, struct key_specs *ks)
+{
+	struct bwstring *ret = NULL;
+
+	if (s && ks) {
+		size_t field_start, key_end, key_start, sz;
+		bool empty_field, empty_key;
+
+		field_start = 0;
+		key_start = 0;
+		empty_field = false;
+		empty_key = false;
+
+		find_field_start(s, ks, &field_start, &key_start,
+		    &empty_field, &empty_key);
+
+		if (empty_key)
+			sz = 0;
+		else {
+			key_end = find_field_end(s, ks);
+			sz = (key_end < key_start) ? 0 : (key_end - key_start);
+		}
+
+		ret = bwsalloc(sz);
+		if (sz)
+			bwsnocpy(ret, s, key_start, sz);
+	} else
+		ret = bwsalloc(0);
+
+	return (ret);
+}
+
+/*
+ * Preprocesses a line applying the necessary transformations
+ * specified by command line options and returns the preprocessed
+ * string, which can be used to compare.
+ */
+int
+preproc(struct bwstring *s, struct keys_array *ka)
+{
+
+	if (sort_opts_vals.kflag)
+		for (size_t i = 0; i < keys_num; i++) {
+			struct bwstring *key;
+			struct key_specs *kspecs;
+			struct sort_mods *sm;
+
+			kspecs = &(keys[i]);
+			key = cut_field(s, kspecs);
+
+			sm = &(kspecs->sm);
+			if (sm->dflag)
+				key = dictionary_order(key);
+			else if (sm->iflag)
+				key = ignore_nonprinting(key);
+			if (sm->fflag || sm->Mflag)
+				key = ignore_case(key);
+
+			set_key_on_keys_array(ka, key, i);
+		}
+	else {
+		struct bwstring *ret = NULL;
+		struct sort_mods *sm = default_sort_mods;
+
+		if (sm->bflag) {
+			if (ret == NULL)
+				ret = bwsdup(s);
+			ret = ignore_leading_blanks(ret);
+		}
+		if (sm->dflag) {
+			if (ret == NULL)
+				ret = bwsdup(s);
+			ret = dictionary_order(ret);
+		} else if (sm->iflag) {
+			if (ret == NULL)
+				ret = bwsdup(s);
+			ret = ignore_nonprinting(ret);
+		}
+		if (sm->fflag || sm->Mflag) {
+			if (ret == NULL)
+				ret = bwsdup(s);
+			ret = ignore_case(ret);
+		}
+		if (ret == NULL)
+			set_key_on_keys_array(ka, s, 0);
+		else
+			set_key_on_keys_array(ka, ret, 0);
+	}
+
+	return 0;
+}
+
+cmpcoll_t
+get_sort_func(struct sort_mods *sm)
+{
+
+	if (sm->nflag)
+		return (numcoll);
+	else if (sm->hflag)
+		return (hnumcoll);
+	else if (sm->gflag)
+		return (gnumcoll);
+	else if (sm->Mflag)
+		return (monthcoll);
+	else if (sm->Rflag)
+		return (randomcoll);
+	else if (sm->Vflag)
+		return (versioncoll);
+	else
+		return (wstrcoll);
+}
+
+/*
+ * Compares the given strings.  Returns a positive number if
+ * the first precedes the second, a negative number if the second is
+ * the preceding one, and zero if they are equal.  This function calls
+ * the underlying collate functions, which done the actual comparison.
+ */
+int
+key_coll(struct keys_array *ps1, struct keys_array *ps2, size_t offset)
+{
+	struct sort_mods *sm;
+	int res = 0;
+
+	for (size_t i = 0; i < keys_num; ++i) {
+		sm = &(keys[i].sm);
+
+		if (sm->rflag)
+			res = sm->func(&(ps2->key[i]), &(ps1->key[i]), offset);
+		else
+			res = sm->func(&(ps1->key[i]), &(ps2->key[i]), offset);
+
+		if (res)
+			break;
+
+		/* offset applies to only the first key */
+		offset = 0;
+	}
+	return (res);
+}
+
+/*
+ * Compare two strings.
+ * Plain symbol-by-symbol comparison.
+ */
+int
+top_level_str_coll(const struct bwstring *s1, const struct bwstring *s2)
+{
+
+	if (default_sort_mods->rflag) {
+		const struct bwstring *tmp;
+
+		tmp = s1;
+		s1 = s2;
+		s2 = tmp;
+	}
+
+	return (bwscoll(s1, s2, 0));
+}
+
+/*
+ * Compare a string and a sort list item, according to the sort specs.
+ */
+int
+str_list_coll(struct bwstring *str1, struct sort_list_item **ss2)
+{
+	struct keys_array *ka1;
+	int ret = 0;
+
+	ka1 = keys_array_alloc();
+
+	preproc(str1, ka1);
+
+	sort_list_item_make_key(*ss2);
+
+	if (debug_sort) {
+		bwsprintf(stdout, str1, "; s1=<", ">");
+		bwsprintf(stdout, (*ss2)->str, ", s2=<", ">");
+	}
+
+	ret = key_coll(ka1, &((*ss2)->ka), 0);
+
+	if (debug_sort)
+		printf("; cmp1=%d", ret);
+
+	clean_keys_array(str1, ka1);
+	sort_free(ka1);
+
+	if ((ret == 0) && !(sort_opts_vals.sflag) && sort_opts_vals.complex_sort) {
+		ret = top_level_str_coll(str1, ((*ss2)->str));
+		if (debug_sort)
+			printf("; cmp2=%d", ret);
+	}
+
+	if (debug_sort)
+		printf("\n");
+
+	return (ret);
+}
+
+/*
+ * Compare two sort list items, according to the sort specs.
+ */
+int
+list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2,
+    size_t offset)
+{
+	int ret;
+
+	ret = key_coll(&((*ss1)->ka), &((*ss2)->ka), offset);
+
+	if (debug_sort) {
+		if (offset)
+			printf("; offset=%d", (int) offset);
+		bwsprintf(stdout, ((*ss1)->str), "; s1=<", ">");
+		bwsprintf(stdout, ((*ss2)->str), ", s2=<", ">");
+		printf("; cmp1=%d\n", ret);
+	}
+
+	if (ret)
+		return (ret);
+
+	if (!(sort_opts_vals.sflag) && sort_opts_vals.complex_sort) {
+		ret = top_level_str_coll(((*ss1)->str), ((*ss2)->str));
+		if (debug_sort)
+			printf("; cmp2=%d\n", ret);
+	}
+
+	return (ret);
+}
+
+/*
+ * Compare two sort list items, according to the sort specs.
+ */
+int
+list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2)
+{
+
+	return (list_coll_offset(ss1, ss2, 0));
+}
+
+#define LSCDEF(N) 											\
+static int 												\
+list_coll_##N(struct sort_list_item **ss1, struct sort_list_item **ss2)					\
+{													\
+													\
+	return (list_coll_offset(ss1, ss2, N));								\
+}
+
+LSCDEF(1)
+LSCDEF(2)
+LSCDEF(3)
+LSCDEF(4)
+LSCDEF(5)
+LSCDEF(6)
+LSCDEF(7)
+LSCDEF(8)
+LSCDEF(9)
+LSCDEF(10)
+LSCDEF(11)
+LSCDEF(12)
+LSCDEF(13)
+LSCDEF(14)
+LSCDEF(15)
+LSCDEF(16)
+LSCDEF(17)
+LSCDEF(18)
+LSCDEF(19)
+LSCDEF(20)
+
+listcoll_t
+get_list_call_func(size_t offset)
+{
+	static const listcoll_t lsarray[] = { list_coll, list_coll_1,
+	    list_coll_2, list_coll_3, list_coll_4, list_coll_5,
+	    list_coll_6, list_coll_7, list_coll_8, list_coll_9,
+	    list_coll_10, list_coll_11, list_coll_12, list_coll_13,
+	    list_coll_14, list_coll_15, list_coll_16, list_coll_17,
+	    list_coll_18, list_coll_19, list_coll_20 };
+
+	if (offset <= 20)
+		return (lsarray[offset]);
+
+	return (list_coll);
+}
+
+/*
+ * Compare two sort list items, only by their original string.
+ */
+int
+list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2)
+{
+
+	return (top_level_str_coll(((*ss1)->str), ((*ss2)->str)));
+}
+
+/*
+ * Maximum size of a number in the string (before or after decimal point)
+ */
+#define MAX_NUM_SIZE (128)
+
+/*
+ * Set suffix value
+ */
+static void setsuffix(wchar_t c, unsigned char *si)
+{
+	switch (c){
+	case L'k':
+	case L'K':
+		*si = 1;
+		break;
+	case L'M':
+		*si = 2;
+		break;
+	case L'G':
+		*si = 3;
+		break;
+	case L'T':
+		*si = 4;
+		break;
+	case L'P':
+		*si = 5;
+		break;
+	case L'E':
+		*si = 6;
+		break;
+	case L'Z':
+		*si = 7;
+		break;
+	case L'Y':
+		*si = 8;
+		break;
+	default:
+		*si = 0;
+	};
+}
+
+/*
+ * Read string s and parse the string into a fixed-decimal-point number.
+ * sign equals -1 if the number is negative (explicit plus is not allowed,
+ * according to GNU sort's "info sort".
+ * The number part before decimal point is in the smain, after the decimal
+ * point is in sfrac, tail is the pointer to the remainder of the string.
+ */
+static int
+read_number(struct bwstring *s0, int *sign, wchar_t *smain, int *main_len, wchar_t *sfrac, int *frac_len, unsigned char *si)
+{
+	bwstring_iterator s;
+
+	s = bws_begin(s0);
+
+	/* always end the fraction with zero, even if we have no fraction */
+	sfrac[0] = 0;
+
+	while (iswblank(bws_get_iter_value(s)))
+		s = bws_iterator_inc(s, 1);
+
+	if (bws_get_iter_value(s) == symbol_negative_sign) {
+		*sign = -1;
+		s = bws_iterator_inc(s, 1);
+	}
+
+	// This is '0', not '\0', do not change this
+	while (iswdigit(bws_get_iter_value(s)) &&
+	    (bws_get_iter_value(s) == L'0'))
+		s = bws_iterator_inc(s, 1);
+
+	while (bws_get_iter_value(s) && *main_len < MAX_NUM_SIZE) {
+		if (iswdigit(bws_get_iter_value(s))) {
+			smain[*main_len] = bws_get_iter_value(s);
+			s = bws_iterator_inc(s, 1);
+			*main_len += 1;
+		} else if (symbol_thousands_sep &&
+		    (bws_get_iter_value(s) == symbol_thousands_sep))
+			s = bws_iterator_inc(s, 1);
+		else
+			break;
+	}
+
+	smain[*main_len] = 0;
+
+	if (bws_get_iter_value(s) == symbol_decimal_point) {
+		s = bws_iterator_inc(s, 1);
+		while (iswdigit(bws_get_iter_value(s)) &&
+		    *frac_len < MAX_NUM_SIZE) {
+			sfrac[*frac_len] = bws_get_iter_value(s);
+			s = bws_iterator_inc(s, 1);
+			*frac_len += 1;
+		}
+		sfrac[*frac_len] = 0;
+
+		while (*frac_len > 0 && sfrac[*frac_len - 1] == L'0') {
+			--(*frac_len);
+			sfrac[*frac_len] = L'\0';
+		}
+	}
+
+	setsuffix(bws_get_iter_value(s),si);
+
+	if ((*main_len + *frac_len) == 0)
+		*sign = 0;
+
+	return (0);
+}
+
+/*
+ * Implements string sort.
+ */
+static int
+wstrcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+{
+
+	if (debug_sort) {
+		if (offset)
+			printf("; offset=%d\n", (int) offset);
+		bwsprintf(stdout, kv1->k, "; k1=<", ">");
+		printf("(%zu)", BWSLEN(kv1->k));
+		bwsprintf(stdout, kv2->k, ", k2=<", ">");
+		printf("(%zu)", BWSLEN(kv2->k));
+	}
+
+	return (bwscoll(kv1->k, kv2->k, offset));
+}
+
+/*
+ * Compare two suffixes
+ */
+static inline int
+cmpsuffix(unsigned char si1, unsigned char si2)
+{
+
+	return ((char)si1 - (char)si2);
+}
+
+/*
+ * Implements numeric sort for -n and -h.
+ */
+static int
+numcoll_impl(struct key_value *kv1, struct key_value *kv2,
+    size_t offset __unused, bool use_suffix)
+{
+	struct bwstring *s1, *s2;
+	wchar_t sfrac1[MAX_NUM_SIZE + 1], sfrac2[MAX_NUM_SIZE + 1];
+	wchar_t smain1[MAX_NUM_SIZE + 1], smain2[MAX_NUM_SIZE + 1];
+	int cmp_res, frac1, frac2, main1, main2, sign1, sign2;
+	unsigned char SI1, SI2;
+	bool e1, e2, key1_read, key2_read;
+
+	s1 = kv1->k;
+	s2 = kv2->k;
+	sign1 = sign2 = 0;
+	main1 = main2 = 0;
+	frac1 = frac2 = 0;
+
+	cmp_res = 0;
+	key1_read = key2_read = false;
+
+	if (debug_sort) {
+		bwsprintf(stdout, s1, "; k1=<", ">");
+		bwsprintf(stdout, s2, ", k2=<", ">");
+	}
+
+	if (s1 == s2)
+		return (0);
+
+	if (kv1->hint->status == HS_UNINITIALIZED) {
+		/* read the number from the string */
+		read_number(s1, &sign1, smain1, &main1, sfrac1, &frac1, &SI1);
+		key1_read = true;
+		kv1->hint->v.nh.n1 = wcstoull(smain1, NULL, 10);
+		if(main1 < 1 && frac1 < 1)
+			kv1->hint->v.nh.empty=true;
+		kv1->hint->v.nh.si = SI1;
+		kv1->hint->status = (kv1->hint->v.nh.n1 != ULLONG_MAX) ?
+		    HS_INITIALIZED : HS_ERROR;
+		kv1->hint->v.nh.neg = (sign1 < 0) ? true : false;
+	}
+
+	if (kv2->hint->status == HS_UNINITIALIZED) {
+		/* read the number from the string */
+		read_number(s2, &sign2, smain2, &main2, sfrac2, &frac2,&SI2);
+		key2_read = true;
+		kv2->hint->v.nh.n1 = wcstoull(smain2, NULL, 10);
+		if(main2 < 1 && frac2 < 1)
+			kv2->hint->v.nh.empty=true;
+		kv2->hint->v.nh.si = SI2;
+		kv2->hint->status = (kv2->hint->v.nh.n1 != ULLONG_MAX) ?
+		    HS_INITIALIZED : HS_ERROR;
+		kv2->hint->v.nh.neg = (sign2 < 0) ? true : false;
+	}
+
+	if (kv1->hint->status == HS_INITIALIZED && kv2->hint->status ==
+	    HS_INITIALIZED) {
+		unsigned long long n1, n2;
+		bool neg1, neg2;
+
+		e1 = kv1->hint->v.nh.empty;
+		e2 = kv2->hint->v.nh.empty;
+
+		if (e1 && e2)
+			return (0);
+
+		neg1 = kv1->hint->v.nh.neg;
+		neg2 = kv2->hint->v.nh.neg;
+
+		if (neg1 && !neg2)
+			return (-1);
+		if (neg2 && !neg1)
+			return (+1);
+
+		if (e1)
+			return (neg2 ? +1 : -1);
+		else if (e2)
+			return (neg1 ? -1 : +1);
+
+
+		if (use_suffix) {
+			cmp_res = cmpsuffix(kv1->hint->v.nh.si, kv2->hint->v.nh.si);
+			if (cmp_res)
+				return (neg1 ? -cmp_res : cmp_res);
+		}
+
+		n1 = kv1->hint->v.nh.n1;
+		n2 = kv2->hint->v.nh.n1;
+		if (n1 < n2)
+			return (neg1 ? +1 : -1);
+		else if (n1 > n2)
+			return (neg1 ? -1 : +1);
+	}
+
+	/* read the numbers from the strings */
+	if (!key1_read)
+		read_number(s1, &sign1, smain1, &main1, sfrac1, &frac1, &SI1);
+	if (!key2_read)
+		read_number(s2, &sign2, smain2, &main2, sfrac2, &frac2, &SI2);
+
+	e1 = ((main1 + frac1) == 0);
+	e2 = ((main2 + frac2) == 0);
+
+	if (e1 && e2)
+		return (0);
+
+	/* we know the result if the signs are different */
+	if (sign1 < 0 && sign2 >= 0)
+		return (-1);
+	if (sign1 >= 0 && sign2 < 0)
+		return (+1);
+
+	if (e1)
+		return ((sign2 < 0) ? +1 : -1);
+	else if (e2)
+		return ((sign1 < 0) ? -1 : +1);
+
+	if (use_suffix) {
+		cmp_res = cmpsuffix(SI1, SI2);
+		if (cmp_res)
+			return ((sign1 < 0) ? -cmp_res : cmp_res);
+	}
+
+	/* if both numbers are empty assume that the strings are equal */
+	if (main1 < 1 && main2 < 1 && frac1 < 1 && frac2 < 1)
+		return (0);
+
+	/*
+	 * if the main part is of different size, we know the result
+	 * (because the leading zeros are removed)
+	 */
+	if (main1 < main2)
+		cmp_res = -1;
+	else if (main1 > main2)
+		cmp_res = +1;
+	/* if the sizes are equal then simple non-collate string compare gives the correct result */
+	else
+		cmp_res = wcscmp(smain1, smain2);
+
+	/* check fraction */
+	if (!cmp_res)
+		cmp_res = wcscmp(sfrac1, sfrac2);
+
+	if (!cmp_res)
+		return (0);
+
+	/* reverse result if the signs are negative */
+	if (sign1 < 0 && sign2 < 0)
+		cmp_res = -cmp_res;
+
+	return (cmp_res);
+}
+
+/*
+ * Implements numeric sort (-n).
+ */
+static int
+numcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+{
+
+	return (numcoll_impl(kv1, kv2, offset, false));
+}
+
+/*
+ * Implements 'human' numeric sort (-h).
+ */
+static int
+hnumcoll(struct key_value *kv1, struct key_value *kv2, size_t offset)
+{
+
+	return (numcoll_impl(kv1, kv2, offset, true));
+}
+
+/*
+ * Implements random sort (-R).
+ */
+static int
+randomcoll(struct key_value *kv1, struct key_value *kv2,
+    size_t offset __unused)
+{
+	struct bwstring *s1, *s2;
+	MD5_CTX ctx1, ctx2;
+	char *b1, *b2;
+
+	s1 = kv1->k;
+	s2 = kv2->k;
+
+	if (debug_sort) {
+		bwsprintf(stdout, s1, "; k1=<", ">");
+		bwsprintf(stdout, s2, ", k2=<", ">");
+	}
+
+	if (s1 == s2)
+		return (0);
+
+	memcpy(&ctx1,&md5_ctx,sizeof(MD5_CTX));
+	memcpy(&ctx2,&md5_ctx,sizeof(MD5_CTX));
+
+	MD5Update(&ctx1, bwsrawdata(s1), bwsrawlen(s1));
+	MD5Update(&ctx2, bwsrawdata(s2), bwsrawlen(s2));
+	b1 = MD5End(&ctx1, NULL);
+	b2 = MD5End(&ctx2, NULL);
+	if (b1 == NULL) {
+		if (b2 == NULL)
+			return (0);
+		else {
+			sort_free(b2);
+			return (-1);
+		}
+	} else if (b2 == NULL) {
+		sort_free(b1);
+		return (+1);
+	} else {
+		int cmp_res;
+
+		cmp_res = strcmp(b1,b2);
+		sort_free(b1);
+		sort_free(b2);
+
+		if (!cmp_res)
+			cmp_res = bwscoll(s1, s2, 0);
+
+		return (cmp_res);
+	}
+}
+
+/*
+ * Implements version sort (-V).
+ */
+static int
+versioncoll(struct key_value *kv1, struct key_value *kv2,
+    size_t offset __unused)
+{
+	struct bwstring *s1, *s2;
+
+	s1 = kv1->k;
+	s2 = kv2->k;
+
+	if (debug_sort) {
+		bwsprintf(stdout, s1, "; k1=<", ">");
+		bwsprintf(stdout, s2, ", k2=<", ">");
+	}
+
+	if (s1 == s2)
+		return (0);
+
+	return (vcmp(s1, s2));
+}
+
+/*
+ * Check for minus infinity
+ */
+static inline bool
+huge_minus(double d, int err1)
+{
+
+	if (err1 == ERANGE)
+		if (d == -HUGE_VAL || d == -HUGE_VALF || d == -HUGE_VALL)
+			return (+1);
+
+	return (0);
+}
+
+/*
+ * Check for plus infinity
+ */
+static inline bool
+huge_plus(double d, int err1)
+{
+
+	if (err1 == ERANGE)
+		if (d == HUGE_VAL || d == HUGE_VALF || d == HUGE_VALL)
+			return (+1);
+
+	return (0);
+}
+
+/*
+ * Check whether a function is a NAN
+ */
+static bool
+is_nan(double d)
+{
+
+	return ((d == NAN) || (isnan(d)));
+}
+
+/*
+ * Compare two NANs
+ */
+static int
+cmp_nans(double d1, double d2)
+{
+
+	if (d1 < d2)
+		return (-1);
+	if (d2 > d2)
+		return (+1);
+	return (0);
+}
+
+/*
+ * Implements general numeric sort (-g).
+ */
+static int
+gnumcoll(struct key_value *kv1, struct key_value *kv2,
+    size_t offset __unused)
+{
+	double d1, d2;
+	int err1, err2;
+	bool empty1, empty2, key1_read, key2_read;
+
+	d1 = d2 = 0;
+	err1 = err2 = 0;
+	key1_read = key2_read = false;
+
+	if (debug_sort) {
+		bwsprintf(stdout, kv1->k, "; k1=<", ">");
+		bwsprintf(stdout, kv2->k, "; k2=<", ">");
+	}
+
+	if (kv1->hint->status == HS_UNINITIALIZED) {
+		errno = 0;
+		d1 = bwstod(kv1->k, &empty1);
+		err1 = errno;
+
+		if (empty1)
+			kv1->hint->v.gh.notnum = true;
+		else if (err1 == 0) {
+			kv1->hint->v.gh.d = d1;
+			kv1->hint->v.gh.nan = is_nan(d1);
+			kv1->hint->status = HS_INITIALIZED;
+		} else
+			kv1->hint->status = HS_ERROR;
+
+		key1_read = true;
+	}
+
+	if (kv2->hint->status == HS_UNINITIALIZED) {
+		errno = 0;
+		d2 = bwstod(kv2->k, &empty2);
+		err2 = errno;
+
+		if (empty2)
+			kv2->hint->v.gh.notnum = true;
+		else if (err2 == 0) {
+			kv2->hint->v.gh.d = d2;
+			kv2->hint->v.gh.nan = is_nan(d2);
+			kv2->hint->status = HS_INITIALIZED;
+		} else
+			kv2->hint->status = HS_ERROR;
+
+		key2_read = true;
+	}
+
+	if (kv1->hint->status == HS_INITIALIZED &&
+	    kv2->hint->status == HS_INITIALIZED) {
+		if (kv1->hint->v.gh.notnum)
+			return ((kv2->hint->v.gh.notnum) ? 0 : -1);
+		else if (kv2->hint->v.gh.notnum)
+			return (+1);
+
+		if (kv1->hint->v.gh.nan)
+			return ((kv2->hint->v.gh.nan) ?
+			    cmp_nans(kv1->hint->v.gh.d, kv2->hint->v.gh.d) :
+			    -1);
+		else if (kv2->hint->v.gh.nan)
+			return (+1);
+
+		d1 = kv1->hint->v.gh.d;
+		d2 = kv2->hint->v.gh.d;
+
+		if (d1 < d2)
+			return (-1);
+		else if (d1 > d2)
+			return (+1);
+		else
+			return (0);
+	}
+
+	if (!key1_read) {
+		errno = 0;
+		d1 = bwstod(kv1->k, &empty1);
+		err1 = errno;
+	}
+
+	if (!key2_read) {
+		errno = 0;
+		d2 = bwstod(kv2->k, &empty2);
+		err2 = errno;
+	}
+
+	/* Non-value case: */
+	if (empty1)
+		return (empty2 ? 0 : -1);
+	else if (empty2)
+		return (+1);
+
+	/* NAN case */
+	if (is_nan(d1))
+		return (is_nan(d2) ? cmp_nans(d1, d2) : -1);
+	else if (is_nan(d2))
+		return (+1);
+
+	/* Infinities */
+	if (err1 == ERANGE || err2 == ERANGE) {
+		/* Minus infinity case */
+		if (huge_minus(d1, err1)) {
+			if (huge_minus(d2, err2)) {
+				if (d1 < d2)
+					return (-1);
+				if (d1 > d2)
+					return (+1);
+				return (0);
+			} else
+				return (-1);
+
+		} else if (huge_minus(d2, err2)) {
+			if (huge_minus(d1, err1)) {
+				if (d1 < d2)
+					return (-1);
+				if (d1 > d2)
+					return (+1);
+				return (0);
+			} else
+				return (+1);
+		}
+
+		/* Plus infinity case */
+		if (huge_plus(d1, err1)) {
+			if (huge_plus(d2, err2)) {
+				if (d1 < d2)
+					return (-1);
+				if (d1 > d2)
+					return (+1);
+				return (0);
+			} else
+				return (+1);
+		} else if (huge_plus(d2, err2)) {
+			if (huge_plus(d1, err1)) {
+				if (d1 < d2)
+					return (-1);
+				if (d1 > d2)
+					return (+1);
+				return (0);
+			} else
+				return (-1);
+		}
+	}
+
+	if (d1 < d2)
+		return (-1);
+	if (d1 > d2)
+		return (+1);
+
+	return (0);
+}
+
+/*
+ * Implements month sort (-M).
+ */
+static int
+monthcoll(struct key_value *kv1, struct key_value *kv2, size_t offset __unused)
+{
+	int val1, val2;
+	bool key1_read, key2_read;
+
+	val1 = val2 = 0;
+	key1_read = key2_read = false;
+
+	if (debug_sort) {
+		bwsprintf(stdout, kv1->k, "; k1=<", ">");
+		bwsprintf(stdout, kv2->k, "; k2=<", ">");
+	}
+
+	if (kv1->hint->status == HS_UNINITIALIZED) {
+		kv1->hint->v.Mh.m = bws_month_score(kv1->k);
+		key1_read = true;
+		kv1->hint->status = HS_INITIALIZED;
+	}
+
+	if (kv2->hint->status == HS_UNINITIALIZED) {
+		kv2->hint->v.Mh.m = bws_month_score(kv2->k);
+		key2_read = true;
+		kv2->hint->status = HS_INITIALIZED;
+	}
+
+	if (kv1->hint->status == HS_INITIALIZED) {
+		val1 = kv1->hint->v.Mh.m;
+		key1_read = true;
+	}
+
+	if (kv2->hint->status == HS_INITIALIZED) {
+		val2 = kv2->hint->v.Mh.m;
+		key2_read = true;
+	}
+
+	if (!key1_read)
+		val1 = bws_month_score(kv1->k);
+	if (!key2_read)
+		val2 = bws_month_score(kv2->k);
+
+	if (val1 == val2) {
+		return (0);
+	}
+	if (val1 < val2)
+		return (-1);
+	return (+1);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/coll.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/coll.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,167 @@
+/*	$FreeBSD: head/usr.bin/sort/coll.h 235267 2012-05-11 12:37:16Z gabor $	*/
+
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__COLL_H__)
+#define __COLL_H__
+
+#include "bwstring.h"
+#include "sort.h"
+
+/*
+ * Sort hint data for -n
+ */
+struct n_hint
+{
+	unsigned long long	 n1;
+	unsigned char		 si;
+	bool			 empty;
+	bool			 neg;
+};
+
+/*
+ * Sort hint data for -g
+ */
+struct g_hint
+{
+	double			 d;
+	bool			 nan;
+	bool			 notnum;
+};
+
+/*
+ * Sort hint data for -M
+ */
+struct M_hint
+{
+	int			 m;
+};
+
+/*
+ * Status of a sort hint object
+ */
+typedef enum
+{
+	HS_ERROR = -1, HS_UNINITIALIZED = 0, HS_INITIALIZED = 1
+} hint_status;
+
+/*
+ * Sort hint object
+ */
+struct key_hint
+{
+	hint_status		status;
+	union
+	{
+		struct n_hint		nh;
+		struct g_hint		gh;
+		struct M_hint		Mh;
+	}			v;
+};
+
+/*
+ * Key value
+ */
+struct key_value
+{
+	struct bwstring		*k; /* key string */
+	struct key_hint		 hint[0]; /* key sort hint */
+};
+
+/*
+ * Set of keys container object.
+ */
+struct keys_array
+{
+	struct key_value	 key[0];
+};
+
+/*
+ * Parsed -k option data
+ */
+struct key_specs
+{
+	struct sort_mods	 sm;
+	size_t			 c1;
+	size_t			 c2;
+	size_t			 f1;
+	size_t			 f2;
+	bool			 pos1b;
+	bool			 pos2b;
+};
+
+/*
+ * Single entry in sort list.
+ */
+struct sort_list_item
+{
+	struct bwstring		*str;
+	struct keys_array	 ka;
+};
+
+/*
+ * Function type, used to compare two list objects
+ */
+typedef int (*listcoll_t)(struct sort_list_item **ss1, struct sort_list_item **ss2);
+
+extern struct key_specs *keys;
+extern size_t keys_num;
+
+/*
+ * Main localised symbols
+ */
+extern wchar_t symbol_decimal_point;
+extern wchar_t symbol_thousands_sep;
+extern wchar_t symbol_negative_sign;
+extern wchar_t symbol_positive_sign;
+
+/* funcs */
+
+cmpcoll_t get_sort_func(struct sort_mods *sm);
+
+struct keys_array *keys_array_alloc(void);
+size_t keys_array_size(void);
+void set_key_on_keys_array(struct keys_array *ka, struct bwstring *s, size_t ind);
+void clean_keys_array(const struct bwstring *s, struct keys_array *ka);
+
+struct sort_list_item *sort_list_item_alloc(void);
+void sort_list_item_set(struct sort_list_item *si, struct bwstring *str);
+void sort_list_item_clean(struct sort_list_item *si);
+size_t sort_list_item_size(struct sort_list_item *si);
+
+int preproc(struct bwstring *s, struct keys_array *ka);
+int top_level_str_coll(const struct bwstring *, const struct bwstring *);
+int key_coll(struct keys_array *ks1, struct keys_array *ks2, size_t offset);
+int str_list_coll(struct bwstring *str1, struct sort_list_item **ss2);
+int list_coll_by_str_only(struct sort_list_item **ss1, struct sort_list_item **ss2);
+int list_coll(struct sort_list_item **ss1, struct sort_list_item **ss2);
+int list_coll_offset(struct sort_list_item **ss1, struct sort_list_item **ss2, size_t offset);
+
+listcoll_t get_list_call_func(size_t offset);
+
+#endif /* __COLL_H__ */
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/file.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/file.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,1632 @@
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/file.c 238108 2012-07-04 16:25:11Z gabor $");
+
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/queue.h>
+
+#include <err.h>
+#include <fcntl.h>
+#if defined(SORT_THREADS)
+#include <pthread.h>
+#endif
+#include <semaphore.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "coll.h"
+#include "file.h"
+#include "radixsort.h"
+
+unsigned long long free_memory = 1000000;
+unsigned long long available_free_memory = 1000000;
+
+bool use_mmap;
+
+const char *tmpdir = "/var/tmp";
+const char *compress_program;
+
+size_t max_open_files = 16;
+
+/*
+ * How much space we read from file at once
+ */
+#define READ_CHUNK (4096)
+
+/*
+ * File reader structure
+ */
+struct file_reader
+{
+	struct reader_buffer	 rb;
+	FILE			*file;
+	char			*fname;
+	unsigned char		*buffer;
+	unsigned char		*mmapaddr;
+	unsigned char		*mmapptr;
+	size_t			 bsz;
+	size_t			 cbsz;
+	size_t			 mmapsize;
+	size_t			 strbeg;
+	int			 fd;
+	char			 elsymb;
+};
+
+/*
+ * Structure to be used in file merge process.
+ */
+struct file_header
+{
+	struct file_reader		*fr;
+	struct sort_list_item		*si; /* current top line */
+	size_t				 file_pos;
+};
+
+/*
+ * List elements of "cleanable" files list.
+ */
+struct CLEANABLE_FILE
+{
+	char				*fn;
+	LIST_ENTRY(CLEANABLE_FILE)	 files;
+};
+
+/*
+ * List header of "cleanable" files list.
+ */
+static LIST_HEAD(CLEANABLE_FILES,CLEANABLE_FILE) tmp_files;
+
+/*
+ * Semaphore to protect the tmp file list.
+ * We use semaphore here because it is signal-safe, according to POSIX.
+ * And semaphore does not require pthread library.
+ */
+static sem_t tmp_files_sem;
+
+static void mt_sort(struct sort_list *list,
+    int (*sort_func)(void *, size_t, size_t,
+    int (*)(const void *, const void *)), const char* fn);
+
+/*
+ * Init tmp files list
+ */
+void
+init_tmp_files(void)
+{
+
+	LIST_INIT(&tmp_files);
+	sem_init(&tmp_files_sem, 0, 1);
+}
+
+/*
+ * Save name of a tmp file for signal cleanup
+ */
+void
+tmp_file_atexit(const char *tmp_file)
+{
+
+	if (tmp_file) {
+		sem_wait(&tmp_files_sem);
+		struct CLEANABLE_FILE *item =
+		    sort_malloc(sizeof(struct CLEANABLE_FILE));
+		item->fn = sort_strdup(tmp_file);
+		LIST_INSERT_HEAD(&tmp_files, item, files);
+		sem_post(&tmp_files_sem);
+	}
+}
+
+/*
+ * Clear tmp files
+ */
+void
+clear_tmp_files(void)
+{
+	struct CLEANABLE_FILE *item;
+
+	sem_wait(&tmp_files_sem);
+	LIST_FOREACH(item,&tmp_files,files) {
+		if ((item) && (item->fn))
+			unlink(item->fn);
+	}
+	sem_post(&tmp_files_sem);
+}
+
+/*
+ * Check whether a file is a temporary file
+ */
+static bool
+file_is_tmp(const char* fn)
+{
+	struct CLEANABLE_FILE *item;
+	bool ret = false;
+
+	if (fn) {
+		sem_wait(&tmp_files_sem);
+		LIST_FOREACH(item,&tmp_files,files) {
+			if ((item) && (item->fn))
+				if (strcmp(item->fn, fn) == 0) {
+					ret = true;
+					break;
+				}
+		}
+		sem_post(&tmp_files_sem);
+	}
+
+	return (ret);
+}
+
+/*
+ * Read zero-terminated line from a file
+ */
+char *
+read_file0_line(struct file0_reader *f0r)
+{
+	size_t pos = 0;
+	int c;
+
+	if ((f0r->f == NULL) || feof(f0r->f))
+		return (NULL);
+
+	if (f0r->current_line && f0r->current_sz > 0)
+		f0r->current_line[0] = 0;
+
+	while (!feof(f0r->f)) {
+		c = fgetc(f0r->f);
+		if (feof(f0r->f) || (c == -1))
+			break;
+		if ((pos + 1) >= f0r->current_sz) {
+			size_t newsz = (f0r->current_sz + 2) * 2;
+			f0r->current_line = sort_realloc(f0r->current_line,
+			    newsz);
+			f0r->current_sz = newsz;
+		}
+		f0r->current_line[pos] = (char)c;
+		if (c == 0)
+			break;
+		else
+			f0r->current_line[pos + 1] = 0;
+		++pos;
+	}
+
+	return f0r->current_line;
+}
+
+/*
+ * Generate new temporary file name
+ */
+char *
+new_tmp_file_name(void)
+{
+	static unsigned int tfcounter = 0;
+	static const char *fn = ".bsdsort.";
+	char *ret;
+	size_t sz;
+
+	sz = strlen(tmpdir) + 1 + strlen(fn) + 32 + 1;
+	ret = sort_malloc(sz);
+
+	sprintf(ret, "%s/%s%d.%u", tmpdir, fn, (int) getpid(), tfcounter++);
+	tmp_file_atexit(ret);
+	return (ret);
+}
+
+/*
+ * Initialize file list
+ */
+void
+file_list_init(struct file_list *fl, bool tmp)
+{
+
+	if (fl) {
+		fl->count = 0;
+		fl->sz = 0;
+		fl->fns = NULL;
+		fl->tmp = tmp;
+	}
+}
+
+/*
+ * Add a file name to the list
+ */
+void
+file_list_add(struct file_list *fl, char *fn, bool allocate)
+{
+
+	if (fl && fn) {
+		if (fl->count >= fl->sz || (fl->fns == NULL)) {
+			fl->sz = (fl->sz) * 2 + 1;
+			fl->fns = sort_realloc(fl->fns, fl->sz *
+			    sizeof(char *));
+		}
+		fl->fns[fl->count] = allocate ? sort_strdup(fn) : fn;
+		fl->count += 1;
+	}
+}
+
+/*
+ * Populate file list from array of file names
+ */
+void
+file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate)
+{
+
+	if (fl && argv) {
+		int i;
+
+		for (i = 0; i < argc; i++)
+			file_list_add(fl, argv[i], allocate);
+	}
+}
+
+/*
+ * Clean file list data and delete the files,
+ * if this is a list of temporary files
+ */
+void
+file_list_clean(struct file_list *fl)
+{
+
+	if (fl) {
+		if (fl->fns) {
+			int i;
+
+			for (i = 0; i < fl->count; i++) {
+				if (fl->fns[i]) {
+					if (fl->tmp)
+						unlink(fl->fns[i]);
+					sort_free(fl->fns[i]);
+					fl->fns[i] = 0;
+				}
+			}
+			sort_free(fl->fns);
+			fl->fns = NULL;
+		}
+		fl->sz = 0;
+		fl->count = 0;
+		fl->tmp = false;
+	}
+}
+
+/*
+ * Init sort list
+ */
+void
+sort_list_init(struct sort_list *l)
+{
+
+	if (l) {
+		l->count = 0;
+		l->size = 0;
+		l->memsize = sizeof(struct sort_list);
+		l->list = NULL;
+	}
+}
+
+/*
+ * Add string to sort list
+ */
+void
+sort_list_add(struct sort_list *l, struct bwstring *str)
+{
+
+	if (l && str) {
+		size_t indx = l->count;
+
+		if ((l->list == NULL) || (indx >= l->size)) {
+			int newsize = (l->size + 1) + 1024;
+
+			l->list = sort_realloc(l->list,
+			    sizeof(struct sort_list_item*) * newsize);
+			l->memsize += (newsize - l->size) *
+			    sizeof(struct sort_list_item*);
+			l->size = newsize;
+		}
+		l->list[indx] = sort_list_item_alloc();
+		sort_list_item_set(l->list[indx], str);
+		l->memsize += sort_list_item_size(l->list[indx]);
+		l->count += 1;
+	}
+}
+
+/*
+ * Clean sort list data
+ */
+void
+sort_list_clean(struct sort_list *l)
+{
+
+	if (l) {
+		if (l->list) {
+			size_t i;
+
+			for (i = 0; i < l->count; i++) {
+				struct sort_list_item *item;
+
+				item = l->list[i];
+
+				if (item) {
+					sort_list_item_clean(item);
+					sort_free(item);
+					l->list[i] = NULL;
+				}
+			}
+			sort_free(l->list);
+			l->list = NULL;
+		}
+		l->count = 0;
+		l->size = 0;
+		l->memsize = sizeof(struct sort_list);
+	}
+}
+
+/*
+ * Write sort list to file
+ */
+void
+sort_list_dump(struct sort_list *l, const char *fn)
+{
+
+	if (l && fn) {
+		FILE *f;
+
+		f = openfile(fn, "w");
+		if (f == NULL)
+			err(2, NULL);
+
+		if (l->list) {
+			size_t i;
+			if (!(sort_opts_vals.uflag)) {
+				for (i = 0; i < l->count; ++i)
+					bwsfwrite(l->list[i]->str, f,
+					    sort_opts_vals.zflag);
+			} else {
+				struct sort_list_item *last_printed_item = NULL;
+				struct sort_list_item *item;
+				for (i = 0; i < l->count; ++i) {
+					item = l->list[i];
+					if ((last_printed_item == NULL) ||
+					    list_coll(&last_printed_item, &item)) {
+						bwsfwrite(item->str, f, sort_opts_vals.zflag);
+						last_printed_item = item;
+					}
+				}
+			}
+		}
+
+		closefile(f, fn);
+	}
+}
+
+/*
+ * Checks if the given file is sorted.  Stops at the first disorder,
+ * prints the disordered line and returns 1.
+ */
+int
+check(const char *fn)
+{
+	struct bwstring *s1, *s2, *s1disorder, *s2disorder;
+	struct file_reader *fr;
+	struct keys_array *ka1, *ka2;
+	int res, pos, posdisorder;
+
+	s1 = s2 = s1disorder = s2disorder = NULL;
+	ka1 = ka2 = NULL;
+
+	fr = file_reader_init(fn);
+
+	res = 0;
+	pos = 1;
+	posdisorder = 1;
+
+	if (fr == NULL) {
+		err(2, NULL);
+		goto end;
+	}
+
+	s1 = file_reader_readline(fr);
+	if (s1 == NULL)
+		goto end;
+
+	ka1 = keys_array_alloc();
+	preproc(s1, ka1);
+
+	s2 = file_reader_readline(fr);
+	if (s2 == NULL)
+		goto end;
+
+	ka2 = keys_array_alloc();
+	preproc(s2, ka2);
+
+	for (;;) {
+
+		if (debug_sort) {
+			bwsprintf(stdout, s2, "s1=<", ">");
+			bwsprintf(stdout, s1, "s2=<", ">");
+		}
+		int cmp = key_coll(ka2, ka1, 0);
+		if (debug_sort)
+			printf("; cmp1=%d", cmp);
+
+		if (!cmp && sort_opts_vals.complex_sort &&
+		    !(sort_opts_vals.uflag) && !(sort_opts_vals.sflag)) {
+			cmp = top_level_str_coll(s2, s1);
+			if (debug_sort)
+				printf("; cmp2=%d", cmp);
+		}
+		if (debug_sort)
+			printf("\n");
+
+		if ((sort_opts_vals.uflag && (cmp <= 0)) || (cmp < 0)) {
+			if (!(sort_opts_vals.csilentflag)) {
+				s2disorder = bwsdup(s2);
+				posdisorder = pos;
+				if (debug_sort)
+					s1disorder = bwsdup(s1);
+			}
+			res = 1;
+			goto end;
+		}
+
+		pos++;
+
+		clean_keys_array(s1, ka1);
+		sort_free(ka1);
+		ka1 = ka2;
+		ka2 = NULL;
+
+		bwsfree(s1);
+		s1 = s2;
+
+		s2 = file_reader_readline(fr);
+		if (s2 == NULL)
+			goto end;
+
+		ka2 = keys_array_alloc();
+		preproc(s2, ka2);
+	}
+
+end:
+	if (ka1) {
+		clean_keys_array(s1, ka1);
+		sort_free(ka1);
+	}
+
+	if (s1)
+		bwsfree(s1);
+
+	if (ka2) {
+		clean_keys_array(s2, ka2);
+		sort_free(ka2);
+	}
+
+	if (s2)
+		bwsfree(s2);
+
+	if ((fn == NULL) || (*fn == 0) || (strcmp(fn, "-") == 0)) {
+		for (;;) {
+			s2 = file_reader_readline(fr);
+			if (s2 == NULL)
+				break;
+			bwsfree(s2);
+		}
+	}
+
+	file_reader_free(fr);
+
+	if (s2disorder) {
+		bws_disorder_warnx(s2disorder, fn, posdisorder);
+		if (s1disorder) {
+			bws_disorder_warnx(s1disorder, fn, posdisorder);
+			if (s1disorder != s2disorder)
+				bwsfree(s1disorder);
+		}
+		bwsfree(s2disorder);
+		s1disorder = NULL;
+		s2disorder = NULL;
+	}
+
+	if (res)
+		exit(res);
+
+	return (0);
+}
+
+/*
+ * Opens a file.  If the given filename is "-", stdout will be
+ * opened.
+ */
+FILE *
+openfile(const char *fn, const char *mode)
+{
+	FILE *file;
+
+	if (strcmp(fn, "-") == 0) {
+		return ((mode && mode[0] == 'r') ? stdin : stdout);
+	} else {
+		mode_t orig_file_mask = 0;
+		int is_tmp = file_is_tmp(fn);
+
+		if (is_tmp && (mode[0] == 'w'))
+			orig_file_mask = umask(S_IWGRP | S_IWOTH |
+			    S_IRGRP | S_IROTH);
+
+		if (is_tmp && (compress_program != NULL)) {
+			char *cmd;
+			size_t cmdsz;
+
+			cmdsz = strlen(fn) + 128;
+			cmd = sort_malloc(cmdsz);
+
+			fflush(stdout);
+
+			if (mode[0] == 'r')
+				snprintf(cmd, cmdsz - 1, "cat %s | %s -d",
+				    fn, compress_program);
+			else if (mode[0] == 'w')
+				snprintf(cmd, cmdsz - 1, "%s > %s",
+				    compress_program, fn);
+			else
+				err(2, "%s", getstr(7));
+
+			if ((file = popen(cmd, mode)) == NULL)
+				err(2, NULL);
+
+			sort_free(cmd);
+
+		} else
+			if ((file = fopen(fn, mode)) == NULL)
+				err(2, NULL);
+
+		if (is_tmp && (mode[0] == 'w'))
+			umask(orig_file_mask);
+	}
+
+	return (file);
+}
+
+/*
+ * Close file
+ */
+void
+closefile(FILE *f, const char *fn)
+{
+	if (f == NULL) {
+		;
+	} else if (f == stdin) {
+		;
+	} else if (f == stdout) {
+		fflush(f);
+	} else {
+		if (file_is_tmp(fn) && compress_program != NULL) {
+			if(pclose(f)<0)
+				err(2,NULL);
+		} else
+			fclose(f);
+	}
+}
+
+/*
+ * Reads a file into the internal buffer.
+ */
+struct file_reader *
+file_reader_init(const char *fsrc)
+{
+	struct file_reader *ret;
+
+	if (fsrc == NULL)
+		fsrc = "-";
+
+	ret = sort_malloc(sizeof(struct file_reader));
+	memset(ret, 0, sizeof(struct file_reader));
+
+	ret->elsymb = '\n';
+	if (sort_opts_vals.zflag)
+		ret->elsymb = 0;
+
+	ret->fname = sort_strdup(fsrc);
+
+	if (strcmp(fsrc, "-") && (compress_program == NULL) && use_mmap) {
+
+		do {
+			struct stat stat_buf;
+			void *addr;
+			size_t sz = 0;
+			int fd, flags;
+
+			flags = MAP_NOCORE | MAP_NOSYNC;
+			addr = MAP_FAILED;
+
+			fd = open(fsrc, O_RDONLY);
+			if (fd < 0)
+				err(2, NULL);
+
+			if (fstat(fd, &stat_buf) < 0) {
+				close(fd);
+				break;
+			}
+
+			sz = stat_buf.st_size;
+
+#if defined(MAP_PREFAULT_READ)
+			flags |= MAP_PREFAULT_READ;
+#endif
+
+			addr = mmap(NULL, sz, PROT_READ, flags, fd, 0);
+			if (addr == MAP_FAILED) {
+				close(fd);
+				break;
+			}
+
+			ret->fd = fd;
+			ret->mmapaddr = addr;
+			ret->mmapsize = sz;
+			ret->mmapptr = ret->mmapaddr;
+
+		} while (0);
+	}
+
+	if (ret->mmapaddr == NULL) {
+		ret->file = openfile(fsrc, "r");
+		if (ret->file == NULL)
+			err(2, NULL);
+
+		if (strcmp(fsrc, "-")) {
+			ret->cbsz = READ_CHUNK;
+			ret->buffer = sort_malloc(ret->cbsz);
+			ret->bsz = 0;
+			ret->strbeg = 0;
+
+			ret->bsz = fread(ret->buffer, 1, ret->cbsz, ret->file);
+			if (ret->bsz == 0) {
+				if (ferror(ret->file))
+					err(2, NULL);
+			}
+		}
+	}
+
+	return (ret);
+}
+
+struct bwstring *
+file_reader_readline(struct file_reader *fr)
+{
+	struct bwstring *ret = NULL;
+
+	if (fr->mmapaddr) {
+		unsigned char *mmapend;
+
+		mmapend = fr->mmapaddr + fr->mmapsize;
+		if (fr->mmapptr >= mmapend)
+			return (NULL);
+		else {
+			unsigned char *strend;
+			size_t sz;
+
+			sz = mmapend - fr->mmapptr;
+			strend = memchr(fr->mmapptr, fr->elsymb, sz);
+
+			if (strend == NULL) {
+				ret = bwscsbdup(fr->mmapptr, sz);
+				fr->mmapptr = mmapend;
+			} else {
+				ret = bwscsbdup(fr->mmapptr, strend -
+				    fr->mmapptr);
+				fr->mmapptr = strend + 1;
+			}
+		}
+
+	} else if (fr->file != stdin) {
+		unsigned char *strend;
+		size_t bsz1, remsz, search_start;
+
+		search_start = 0;
+		remsz = 0;
+		strend = NULL;
+
+		if (fr->bsz > fr->strbeg)
+			remsz = fr->bsz - fr->strbeg;
+
+		/* line read cycle */
+		for (;;) {
+			if (remsz > search_start)
+				strend = memchr(fr->buffer + fr->strbeg +
+				    search_start, fr->elsymb, remsz -
+				    search_start);
+			else
+				strend = NULL;
+
+			if (strend)
+				break;
+			if (feof(fr->file))
+				break;
+
+			if (fr->bsz != fr->cbsz)
+				/* NOTREACHED */
+				err(2, "File read software error 1");
+
+			if (remsz > (READ_CHUNK >> 1)) {
+				search_start = fr->cbsz - fr->strbeg;
+				fr->cbsz += READ_CHUNK;
+				fr->buffer = sort_realloc(fr->buffer,
+				    fr->cbsz);
+				bsz1 = fread(fr->buffer + fr->bsz, 1,
+				    READ_CHUNK, fr->file);
+				if (bsz1 == 0) {
+					if (ferror(fr->file))
+						err(2, NULL);
+					break;
+				}
+				fr->bsz += bsz1;
+				remsz += bsz1;
+			} else {
+				if (remsz > 0 && fr->strbeg>0)
+					bcopy(fr->buffer + fr->strbeg,
+					    fr->buffer, remsz);
+
+				fr->strbeg = 0;
+				search_start = remsz;
+				bsz1 = fread(fr->buffer + remsz, 1,
+				    fr->cbsz - remsz, fr->file);
+				if (bsz1 == 0) {
+					if (ferror(fr->file))
+						err(2, NULL);
+					break;
+				}
+				fr->bsz = remsz + bsz1;
+				remsz = fr->bsz;
+			}
+		}
+
+		if (strend == NULL)
+			strend = fr->buffer + fr->bsz;
+
+		if ((fr->buffer + fr->strbeg <= strend) &&
+		    (fr->strbeg < fr->bsz) && (remsz>0))
+			ret = bwscsbdup(fr->buffer + fr->strbeg, strend -
+			    fr->buffer - fr->strbeg);
+
+		fr->strbeg = (strend - fr->buffer) + 1;
+
+	} else {
+		size_t len = 0;
+
+		ret = bwsfgetln(fr->file, &len, sort_opts_vals.zflag,
+		    &(fr->rb));
+	}
+
+	return (ret);
+}
+
+static void
+file_reader_clean(struct file_reader *fr)
+{
+
+	if (fr) {
+		if (fr->mmapaddr)
+			munmap(fr->mmapaddr, fr->mmapsize);
+
+		if (fr->fd)
+			close(fr->fd);
+
+		if (fr->buffer)
+			sort_free(fr->buffer);
+
+		if (fr->file)
+			if (fr->file != stdin)
+				closefile(fr->file, fr->fname);
+
+		if(fr->fname)
+			sort_free(fr->fname);
+
+		memset(fr, 0, sizeof(struct file_reader));
+	}
+}
+
+void
+file_reader_free(struct file_reader *fr)
+{
+
+	if (fr) {
+		file_reader_clean(fr);
+		sort_free(fr);
+	}
+}
+
+int
+procfile(const char *fsrc, struct sort_list *list, struct file_list *fl)
+{
+	struct file_reader *fr;
+
+	fr = file_reader_init(fsrc);
+	if (fr == NULL)
+		err(2, NULL);
+
+	/* file browse cycle */
+	for (;;) {
+		struct bwstring *bws;
+
+		bws = file_reader_readline(fr);
+
+		if (bws == NULL)
+			break;
+
+		sort_list_add(list, bws);
+
+		if (list->memsize >= available_free_memory) {
+			char *fn;
+
+			fn = new_tmp_file_name();
+			sort_list_to_file(list, fn);
+			file_list_add(fl, fn, false);
+			sort_list_clean(list);
+		}
+	}
+
+	file_reader_free(fr);
+
+	return (0);
+}
+
+/*
+ * Compare file headers. Files with EOF always go to the end of the list.
+ */
+static int
+file_header_cmp(struct file_header *f1, struct file_header *f2)
+{
+
+	if (f1 == f2)
+		return (0);
+	else {
+		if (f1->fr == NULL) {
+			return ((f2->fr == NULL) ? 0 : +1);
+		} else if (f2->fr == NULL)
+			return (-1);
+		else {
+			int ret;
+
+			ret = list_coll(&(f1->si), &(f2->si));
+			if (!ret)
+				return ((f1->file_pos < f2->file_pos) ? -1 : +1);
+			return (ret);
+		}
+	}
+}
+
+/*
+ * Allocate and init file header structure
+ */
+static void
+file_header_init(struct file_header **fh, const char *fn, size_t file_pos)
+{
+
+	if (fh && fn) {
+		struct bwstring *line;
+
+		*fh = sort_malloc(sizeof(struct file_header));
+		(*fh)->file_pos = file_pos;
+		(*fh)->fr = file_reader_init(fn);
+		if ((*fh)->fr == NULL) {
+			perror(fn);
+			err(2, "%s", getstr(8));
+		}
+		line = file_reader_readline((*fh)->fr);
+		if (line == NULL) {
+			file_reader_free((*fh)->fr);
+			(*fh)->fr = NULL;
+			(*fh)->si = NULL;
+		} else {
+			(*fh)->si = sort_list_item_alloc();
+			sort_list_item_set((*fh)->si, line);
+		}
+	}
+}
+
+/*
+ * Close file
+ */
+static void
+file_header_close(struct file_header **fh)
+{
+
+	if (fh && *fh) {
+		if ((*fh)->fr) {
+			file_reader_free((*fh)->fr);
+			(*fh)->fr = NULL;
+		}
+		if ((*fh)->si) {
+			sort_list_item_clean((*fh)->si);
+			sort_free((*fh)->si);
+			(*fh)->si = NULL;
+		}
+		sort_free(*fh);
+		*fh = NULL;
+	}
+}
+
+/*
+ * Swap two array elements
+ */
+static void
+file_header_swap(struct file_header **fh, int i1, int i2)
+{
+	struct file_header *tmp;
+
+	tmp = fh[i1];
+	fh[i1] = fh[i2];
+	fh[i2] = tmp;
+}
+
+/* heap algorithm ==>> */
+
+/*
+ * See heap sort algorithm
+ * "Raises" last element to its right place
+ */
+static void
+file_header_heap_swim(struct file_header **fh, int indx)
+{
+
+	if (indx > 0) {
+		int parent_index;
+
+		parent_index = (indx - 1) >> 1;
+
+		if (file_header_cmp(fh[indx], fh[parent_index]) < 0) {
+			/* swap child and parent and continue */
+			file_header_swap(fh, indx, parent_index);
+			file_header_heap_swim(fh, parent_index);
+		}
+	}
+}
+
+/*
+ * Sink the top element to its correct position
+ */
+static void
+file_header_heap_sink(struct file_header **fh, int indx, int size)
+{
+	int left_child_index;
+	int right_child_index;
+
+	left_child_index = indx + indx + 1;
+	right_child_index = left_child_index + 1;
+
+	if (left_child_index < size) {
+		int min_child_index;
+
+		min_child_index = left_child_index;
+
+		if ((right_child_index < size) &&
+		    (file_header_cmp(fh[left_child_index],
+		    fh[right_child_index]) > 0))
+			min_child_index = right_child_index;
+		if (file_header_cmp(fh[indx], fh[min_child_index]) > 0) {
+			file_header_swap(fh, indx, min_child_index);
+			file_header_heap_sink(fh, min_child_index, size);
+		}
+	}
+}
+
+/* <<== heap algorithm */
+
+/*
+ * Adds element to the "left" end
+ */
+static void
+file_header_list_rearrange_from_header(struct file_header **fh, int size)
+{
+
+	file_header_heap_sink(fh, 0, size);
+}
+
+/*
+ * Adds element to the "right" end
+ */
+static void
+file_header_list_push(struct file_header *f, struct file_header **fh, int size)
+{
+
+	fh[size++] = f;
+	file_header_heap_swim(fh, size - 1);
+}
+
+struct last_printed
+{
+	struct bwstring *str;
+};
+
+/*
+ * Prints the current line of the file
+ */
+static void
+file_header_print(struct file_header *fh, FILE *f_out, struct last_printed *lp)
+{
+
+	if (fh && fh->fr && f_out && fh->si && fh->si->str) {
+		if (sort_opts_vals.uflag) {
+			if ((lp->str == NULL) || (str_list_coll(lp->str, &(fh->si)))) {
+				bwsfwrite(fh->si->str, f_out, sort_opts_vals.zflag);
+				if (lp->str)
+					bwsfree(lp->str);
+				lp->str = bwsdup(fh->si->str);
+			}
+		} else
+			bwsfwrite(fh->si->str, f_out, sort_opts_vals.zflag);
+	}
+}
+
+/*
+ * Read next line
+ */
+static void
+file_header_read_next(struct file_header *fh)
+{
+
+	if (fh && fh->fr) {
+		struct bwstring *tmp;
+
+		tmp = file_reader_readline(fh->fr);
+		if (tmp == NULL) {
+			file_reader_free(fh->fr);
+			fh->fr = NULL;
+			if (fh->si) {
+				sort_list_item_clean(fh->si);
+				sort_free(fh->si);
+				fh->si = NULL;
+			}
+		} else {
+			if (fh->si == NULL)
+				fh->si = sort_list_item_alloc();
+			sort_list_item_set(fh->si, tmp);
+		}
+	}
+}
+
+/*
+ * Merge array of "files headers"
+ */
+static void
+file_headers_merge(int fnum, struct file_header **fh, FILE *f_out)
+{
+	struct last_printed lp;
+	int i;
+
+	memset(&lp, 0, sizeof(lp));
+
+	/*
+	 * construct the initial sort structure 
+	 */
+	for (i = 0; i < fnum; i++)
+		file_header_list_push(fh[i], fh, i);
+
+	while (fh[0]->fr) { /* unfinished files are always in front */
+		/* output the smallest line: */
+		file_header_print(fh[0], f_out, &lp);
+		/* read a new line, if possible: */
+		file_header_read_next(fh[0]);
+		/* re-arrange the list: */
+		file_header_list_rearrange_from_header(fh, fnum);
+	}
+
+	if (lp.str)
+		bwsfree(lp.str);
+}
+
+/*
+ * Merges the given files into the output file, which can be
+ * stdout.
+ */
+static void
+merge_files_array(int argc, char **argv, const char *fn_out)
+{
+
+	if (argv && fn_out) {
+		struct file_header **fh;
+		FILE *f_out;
+		int i;
+
+		f_out = openfile(fn_out, "w");
+
+		if (f_out == NULL)
+			err(2, NULL);
+
+		fh = sort_malloc((argc + 1) * sizeof(struct file_header *));
+
+		for (i = 0; i < argc; i++)
+			file_header_init(fh + i, argv[i], (size_t) i);
+
+		file_headers_merge(argc, fh, f_out);
+
+		for (i = 0; i < argc; i++)
+			file_header_close(fh + i);
+
+		sort_free(fh);
+
+		closefile(f_out, fn_out);
+	}
+}
+
+/*
+ * Shrinks the file list until its size smaller than max number of opened files
+ */
+static int
+shrink_file_list(struct file_list *fl)
+{
+
+	if ((fl == NULL) || (size_t) (fl->count) < max_open_files)
+		return (0);
+	else {
+		struct file_list new_fl;
+		int indx = 0;
+
+		file_list_init(&new_fl, true);
+		while (indx < fl->count) {
+			char *fnew;
+			int num;
+
+			num = fl->count - indx;
+			fnew = new_tmp_file_name();
+
+			if ((size_t) num >= max_open_files)
+				num = max_open_files - 1;
+			merge_files_array(num, fl->fns + indx, fnew);
+			if (fl->tmp) {
+				int i;
+
+				for (i = 0; i < num; i++)
+					unlink(fl->fns[indx + i]);
+			}
+			file_list_add(&new_fl, fnew, false);
+			indx += num;
+		}
+		fl->tmp = false; /* already taken care of */
+		file_list_clean(fl);
+
+		fl->count = new_fl.count;
+		fl->fns = new_fl.fns;
+		fl->sz = new_fl.sz;
+		fl->tmp = new_fl.tmp;
+
+		return (1);
+	}
+}
+
+/*
+ * Merge list of files
+ */
+void
+merge_files(struct file_list *fl, const char *fn_out)
+{
+
+	if (fl && fn_out) {
+		while (shrink_file_list(fl));
+
+		merge_files_array(fl->count, fl->fns, fn_out);
+	}
+}
+
+static const char *
+get_sort_method_name(int sm)
+{
+
+	if (sm == SORT_MERGESORT)
+		return "mergesort";
+	else if (sort_opts_vals.sort_method == SORT_RADIXSORT)
+		return "radixsort";
+	else if (sort_opts_vals.sort_method == SORT_HEAPSORT)
+		return "heapsort";
+	else
+		return "quicksort";
+}
+
+/*
+ * Wrapper for qsort
+ */
+static int sort_qsort(void *list, size_t count, size_t elem_size,
+    int (*cmp_func)(const void *, const void *))
+{
+
+	qsort(list, count, elem_size, cmp_func);
+	return (0);
+}
+
+/*
+ * Sort list of lines and writes it to the file
+ */
+void
+sort_list_to_file(struct sort_list *list, const char *outfile)
+{
+	struct sort_mods *sm = &(keys[0].sm);
+
+	if (!(sm->Mflag) && !(sm->Rflag) && !(sm->Vflag) && !(sm->Vflag) &&
+	    !(sm->gflag) && !(sm->hflag) && !(sm->nflag)) {
+		if ((sort_opts_vals.sort_method == SORT_DEFAULT) && byte_sort)
+			sort_opts_vals.sort_method = SORT_RADIXSORT;
+
+	} else if (sort_opts_vals.sort_method == SORT_RADIXSORT)
+		err(2, "%s", getstr(9));
+
+	/*
+	 * to handle stable sort and the unique cases in the
+	 * right order, we need stable basic algorithm
+	 */
+	if (sort_opts_vals.sflag) {
+		switch (sort_opts_vals.sort_method){
+		case SORT_MERGESORT:
+			break;
+		case SORT_RADIXSORT:
+			break;
+		case SORT_DEFAULT:
+			sort_opts_vals.sort_method = SORT_MERGESORT;
+			break;
+		default:
+			errx(2, "%s", getstr(10));
+		};
+	}
+
+	if (sort_opts_vals.sort_method == SORT_DEFAULT)
+		sort_opts_vals.sort_method = DEFAULT_SORT_ALGORITHM;
+
+	if (debug_sort)
+		printf("sort_method=%s\n",
+		    get_sort_method_name(sort_opts_vals.sort_method));
+
+	switch (sort_opts_vals.sort_method){
+	case SORT_RADIXSORT:
+		rxsort(list->list, list->count);
+		sort_list_dump(list, outfile);
+		break;
+	case SORT_MERGESORT:
+		mt_sort(list, mergesort, outfile);
+		break;
+	case SORT_HEAPSORT:
+		mt_sort(list, heapsort,	outfile);
+		break;
+	case SORT_QSORT:
+		mt_sort(list, sort_qsort, outfile);
+		break;
+	default:
+		mt_sort(list, DEFAULT_SORT_FUNC, outfile);
+		break;
+	}
+}
+
+/******************* MT SORT ************************/
+
+#if defined(SORT_THREADS)
+/* semaphore to count threads */
+static sem_t mtsem;
+
+/* current system sort function */
+static int (*g_sort_func)(void *, size_t, size_t,
+    int(*)(const void *, const void *));
+
+/*
+ * Sort cycle thread (in multi-threaded mode)
+ */
+static void*
+mt_sort_thread(void* arg)
+{
+	struct sort_list *list = arg;
+
+	g_sort_func(list->list, list->count, sizeof(struct sort_list_item *),
+	    (int(*)(const void *, const void *)) list_coll);
+
+	sem_post(&mtsem);
+
+	return (arg);
+}
+
+/*
+ * Compare sub-lists. Empty sub-lists always go to the end of the list.
+ */
+static int
+sub_list_cmp(struct sort_list *l1, struct sort_list *l2)
+{
+
+	if (l1 == l2)
+		return (0);
+	else {
+		if (l1->count == 0) {
+			return ((l2->count == 0) ? 0 : +1);
+		} else if (l2->count == 0) {
+			return (-1);
+		} else {
+			int ret;
+
+			ret = list_coll(&(l1->list[0]), &(l2->list[0]));
+			if (!ret)
+				return ((l1->sub_list_pos < l2->sub_list_pos) ?
+				    -1 : +1);
+			return (ret);
+		}
+	}
+}
+
+/*
+ * Swap two array elements
+ */
+static void
+sub_list_swap(struct sort_list **sl, int i1, int i2)
+{
+	struct sort_list *tmp;
+
+	tmp = sl[i1];
+	sl[i1] = sl[i2];
+	sl[i2] = tmp;
+}
+
+/* heap algorithm ==>> */
+
+/*
+ * See heap sort algorithm
+ * "Raises" last element to its right place
+ */
+static void
+sub_list_swim(struct sort_list **sl, int indx)
+{
+
+	if (indx > 0) {
+		int parent_index;
+
+		parent_index = (indx - 1) >> 1;
+
+		if (sub_list_cmp(sl[indx], sl[parent_index]) < 0) {
+			/* swap child and parent and continue */
+			sub_list_swap(sl, indx, parent_index);
+			sub_list_swim(sl, parent_index);
+		}
+	}
+}
+
+/*
+ * Sink the top element to its correct position
+ */
+static void
+sub_list_sink(struct sort_list **sl, int indx, int size)
+{
+	int left_child_index;
+	int right_child_index;
+
+	left_child_index = indx + indx + 1;
+	right_child_index = left_child_index + 1;
+
+	if (left_child_index < size) {
+		int min_child_index;
+
+		min_child_index = left_child_index;
+
+		if ((right_child_index < size) &&
+		    (sub_list_cmp(sl[left_child_index],
+		    sl[right_child_index]) > 0))
+			min_child_index = right_child_index;
+		if (sub_list_cmp(sl[indx], sl[min_child_index]) > 0) {
+			sub_list_swap(sl, indx, min_child_index);
+			sub_list_sink(sl, min_child_index, size);
+		}
+	}
+}
+
+/* <<== heap algorithm */
+
+/*
+ * Adds element to the "right" end
+ */
+static void
+sub_list_push(struct sort_list *s, struct sort_list **sl, int size)
+{
+
+	sl[size++] = s;
+	sub_list_swim(sl, size - 1);
+}
+
+struct last_printed_item
+{
+	struct sort_list_item *item;
+};
+
+/*
+ * Prints the current line of the file
+ */
+static void
+sub_list_header_print(struct sort_list *sl, FILE *f_out,
+    struct last_printed_item *lp)
+{
+
+	if (sl && sl->count && f_out && sl->list[0]->str) {
+		if (sort_opts_vals.uflag) {
+			if ((lp->item == NULL) || (list_coll(&(lp->item),
+			    &(sl->list[0])))) {
+				bwsfwrite(sl->list[0]->str, f_out,
+				    sort_opts_vals.zflag);
+				lp->item = sl->list[0];
+			}
+		} else
+			bwsfwrite(sl->list[0]->str, f_out,
+			    sort_opts_vals.zflag);
+	}
+}
+
+/*
+ * Read next line
+ */
+static void
+sub_list_next(struct sort_list *sl)
+{
+
+	if (sl && sl->count) {
+		sl->list += 1;
+		sl->count -= 1;
+	}
+}
+
+/*
+ * Merge sub-lists to a file
+ */
+static void
+merge_sub_lists(struct sort_list **sl, size_t n, FILE* f_out)
+{
+	struct last_printed_item lp;
+	size_t i;
+
+	memset(&lp,0,sizeof(lp));
+
+	/* construct the initial list: */
+	for (i = 0; i < n; i++)
+		sub_list_push(sl[i], sl, i);
+
+	while (sl[0]->count) { /* unfinished lists are always in front */
+		/* output the smallest line: */
+		sub_list_header_print(sl[0], f_out, &lp);
+		/* move to a new line, if possible: */
+		sub_list_next(sl[0]);
+		/* re-arrange the list: */
+		sub_list_sink(sl, 0, n);
+	}
+}
+
+/*
+ * Merge sub-lists to a file
+ */
+static void
+merge_list_parts(struct sort_list **parts, size_t n, const char *fn)
+{
+	FILE* f_out;
+
+	f_out = openfile(fn,"w");
+
+	merge_sub_lists(parts, n, f_out);
+
+	closefile(f_out, fn);
+}
+
+#endif /* defined(SORT_THREADS) */
+/*
+ * Multi-threaded sort algorithm "driver"
+ */
+static void
+mt_sort(struct sort_list *list,
+    int(*sort_func)(void *, size_t, size_t, int(*)(const void *, const void *)),
+    const char* fn)
+{
+#if defined(SORT_THREADS)
+	if (nthreads < 2 || list->count < MT_SORT_THRESHOLD) {
+		size_t nthreads_save = nthreads;
+		nthreads = 1;
+#endif
+		/* if single thread or small data, do simple sort */
+		sort_func(list->list, list->count,
+		    sizeof(struct sort_list_item *),
+		    (int(*)(const void *, const void *)) list_coll);
+		sort_list_dump(list, fn);
+#if defined(SORT_THREADS)
+		nthreads = nthreads_save;
+	} else {
+		/* multi-threaded sort */
+		struct sort_list **parts;
+		size_t avgsize, cstart, i;
+
+		/* array of sub-lists */
+		parts = sort_malloc(sizeof(struct sort_list*) * nthreads);
+		cstart = 0;
+		avgsize = list->count / nthreads;
+
+		/* set global system sort function */
+		g_sort_func = sort_func;
+
+		/* set sublists */
+		for (i = 0; i < nthreads; ++i) {
+			size_t sz = 0;
+
+			parts[i] = sort_malloc(sizeof(struct sort_list));
+			parts[i]->list = list->list + cstart;
+			parts[i]->memsize = 0;
+			parts[i]->sub_list_pos = i;
+
+			sz = (i == nthreads - 1) ? list->count - cstart :
+			    avgsize;
+
+			parts[i]->count = sz;
+
+			parts[i]->size = parts[i]->count;
+
+			cstart += sz;
+		}
+
+		/* init threads counting semaphore */
+		sem_init(&mtsem, 0, 0);
+
+		/* start threads */
+		for (i = 0; i < nthreads; ++i) {
+			pthread_t pth;
+			pthread_attr_t attr;
+
+			pthread_attr_init(&attr);
+			pthread_attr_setdetachstate(&attr, PTHREAD_DETACHED);
+
+			for (;;) {
+				int res = pthread_create(&pth, &attr,
+				    mt_sort_thread, parts[i]);
+
+				if (res >= 0)
+					break;
+				if (errno == EAGAIN) {
+					pthread_yield();
+					continue;
+				}
+				err(2, NULL);
+			}
+
+			pthread_attr_destroy(&attr);
+		}
+
+		/* wait for threads completion */
+		for (i = 0; i < nthreads; ++i) {
+			sem_wait(&mtsem);
+		}
+		/* destroy the semaphore - we do not need it anymore */
+		sem_destroy(&mtsem);
+
+		/* merge sorted sub-lists to the file */
+		merge_list_parts(parts, nthreads, fn);
+
+		/* free sub-lists data */
+		for (i = 0; i < nthreads; ++i) {
+			sort_free(parts[i]);
+		}
+		sort_free(parts);
+	}
+#endif /* defined(SORT_THREADS) */
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/file.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/file.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,138 @@
+/*	$FreeBSD: head/usr.bin/sort/file.h 238108 2012-07-04 16:25:11Z gabor $	*/
+
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__SORT_FILE_H__)
+#define __SORT_FILE_H__
+
+#include "coll.h"
+#include "sort.h"
+
+#define	SORT_DEFAULT	0
+#define	SORT_QSORT	1
+#define	SORT_MERGESORT	2
+#define	SORT_HEAPSORT	3
+#define	SORT_RADIXSORT  4
+
+#define DEFAULT_SORT_ALGORITHM SORT_HEAPSORT
+#define DEFAULT_SORT_FUNC heapsort
+
+/*
+ * List of data to be sorted.
+ */
+struct sort_list
+{
+	struct sort_list_item	**list;
+	unsigned long long	 memsize;
+	size_t			 count;
+	size_t			 size;
+	size_t			 sub_list_pos;
+};
+
+/*
+ * File reader object 
+ */
+struct file_reader;
+
+/*
+ * List of files to be sorted
+ */
+struct file_list
+{
+	char			**fns;
+	int			 count;
+	int			 sz;
+	bool			 tmp;
+};
+
+/*
+ * Structure for zero-separated file reading (for input files list)
+ */
+struct file0_reader
+{
+	char			*current_line;
+	FILE			*f;
+	size_t			 current_sz;
+};
+
+/* memory */
+
+/**/
+
+extern unsigned long long free_memory;
+extern unsigned long long available_free_memory;
+
+/* Are we using mmap ? */
+extern bool use_mmap;
+
+/* temporary file dir */
+
+extern const char *tmpdir;
+
+/*
+ * Max number of simultaneously open files (including the output file).
+ */
+extern size_t max_open_files;
+
+/*
+ * Compress program
+ */
+extern const char* compress_program;
+
+/* funcs */
+
+struct file_reader *file_reader_init(const char *fsrc);
+struct bwstring *file_reader_readline(struct file_reader *fr);
+void file_reader_free(struct file_reader *fr);
+
+char *read_file0_line(struct file0_reader *f0r);
+
+void init_tmp_files(void);
+void clear_tmp_files(void);
+char *new_tmp_file_name(void);
+void tmp_file_atexit(const char *tmp_file);
+
+void file_list_init(struct file_list *fl, bool tmp);
+void file_list_add(struct file_list *fl, char *fn, bool allocate);
+void file_list_populate(struct file_list *fl, int argc, char **argv, bool allocate);
+void file_list_clean(struct file_list *fl);
+
+int check(const char *);
+void merge_files(struct file_list *fl, const char *fn_out);
+FILE *openfile(const char *, const char *);
+void closefile(FILE *, const char *);
+int procfile(const char *fn, struct sort_list *list, struct file_list *fl);
+
+void sort_list_init(struct sort_list *l);
+void sort_list_add(struct sort_list *l, struct bwstring *str);
+void sort_list_clean(struct sort_list *l);
+void sort_list_dump(struct sort_list *l, const char *fn);
+
+void sort_list_to_file(struct sort_list *list, const char *outfile);
+
+#endif /* __SORT_FILE_H__ */
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/mem.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/mem.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/mem.c 235267 2012-05-11 12:37:16Z gabor $");
+
+#include <err.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "mem.h"
+
+/*
+ * malloc() wrapper.
+ */
+void *
+sort_malloc(size_t size)
+{
+	void *ptr;
+
+	if ((ptr = malloc(size)) == NULL)
+		err(2, NULL);
+	return (ptr);
+}
+
+/*
+ * free() wrapper.
+ */
+void
+sort_free(const void *ptr)
+{
+
+	if (ptr)
+		free(__DECONST(void *, ptr));
+}
+
+/*
+ * realloc() wrapper.
+ */
+void *
+sort_realloc(void *ptr, size_t size)
+{
+
+	if ((ptr = realloc(ptr, size)) == NULL)
+		err(2, NULL);
+	return (ptr);
+}
+
+char *
+sort_strdup(const char *str)
+{
+	char *dup;
+
+	if ((dup = strdup(str)) == NULL)
+		err(2, NULL);
+	return (dup);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/mem.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/mem.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,45 @@
+/*	$FreeBSD: head/usr.bin/sort/mem.h 235267 2012-05-11 12:37:16Z gabor $	*/
+
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__SORT_MEM_H__)
+#define __SORT_MEM_H__
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+/*
+ * mem.c
+ */
+void *sort_malloc(size_t);
+void sort_free(const void *ptr);
+void *sort_realloc(void *, size_t);
+char *sort_strdup(const char *);
+
+#endif /* __SORT_MEM_H__ */
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/nls/C.msg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/nls/C.msg	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,16 @@
+$ $FreeBSD: head/usr.bin/sort/nls/C.msg 235434 2012-05-14 09:55:23Z gabor $
+$
+$set 1
+$quote "
+1 "mutually exclusive flags"
+2 "extra argument not allowed with -c"
+3 "Unknown feature"
+4 "Wrong memory buffer specification"
+5 "0 field in key specs"
+6 "0 column in key specs"
+7 "Wrong file mode"
+8 "Cannot open file for reading"
+9 "Radix sort cannot be used with these sort options"
+10 "The chosen sort method cannot be used with stable and/or unique sort"
+11 "Invalid key position"
+12 "Usage: %s [-bcCdfigMmnrsuz] [-kPOS1[,POS2] ... ] [+POS1 [-POS2]] [-S memsize] [-T tmpdir] [-t separator] [-o outfile] [--batch-size size] [--files0-from file] [--heapsort] [--mergesort] [--radixsort] [--qsort] [--nthreads thread_no] [--human-numeric-sort] [--version-sort] [--random-sort [--random-source file]] [--compress-program program] [file ...]\n"
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/nls/hu_HU.ISO8859-2.msg
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/nls/hu_HU.ISO8859-2.msg	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,16 @@
+$ $FreeBSD: head/usr.bin/sort/nls/hu_HU.ISO8859-2.msg 235434 2012-05-14 09:55:23Z gabor $
+$
+$set 1
+$quote "
+1 "egymást kizáró opciók"
+2 "extra argumentum a -%c opcióval"
+3 "Ismeretlen funkció\n"
+4 "Rossz memória puffer érték"
+5 "0 mezõ a kulcsspecifikációban\n"
+6 "0 oszlop a kulcsspecifikációban\n"
+7 "Helytelen fájl mód"
+8 "A fájl nem nyitható meg olvasásra"
+9 "A radix rendezés nem használható a megadott rendezési opciókkal"
+10 "A választott rendezési mód nem használható a --stable és --unique opciókkal"
+11 "Érvénytelen kulcs pozíció"
+12 "Használat: %s [-bcCdfigMmnrsuz] [-kPOS1[,POS2] ... ] [+POS1 [-POS2]] [-S memóriaméret] [-T ideiglenes_könyvtár] [-t elválasztó] [-o kimeneti_fájl] [--batch-size méret] [--files0-from fájl] [--heapsort] [--mergesort] [--radixsort] [--qsort] [--nthreads szálak_száma] [--human-numeric-sort] [--version-sort] [--random-sort [--random-source fájl]] [--compress-program program] [fájl ...]\n"
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/radixsort.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/radixsort.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,691 @@
+/*-
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * Copyright (C) 2012 Gabor Kovesdan <gabor at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/radixsort.c 238108 2012-07-04 16:25:11Z gabor $");
+
+#include <errno.h>
+#include <err.h>
+#include <langinfo.h>
+#include <math.h>
+#if defined(SORT_THREADS)
+#include <pthread.h>
+#include <semaphore.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <unistd.h>
+
+#include "coll.h"
+#include "radixsort.h"
+
+#define DEFAULT_SORT_FUNC_RADIXSORT mergesort
+
+#define TINY_NODE(sl) ((sl)->tosort_num < 65)
+#define SMALL_NODE(sl) ((sl)->tosort_num < 5)
+
+/* are we sorting in reverse order ? */
+static bool reverse_sort;
+
+/* sort sub-levels array size */
+static const size_t slsz = 256 * sizeof(struct sort_level*);
+
+/* one sort level structure */
+struct sort_level
+{
+	struct sort_level	**sublevels;
+	struct sort_list_item	**leaves;
+	struct sort_list_item	**sorted;
+	struct sort_list_item	**tosort;
+	size_t			  leaves_num;
+	size_t			  leaves_sz;
+	size_t			  level;
+	size_t			  real_sln;
+	size_t			  start_position;
+	size_t			  sln;
+	size_t			  tosort_num;
+	size_t			  tosort_sz;
+};
+
+/* stack of sort levels ready to be sorted */
+struct level_stack {
+	struct level_stack	 *next;
+	struct sort_level	 *sl;
+};
+
+static struct level_stack *g_ls;
+
+#if defined(SORT_THREADS)
+/* stack guarding mutex */
+static pthread_mutex_t g_ls_mutex;
+
+/* counter: how many items are left */
+static size_t sort_left;
+/* guarding mutex */
+static pthread_mutex_t sort_left_mutex;
+
+/* semaphore to count threads */
+static sem_t mtsem;
+
+/*
+ * Decrement items counter
+ */
+static inline void
+sort_left_dec(size_t n)
+{
+
+	pthread_mutex_lock(&sort_left_mutex);
+	sort_left -= n;
+	pthread_mutex_unlock(&sort_left_mutex);
+}
+
+/*
+ * Do we have something to sort ?
+ */
+static inline bool
+have_sort_left(void)
+{
+	bool ret;
+
+	pthread_mutex_lock(&sort_left_mutex);
+	ret = (sort_left > 0);
+	pthread_mutex_unlock(&sort_left_mutex);
+	return (ret);
+}
+
+#else
+
+#define sort_left_dec(n)
+
+#endif /* SORT_THREADS */
+
+/*
+ * Push sort level to the stack
+ */
+static inline void
+push_ls(struct sort_level* sl)
+{
+	struct level_stack *new_ls;
+
+	new_ls = sort_malloc(sizeof(struct level_stack));
+	new_ls->sl = sl;
+
+#if defined(SORT_THREADS)
+	if (nthreads > 1)
+		pthread_mutex_lock(&g_ls_mutex);
+#endif
+
+	new_ls->next = g_ls;
+	g_ls = new_ls;
+
+#if defined(SORT_THREADS)
+	if (nthreads > 1)
+		pthread_mutex_unlock(&g_ls_mutex);
+#endif
+}
+
+/*
+ * Pop sort level from the stack (single-threaded style)
+ */
+static inline struct sort_level*
+pop_ls_st(void)
+{
+	struct sort_level *sl;
+
+	if (g_ls) {
+		struct level_stack *saved_ls;
+
+		sl = g_ls->sl;
+		saved_ls = g_ls;
+		g_ls = g_ls->next;
+		sort_free(saved_ls);
+	} else
+		sl = NULL;
+
+	return (sl);
+}
+
+/*
+ * Pop sort level from the stack (multi-threaded style)
+ */
+static inline struct sort_level*
+pop_ls_mt(void)
+{
+	struct level_stack *saved_ls;
+	struct sort_level *sl;
+
+#if defined(SORT_THREADS)
+	pthread_mutex_lock(&g_ls_mutex);
+#endif
+
+	if (g_ls) {
+		sl = g_ls->sl;
+		saved_ls = g_ls;
+		g_ls = g_ls->next;
+	} else {
+		sl = NULL;
+		saved_ls = NULL;
+	}
+
+#if defined(SORT_THREADS)
+	pthread_mutex_unlock(&g_ls_mutex);
+#endif
+
+	sort_free(saved_ls);
+
+	return (sl);
+}
+
+static void
+add_to_sublevel(struct sort_level *sl, struct sort_list_item *item, int indx)
+{
+	struct sort_level *ssl;
+
+	ssl = sl->sublevels[indx];
+
+	if (ssl == NULL) {
+		ssl = sort_malloc(sizeof(struct sort_level));
+		memset(ssl, 0, sizeof(struct sort_level));
+
+		ssl->level = sl->level + 1;
+		sl->sublevels[indx] = ssl;
+
+		++(sl->real_sln);
+	}
+
+	if (++(ssl->tosort_num) > ssl->tosort_sz) {
+		ssl->tosort_sz = ssl->tosort_num + 128;
+		ssl->tosort = sort_realloc(ssl->tosort,
+		    sizeof(struct sort_list_item*) * (ssl->tosort_sz));
+	}
+
+	ssl->tosort[ssl->tosort_num - 1] = item;
+}
+
+static inline void
+add_leaf(struct sort_level *sl, struct sort_list_item *item)
+{
+
+	if (++(sl->leaves_num) > sl->leaves_sz) {
+		sl->leaves_sz = sl->leaves_num + 128;
+		sl->leaves = sort_realloc(sl->leaves,
+		    (sizeof(struct sort_list_item*) * (sl->leaves_sz)));
+	}
+	sl->leaves[sl->leaves_num - 1] = item;
+}
+
+static inline int
+get_wc_index(struct sort_list_item *sli, size_t level)
+{
+	const struct bwstring *bws;
+
+	bws = sli->ka.key[0].k;
+
+	if ((BWSLEN(bws) > level))
+		return (unsigned char) BWS_GET(bws,level);
+	return (-1);
+}
+
+static void
+place_item(struct sort_level *sl, size_t item)
+{
+	struct sort_list_item *sli;
+	int c;
+
+	sli = sl->tosort[item];
+	c = get_wc_index(sli, sl->level);
+
+	if (c == -1)
+		add_leaf(sl, sli);
+	else
+		add_to_sublevel(sl, sli, c);
+}
+
+static void
+free_sort_level(struct sort_level *sl)
+{
+
+	if (sl) {
+		if (sl->leaves)
+			sort_free(sl->leaves);
+
+		if (sl->level > 0)
+			sort_free(sl->tosort);
+
+		if (sl->sublevels) {
+			struct sort_level *slc;
+			size_t sln;
+
+			sln = sl->sln;
+
+			for (size_t i = 0; i < sln; ++i) {
+				slc = sl->sublevels[i];
+				if (slc)
+					free_sort_level(slc);
+			}
+
+			sort_free(sl->sublevels);
+		}
+
+		sort_free(sl);
+	}
+}
+
+static void
+run_sort_level_next(struct sort_level *sl)
+{
+	struct sort_level *slc;
+	size_t i, sln, tosort_num;
+
+	if (sl->sublevels) {
+		sort_free(sl->sublevels);
+		sl->sublevels = NULL;
+	}
+
+	switch (sl->tosort_num){
+	case 0:
+		goto end;
+	case (1):
+		sl->sorted[sl->start_position] = sl->tosort[0];
+		sort_left_dec(1);
+		goto end;
+	case (2):
+		if (list_coll_offset(&(sl->tosort[0]), &(sl->tosort[1]),
+		    sl->level) > 0) {
+			sl->sorted[sl->start_position++] = sl->tosort[1];
+			sl->sorted[sl->start_position] = sl->tosort[0];
+		} else {
+			sl->sorted[sl->start_position++] = sl->tosort[0];
+			sl->sorted[sl->start_position] = sl->tosort[1];
+		}
+		sort_left_dec(2);
+
+		goto end;
+	default:
+		if (TINY_NODE(sl) || (sl->level > 15)) {
+			listcoll_t func;
+
+			func = get_list_call_func(sl->level);
+
+			sl->leaves = sl->tosort;
+			sl->leaves_num = sl->tosort_num;
+			sl->leaves_sz = sl->leaves_num;
+			sl->leaves = sort_realloc(sl->leaves,
+			    (sizeof(struct sort_list_item *) *
+			    (sl->leaves_sz)));
+			sl->tosort = NULL;
+			sl->tosort_num = 0;
+			sl->tosort_sz = 0;
+			sl->sln = 0;
+			sl->real_sln = 0;
+			if (sort_opts_vals.sflag) {
+				if (mergesort(sl->leaves, sl->leaves_num,
+				    sizeof(struct sort_list_item *),
+				    (int(*)(const void *, const void *)) func) == -1)
+					/* NOTREACHED */
+					err(2, "Radix sort error 3");
+			} else
+				DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
+				    sizeof(struct sort_list_item *),
+				    (int(*)(const void *, const void *)) func);
+
+			memcpy(sl->sorted + sl->start_position,
+			    sl->leaves, sl->leaves_num *
+			    sizeof(struct sort_list_item*));
+
+			sort_left_dec(sl->leaves_num);
+
+			goto end;
+		} else {
+			sl->tosort_sz = sl->tosort_num;
+			sl->tosort = sort_realloc(sl->tosort,
+			    sizeof(struct sort_list_item*) * (sl->tosort_sz));
+		}
+	}
+
+	sl->sln = 256;
+	sl->sublevels = sort_malloc(slsz);
+	memset(sl->sublevels, 0, slsz);
+
+	sl->real_sln = 0;
+
+	tosort_num = sl->tosort_num;
+	for (i = 0; i < tosort_num; ++i)
+		place_item(sl, i);
+
+	sort_free(sl->tosort);
+	sl->tosort = NULL;
+	sl->tosort_num = 0;
+	sl->tosort_sz = 0;
+
+	if (sl->leaves_num > 1) {
+		if (keys_num > 1) {
+			if (sort_opts_vals.sflag) {
+				mergesort(sl->leaves, sl->leaves_num,
+				    sizeof(struct sort_list_item *),
+				    (int(*)(const void *, const void *)) list_coll);
+			} else {
+				DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
+				    sizeof(struct sort_list_item *),
+				    (int(*)(const void *, const void *)) list_coll);
+			}
+		} else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) {
+			DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
+			    sizeof(struct sort_list_item *),
+			    (int(*)(const void *, const void *)) list_coll_by_str_only);
+		}
+	}
+
+	sl->leaves_sz = sl->leaves_num;
+	sl->leaves = sort_realloc(sl->leaves, (sizeof(struct sort_list_item *) *
+	    (sl->leaves_sz)));
+
+	if (!reverse_sort) {
+		memcpy(sl->sorted + sl->start_position, sl->leaves,
+		    sl->leaves_num * sizeof(struct sort_list_item*));
+		sl->start_position += sl->leaves_num;
+		sort_left_dec(sl->leaves_num);
+
+		sort_free(sl->leaves);
+		sl->leaves = NULL;
+		sl->leaves_num = 0;
+		sl->leaves_sz = 0;
+
+		sln = sl->sln;
+
+		for (i = 0; i < sln; ++i) {
+			slc = sl->sublevels[i];
+
+			if (slc) {
+				slc->sorted = sl->sorted;
+				slc->start_position = sl->start_position;
+				sl->start_position += slc->tosort_num;
+				if (SMALL_NODE(slc))
+					run_sort_level_next(slc);
+				else
+					push_ls(slc);
+				sl->sublevels[i] = NULL;
+			}
+		}
+
+	} else {
+		size_t n;
+
+		sln = sl->sln;
+
+		for (i = 0; i < sln; ++i) {
+			n = sln - i - 1;
+			slc = sl->sublevels[n];
+
+			if (slc) {
+				slc->sorted = sl->sorted;
+				slc->start_position = sl->start_position;
+				sl->start_position += slc->tosort_num;
+				if (SMALL_NODE(slc))
+					run_sort_level_next(slc);
+				else
+					push_ls(slc);
+				sl->sublevels[n] = NULL;
+			}
+		}
+
+		memcpy(sl->sorted + sl->start_position, sl->leaves,
+		    sl->leaves_num * sizeof(struct sort_list_item*));
+		sort_left_dec(sl->leaves_num);
+	}
+
+end:
+	free_sort_level(sl);
+}
+
+/*
+ * Single-threaded sort cycle
+ */
+static void
+run_sort_cycle_st(void)
+{
+	struct sort_level *slc;
+
+	for (;;) {
+		slc = pop_ls_st();
+		if (slc == NULL) {
+			break;
+		}
+		run_sort_level_next(slc);
+	}
+}
+
+#if defined(SORT_THREADS)
+
+/*
+ * Multi-threaded sort cycle
+ */
+static void
+run_sort_cycle_mt(void)
+{
+	struct sort_level *slc;
+
+	for (;;) {
+		slc = pop_ls_mt();
+		if (slc == NULL) {
+			if (have_sort_left()) {
+				pthread_yield();
+				continue;
+			}
+			break;
+		}
+		run_sort_level_next(slc);
+	}
+}
+
+/*
+ * Sort cycle thread (in multi-threaded mode)
+ */
+static void*
+sort_thread(void* arg)
+{
+
+	run_sort_cycle_mt();
+
+	sem_post(&mtsem);
+
+	return (arg);
+}
+
+#endif /* defined(SORT_THREADS) */
+
+static void
+run_top_sort_level(struct sort_level *sl)
+{
+	struct sort_level *slc;
+
+	reverse_sort = sort_opts_vals.kflag ? keys[0].sm.rflag :
+	    default_sort_mods->rflag;
+
+	sl->start_position = 0;
+	sl->sln = 256;
+	sl->sublevels = sort_malloc(slsz);
+	memset(sl->sublevels, 0, slsz);
+
+	for (size_t i = 0; i < sl->tosort_num; ++i)
+		place_item(sl, i);
+
+	if (sl->leaves_num > 1) {
+		if (keys_num > 1) {
+			if (sort_opts_vals.sflag) {
+				mergesort(sl->leaves, sl->leaves_num,
+				    sizeof(struct sort_list_item *),
+				    (int(*)(const void *, const void *)) list_coll);
+			} else {
+				DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
+				    sizeof(struct sort_list_item *),
+				    (int(*)(const void *, const void *)) list_coll);
+			}
+		} else if (!sort_opts_vals.sflag && sort_opts_vals.complex_sort) {
+			DEFAULT_SORT_FUNC_RADIXSORT(sl->leaves, sl->leaves_num,
+			    sizeof(struct sort_list_item *),
+			    (int(*)(const void *, const void *)) list_coll_by_str_only);
+		}
+	}
+
+	if (!reverse_sort) {
+		memcpy(sl->tosort + sl->start_position, sl->leaves,
+		    sl->leaves_num * sizeof(struct sort_list_item*));
+		sl->start_position += sl->leaves_num;
+		sort_left_dec(sl->leaves_num);
+
+		for (size_t i = 0; i < sl->sln; ++i) {
+			slc = sl->sublevels[i];
+
+			if (slc) {
+				slc->sorted = sl->tosort;
+				slc->start_position = sl->start_position;
+				sl->start_position += slc->tosort_num;
+				push_ls(slc);
+				sl->sublevels[i] = NULL;
+			}
+		}
+
+	} else {
+		size_t n;
+
+		for (size_t i = 0; i < sl->sln; ++i) {
+
+			n = sl->sln - i - 1;
+			slc = sl->sublevels[n];
+
+			if (slc) {
+				slc->sorted = sl->tosort;
+				slc->start_position = sl->start_position;
+				sl->start_position += slc->tosort_num;
+				push_ls(slc);
+				sl->sublevels[n] = NULL;
+			}
+		}
+
+		memcpy(sl->tosort + sl->start_position, sl->leaves,
+		    sl->leaves_num * sizeof(struct sort_list_item*));
+
+		sort_left_dec(sl->leaves_num);
+	}
+
+#if defined(SORT_THREADS)
+	if (nthreads < 2) {
+#endif
+		run_sort_cycle_st();
+#if defined(SORT_THREADS)
+	} else {
+		size_t i;
+
+		for(i = 0; i < nthreads; ++i) {
+			pthread_attr_t attr;
+			pthread_t pth;
+
+			pthread_attr_init(&attr);
+			pthread_attr_setdetachstate(&attr,
+			    PTHREAD_DETACHED);
+
+			for (;;) {
+				int res = pthread_create(&pth, &attr,
+				    sort_thread, NULL);
+				if (res >= 0)
+					break;
+				if (errno == EAGAIN) {
+					pthread_yield();
+					continue;
+				}
+				err(2, NULL);
+			}
+
+			pthread_attr_destroy(&attr);
+		}
+
+		for(i = 0; i < nthreads; ++i)
+			sem_wait(&mtsem);
+	}
+#endif /* defined(SORT_THREADS) */
+}
+
+static void
+run_sort(struct sort_list_item **base, size_t nmemb)
+{
+	struct sort_level *sl;
+
+#if defined(SORT_THREADS)
+	size_t nthreads_save = nthreads;
+	if (nmemb < MT_SORT_THRESHOLD)
+		nthreads = 1;
+
+	if (nthreads > 1) {
+		pthread_mutexattr_t mattr;
+
+		pthread_mutexattr_init(&mattr);
+		pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ADAPTIVE_NP);
+
+		pthread_mutex_init(&g_ls_mutex, &mattr);
+		pthread_mutex_init(&sort_left_mutex, &mattr);
+
+		pthread_mutexattr_destroy(&mattr);
+
+		sem_init(&mtsem, 0, 0);
+
+	}
+#endif
+
+	sl = sort_malloc(sizeof(struct sort_level));
+	memset(sl, 0, sizeof(struct sort_level));
+
+	sl->tosort = base;
+	sl->tosort_num = nmemb;
+	sl->tosort_sz = nmemb;
+
+#if defined(SORT_THREADS)
+	sort_left = nmemb;
+#endif
+
+	run_top_sort_level(sl);
+
+	free_sort_level(sl);
+
+#if defined(SORT_THREADS)
+	if (nthreads > 1) {
+		sem_destroy(&mtsem);
+		pthread_mutex_destroy(&g_ls_mutex);
+		pthread_mutex_destroy(&sort_left_mutex);
+	}
+	nthreads = nthreads_save;
+#endif
+}
+
+void
+rxsort(struct sort_list_item **base, size_t nmemb)
+{
+
+	run_sort(base, nmemb);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/radixsort.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/radixsort.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,38 @@
+/*	$FreeBSD: head/usr.bin/sort/radixsort.h 235267 2012-05-11 12:37:16Z gabor $	*/
+
+/*-
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * Copyright (C) 2012 Gabor Kovesdan <gabor at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__SORT_RADIX_H__)
+#define __SORT_RADIX_H__
+
+#include "coll.h"
+#include "sort.h"
+
+void rxsort(struct sort_list_item **base, size_t nmemb);
+
+#endif /* __SORT_RADIX_H__ */
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/sort.1.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/sort.1.in	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,638 @@
+.\"	$OpenBSD: sort.1,v 1.31 2007/08/21 21:22:37 millert Exp $
+.\"	$FreeBSD: head/usr.bin/sort/sort.1.in 238108 2012-07-04 16:25:11Z gabor $
+.\"
+.\" Copyright (c) 1991, 1993
+.\"	The Regents of the University of California.  All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the Institute of Electrical and Electronics Engineers, Inc.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"     @(#)sort.1	8.1 (Berkeley) 6/6/93
+.\"
+.Dd July 3, 2012
+.Dt SORT 1
+.Os
+.Sh NAME
+.Nm sort
+.Nd sort or merge records (lines) of text and binary files
+.Sh SYNOPSIS
+.Nm sort
+.Bk -words
+.Op Fl bcCdfghiRMmnrsuVz
+.Sm off
+.Op Fl k\ \& Ar field1 Op , Ar field2
+.Sm on
+.Op Fl S Ar memsize
+.Ek
+.Op Fl T Ar dir
+.Op Fl t Ar char
+.Op Fl o Ar output
+.Op Ar file ...
+.Nm sort
+.Fl Fl help
+.Nm sort
+.Fl Fl version
+.Sh DESCRIPTION
+The
+.Nm
+utility sorts text and binary files by lines.
+A line is a record separated from the subsequent record by a
+newline (default) or NUL \'\\0\' character (-z option).
+A record can contain any printable or unprintable characters.
+Comparisons are based on one or more sort keys extracted from
+each line of input, and are performed lexicographically,
+according to the current locale's collating rules and the
+specified command-line options that can tune the actual
+sorting behavior.
+By default, if keys are not given,
+.Nm
+uses entire lines for comparison.
+.Pp
+The command line options are as follows:
+.Bl -tag -width Ds
+.It Fl c, Fl Fl check, Fl C, Fl Fl check=silent|quiet
+Check that the single input file is sorted.
+If the file is not sorted,
+.Nm
+produces the appropriate error messages and exits with code 1,
+otherwise returns 0.
+If
+.Fl C
+or
+.Fl Fl check=silent
+is specified,
+.Nm
+produces no output.
+This is a "silent" version of
+.Fl c.
+.It Fl m , Fl Fl merge
+Merge only.
+The input files are assumed to be pre-sorted.
+If they are not sorted the output order is undefined.
+.It Fl o Ar output , Fl Fl output Ns = Ns Ar output
+Print the output to the
+.Ar output
+file instead of the standard output.
+.It Fl S Ar size, Fl Fl buffer-size Ns = Ns Ar size
+Use
+.Ar size
+for the maximum size of the memory buffer.
+Size modifiers %,b,K,M,G,T,P,E,Z,Y can be used.
+If a memory limit is not explicitly specified,
+.Nm
+takes up to about 90% of available memory.
+If the file size is too big to fit into the memory buffer,
+the temporary disk files are used to perform the sorting.
+.It Fl T Ar dir , Fl Fl temporary-directory Ns = Ns Ar dir
+Store temporary files in the directory
+.Ar dir .
+The default path is the value of the environment variable
+.Ev TMPDIR
+or
+.Pa /var/tmp
+if
+.Ev TMPDIR
+is not defined.
+.It Fl u , Fl Fl unique
+Unique keys.
+Suppress all lines that have a key that is equal to an already
+processed one.
+This option, similarly to
+.Fl s ,
+implies a stable sort.
+If used with
+.Fl c
+or
+.Fl C ,
+.Nm
+also checks that there are no lines with duplicate keys.
+.It Fl s
+Stable sort.
+This option maintains the original record order of records that have
+and equal key.
+This is a non-standard feature, but it is widely accepted and used.
+.It Fl Fl version
+Print the version and silently exits.
+.It Fl Fl help
+Print the help text and silently exits.
+.El
+.Pp
+The following options override the default ordering rules.
+When ordering options appear independently of key field
+specifications, they apply globally to all sort keys.
+When attached to a specific key (see
+.Fl k ) ,
+the ordering options override all global ordering options for
+the key they are attahced to.
+.Bl -tag -width indent
+.It Fl b, Fl Fl ignore-leading-blanks
+Ignore leading blank characters when comparing lines.
+.It Fl d , Fl Fl dictionary-order
+Consider only blank spaces and alphanumeric characters in comparisons.
+.It Fl f , Fl Fl ignore-case
+Convert all lowercase characters to their uppercase equivalent
+before comparison, that is, perform case-independent sorting.
+.It Fl g, Fl Fl general-numeric-sort, Fl Fl sort=general-numeric
+Sort by general numerical value.
+As opposed to
+.Fl n ,
+this option handles general floating points, which have a much
+permissive format than those allowed by
+. Fl n ,
+but it has a significant performance drawback.
+.It Fl h, Fl Fl human-numeric-sort, Fl Fl sort=human-numeric
+Sort by numerical value, but take into account the SI suffix,
+if present.
+Sort first by numeric sign (negative, zero, or
+positive); then by SI suffix (either empty, or `k' or `K', or one
+of `MGTPEZY', in that order); and finally by numeric value.
+The SI suffix must immediately follow the number.
+For example, '12345K' sorts before '1M', because M is "larger" than K.
+This sort option is useful for sorting the output of a single invocation
+of 'df' command with
+.Fl h
+or
+.Fl H
+options (human-readable).
+.It Fl i , Fl Fl ignore-nonprinting
+Ignore all non-printable characters.
+.It Fl M, Fl Fl month-sort, Fl Fl sort=month
+Sort by month abbreviations.
+Unknown strings are considered smaller than the month names.
+.It Fl n , Fl Fl numeric-sort, Fl Fl sort=numeric
+Sort fields numerically by arithmetic value.
+Fields are supposed to have optional blanks in the beginning, an
+optional minus sign, zero or more digits (including decimal point and
+possible thousand separators).
+.It Fl R, Fl Fl random-sort, Fl Fl sort=random
+Sort by a random order.
+This is a random permutation of the inputs except that
+the equal keys sort together.
+It is implemented by hashing the input keys and sorting
+the hash values.
+The hash function is choosen randomly.
+The hash function is randomized by
+.Cm /dev/random
+content, or by file content if it is specified by
+.Fl Fl random-source .
+Even if multiple sort fields are specified,
+the same random hash function is used for all of them.
+.It Fl r , Fl Fl reverse
+Sort in reverse order.
+.It Fl V, Fl Fl version-sort
+Sort version numbers.
+The input lines are treated as file names in form
+PREFIX VERSION SUFFIX, where SUFFIX matches the regular expression
+"(\.([A-Za-z~][A-Za-z0-9~]*)?)*".
+The files are compared by their prefixes and versions (leading
+zeros are ignored in version numbers, see example below).
+If an input string does not match the pattern, then it is compared
+using the byte compare function.
+All string comparisions are performed in C locale, the locale
+environment setting is ignored.
+.Bl -tag -width indent
+.It Example:
+.It $ ls sort* | sort -V
+.It sort-1.022.tgz
+.It sort-1.23.tgz
+.It sort-1.23.1.tgz
+.It sort-1.024.tgz
+.It sort-1.024.003.
+.It sort-1.024.003.tgz
+.It sort-1.024.07.tgz
+.It sort-1.024.009.tgz
+.El
+.El
+.Pp
+The treatment of field separators can be altered using these options:
+.Bl -tag -width indent
+.It Fl b , Fl Fl ignore-leading-blanks
+Ignore leading blank space when determining the start
+and end of a restricted sort key (see
+.Fl k
+).
+If
+.Fl b
+is specified before the first
+.Fl k
+option, it applies globally to all key specifications.
+Otherwise,
+.Fl b
+can be attached independently to each
+.Ar field
+argument of the key specifications.
+.Fl b .
+.It Xo
+.Sm off
+.Fl k\ \& Ar field1 Op , Ar field2 , Fl Fl key Ns = Ns Ar field1 Op , Ar field2
+.Sm on
+.Xc
+Define a restricted sort key that has the starting position
+.Ar field1 ,
+and optional ending position
+.Ar field2
+of a key field.
+The
+.Fl k
+option may be specified multiple times,
+in which case subsequent keys are compared when earlier keys compare equal.
+The
+.Fl k
+option replaces the obsolete options
+.Cm \(pl Ns Ar pos1
+and
+.Fl Ns Ar pos2 ,
+but the old notation is also supported.
+.It Fl t Ar char , Fl Fl field-separator Ns = Ns Ar char
+Use
+.Ar char
+as a field separator character.
+The initial
+.Ar char
+is not considered to be part of a field when determining key offsets.
+Each occurrence of
+.Ar char
+is significant (for example,
+.Dq Ar charchar
+delimits an empty field).
+If
+.Fl t
+is not specified, the default field separator is a sequence of
+blank space characters, and consecutive blank spaces do
+.Em not
+delimit an empty field, however, the initial blank space
+.Em is
+considered part of a field when determining key offsets.
+To use NUL as field separator, use
+.Fl t
+\'\\0\'.
+.It Fl z , Fl Fl zero-terminated
+Use NUL as record separator.
+By default, records in the files are supposed to be separated by
+the newline characters.
+With this option, NUL (\'\\0\') is used as a record separator character.
+.El
+.Pp
+Other options:
+.Bl -tag -width indent
+.It Fl Fl batch-size Ns = Ns Ar num
+Specify maximum number of files that can be opened by
+.Nm
+at once.
+This option affects behavior when having many input files or using
+temporary files.
+The default value is 16.
+.It Fl Fl compress-program Ns = Ns Ar PROGRAM
+Use PROGRAM to compress temporary files.
+PROGRAM must compress standard input to standard output, when called
+without arguments.
+When called with argument
+.Fl d
+it must decompress standard input to standard output.
+If PROGRAM fails, 
+.Nm 
+must exit with error.
+An example of PROGRAM that can be used here is bzip2.
+.It Fl Fl random-source Ns = Ns Ar filename
+In random sort, the file content is used as the source of the 'seed' data
+for the hash function choice.
+Two invocations of random sort with the same seed data will use
+the same hash function and will produce the same result if the input is
+also identical.
+By default, file
+.Cm /dev/random
+is used.
+.It Fl Fl debug
+Print some extra information about the sorting process to the
+standard output.
+%%THREADS%%.It Fl Fl parallel
+%%THREADS%%Set the maximum number of execution threads.
+%%THREADS%%Default number equals to the number of CPUs.
+.It Fl Fl files0-from Ns = Ns Ar filename
+Take the input file list from the file
+.Ar filename.
+The file names must be separated by NUL
+(like the output produced by the command "find ... -print0").
+.It Fl Fl radixsort
+Try to use radix sort, if the sort specifications allow.
+The radix sort can only be used for trivial locales (C and POSIX),
+and it cannot be used for numeric or month sort.
+Radix sort is very fast and stable.
+.It Fl Fl mergesort
+Use mergesort.
+This is a universal algorithm that can always be used,
+but it is not always the fastest.
+.It Fl Fl qsort
+Try to use quick sort, if the sort specifications allow.
+This sort algorithm cannot be used with
+.Fl u
+and
+.Fl s .
+.It Fl Fl heapsort
+Try to use heap sort, if the sort specifications allow.
+This sort algorithm cannot be used with
+.Fl u
+and
+.Fl s .
+.It Fl Fl mmap
+Try to use file memory mapping system call.
+It may increase speed in some cases.
+.El
+.Pp
+The following operands are available:
+.Bl -tag -width indent
+.It Ar file
+The pathname of a file to be sorted, merged, or checked.
+If no
+.Ar file
+operands are specified, or if a
+.Ar file
+operand is
+.Fl ,
+the standard input is used.
+.El
+.Pp
+A field is defined as a maximal sequence of characters other than the
+field separator and record separator (newline by default).
+Initial blank spaces are included in the field unless
+.Fl b
+has been specified;
+the first blank space of a sequence of blank spaces acts as the field
+separator and is included in the field (unless
+.Fl t
+is specified).
+For example, all blank spaces at the beginning of a line are
+considered to be part of the first field.
+.Pp
+Fields are specified by the
+.Sm off
+.Fl k\ \& Ar field1 Op , Ar field2
+.Sm on
+command-line option.
+If
+.Ar field2
+is missing, the end of the key defaults to the end of the line.
+.Pp
+The arguments
+.Ar field1
+and
+.Ar field2
+have the form
+.Em m.n
+.Em (m,n > 0)
+and can be followed by one or more of the modifiers
+.Cm b , d , f , i ,
+.Cm n , g , M
+and
+.Cm r ,
+which correspond to the options discussed above.
+When
+.Cm b
+is specified it applies only to
+.Ar field1
+or
+.Ar field2
+where it is specified while the rest of the modifiers
+apply to the whole key field regardless if they are
+specified only with
+.Ar field1
+or
+.Ar field2
+or both.
+A
+.Ar field1
+position specified by
+.Em m.n
+is interpreted as the
+.Em n Ns th
+character from the beginning of the
+.Em m Ns th
+field.
+A missing
+.Em \&.n
+in
+.Ar field1
+means
+.Ql \&.1 ,
+indicating the first character of the
+.Em m Ns th
+field; if the
+.Fl b
+option is in effect,
+.Em n
+is counted from the first non-blank character in the
+.Em m Ns th
+field;
+.Em m Ns \&.1b
+refers to the first non-blank character in the
+.Em m Ns th
+field.
+.No 1\&. Ns Em n
+refers to the
+.Em n Ns th
+character from the beginning of the line;
+if
+.Em n
+is greater than the length of the line, the field is taken to be empty.
+.Pp
+.Em n Ns th
+positions are always counted from the field beginning, even if the field
+is shorter than the number of specified positions.
+Thus, the key can really start from a position in a subsequent field.
+.Pp
+A
+.Ar field2
+position specified by
+.Em m.n
+is interpreted as the
+.Em n Ns th
+character (including separators) from the beginning of the
+.Em m Ns th
+field.
+A missing
+.Em \&.n
+indicates the last character of the
+.Em m Ns th
+field;
+.Em m
+= \&0
+designates the end of a line.
+Thus the option
+.Fl k Ar v.x,w.y
+is synonymous with the obsolete option
+.Cm \(pl Ns Ar v-\&1.x-\&1
+.Fl Ns Ar w-\&1.y ;
+when
+.Em y
+is omitted,
+.Fl k Ar v.x,w
+is synonymous with
+.Cm \(pl Ns Ar v-\&1.x-\&1
+.Fl Ns Ar w\&.0 .
+The obsolete
+.Cm \(pl Ns Ar pos1
+.Fl Ns Ar pos2
+option is still supported, except for
+.Fl Ns Ar w\&.0b ,
+which has no
+.Fl k
+equivalent.
+.Sh ENVIRONMENT
+.Bl -tag -width Fl
+.It Ev LC_COLLATE
+Locale settings to be used to determine the collation for
+sorting records.
+.It Ev LC_CTYPE
+Locale settings to be used to case conversion and classification
+of characters, that is, which characters are considered
+whitespaces, etc.
+.It Ev LC_MESSAGES
+Locale settings that determine the language of output messages
+that
+.Nm
+prints out.
+.It Ev LC_NUMERIC
+Locale settings that determine the number format used in numeric sort.
+.It Ev LC_TIME
+Locale settings that determine the month format used in month sort.
+.It Ev LC_ALL
+Locale settings that override all of the above locale settings.
+This environment variable can be used to set all these settings
+to the same value at once.
+.It Ev LANG
+Used as a last resort to determine different kinds of locale-specific
+behavior if neither the respective environment variable, nor
+.Ev LC_ALL
+are set.
+%%NLS%%.It Ev NLSPATH
+%%NLS%%Path to NLS catalogs.
+.It Ev TMPDIR
+Path to the directory in which temporary files will be stored.
+Note that
+.Ev TMPDIR
+may be overridden by the
+.Fl T
+option.
+.It Ev GNUSORT_NUMERIC_COMPATIBILITY
+If defined
+.Fl t
+will not override the locale numeric symbols, that is, thousand
+separators and decimal separators.
+By default, if we specify
+.Fl t
+with the same symbol as the thousand separator or decimal point,
+the symbol will be treated as the field separator.
+Older behavior was less definite; the symbol was treated as both field
+separator and numeric separator, simultaneously.
+This environment variable enables the old behavior.
+.El
+.Sh FILES
+.Bl -tag -width Pa -compact
+.It Pa /var/tmp/.bsdsort.PID.*
+Temporary files.
+.It Pa /dev/random
+Default seed file for the random sort.
+.El
+.Sh EXIT STATUS
+The
+.Nm
+utility shall exit with one of the following values:
+.Pp
+.Bl -tag -width flag -compact
+.It 0
+Successfully sorted the input files or if used with
+.Fl c
+or
+.Fl C ,
+the input file already met the sorting criteria.
+.It 1
+On disorder (or non-uniqueness) with the
+.Fl c
+or
+.Fl C
+options.
+.It 2
+An error occurred.
+.El
+.Sh SEE ALSO
+.Xr comm 1 ,
+.Xr join 1 ,
+.Xr uniq 1 .
+.Sh STANDARDS
+The
+.Nm
+utility is compliant with the
+.St -p1003.1-2008
+specification.
+.Pp
+The flags
+.Op Fl ghRMSsTVz
+are extensions to the POSIX specification.
+.Pp
+All long options are extensions to the specification, some of them are
+provided for compatibility with GNU versions and some of them are
+own extensions.
+.Pp
+The old key notations
+.Cm \(pl Ns Ar pos1
+and
+.Fl Ns Ar pos2
+come from older versions of
+.Nm
+and are still supported but their use is highly discouraged.
+.Sh HISTORY
+A
+.Nm
+command first appeared in
+.At v3 .
+.Sh AUTHORS
+Gabor Kovesdan <gabor at FreeBSD.org>,
+.Pp
+Oleg Moskalenko <oleg.moskalenko at citrix.com>
+.Sh NOTES
+This implementation of
+.Nm
+has no limits on input line length (other than imposed by available
+memory) or any restrictions on bytes allowed within lines.
+.Pp
+The performance depends highly on locale settings,
+efficient choice of sort keys and key complexity.
+The fastest sort is with locale C, on whole lines,
+with option
+.Fl s.
+In general, locale C is the fastest, then single-byte
+locales follow and multi-byte locales as the slowest but
+the correct collation order is always respected.
+As for the key specification, the simpler to process the
+lines the faster the search will be.
+.Pp
+When sorting by arithmetic value, using
+.Fl n
+results in much better performance than
+.Fl g
+so its use is encouraged
+whenever possible.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/sort.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/sort.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,1335 @@
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/sort.c 238108 2012-07-04 16:25:11Z gabor $");
+
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
+
+#include <err.h>
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <locale.h>
+#include <md5.h>
+#include <regex.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "coll.h"
+#include "file.h"
+#include "sort.h"
+
+#ifndef WITHOUT_NLS
+#include <nl_types.h>
+nl_catd catalog;
+#endif
+
+#define	OPTIONS	"bcCdfghik:Mmno:RrsS:t:T:uVz"
+
+#define DEFAULT_RANDOM_SORT_SEED_FILE ("/dev/random")
+#define MAX_DEFAULT_RANDOM_SEED_DATA_SIZE (1024)
+
+static bool need_random;
+static const char *random_source = DEFAULT_RANDOM_SORT_SEED_FILE;
+static const void *random_seed;
+static size_t random_seed_size;
+
+MD5_CTX md5_ctx;
+
+/*
+ * Default messages to use when NLS is disabled or no catalogue
+ * is found.
+ */
+const char *nlsstr[] = { "",
+/* 1*/"mutually exclusive flags",
+/* 2*/"extra argument not allowed with -c",
+/* 3*/"Unknown feature",
+/* 4*/"Wrong memory buffer specification",
+/* 5*/"0 field in key specs",
+/* 6*/"0 column in key specs",
+/* 7*/"Wrong file mode",
+/* 8*/"Cannot open file for reading",
+/* 9*/"Radix sort cannot be used with these sort options",
+/*10*/"The chosen sort method cannot be used with stable and/or unique sort",
+/*11*/"Invalid key position",
+/*12*/"Usage: %s [-bcCdfigMmnrsuz] [-kPOS1[,POS2] ... ] "
+      "[+POS1 [-POS2]] [-S memsize] [-T tmpdir] [-t separator] "
+      "[-o outfile] [--batch-size size] [--files0-from file] "
+      "[--heapsort] [--mergesort] [--radixsort] [--qsort] "
+      "[--mmap] "
+#if defined(SORT_THREADS)
+      "[--parallel thread_no] "
+#endif
+      "[--human-numeric-sort] "
+      "[--version-sort] [--random-sort [--random-source file]] "
+      "[--compress-program program] [file ...]\n" };
+
+struct sort_opts sort_opts_vals;
+
+bool debug_sort;
+bool need_hint;
+
+#if defined(SORT_THREADS)
+size_t ncpu = 1;
+size_t nthreads = 1;
+#endif
+
+static bool gnusort_numeric_compatibility;
+
+static struct sort_mods default_sort_mods_object;
+struct sort_mods * const default_sort_mods = &default_sort_mods_object;
+
+static bool print_symbols_on_debug;
+
+/*
+ * Arguments from file (when file0-from option is used:
+ */
+static int argc_from_file0 = -1;
+static char **argv_from_file0;
+
+/*
+ * Placeholder symbols for options which have no single-character equivalent
+ */
+enum
+{
+	SORT_OPT = CHAR_MAX + 1,
+	HELP_OPT,
+	FF_OPT,
+	BS_OPT,
+	VERSION_OPT,
+	DEBUG_OPT,
+#if defined(SORT_THREADS)
+	PARALLEL_OPT,
+#endif
+	RANDOMSOURCE_OPT,
+	COMPRESSPROGRAM_OPT,
+	QSORT_OPT,
+	MERGESORT_OPT,
+	HEAPSORT_OPT,
+	RADIXSORT_OPT,
+	MMAP_OPT
+};
+
+#define	NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS 6
+static const char mutually_exclusive_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] = { 'M', 'n', 'g', 'R', 'h', 'V' };
+
+struct option long_options[] = {
+				{ "batch-size", required_argument, NULL, BS_OPT },
+				{ "buffer-size", required_argument, NULL, 'S' },
+				{ "check", optional_argument, NULL, 'c' },
+				{ "check=silent|quiet", optional_argument, NULL, 'C' },
+				{ "compress-program", required_argument, NULL, COMPRESSPROGRAM_OPT },
+				{ "debug", no_argument, NULL, DEBUG_OPT },
+				{ "dictionary-order", no_argument, NULL, 'd' },
+				{ "field-separator", required_argument, NULL, 't' },
+				{ "files0-from", required_argument, NULL, FF_OPT },
+				{ "general-numeric-sort", no_argument, NULL, 'g' },
+				{ "heapsort", no_argument, NULL, HEAPSORT_OPT },
+				{ "help",no_argument, NULL, HELP_OPT },
+				{ "human-numeric-sort", no_argument, NULL, 'h' },
+				{ "ignore-leading-blanks", no_argument, NULL, 'b' },
+				{ "ignore-case", no_argument, NULL, 'f' },
+				{ "ignore-nonprinting", no_argument, NULL, 'i' },
+				{ "key", required_argument, NULL, 'k' },
+				{ "merge", no_argument, NULL, 'm' },
+				{ "mergesort", no_argument, NULL, MERGESORT_OPT },
+				{ "mmap", no_argument, NULL, MMAP_OPT },
+				{ "month-sort", no_argument, NULL, 'M' },
+				{ "numeric-sort", no_argument, NULL, 'n' },
+				{ "output", required_argument, NULL, 'o' },
+#if defined(SORT_THREADS)
+				{ "parallel", required_argument, NULL, PARALLEL_OPT },
+#endif
+				{ "qsort", no_argument, NULL, QSORT_OPT },
+				{ "radixsort", no_argument, NULL, RADIXSORT_OPT },
+				{ "random-sort", no_argument, NULL, 'R' },
+				{ "random-source", required_argument, NULL, RANDOMSOURCE_OPT },
+				{ "reverse", no_argument, NULL, 'r' },
+				{ "sort", required_argument, NULL, SORT_OPT },
+				{ "stable", no_argument, NULL, 's' },
+				{ "temporary-directory",required_argument, NULL, 'T' },
+				{ "unique", no_argument, NULL, 'u' },
+				{ "version", no_argument, NULL, VERSION_OPT },
+				{ "version-sort",no_argument, NULL, 'V' },
+				{ "zero-terminated", no_argument, NULL, 'z' },
+				{ NULL, no_argument, NULL, 0 }
+};
+
+void fix_obsolete_keys(int *argc, char **argv);
+
+/*
+ * Check where sort modifier is present
+ */
+static bool
+sort_modifier_empty(struct sort_mods *sm)
+{
+
+	if (sm == NULL)
+		return (true);
+	return (!(sm->Mflag || sm->Vflag || sm->nflag || sm->gflag ||
+	    sm->rflag || sm->Rflag || sm->hflag || sm->dflag || sm->fflag));
+}
+
+/*
+ * Print out usage text.
+ */
+static void
+usage(bool opt_err)
+{
+	struct option *o;
+	FILE *out;
+
+	out = stdout;
+	o = &(long_options[0]);
+
+	if (opt_err)
+		out = stderr;
+	fprintf(out, getstr(12), getprogname());
+	if (opt_err)
+		exit(2);
+	exit(0);
+}
+
+/*
+ * Read input file names from a file (file0-from option).
+ */
+static void
+read_fns_from_file0(const char *fn)
+{
+	if (fn) {
+		struct file0_reader f0r;
+		FILE *f;
+
+		f = fopen(fn, "r");
+		if (f == NULL)
+			err(2, NULL);
+
+		memset(&f0r, 0, sizeof(f0r));
+		f0r.f = f;
+
+		while (!feof(f)) {
+			char *line = read_file0_line(&f0r);
+
+			if (line && *line) {
+				++argc_from_file0;
+				if (argc_from_file0 < 1)
+					argc_from_file0 = 1;
+				argv_from_file0 = sort_realloc(argv_from_file0,
+				    argc_from_file0 * sizeof(char *));
+				if (argv_from_file0 == NULL)
+					err(2, NULL);
+				argv_from_file0[argc_from_file0 - 1] =
+				    sort_strdup(line);
+			}
+		}
+		closefile(f, fn);
+	}
+}
+
+/*
+ * Check how much RAM is available for the sort.
+ */
+static void
+set_hw_params(void)
+{
+#if defined(SORT_THREADS)
+	size_t ncpusz;
+#endif
+	size_t pages, psize, psz, pszsz;
+
+	pages = psize = 0;
+#if defined(SORT_THREADS)
+	ncpu = 1;
+	ncpusz = sizeof(size_t);
+#endif
+	psz = pszsz = sizeof(size_t);
+
+	if (sysctlbyname("vm.stats.vm.v_free_count", &pages, &psz,
+	    NULL, 0) < 0) {
+		perror("vm.stats.vm.v_free_count");
+		return;
+	}
+	if (sysctlbyname("vm.stats.vm.v_page_size", &psize, &pszsz,
+	    NULL, 0) < 0) {
+		perror("vm.stats.vm.v_page_size");
+		return;
+	}
+#if defined(SORT_THREADS)
+	if (sysctlbyname("hw.ncpu", &ncpu, &ncpusz,
+	    NULL, 0) < 0)
+		ncpu = 1;
+	else if(ncpu > 32)
+		ncpu = 32;
+
+	nthreads = ncpu;
+#endif
+
+	free_memory = (unsigned long long) pages * (unsigned long long) psize;
+	available_free_memory = (free_memory * 9) / 10;
+}
+
+/*
+ * Convert "plain" symbol to wide symbol, with default value.
+ */
+static void
+conv_mbtowc(wchar_t *wc, const char *c, const wchar_t def)
+{
+
+	if (wc && c) {
+		int res;
+
+		res = mbtowc(wc, c, MB_CUR_MAX);
+		if (res < 1)
+			*wc = def;
+	}
+}
+
+/*
+ * Set current locale symbols.
+ */
+static void
+set_locale(void)
+{
+	struct lconv *lc;
+	const char *locale;
+
+	setlocale(LC_ALL, "");
+
+	lc = localeconv();
+
+	if (lc) {
+		/* obtain LC_NUMERIC info */
+		/* Convert to wide char form */
+		conv_mbtowc(&symbol_decimal_point, lc->decimal_point,
+		    symbol_decimal_point);
+		conv_mbtowc(&symbol_thousands_sep, lc->thousands_sep,
+		    symbol_thousands_sep);
+		conv_mbtowc(&symbol_positive_sign, lc->positive_sign,
+		    symbol_positive_sign);
+		conv_mbtowc(&symbol_negative_sign, lc->negative_sign,
+		    symbol_negative_sign);
+	}
+
+	if (getenv("GNUSORT_NUMERIC_COMPATIBILITY"))
+		gnusort_numeric_compatibility = true;
+
+	locale = setlocale(LC_COLLATE, NULL);
+
+	if (locale) {
+		char *tmpl;
+		const char *cclocale;
+
+		tmpl = sort_strdup(locale);
+		cclocale = setlocale(LC_COLLATE, "C");
+		if (cclocale && !strcmp(cclocale, tmpl))
+			byte_sort = true;
+		else {
+			const char *pclocale;
+
+			pclocale = setlocale(LC_COLLATE, "POSIX");
+			if (pclocale && !strcmp(pclocale, tmpl))
+				byte_sort = true;
+		}
+		setlocale(LC_COLLATE, tmpl);
+		sort_free(tmpl);
+	}
+}
+
+/*
+ * Set directory temporary files.
+ */
+static void
+set_tmpdir(void)
+{
+	char *td;
+
+	td = getenv("TMPDIR");
+	if (td != NULL)
+		tmpdir = sort_strdup(td);
+}
+
+/*
+ * Parse -S option.
+ */
+static unsigned long long
+parse_memory_buffer_value(const char *value)
+{
+
+	if (value == NULL)
+		return (available_free_memory);
+	else {
+		char *endptr;
+		unsigned long long membuf;
+
+		endptr = NULL;
+		errno = 0;
+		membuf = strtoll(value, &endptr, 10);
+
+		if (errno != 0) {
+			warn("%s",getstr(4));
+			membuf = available_free_memory;
+		} else {
+			switch (*endptr){
+			case 'Y':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'Z':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'E':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'P':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'T':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'G':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'M':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case '\0':
+			case 'K':
+				membuf *= 1024;
+				/* FALLTHROUGH */
+			case 'b':
+				break;
+			case '%':
+				membuf = (available_free_memory * membuf) /
+				    100;
+				break;
+			default:
+				fprintf(stderr, "%s: %s\n", strerror(EINVAL),
+				   optarg);
+				membuf = available_free_memory;
+			}
+		}
+		return (membuf);
+	}
+}
+
+/*
+ * Signal handler that clears the temporary files.
+ */
+static void
+sig_handler(int sig __unused, siginfo_t *siginfo __unused,
+    void *context __unused)
+{
+
+	clear_tmp_files();
+	exit(-1);
+}
+
+/*
+ * Set signal handler on panic signals.
+ */
+static void
+set_signal_handler(void)
+{
+	struct sigaction sa;
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_sigaction = &sig_handler;
+	sa.sa_flags = SA_SIGINFO;
+
+	if (sigaction(SIGTERM, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGHUP, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGINT, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGQUIT, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGABRT, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGBUS, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGSEGV, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGUSR1, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+	if (sigaction(SIGUSR2, &sa, NULL) < 0) {
+		perror("sigaction");
+		return;
+	}
+}
+
+/*
+ * Print "unknown" message and exit with status 2.
+ */
+static void
+unknown(const char *what)
+{
+
+	errx(2, "%s: %s", getstr(3), what);
+}
+
+/*
+ * Check whether contradictory input options are used.
+ */
+static void
+check_mutually_exclusive_flags(char c, bool *mef_flags)
+{
+	int fo_index, mec;
+	bool found_others, found_this;
+
+	found_others = found_this =false;
+	fo_index = 0;
+
+	for (int i = 0; i < NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS; i++) {
+		mec = mutually_exclusive_flags[i];
+
+		if (mec != c) {
+			if (mef_flags[i]) {
+				if (found_this)
+					errx(1, "%c:%c: %s", c, mec, getstr(1));
+				found_others = true;
+				fo_index = i;
+			}
+		} else {
+			if (found_others)
+				errx(1, "%c:%c: %s", c, mutually_exclusive_flags[fo_index], getstr(1));
+			mef_flags[i] = true;
+			found_this = true;
+		}
+	}
+}
+
+/*
+ * Initialise sort opts data.
+ */
+static void
+set_sort_opts(void)
+{
+
+	memset(&default_sort_mods_object, 0,
+	    sizeof(default_sort_mods_object));
+	memset(&sort_opts_vals, 0, sizeof(sort_opts_vals));
+	default_sort_mods_object.func =
+	    get_sort_func(&default_sort_mods_object);
+}
+
+/*
+ * Set a sort modifier on a sort modifiers object.
+ */
+static bool
+set_sort_modifier(struct sort_mods *sm, int c)
+{
+
+	if (sm) {
+		switch (c){
+		case 'b':
+			sm->bflag = true;
+			break;
+		case 'd':
+			sm->dflag = true;
+			break;
+		case 'f':
+			sm->fflag = true;
+			break;
+		case 'g':
+			sm->gflag = true;
+			need_hint = true;
+			break;
+		case 'i':
+			sm->iflag = true;
+			break;
+		case 'R':
+			sm->Rflag = true;
+			need_random = true;
+			break;
+		case 'M':
+			initialise_months();
+			sm->Mflag = true;
+			need_hint = true;
+			break;
+		case 'n':
+			sm->nflag = true;
+			need_hint = true;
+			print_symbols_on_debug = true;
+			break;
+		case 'r':
+			sm->rflag = true;
+			break;
+		case 'V':
+			sm->Vflag = true;
+			break;
+		case 'h':
+			sm->hflag = true;
+			need_hint = true;
+			print_symbols_on_debug = true;
+			break;
+		default:
+			return false;
+		}
+		sort_opts_vals.complex_sort = true;
+		sm->func = get_sort_func(sm);
+	}
+	return (true);
+}
+
+/*
+ * Parse POS in -k option.
+ */
+static int
+parse_pos(const char *s, struct key_specs *ks, bool *mef_flags, bool second)
+{
+	regmatch_t pmatch[4];
+	regex_t re;
+	char *c, *f;
+	const char *sregexp = "^([0-9]+)(\\.[0-9]+)?([bdfirMngRhV]+)?$";
+	size_t len, nmatch;
+	int ret;
+
+	ret = -1;
+	nmatch = 4;
+	c = f = NULL;
+
+	if (regcomp(&re, sregexp, REG_EXTENDED) != 0)
+		return (-1);
+
+	if (regexec(&re, s, nmatch, pmatch, 0) != 0)
+		goto end;
+
+	if (pmatch[0].rm_eo <= pmatch[0].rm_so)
+		goto end;
+
+	if (pmatch[1].rm_eo <= pmatch[1].rm_so)
+		goto end;
+
+	len = pmatch[1].rm_eo - pmatch[1].rm_so;
+	f = sort_malloc((len + 1) * sizeof(char));
+
+	strncpy(f, s + pmatch[1].rm_so, len);
+	f[len] = '\0';
+
+	if (second) {
+		errno = 0;
+		ks->f2 = (size_t) strtoul(f, NULL, 10);
+		if (errno != 0)
+			errx(2, "%s: -k", strerror(errno));
+		if (ks->f2 == 0) {
+			warn("%s",getstr(5));
+			goto end;
+		}
+	} else {
+		errno = 0;
+		ks->f1 = (size_t) strtoul(f, NULL, 10);
+		if (errno != 0)
+			errx(2, "%s: -k", strerror(errno));
+		if (ks->f1 == 0) {
+			warn("%s",getstr(5));
+			goto end;
+		}
+	}
+
+	if (pmatch[2].rm_eo > pmatch[2].rm_so) {
+		len = pmatch[2].rm_eo - pmatch[2].rm_so - 1;
+		c = sort_malloc((len + 1) * sizeof(char));
+
+		strncpy(c, s + pmatch[2].rm_so + 1, len);
+		c[len] = '\0';
+
+		if (second) {
+			errno = 0;
+			ks->c2 = (size_t) strtoul(c, NULL, 10);
+			if (errno != 0)
+				errx(2, "%s: -k", strerror(errno));
+		} else {
+			errno = 0;
+			ks->c1 = (size_t) strtoul(c, NULL, 10);
+			if (errno != 0)
+				errx(2, "%s: -k", strerror(errno));
+			if (ks->c1 == 0) {
+				warn("%s",getstr(6));
+				goto end;
+			}
+		}
+	} else {
+		if (second)
+			ks->c2 = 0;
+		else
+			ks->c1 = 1;
+	}
+
+	if (pmatch[3].rm_eo > pmatch[3].rm_so) {
+		regoff_t i = 0;
+
+		for (i = pmatch[3].rm_so; i < pmatch[3].rm_eo; i++) {
+			check_mutually_exclusive_flags(s[i], mef_flags);
+			if (s[i] == 'b') {
+				if (second)
+					ks->pos2b = true;
+				else
+					ks->pos1b = true;
+			} else if (!set_sort_modifier(&(ks->sm), s[i]))
+				goto end;
+		}
+	}
+
+	ret = 0;
+
+end:
+
+	if (c)
+		sort_free(c);
+	if (f)
+		sort_free(f);
+	regfree(&re);
+
+	return (ret);
+}
+
+/*
+ * Parse -k option value.
+ */
+static int
+parse_k(const char *s, struct key_specs *ks)
+{
+	int ret = -1;
+	bool mef_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] =
+	    { false, false, false, false, false, false };
+
+	if (s && *s) {
+		char *sptr;
+
+		sptr = strchr(s, ',');
+		if (sptr) {
+			size_t size1;
+			char *pos1, *pos2;
+
+			size1 = sptr - s;
+
+			if (size1 < 1)
+				return (-1);
+			pos1 = sort_malloc((size1 + 1) * sizeof(char));
+
+			strncpy(pos1, s, size1);
+			pos1[size1] = '\0';
+
+			ret = parse_pos(pos1, ks, mef_flags, false);
+
+			sort_free(pos1);
+			if (ret < 0)
+				return (ret);
+
+			pos2 = sort_strdup(sptr + 1);
+			ret = parse_pos(pos2, ks, mef_flags, true);
+			sort_free(pos2);
+		} else
+			ret = parse_pos(s, ks, mef_flags, false);
+	}
+
+	return (ret);
+}
+
+/*
+ * Parse POS in +POS -POS option.
+ */
+static int
+parse_pos_obs(const char *s, int *nf, int *nc, char* sopts)
+{
+	regex_t re;
+	regmatch_t pmatch[4];
+	char *c, *f;
+	const char *sregexp = "^([0-9]+)(\\.[0-9]+)?([A-Za-z]+)?$";
+	int ret;
+	size_t len, nmatch;
+
+	ret = -1;
+	nmatch = 4;
+	c = f = NULL;
+	*nc = *nf = 0;
+
+	if (regcomp(&re, sregexp, REG_EXTENDED) != 0)
+		return (-1);
+
+	if (regexec(&re, s, nmatch, pmatch, 0) != 0)
+		goto end;
+
+	if (pmatch[0].rm_eo <= pmatch[0].rm_so)
+		goto end;
+
+	if (pmatch[1].rm_eo <= pmatch[1].rm_so)
+		goto end;
+
+	len = pmatch[1].rm_eo - pmatch[1].rm_so;
+	f = sort_malloc((len + 1) * sizeof(char));
+
+	strncpy(f, s + pmatch[1].rm_so, len);
+	f[len] = '\0';
+
+	errno = 0;
+	*nf = (size_t) strtoul(f, NULL, 10);
+	if (errno != 0)
+		errx(2, "%s", getstr(11));
+
+	if (pmatch[2].rm_eo > pmatch[2].rm_so) {
+		len = pmatch[2].rm_eo - pmatch[2].rm_so - 1;
+		c = sort_malloc((len + 1) * sizeof(char));
+
+		strncpy(c, s + pmatch[2].rm_so + 1, len);
+		c[len] = '\0';
+
+		errno = 0;
+		*nc = (size_t) strtoul(c, NULL, 10);
+		if (errno != 0)
+			errx(2, "%s", getstr(11));
+	}
+
+	if (pmatch[3].rm_eo > pmatch[3].rm_so) {
+
+		len = pmatch[3].rm_eo - pmatch[3].rm_so;
+
+		strncpy(sopts, s + pmatch[3].rm_so, len);
+		sopts[len] = '\0';
+	}
+
+	ret = 0;
+
+end:
+	if (c)
+		sort_free(c);
+	if (f)
+		sort_free(f);
+	regfree(&re);
+
+	return (ret);
+}
+
+/*
+ * "Translate" obsolete +POS1 -POS2 syntax into new -kPOS1,POS2 syntax
+ */
+void
+fix_obsolete_keys(int *argc, char **argv)
+{
+	char sopt[129];
+
+	for (int i = 1; i < *argc; i++) {
+		char *arg1;
+
+		arg1 = argv[i];
+
+		if (strlen(arg1) > 1 && arg1[0] == '+') {
+			int c1, f1;
+			char sopts1[128];
+
+			sopts1[0] = 0;
+			c1 = f1 = 0;
+
+			if (parse_pos_obs(arg1 + 1, &f1, &c1, sopts1) < 0)
+				continue;
+			else {
+				f1 += 1;
+				c1 += 1;
+				if (i + 1 < *argc) {
+					char *arg2 = argv[i + 1];
+
+					if (strlen(arg2) > 1 &&
+					    arg2[0] == '-') {
+						int c2, f2;
+						char sopts2[128];
+
+						sopts2[0] = 0;
+						c2 = f2 = 0;
+
+						if (parse_pos_obs(arg2 + 1,
+						    &f2, &c2, sopts2) >= 0) {
+							if (c2 > 0)
+								f2 += 1;
+							sprintf(sopt, "-k%d.%d%s,%d.%d%s",
+							    f1, c1, sopts1, f2, c2, sopts2);
+							argv[i] = sort_strdup(sopt);
+							for (int j = i + 1; j + 1 < *argc; j++)
+								argv[j] = argv[j + 1];
+							*argc -= 1;
+							continue;
+						}
+					}
+				}
+				sprintf(sopt, "-k%d.%d", f1, c1);
+				argv[i] = sort_strdup(sopt);
+			}
+		}
+	}
+}
+
+/*
+ * Set random seed
+ */
+static void
+set_random_seed(void)
+{
+	if (need_random) {
+
+		if (strcmp(random_source, DEFAULT_RANDOM_SORT_SEED_FILE) == 0) {
+			FILE* fseed;
+			MD5_CTX ctx;
+			char rsd[MAX_DEFAULT_RANDOM_SEED_DATA_SIZE];
+			size_t sz = 0;
+
+			fseed = openfile(random_source, "r");
+			while (!feof(fseed)) {
+				int cr;
+
+				cr = fgetc(fseed);
+				if (cr == EOF)
+					break;
+
+				rsd[sz++] = (char) cr;
+
+				if (sz >= MAX_DEFAULT_RANDOM_SEED_DATA_SIZE)
+					break;
+			}
+
+			closefile(fseed, random_source);
+
+			MD5Init(&ctx);
+			MD5Update(&ctx, rsd, sz);
+
+			random_seed = MD5End(&ctx, NULL);
+			random_seed_size = strlen(random_seed);
+
+		} else {
+			MD5_CTX ctx;
+			char *b;
+
+			MD5Init(&ctx);
+			b = MD5File(random_source, NULL);
+			if (b == NULL)
+				err(2, NULL);
+
+			random_seed = b;
+			random_seed_size = strlen(b);
+		}
+
+		MD5Init(&md5_ctx);
+		if(random_seed_size>0) {
+			MD5Update(&md5_ctx, random_seed, random_seed_size);
+		}
+	}
+}
+
+/*
+ * Main function.
+ */
+int
+main(int argc, char **argv)
+{
+	char *outfile, *real_outfile;
+	int c, result;
+	bool mef_flags[NUMBER_OF_MUTUALLY_EXCLUSIVE_FLAGS] =
+	    { false, false, false, false, false, false };
+
+	result = 0;
+	outfile = sort_strdup("-");
+	real_outfile = NULL;
+
+	struct sort_mods *sm = &default_sort_mods_object;
+
+	init_tmp_files();
+
+	set_signal_handler();
+
+	set_hw_params();
+	set_locale();
+	set_tmpdir();
+	set_sort_opts();
+
+#if 0
+	{
+		static int counter = 0;
+		char fn[128];
+		sprintf(fn, "/var/tmp/debug.sort.%d", counter++);
+		FILE* f = fopen(fn, "w");
+		fprintf(f, ">>sort>>");
+		for (int i = 0; i < argc; i++) {
+			fprintf(f, "<%s>", argv[i]);
+		}
+		fprintf(f, "<<sort<<\n");
+		fclose(f);
+	}
+#endif
+
+	fix_obsolete_keys(&argc, argv);
+
+	while (((c = getopt_long(argc, argv, OPTIONS, long_options, NULL))
+	    != -1)) {
+
+		check_mutually_exclusive_flags(c, mef_flags);
+
+		if (!set_sort_modifier(sm, c)) {
+
+			switch (c) {
+			case 'c':
+				sort_opts_vals.cflag = true;
+				if (optarg) {
+					if (!strcmp(optarg, "diagnose-first"))
+						;
+					else if (!strcmp(optarg, "silent") ||
+					    !strcmp(optarg, "quiet"))
+						sort_opts_vals.csilentflag = true;
+					else if (*optarg)
+						unknown(optarg);
+				}
+				break;
+			case 'C':
+				sort_opts_vals.cflag = true;
+				sort_opts_vals.csilentflag = true;
+				break;
+			case 'k':
+			{
+				sort_opts_vals.complex_sort = true;
+				sort_opts_vals.kflag = true;
+
+				keys_num++;
+				keys = sort_realloc(keys, keys_num *
+				    sizeof(struct key_specs));
+				memset(&(keys[keys_num - 1]), 0,
+				    sizeof(struct key_specs));
+
+				if (parse_k(optarg, &(keys[keys_num - 1]))
+				    < 0) {
+					errx(2, "%s: -k %s\n",
+					    strerror(EINVAL), optarg);
+				}
+
+				break;
+			}
+			case 'm':
+				sort_opts_vals.mflag = true;
+				break;
+			case 'o':
+				outfile = sort_realloc(outfile, (strlen(optarg) + 1));
+				strcpy(outfile, optarg);
+				break;
+			case 's':
+				sort_opts_vals.sflag = true;
+				break;
+			case 'S':
+				available_free_memory =
+				    parse_memory_buffer_value(optarg);
+				break;
+			case 'T':
+				tmpdir = sort_strdup(optarg);
+				break;
+			case 't':
+				while (strlen(optarg) > 1) {
+					if (optarg[0] != '\\') {
+						errx(2, "%s: %s\n",
+						    strerror(EINVAL), optarg);
+					}
+					optarg += 1;
+					if (*optarg == '0') {
+						*optarg = 0;
+						break;
+					}
+				}
+				sort_opts_vals.tflag = true;
+				sort_opts_vals.field_sep = btowc(optarg[0]);
+				if (sort_opts_vals.field_sep == WEOF) {
+					errno = EINVAL;
+					err(2, NULL);
+				}
+				if (!gnusort_numeric_compatibility) {
+					if (symbol_decimal_point == sort_opts_vals.field_sep)
+						symbol_decimal_point = WEOF;
+					if (symbol_thousands_sep == sort_opts_vals.field_sep)
+						symbol_thousands_sep = WEOF;
+					if (symbol_negative_sign == sort_opts_vals.field_sep)
+						symbol_negative_sign = WEOF;
+					if (symbol_positive_sign == sort_opts_vals.field_sep)
+						symbol_positive_sign = WEOF;
+				}
+				break;
+			case 'u':
+				sort_opts_vals.uflag = true;
+				/* stable sort for the correct unique val */
+				sort_opts_vals.sflag = true;
+				break;
+			case 'z':
+				sort_opts_vals.zflag = true;
+				break;
+			case SORT_OPT:
+				if (optarg) {
+					if (!strcmp(optarg, "general-numeric"))
+						set_sort_modifier(sm, 'g');
+					else if (!strcmp(optarg, "human-numeric"))
+						set_sort_modifier(sm, 'h');
+					else if (!strcmp(optarg, "numeric"))
+						set_sort_modifier(sm, 'n');
+					else if (!strcmp(optarg, "month"))
+						set_sort_modifier(sm, 'M');
+					else if (!strcmp(optarg, "random"))
+						set_sort_modifier(sm, 'R');
+					else
+						unknown(optarg);
+				}
+				break;
+#if defined(SORT_THREADS)
+			case PARALLEL_OPT:
+				nthreads = (size_t)(atoi(optarg));
+				if (nthreads < 1)
+					nthreads = 1;
+				if (nthreads > 1024)
+					nthreads = 1024;
+				break;
+#endif
+			case QSORT_OPT:
+				sort_opts_vals.sort_method = SORT_QSORT;
+				break;
+			case MERGESORT_OPT:
+				sort_opts_vals.sort_method = SORT_MERGESORT;
+				break;
+			case MMAP_OPT:
+				use_mmap = true;
+				break;
+			case HEAPSORT_OPT:
+				sort_opts_vals.sort_method = SORT_HEAPSORT;
+				break;
+			case RADIXSORT_OPT:
+				sort_opts_vals.sort_method = SORT_RADIXSORT;
+				break;
+			case RANDOMSOURCE_OPT:
+				random_source = strdup(optarg);
+				break;
+			case COMPRESSPROGRAM_OPT:
+				compress_program = strdup(optarg);
+				break;
+			case FF_OPT:
+				read_fns_from_file0(optarg);
+				break;
+			case BS_OPT:
+			{
+				errno = 0;
+				long mof = strtol(optarg, NULL, 10);
+				if (errno != 0)
+					errx(2, "--batch-size: %s",
+					    strerror(errno));
+				if (mof >= 2)
+					max_open_files = (size_t) mof + 1;
+			}
+				break;
+			case VERSION_OPT:
+				printf("%s\n", VERSION);
+				exit(EXIT_SUCCESS);
+				/* NOTREACHED */
+				break;
+			case DEBUG_OPT:
+				debug_sort = true;
+				break;
+			case HELP_OPT:
+				usage(false);
+				/* NOTREACHED */
+				break;
+			default:
+				usage(true);
+				/* NOTREACHED */
+			}
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+#ifndef WITHOUT_NLS
+	catalog = catopen("sort", NL_CAT_LOCALE);
+#endif
+
+	if (sort_opts_vals.cflag && sort_opts_vals.mflag)
+		errx(1, "%c:%c: %s", 'm', 'c', getstr(1));
+
+#ifndef WITHOUT_NLS
+	catclose(catalog);
+#endif
+
+	if (keys_num == 0) {
+		keys_num = 1;
+		keys = sort_realloc(keys, sizeof(struct key_specs));
+		memset(&(keys[0]), 0, sizeof(struct key_specs));
+		keys[0].c1 = 1;
+		keys[0].pos1b = default_sort_mods->bflag;
+		keys[0].pos2b = default_sort_mods->bflag;
+		memcpy(&(keys[0].sm), default_sort_mods,
+		    sizeof(struct sort_mods));
+	}
+
+	for (size_t i = 0; i < keys_num; i++) {
+		struct key_specs *ks;
+
+		ks = &(keys[i]);
+
+		if (sort_modifier_empty(&(ks->sm)) && !(ks->pos1b) &&
+		    !(ks->pos2b)) {
+			ks->pos1b = sm->bflag;
+			ks->pos2b = sm->bflag;
+			memcpy(&(ks->sm), sm, sizeof(struct sort_mods));
+		}
+
+		ks->sm.func = get_sort_func(&(ks->sm));
+	}
+
+	if (argc_from_file0 >= 0) {
+		argc = argc_from_file0;
+		argv = argv_from_file0;
+	}
+
+	if (debug_sort) {
+#if defined(SORT_THREADS)
+		nthreads = 1;
+#endif
+		printf("Using collate rules of %s locale\n",
+		    setlocale(LC_COLLATE, NULL));
+		if (byte_sort)
+			printf("Byte sort is used\n");
+		if (print_symbols_on_debug) {
+			printf("Decimal Point: <%lc>\n", symbol_decimal_point);
+			if (symbol_thousands_sep)
+				printf("Thousands separator: <%lc>\n",
+				    symbol_thousands_sep);
+			printf("Positive sign: <%lc>\n", symbol_positive_sign);
+			printf("Negative sign: <%lc>\n", symbol_negative_sign);
+		}
+	}
+
+	set_random_seed();
+
+	/* Case when the outfile equals one of the input files: */
+	if (strcmp(outfile, "-")) {
+
+		for(int i = 0; i < argc; ++i) {
+			if (strcmp(argv[i], outfile) == 0) {
+				real_outfile = sort_strdup(outfile);
+				for(;;) {
+					char* tmp = sort_malloc(strlen(outfile) +
+					    strlen(".tmp") + 1);
+
+					strcpy(tmp, outfile);
+					strcpy(tmp + strlen(tmp), ".tmp");
+					sort_free(outfile);
+					outfile = tmp;
+					if (access(outfile, F_OK) < 0)
+						break;
+				}
+				tmp_file_atexit(outfile);
+			}
+		}
+	}
+
+#if defined(SORT_THREADS)
+	if ((argc < 1) || (strcmp(outfile, "-") == 0) || (*outfile == 0))
+		nthreads = 1;
+#endif
+
+	if (!sort_opts_vals.cflag && !sort_opts_vals.mflag) {
+		struct file_list fl;
+		struct sort_list list;
+
+		sort_list_init(&list);
+		file_list_init(&fl, true);
+
+		if (argc < 1)
+			procfile("-", &list, &fl);
+		else {
+			while (argc > 0) {
+				procfile(*argv, &list, &fl);
+				--argc;
+				++argv;
+			}
+		}
+
+		if (fl.count < 1)
+			sort_list_to_file(&list, outfile);
+		else {
+			if (list.count > 0) {
+				char *flast = new_tmp_file_name();
+
+				sort_list_to_file(&list, flast);
+				file_list_add(&fl, flast, false);
+			}
+			merge_files(&fl, outfile);
+		}
+
+		file_list_clean(&fl);
+
+		/*
+		 * We are about to exit the program, so we can ignore
+		 * the clean-up for speed
+		 *
+		 * sort_list_clean(&list);
+		 */
+
+	} else if (sort_opts_vals.cflag) {
+		result = (argc == 0) ? (check("-")) : (check(*argv));
+	} else if (sort_opts_vals.mflag) {
+		struct file_list fl;
+
+		file_list_init(&fl, false);
+		file_list_populate(&fl, argc, argv, true);
+		merge_files(&fl, outfile);
+		file_list_clean(&fl);
+	}
+
+	if (real_outfile) {
+		unlink(real_outfile);
+		if (rename(outfile, real_outfile) < 0)
+			err(2, NULL);
+		sort_free(real_outfile);
+	}
+
+	sort_free(outfile);
+
+	return (result);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/sort.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/sort.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,128 @@
+/*	$FreeBSD: head/usr.bin/sort/sort.h 236764 2012-06-08 19:21:49Z gabor $	*/
+
+/*-
+ * Copyright (C) 2009 Gabor Kovesdan <gabor at FreeBSD.org>
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__BSD_SORT_H__)
+#define __BSD_SORT_H__
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sysexits.h>
+#include <wchar.h>
+
+#include <sys/types.h>
+#include <md5.h>
+
+#define	VERSION	"2.3-FreeBSD"
+
+#ifdef WITHOUT_NLS
+#define	getstr(n)	 nlsstr[n]
+#else
+#include <nl_types.h>
+
+extern nl_catd catalog;
+#define	getstr(n)	 catgets(catalog, 1, n, nlsstr[n])
+#endif
+
+extern const char *nlsstr[];
+
+#if defined(SORT_THREADS)
+#define MT_SORT_THRESHOLD (10000)
+extern size_t ncpu;
+extern size_t nthreads;
+#endif
+
+/*
+ * If true, we output some debug information.
+ */
+extern bool debug_sort;
+
+/*
+ * MD5 context for random hash function
+ */
+extern MD5_CTX md5_ctx;
+
+/*
+ * sort.c
+ */
+
+/*
+ * This structure holds main sort options which are NOT affecting the sort ordering.
+ */
+struct sort_opts
+{
+	wchar_t		field_sep;
+	int		sort_method;
+	bool		cflag;
+	bool		csilentflag;
+	bool		kflag;
+	bool		mflag;
+	bool		sflag;
+	bool		uflag;
+	bool		zflag;
+	bool		tflag;
+	bool		complex_sort;
+};
+
+/*
+ * Key value structure forward declaration
+ */
+struct key_value;
+
+/*
+ * Cmp function
+ */
+typedef int (*cmpcoll_t)(struct key_value *kv1, struct key_value *kv2, size_t offset);
+
+/*
+ * This structure holds "sort modifiers" - options which are affecting the sort ordering.
+ */
+struct sort_mods
+{
+	cmpcoll_t	func;
+	bool		bflag;
+	bool		dflag;
+	bool		fflag;
+	bool		gflag;
+	bool		iflag;
+	bool		Mflag;
+	bool		nflag;
+	bool		rflag;
+	bool		Rflag;
+	bool		Vflag;
+	bool		hflag;
+};
+
+extern bool need_hint;
+
+extern struct sort_opts sort_opts_vals;
+
+extern struct sort_mods * const default_sort_mods;
+
+#endif /* __BSD_SORT_H__ */
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/vsort.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/vsort.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,265 @@
+/*-
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * Copyright (C) 2012 Gabor Kovesdan <gabor at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/usr.bin/sort/vsort.c 235267 2012-05-11 12:37:16Z gabor $");
+
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "sort.h"
+#include "vsort.h"
+
+static inline bool
+isdigit_clocale(wchar_t c)
+{
+
+	return (c >= L'0' && c <= L'9');
+}
+
+static inline bool
+isalpha_clocale(wchar_t c)
+{
+
+	return ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'));
+}
+
+static inline bool
+isalnum_clocale(wchar_t c)
+{
+
+	return ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z') ||
+	    (c >= L'0' && c <= L'9'));
+}
+
+/*
+ * Find string suffix of format: (\.[A-Za-z~][A-Za-z0-9~]*)*$
+ * Set length of string before suffix.
+ */
+static void
+find_suffix(bwstring_iterator si, bwstring_iterator se, size_t *len)
+{
+	wchar_t c;
+	size_t clen;
+	bool expect_alpha, sfx;
+
+	sfx = false;
+	expect_alpha = false;
+	*len = 0;
+	clen = 0;
+
+	while ((si < se) && (c = bws_get_iter_value(si))) {
+		if (expect_alpha) {
+			expect_alpha = false;
+			if (!isalpha_clocale(c) && (c != L'~'))
+				sfx = false;
+		} else if (c == L'.') {
+			expect_alpha = true;
+			if (!sfx) {
+				sfx = true;
+				*len = clen;
+			}
+		} else if (!isalnum_clocale(c) && (c != L'~'))
+			sfx = false;
+
+		si = bws_iterator_inc(si, 1);
+		++clen;
+	}
+
+	/* This code must be here to make the implementation compatible
+	 * with WORDING of GNU sort documentation.
+	 * But the GNU sort implementation is not following its own
+	 * documentation.  GNU sort allows empty file extensions
+	 * (just dot with nothing after); but the regular expression in
+	 * their documentation does not allow empty file extensions.
+	 * We chose to make our implementation compatible with GNU sort
+	 * implementation.  If they will ever fix their bug, this code
+	 * must be uncommented. Or they may choose to fix the info page,
+	 * then the code stays commented.
+	 *
+	 if (expect_alpha)
+	 	sfx = false;
+	 */
+
+	if (!sfx)
+		*len = clen;
+}
+
+static inline int
+cmp_chars(wchar_t c1, wchar_t c2)
+{
+
+	if (c1 == c2)
+		return (0);
+
+	if (c1 == L'~')
+		return (-1);
+	if (c2 == L'~')
+		return (+1);
+
+	if (isdigit_clocale(c1) || !c1)
+		return ((isdigit_clocale(c2) || !c2) ? 0 : -1);
+
+	if (isdigit_clocale(c2) || !c2)
+		return (+1);
+
+	if (isalpha_clocale(c1))
+		return ((isalpha_clocale(c2)) ? ((int) c1 - (int) c2) : -1);
+
+	if (isalpha_clocale(c2))
+		return (+1);
+
+	return ((int) c1 - (int) c2);
+}
+
+static int
+cmpversions(bwstring_iterator si1, bwstring_iterator se1,
+    bwstring_iterator si2, bwstring_iterator se2)
+{
+	int cmp, diff;
+
+	while ((si1 < se1) || (si2 < se2)) {
+		diff = 0;
+
+		while (((si1 < se1) &&
+		    !isdigit_clocale(bws_get_iter_value(si1))) ||
+		    ((si2 < se2) && !isdigit_clocale(bws_get_iter_value(si2)))) {
+			wchar_t c1, c2;
+
+			c1 = (si1 < se1) ? bws_get_iter_value(si1) : 0;
+			c2 = (si2 < se2) ? bws_get_iter_value(si2) : 0;
+
+			cmp = cmp_chars(c1, c2);
+			if (cmp)
+				return (cmp);
+
+			if (si1 < se1)
+				si1 = bws_iterator_inc(si1, 1);
+			if (si2 < se2)
+				si2 = bws_iterator_inc(si2, 1);
+		}
+
+		while (bws_get_iter_value(si1) == L'0')
+			si1 = bws_iterator_inc(si1, 1);
+
+		while (bws_get_iter_value(si2) == L'0')
+			si2 = bws_iterator_inc(si2, 1);
+
+		while (isdigit_clocale(bws_get_iter_value(si1)) &&
+		    isdigit_clocale(bws_get_iter_value(si2))) {
+			if (!diff)
+				diff = ((int)bws_get_iter_value(si1) -
+				    (int)bws_get_iter_value(si2));
+			si1 = bws_iterator_inc(si1, 1);
+			si2 = bws_iterator_inc(si2, 1);
+		}
+
+		if (isdigit_clocale(bws_get_iter_value(si1)))
+			return (1);
+
+		if (isdigit_clocale(bws_get_iter_value(si2)))
+			return (-1);
+
+		if (diff)
+			return (diff);
+	}
+
+	return (0);
+}
+
+/*
+ * Compare two version strings
+ */
+int
+vcmp(struct bwstring *s1, struct bwstring *s2)
+{
+	bwstring_iterator si1, si2;
+	wchar_t c1, c2;
+	size_t len1, len2, slen1, slen2;
+	int cmp_bytes, cmp_res;
+
+	if (s1 == s2)
+		return (0);
+
+	cmp_bytes = bwscmp(s1, s2, 0);
+	if (cmp_bytes == 0)
+		return (0);
+
+	len1 = slen1 = BWSLEN(s1);
+	len2 = slen2 = BWSLEN(s2);
+
+	if (slen1 < 1)
+		return (-1);
+	if (slen2 < 1)
+		return (+1);
+
+	si1 = bws_begin(s1);
+	si2 = bws_begin(s2);
+
+	c1 = bws_get_iter_value(si1);
+	c2 = bws_get_iter_value(si2);
+
+	if (c1 == L'.' && (slen1 == 1))
+		return (-1);
+
+	if (c2 == L'.' && (slen2 == 1))
+		return (+1);
+
+	if (slen1 == 2 && c1 == L'.' &&
+	    bws_get_iter_value(bws_iterator_inc(si1, 1)) == L'.')
+		return (-1);
+	if (slen2 == 2 && c2 == L'.' &&
+	    bws_get_iter_value(bws_iterator_inc(si2, 1)) == L'.')
+		return (+1);
+
+	if (c1 == L'.' && c2 != L'.')
+		return (-1);
+	if (c1 != L'.' && c2 == L'.')
+		return (+1);
+
+	if (c1 == L'.' && c2 == L'.') {
+		si1 = bws_iterator_inc(si1, 1);
+		si2 = bws_iterator_inc(si2, 1);
+	}
+
+	find_suffix(si1, bws_end(s1), &len1);
+	find_suffix(si2, bws_end(s2), &len2);
+
+	if ((len1 == len2) && (bws_iterator_cmp(si1, si2, len1) == 0))
+		return (cmp_bytes);
+
+	cmp_res = cmpversions(si1, bws_iterator_inc(si1, len1), si2,
+	    bws_iterator_inc(si2, len2));
+
+	if (cmp_res == 0)
+	  cmp_res = cmp_bytes;
+
+	return (cmp_res);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/sort/vsort.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/sort/vsort.h	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,37 @@
+/*	$FreeBSD: head/usr.bin/sort/vsort.h 235267 2012-05-11 12:37:16Z gabor $	*/
+
+/*-
+ * Copyright (C) 2012 Oleg Moskalenko <oleg.moskalenko at citrix.com>
+ * Copyright (C) 2012 Gabor Kovesdan <gabor at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if !defined(__VSORT_H__)
+#define _VSORT_H__
+
+#include "bwstring.h"
+
+int vcmp(struct bwstring *s1, struct bwstring *s2);
+
+#endif
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/stat/stat.1
--- a/head/usr.bin/stat/stat.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/stat/stat.1	Wed Jul 25 16:31:11 2012 +0300
@@ -27,9 +27,9 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/stat/stat.1 234577 2012-04-22 18:18:49Z brueffer $
 .\"
-.Dd December 5, 2010
+.Dd April 22, 2012
 .Dt STAT 1
 .Os
 .Sh NAME
@@ -140,10 +140,6 @@
 fall back on
 .Xr lstat 2
 and report information about the link.
-.It Fl l
-Display output in
-.Ic ls Fl lT
-format.
 .It Fl n
 Do not force a newline to appear at the end of each piece of output.
 .It Fl q
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/stdbuf/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/stdbuf/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,8 @@
+# $FreeBSD: head/usr.bin/stdbuf/Makefile 234772 2012-04-28 20:52:20Z jlh $
+
+PROG=   stdbuf
+SRCS=   stdbuf.c
+
+WARNS?=	6
+
+.include <bsd.prog.mk>
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/stdbuf/stdbuf.1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/stdbuf/stdbuf.1	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,116 @@
+.\" Copyright (c) 2012 Jeremie Le Hen <jlh at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code and documentation must retain the above
+.\"    copyright notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: head/usr.bin/stdbuf/stdbuf.1 235355 2012-05-12 19:59:37Z joel $
+.\"
+.Dd April 28, 2012
+.Dt STDBUF 1
+.Os
+.Sh NAME
+.Nm stdbuf
+.Nd change standard streams initial buffering
+.Sh SYNOPSIS
+.Nm
+.Op Fl e Ar bufdef
+.Op Fl i Ar bufdef
+.Op Fl o Ar bufdef
+.Op Ar command Op ...
+.Sh DESCRIPTION
+.Nm
+is used to change the initial buffering of standard input,
+standard output and/or standard error streams for
+.Ar command .
+It relies on
+.Xr libstdbuf 3
+which is loaded and configured by
+.Nm
+through environment variables.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl e Ar bufdef
+Set initial buffering of the standard error stream for
+.Ar command
+as defined by
+.Ar bufdef
+.Pq see Sx BUFFER DEFINITION .
+.It Fl i Ar bufdef
+Set initial buffering of the standard input stream for
+.Ar command
+as defined by
+.Ar bufdef
+.Pq see Sx BUFFER DEFINITION .
+.It Fl o Ar bufdef
+Set initial buffering of the standard output stream for
+.Ar command
+as defined by
+.Ar bufdef
+.Pq see Sx BUFFER DEFINITION .
+.El
+.Sh BUFFER DEFINITION
+Buffer definition is the same as in
+.Xr libstdbuf 3 :
+.Bl -tag -width size -offset indent
+.It Qq 0
+unbuffered
+.It Qq L
+line buffered
+.It Qq B
+fully buffered with the default buffer size
+.It Ar size
+fully buffered with a buffer of
+.Ar size
+bytes (suffixes 'k', 'M' and 'G' are accepted)
+.El
+.Sh EXAMPLES
+In the following example, the stdout stream of the
+.Xr awk 1
+command
+will be fully buffered by default because it does not refer
+to a terminal.
+.Nm
+is used to force it to be line-buffered so
+.Xr vmstat 8 Ns 's
+output will not stall until the full buffer fills.
+.Bd -literal -offset indent
+# vmstat 1 | stdbuf -o L awk '$2 > 1 || $3 > 1' | cat -n
+.Ed
+.Sh SEE ALSO
+.Xr libstdbuf 3 ,
+.Xr setvbuf 3
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 8.4 .
+.Sh AUTHORS
+.An -nosplit
+The original idea of the
+.Nm
+command comes from
+.An Padraig Brady
+who implemented it in the GNU coreutils.
+.An Jeremie Le Hen
+implemented it on
+.Fx .
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/stdbuf/stdbuf.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/usr.bin/stdbuf/stdbuf.c	Wed Jul 25 16:31:11 2012 +0300
@@ -0,0 +1,110 @@
+/*-
+ * Copyright (c) 2012 Jeremie Le Hen <jlh at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: head/usr.bin/stdbuf/stdbuf.c 235142 2012-05-08 19:43:32Z jlh $
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define	LIBSTDBUF	"/usr/lib/libstdbuf.so"
+#define	LIBSTDBUF32	"/usr/lib32/libstdbuf.so"
+
+extern char *__progname;
+
+static void
+usage(int s)
+{
+	
+	fprintf(stderr, "Usage: %s [-e 0|L|<sz>] [-i 0|L|<sz>] [-o 0|L|<sz>] "
+	    "<cmd> [args ...]\n", __progname);
+	exit(s);
+}
+
+int
+main(int argc, char *argv[])
+{
+	char *ibuf, *obuf, *ebuf;
+	char *preload0, *preload1;
+	int i;
+
+	ibuf = obuf = ebuf = NULL;
+	while ((i = getopt(argc, argv, "e:i:o:")) != -1) {
+		switch (i) {
+		case 'e':
+			ebuf = optarg;
+			break;
+		case 'i':
+			ibuf = optarg;
+			break;
+		case 'o':
+			obuf = optarg;
+			break;
+		case '?':
+		default:
+			usage(1);
+			break;
+		}
+	}
+	argc -= optind;
+	argv += optind;
+	if (argc < 2)
+		usage(0);
+
+	if (ibuf != NULL && setenv("_STDBUF_I", ibuf, 1) == -1)
+		warn("Failed to set environment variable: %s=%s",
+		    "_STDBUF_I", ibuf);
+	if (obuf != NULL && setenv("_STDBUF_O", obuf, 1) == -1)
+		warn("Failed to set environment variable: %s=%s",
+		    "_STDBUF_O", obuf);
+	if (ebuf != NULL && setenv("_STDBUF_E", ebuf, 1) == -1)
+		warn("Failed to set environment variable: %s=%s",
+		    "_STDBUF_E", ebuf);
+
+	preload0 = getenv("LD_PRELOAD");
+	if (preload0 == NULL)
+		i = asprintf(&preload1, "LD_PRELOAD=" LIBSTDBUF);
+	else
+		i = asprintf(&preload1, "LD_PRELOAD=%s:%s", preload0,
+		    LIBSTDBUF);
+
+	if (i < 0 || putenv(preload1) == -1)
+		warn("Failed to set environment variable: LD_PRELOAD");
+	
+	preload0 = getenv("LD_32_PRELOAD");
+	if (preload0 == NULL)
+		i = asprintf(&preload1, "LD_32_PRELOAD=" LIBSTDBUF32);
+	else
+		i = asprintf(&preload1, "LD_32_PRELOAD=%s:%s", preload0,
+		    LIBSTDBUF32);
+
+	if (i < 0 || putenv(preload1) == -1)
+		warn("Failed to set environment variable: LD_32_PRELOAD");
+
+	execvp(argv[0], argv);
+	err(2, "%s", argv[0]);
+}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/tftp/tftp.1
--- a/head/usr.bin/tftp/tftp.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/tftp/tftp.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)tftp.1	8.2 (Berkeley) 4/18/94
-.\" $FreeBSD: head/usr.bin/tftp/tftp.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/tftp/tftp.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
 .Dd June 22, 2011
 .Dt TFTP 1
@@ -112,9 +112,9 @@
 Enable or disable debugging levels during verbose output.  The value of
 .Ar level
 can be one of
-.Cm packet, simple, options,
+.Cm packet , simple , options ,
 or
-.Cm access.
+.Cm access .
 .Pp
 .It Cm get Oo Ar host : Oc Ns Ar file Op Ar localname
 .It Cm get Xo
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/top/machine.c
--- a/head/usr.bin/top/machine.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/top/machine.c	Wed Jul 25 16:31:11 2012 +0300
@@ -20,7 +20,7 @@
  *          Wolfram Schneider <wosch at FreeBSD.org>
  *          Thomas Moestl <tmoestl at gmx.net>
  *
- * $FreeBSD: head/usr.bin/top/machine.c 234416 2012-04-18 10:23:42Z kib $
+ * $FreeBSD: head/usr.bin/top/machine.c 238020 2012-07-02 20:08:11Z jhb $
  */
 
 #include <sys/param.h>
@@ -176,6 +176,12 @@
 	"K Free", NULL
 };
 
+int arc_stats[7];
+char *arcnames[] = {
+	"K Total, ", "K MRU, ", "K MFU, ", "K Anon, ", "K Header, ", "K Other",
+	NULL
+};
+
 int swap_stats[7];
 char *swapnames[] = {
 	"K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out",
@@ -194,6 +200,7 @@
 static struct kinfo_proc **previous_pref;
 static int previous_proc_count = 0;
 static int previous_proc_count_max = 0;
+static int arc_enabled;
 
 /* total number of io operations */
 static long total_inblock;
@@ -239,6 +246,7 @@
 static const char *format_nice(const struct kinfo_proc *pp);
 static void getsysctl(const char *name, void *ptr, size_t len);
 static int swapmode(int *retavail, int *retfree);
+static void update_layout(void);
 
 void
 toggle_pcpustats(void)
@@ -246,24 +254,32 @@
 
 	if (ncpus == 1)
 		return;
+	update_layout();
+}
 
-	/* Adjust display based on ncpus */
+/* Adjust display based on ncpus and the ARC state. */
+static void
+update_layout(void)
+{
+
+	y_mem = 3;
+	y_arc = 4;
+	y_swap = 4 + arc_enabled;
+	y_idlecursor = 5 + arc_enabled;
+	y_message = 5 + arc_enabled;
+	y_header = 6 + arc_enabled;
+	y_procs = 7 + arc_enabled;
+	Header_lines = 7 + arc_enabled;
+
 	if (pcpu_stats) {
-		y_mem += ncpus - 1;	/* 3 */
-		y_swap += ncpus - 1;	/* 4 */
-		y_idlecursor += ncpus - 1; /* 5 */
-		y_message += ncpus - 1;	/* 5 */
-		y_header += ncpus - 1;	/* 6 */
-		y_procs += ncpus - 1;	/* 7 */
-		Header_lines += ncpus - 1; /* 7 */
-	} else {
-		y_mem = 3;
-		y_swap = 4;
-		y_idlecursor = 5;
-		y_message = 5;
-		y_header = 6;
-		y_procs = 7;
-		Header_lines = 7;
+		y_mem += ncpus - 1;
+		y_arc += ncpus - 1;
+		y_swap += ncpus - 1;
+		y_idlecursor += ncpus - 1;
+		y_message += ncpus - 1;
+		y_header += ncpus - 1;
+		y_procs += ncpus - 1;
+		Header_lines += ncpus - 1;
 	}
 }
 
@@ -271,6 +287,7 @@
 machine_init(struct statics *statics, char do_unames)
 {
 	int i, j, empty, pagesize;
+	uint64_t arc_size;
 	size_t size;
 	struct passwd *pw;
 
@@ -282,6 +299,11 @@
 	    size != sizeof(smpmode))
 		smpmode = 0;
 
+	size = sizeof(arc_size);
+	if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc_size, &size,
+	    NULL, 0) == 0 && arc_size != 0)
+		arc_enabled = 1;
+
 	if (do_unames) {
 	    while ((pw = getpwent()) != NULL) {
 		if (strlen(pw->pw_name) > namelength)
@@ -322,6 +344,10 @@
 	statics->procstate_names = procstatenames;
 	statics->cpustate_names = cpustatenames;
 	statics->memory_names = memorynames;
+	if (arc_enabled)
+		statics->arc_names = arcnames;
+	else
+		statics->arc_names = NULL;
 	statics->swap_names = swapnames;
 #ifdef ORDER
 	statics->order_names = ordernames;
@@ -356,8 +382,7 @@
 	pcpu_cpu_states = calloc(1, size);
 	statics->ncpus = ncpus;
 
-	if (pcpu_stats)
-		toggle_pcpustats();
+	update_layout();
 
 	/* all done! */
 	return (0);
@@ -408,7 +433,7 @@
 	struct loadavg sysload;
 	int mib[2];
 	struct timeval boottime;
-	size_t bt_size;
+	uint64_t arc_stat, arc_stat2;
 	int i, j;
 	size_t size;
 
@@ -487,6 +512,23 @@
 		swap_stats[6] = -1;
 	}
 
+	if (arc_enabled) {
+		GETSYSCTL("kstat.zfs.misc.arcstats.size", arc_stat);
+		arc_stats[0] = arc_stat >> 10;
+		GETSYSCTL("vfs.zfs.mfu_size", arc_stat);
+		arc_stats[1] = arc_stat >> 10;
+		GETSYSCTL("vfs.zfs.mru_size", arc_stat);
+		arc_stats[2] = arc_stat >> 10;
+		GETSYSCTL("vfs.zfs.anon_size", arc_stat);
+		arc_stats[3] = arc_stat >> 10;
+		GETSYSCTL("kstat.zfs.misc.arcstats.hdr_size", arc_stat);
+		GETSYSCTL("kstat.zfs.misc.arcstats.l2_hdr_size", arc_stat2);
+		arc_stats[4] = arc_stat + arc_stat2 >> 10;
+		GETSYSCTL("kstat.zfs.misc.arcstats.other_size", arc_stat);
+		arc_stats[5] = arc_stat >> 10;
+		si->arc = arc_stats;
+	}
+		    
 	/* set arrays and strings */
 	if (pcpu_stats) {
 		si->cpustates = pcpu_cpu_states;
@@ -511,8 +553,8 @@
 	 */
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_BOOTTIME;
-	bt_size = sizeof(boottime);
-	if (sysctl(mib, 2, &boottime, &bt_size, NULL, 0) != -1 &&
+	size = sizeof(boottime);
+	if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
 	    boottime.tv_sec != 0) {
 		si->boottime = boottime;
 	} else {
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/top/top.local.1
--- a/head/usr.bin/top/top.local.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/top/top.local.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,8 +1,9 @@
-.\" $FreeBSD: head/usr.bin/top/top.local.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/top/top.local.1 237656 2012-06-27 18:08:48Z jhb $
 .SH "FreeBSD NOTES"
 
 .SH DESCRIPTION OF MEMORY
 Mem: 9220K Active, 1M Inact, 3284K Wired, 1M Cache, 2M Buf, 1320K Free
+ARC: 2048K Total, 342K MRU, 760K MFU, 272K Anon, 232K Header, 442K Other
 Swap: 91M Total, 79M Free, 13% Inuse, 80K In, 104K Out
 .TP
 .B K:
@@ -16,6 +17,7 @@
 .TP
 .B %:
 1/100
+.SS Physical Memory Stats
 .TP
 .B Active:
 number of bytes active
@@ -24,7 +26,7 @@
 number of bytes inactive
 .TP
 .B Wired:
-number of bytes wired down, including cached file data pages
+number of bytes wired down, including BIO-level cached file data pages
 .TP
 .B Cache:
 number of clean bytes caching data that are available for
@@ -35,6 +37,27 @@
 .TP
 .B Free:
 number of bytes free
+.SS ZFS ARC Stats
+These stats are only displayed when the ARC is in use.
+.TP
+.B Total:
+number of wired bytes used for the ZFS ARC
+.TP
+.B MRU:
+number of ARC bytes holding most recently used data
+.TP
+.B MFU:
+number of ARC bytes holding most frequently used data
+.TP
+.B Anon:
+number of ARC bytes holding in flight data
+.TP
+.B Header:
+number of ARC bytes holding headers
+.TP
+.B Other
+miscellaneous ARC bytes
+.SS Swap Stats
 .TP
 .B Total:
 total available swap usage
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/touch/touch.1
--- a/head/usr.bin/touch/touch.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/touch/touch.1	Wed Jul 25 16:31:11 2012 +0300
@@ -29,9 +29,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)touch.1	8.3 (Berkeley) 4/28/95
-.\" $FreeBSD: head/usr.bin/touch/touch.1 233648 2012-03-29 05:02:12Z eadler $
+.\" $FreeBSD: head/usr.bin/touch/touch.1 236852 2012-06-10 14:26:51Z jilles $
 .\"
-.Dd February 4, 2012
+.Dd June 10, 2012
 .Dt TOUCH 1
 .Os
 .Sh NAME
@@ -43,6 +43,7 @@
 .Op Fl achm
 .Op Fl r Ar file
 .Op Fl t Ar [[CC]YY]MMDDhhmm[.SS]
+.Op Fl d Ar YYYY-MM-DDThh:mm:SS[.frac][tz]
 .Ar
 .Sh DESCRIPTION
 The
@@ -61,8 +62,10 @@
 Selecting both is equivalent to the default.
 By default, the timestamps are set to the current time.
 The
+.Fl d
+and
 .Fl t
-flag explicitly specifies a different time, and the
+flags explicitly specify a different time, and the
 .Fl r
 flag specifies to set the times those of the specified file.
 The
@@ -109,6 +112,41 @@
 .Nm
 utility does not treat this as an error.
 No error messages are displayed and the exit value is not affected.
+.It Fl d
+Change the access and modification times to the specified time instead
+of the current time of day.
+The argument is of the form
+.Dq YYYY-MM-DDThh:mm:SS[.frac][tz]
+where the letters represent the following:
+.Bl -tag -width Ds -compact -offset indent
+.It Ar YYYY
+The year.
+.It Ar MM
+The month of the year, from 01 to 12.
+.It Ar DD
+The day of the month, from 01 to 31.
+.It Ar T
+The letter
+.Li T
+or a space.
+.It Ar hh
+The hour of the day, from 00 to 23.
+.It Ar mm
+The minute of the hour, from 00 to 59.
+.It Ar SS
+The second of the minute, from 00 to 61.
+.It Ar .frac
+An optional fraction,
+consisting of a period or a comma followed by one or more digits.
+The number of significant digits depends on the kernel configuration and
+the filesystem, and may be zero.
+.It Ar tz
+An optional letter
+.Li Z
+indicating the time is in
+.Tn UTC .
+Otherwise, the time is assumed to be in local time.
+.El
 .It Fl h
 If the file is a symbolic link, change the times of the link
 itself rather than the file that the link points to.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/touch/touch.c
--- a/head/usr.bin/touch/touch.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/touch/touch.c	Wed Jul 25 16:31:11 2012 +0300
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD: head/usr.bin/touch/touch.c 230979 2012-02-04 13:37:31Z jh $");
+__FBSDID("$FreeBSD: head/usr.bin/touch/touch.c 236852 2012-06-10 14:26:51Z jilles $");
 
 #ifndef lint
 static const char copyright[] =
@@ -45,6 +45,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
+#include <ctype.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -57,6 +58,7 @@
 
 void	stime_arg1(char *, struct timeval *);
 void	stime_arg2(char *, int, struct timeval *);
+void	stime_darg(char *, struct timeval *);
 void	stime_file(char *, struct timeval *);
 int	timeoffset(char *);
 void	usage(char *);
@@ -79,7 +81,7 @@
 	if (gettimeofday(&tv[0], NULL))
 		err(1, "gettimeofday");
 
-	while ((ch = getopt(argc, argv, "A:acfhmr:t:")) != -1)
+	while ((ch = getopt(argc, argv, "A:acd:fhmr:t:")) != -1)
 		switch(ch) {
 		case 'A':
 			Aflag = timeoffset(optarg);
@@ -90,6 +92,10 @@
 		case 'c':
 			cflag = 1;
 			break;
+		case 'd':
+			timeset = 1;
+			stime_darg(optarg, tv);
+			break;
 		case 'f':
 			/* No-op for compatibility. */
 			break;
@@ -320,6 +326,50 @@
 	tvp[0].tv_usec = tvp[1].tv_usec = 0;
 }
 
+void
+stime_darg(char *arg, struct timeval *tvp)
+{
+	struct tm t = { .tm_sec = 0 };
+	const char *fmt, *colon;
+	char *p;
+	int val, isutc = 0;
+
+	tvp[0].tv_usec = 0;
+	t.tm_isdst = -1;
+	colon = strchr(arg, ':');
+	if (colon == NULL || strchr(colon + 1, ':') == NULL)
+		goto bad;
+	fmt = strchr(arg, 'T') != NULL ? "%Y-%m-%dT%H:%M:%S" :
+	    "%Y-%m-%d %H:%M:%S";
+	p = strptime(arg, fmt, &t);
+	if (p == NULL)
+		goto bad;
+	/* POSIX: must have at least one digit after dot */
+	if ((*p == '.' || *p == ',') && isdigit((unsigned char)p[1])) {
+		p++;
+		val = 100000;
+		while (isdigit((unsigned char)*p)) {
+			tvp[0].tv_usec += val * (*p - '0');
+			p++;
+			val /= 10;
+		}
+	}
+	if (*p == 'Z') {
+		isutc = 1;
+		p++;
+	}
+	if (*p != '\0')
+		goto bad;
+
+	tvp[0].tv_sec = isutc ? timegm(&t) : mktime(&t);
+
+	tvp[1] = tvp[0];
+	return;
+
+bad:
+	errx(1, "out of range or illegal time specification: YYYY-MM-DDThh:mm:SS[.frac][tz]");
+}
+
 /* Calculate a time offset in seconds, given an arg of the format [-]HHMMSS. */
 int
 timeoffset(char *arg)
@@ -364,7 +414,9 @@
 void
 usage(char *myname)
 {
-	fprintf(stderr, "usage:\n" "%s [-A [-][[hh]mm]SS] [-achm] [-r file] "
-		"[-t [[CC]YY]MMDDhhmm[.SS]] file ...\n", myname);
+	fprintf(stderr, "usage: %s [-A [-][[hh]mm]SS] [-achm] [-r file] "
+		"[-t [[CC]YY]MMDDhhmm[.SS]]\n"
+		"       [-d YYYY-MM-DDThh:mm:SS[.frac][tz]] "
+		"file ...\n", myname);
 	exit(1);
 }
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/unzip/unzip.1
--- a/head/usr.bin/unzip/unzip.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/unzip/unzip.1	Wed Jul 25 16:31:11 2012 +0300
@@ -23,9 +23,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: head/usr.bin/unzip/unzip.1 234311 2012-04-15 13:39:39Z des $
+.\" $FreeBSD: head/usr.bin/unzip/unzip.1 235252 2012-05-11 00:19:06Z gjb $
 .\"
-.Dd October 21, 2010
+.Dd May 10, 2012
 .Dt UNZIP 1
 .Os
 .Sh NAME
@@ -102,6 +102,16 @@
 .It Fl x Ar pattern
 Exclude files matching the pattern
 .Ar pattern .
+.It Fl Z Ar mode
+Emulate
+.Xr zipinfo 1L
+mode.
+Enabling
+.Xr zipinfo 1L
+mode changes the way in which additional arguments are parsed.
+Currently only
+.Xr zipinfo 1L
+mode 1 is supported, which lists the file names one per line.
 .El
 .Pp
 Note that only one of
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/unzip/unzip.c
--- a/head/usr.bin/unzip/unzip.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/unzip/unzip.c	Wed Jul 25 16:31:11 2012 +0300
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/usr.bin/unzip/unzip.c 234311 2012-04-15 13:39:39Z des $
+ * $FreeBSD: head/usr.bin/unzip/unzip.c 236226 2012-05-29 09:11:19Z des $
  *
  * This file would be much shorter if we didn't care about command-line
  * compatibility with Info-ZIP's UnZip, which requires us to duplicate
@@ -865,19 +865,14 @@
 {
 	struct archive *a;
 	struct archive_entry *e;
-	int fd, ret;
+	int ret;
 	uintmax_t total_size, file_count, error_count;
 
-	if (strcmp(fn, "-") == 0)
-		fd = STDIN_FILENO;
-	else if ((fd = open(fn, O_RDONLY)) < 0)
-		error("%s", fn);
-
 	if ((a = archive_read_new()) == NULL)
 		error("archive_read_new failed");
 
 	ac(archive_read_support_format_zip(a));
-	ac(archive_read_open_fd(a, fd, 8192));
+	ac(archive_read_open_filename(a, fn, 8192));
 
 	if (!zipinfo_mode) {
 		if (!p_opt && !q_opt)
@@ -933,9 +928,6 @@
 	ac(archive_read_close(a));
 	(void)archive_read_finish(a);
 
-	if (fd != STDIN_FILENO && close(fd) != 0)
-		error("%s", fn);
-
 	if (t_opt) {
 		if (error_count > 0) {
 			errorx("%d checksum error(s) found.", error_count);
@@ -1061,6 +1053,9 @@
 		usage();
 	zipfile = argv[nopts++];
 
+	if (strcmp(zipfile, "-") == 0)
+		zipfile = NULL; /* STDIN */
+
 	while (nopts < argc && *argv[nopts] != '-')
 		add_pattern(&include, argv[nopts++]);
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/usbhidctl/usbhid.c
--- a/head/usr.bin/usbhidctl/usbhid.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/usbhidctl/usbhid.c	Wed Jul 25 16:31:11 2012 +0300
@@ -1,5 +1,5 @@
 /*	$NetBSD: usbhid.c,v 1.14 2000/07/03 02:51:37 matt Exp $	*/
-/*	$FreeBSD: head/usr.bin/usbhidctl/usbhid.c 227196 2011-11-06 08:18:30Z ed $ */
+/*	$FreeBSD: head/usr.bin/usbhidctl/usbhid.c 235519 2012-05-16 20:30:20Z mav $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -182,11 +182,11 @@
 
 	fprintf(stderr,
                 "usage: %s -f device "
-                "[-l] [-n] [-r] [-t tablefile] [-v] [-x] name ...\n",
+                "[-l] [-n] [-r] [-t tablefile] [-v] [-x] [-z] name ...\n",
                 getprogname());
 	fprintf(stderr,
                 "       %s -f device "
-                "[-l] [-n] [-r] [-t tablefile] [-v] [-x] -a\n",
+                "[-l] [-n] [-r] [-t tablefile] [-v] [-x] [-z] -a\n",
                 getprogname());
 	fprintf(stderr,
                 "       %s -f device "
@@ -304,7 +304,7 @@
 	u_char *dbuf;
 	enum hid_kind kind;
 
-	kind = 0;
+	kind = zflag ? 3 : 0;
 	rid = -1;
 	use_rid = !!hid_get_report_id(f);
 	do {
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/usbhidctl/usbhidctl.1
--- a/head/usr.bin/usbhidctl/usbhidctl.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/usbhidctl/usbhidctl.1	Wed Jul 25 16:31:11 2012 +0300
@@ -1,5 +1,5 @@
 .\" $NetBSD: usbhidctl.1,v 1.8 1999/05/11 21:03:58 augustss Exp $
-.\" $FreeBSD: head/usr.bin/usbhidctl/usbhidctl.1 225839 2011-09-28 14:52:25Z mav $
+.\" $FreeBSD: head/usr.bin/usbhidctl/usbhidctl.1 236596 2012-06-05 03:14:39Z eadler $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd August 01, 2011
+.Dd August 1, 2011
 .Dt USBHIDCTL 1
 .Os
 .Sh NAME
@@ -47,6 +47,7 @@
 .Op Fl l
 .Op Fl v
 .Op Fl x
+.Op Fl z
 .Fl a
 .Nm
 .Fl f Ar device
@@ -55,6 +56,7 @@
 .Op Fl n
 .Op Fl v
 .Op Fl x
+.Op Fl z
 .Ar item ...
 .Nm
 .Fl f Ar device
@@ -99,9 +101,8 @@
 .It Fl x
 Dump data in hexadecimal as well as decimal.
 .It Fl z
-Reset reports to zero before processing
-.Fl w
-arguments. If not specified, current values will be requested from device.
+Reset reports to zero before processing other arguments.
+If not specified, current values will be requested from device.
 .El
 .Sh SYNTAX
 .Nm
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/who/who.1
--- a/head/usr.bin/who/who.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/who/who.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)who.1	8.2 (Berkeley) 12/30/93
-.\" $FreeBSD: head/usr.bin/who/who.1 231536 2012-02-11 21:49:23Z ed $
+.\" $FreeBSD: head/usr.bin/who/who.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
 .Dd February 11, 2012
 .Dt WHO 1
@@ -82,7 +82,7 @@
 Show idle time for each user in hours and minutes as
 .Ar hh Ns : Ns Ar mm ,
 .Ql \&.
-if the user has been idle less that a minute, and
+if the user has been idle less than a minute, and
 .Dq Li old
 if the user has been idle more than 24 hours.
 .It Cm am I
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/whois/whois.1
--- a/head/usr.bin/whois/whois.1	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/whois/whois.1	Wed Jul 25 16:31:11 2012 +0300
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     From: @(#)whois.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/whois/whois.1 235211 2012-05-10 02:07:00Z gjb $
 .\"
 .Dd October 2, 2009
 .Dt WHOIS 1
@@ -203,12 +203,12 @@
 option with an argument of
 .Qq Li RU
 instead.
+.El
 .Pp
 The operands specified to
 .Nm
 are treated independently and may be used
 as queries on different whois servers.
-.El
 .Sh EXIT STATUS
 .Ex -std
 .Sh EXAMPLES
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/xinstall/xinstall.c
--- a/head/usr.bin/xinstall/xinstall.c	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/xinstall/xinstall.c	Wed Jul 25 16:31:11 2012 +0300
@@ -40,7 +40,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/xinstall/xinstall.c 227202 2011-11-06 08:19:07Z ed $");
+__FBSDID("$FreeBSD: head/usr.bin/xinstall/xinstall.c 237988 2012-07-02 09:53:57Z kib $");
 
 #include <sys/param.h>
 #include <sys/mman.h>
@@ -55,6 +55,7 @@
 #include <grp.h>
 #include <paths.h>
 #include <pwd.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -671,11 +672,18 @@
 	if (size <= 8 * 1048576 && trymmap(from_fd) &&
 	    (p = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED,
 		    from_fd, (off_t)0)) != (char *)MAP_FAILED) {
-		if ((nw = write(to_fd, p, size)) != size) {
+		nw = write(to_fd, p, size);
+		if (nw != size) {
 			serrno = errno;
 			(void)unlink(to_name);
-			errno = nw > 0 ? EIO : serrno;
-			err(EX_OSERR, "%s", to_name);
+			if (nw >= 0) {
+				errx(EX_OSERR,
+     "short write to %s: %jd bytes written, %jd bytes asked to write",
+				    to_name, (uintmax_t)nw, (uintmax_t)size);
+			} else {
+				errno = serrno;
+				err(EX_OSERR, "%s", to_name);
+			}
 		}
 		done_copy = 1;
 	}
@@ -684,8 +692,15 @@
 			if ((nw = write(to_fd, buf, nr)) != nr) {
 				serrno = errno;
 				(void)unlink(to_name);
-				errno = nw > 0 ? EIO : serrno;
-				err(EX_OSERR, "%s", to_name);
+				if (nw >= 0) {
+					errx(EX_OSERR,
+     "short write to %s: %jd bytes written, %jd bytes asked to write",
+					    to_name, (uintmax_t)nw,
+					    (uintmax_t)size);
+				} else {
+					errno = serrno;
+					err(EX_OSERR, "%s", to_name);
+				}
 			}
 		if (nr != 0) {
 			serrno = errno;
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/ACKNOWLEDGEMENTS
--- a/head/usr.bin/yacc/ACKNOWLEDGEMENTS	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-     Berkeley Yacc owes much to the unflagging efforts of Keith Bostic.
-His badgering kept me working on it long after I was ready to quit.
-
-     Berkeley Yacc is based on the excellent algorithm for computing LALR(1)
-lookaheads developed by Tom Pennello and Frank DeRemer.  The algorithm is
-described in their almost impenetrable article in TOPLAS 4,4.
-
-     Finally, much of the credit for the latest version must go to those
-who pointed out deficiencies of my earlier releases.  Among the most
-prolific contributors were
-
-	  Benson I. Margulies
-	  Dave Gentzel
-	  Antoine Verheijen
-	  Peter S. Housel
-	  Dale Smith
-	  Ozan Yigit
-	  John Campbell
-	  Bill Sommerfeld
-	  Paul Hilfinger
-	  Gary Bridgewater
-	  Dave Bakken
-	  Dan Lanciani
-	  Richard Sargent
-	  Parag Patel
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/Makefile
--- a/head/usr.bin/yacc/Makefile	Wed Jul 25 16:29:58 2012 +0300
+++ b/head/usr.bin/yacc/Makefile	Wed Jul 25 16:31:11 2012 +0300
@@ -1,11 +1,18 @@
 #	@(#)Makefile	5.3 (Berkeley) 5/12/90
-# $FreeBSD$
+# $FreeBSD: head/usr.bin/yacc/Makefile 235723 2012-05-21 13:31:26Z bapt $
+
+.PATH: ${.CURDIR}/../../contrib/byacc
 
 PROG=	yacc
-SRCS=	closure.c error.c lalr.c lr0.c main.c mkpar.c output.c reader.c \
-	skeleton.c symtab.c verbose.c warshall.c
-SCRIPTS=yyfix.sh
-MAN=	yacc.1 yyfix.1
+SRCS=	closure.c error.c graph.c lalr.c lr0.c main.c mkpar.c output.c \
+	reader.c skeleton.c symtab.c verbose.c warshall.c
+
+CFLAGS+=	-DMIXEDCASE_FILENAMES=1 \
+		-DCC_HAS_PROTOS=1 \
+		-DHAVE_FCNTL_H=1 \
+		-DHAVE_ATEXIT=1 \
+		-DHAVE_MKSTEMP=1
+		
 LINKS=	${BINDIR}/yacc ${BINDIR}/byacc
 MLINKS=	yacc.1 byacc.1
 
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/NEW_FEATURES
--- a/head/usr.bin/yacc/NEW_FEATURES	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-$FreeBSD: head/usr.bin/yacc/NEW_FEATURES 228992 2011-12-30 11:02:40Z uqs $
-
-     The -r option has been implemented.  The -r option tells Yacc to
-put the read-only tables in y.tab.c and the code and variables in
-y.code.c.  Keith Bostic asked for this option so that :yyfix could be
-eliminated.
-
-     The -l and -t options have been implemented.  The -l option tells
-Yacc not to include #line directives in the code it produces.  The -t
-option causes debugging code to be included in the compiled parser.
-
-     The code for error recovery has been changed to implement the same
-algorithm as AT&T Yacc.  There will still be differences in the way
-error recovery works because AT&T Yacc uses more default reductions
-than Berkeley Yacc.
-
-     The environment variable TMPDIR determines the directory where
-temporary files will be created.  If TMPDIR is defined, temporary files
-will be created in the directory whose pathname is the value of TMPDIR.
-By default, temporary files are created in /tmp.
-
-     The keywords are now case-insensitive.  For example, %nonassoc,
-%NONASSOC, %NonAssoc, and %nOnAsSoC are all equivalent.
-
-     Commas and semicolons that are not part of C code are treated as
-commentary.
-
-     Line-end comments, as in BCPL, are permitted.  Line-end comments
-begin with // and end at the next end-of-line.  Line-end comments are
-permitted in C code; they are converted to C comments on output.
-
-     The form of y.output files has been changed to look more like
-those produced by AT&T Yacc.
-
-     A new kind of declaration has been added.  The form of the declaration
-is
-
-	  %ident string
-
-where string is a sequence of characters beginning with a double quote
-and ending with either a double quote or the next end-of-line, whichever
-comes first.  The declaration will cause a #ident directive to be written
-near the start of the output file.
-
-     If a parser has been compiled with debugging code, that code can be
-enabled by setting an environment variable.  If the environment variable
-YYDEBUG is set to 0, debugging output is suppressed.  If it is set to 1,
-debugging output is written to standard output.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/NOTES
--- a/head/usr.bin/yacc/NOTES	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-Berkeley Yacc reflects its origins.  The reason so many routines
-use exactly six register variables is that Berkeley Yacc was
-developed on a VAX using PCC.  PCC placed at most six variables
-in registers.  I went to considerable effort to find which six
-variables most belonged in registers.  Changes in machines and
-compilers make that effort worthless, perhaps even harmful.
-
-The code contains many instances where address calculations are
-performed in particular ways to optimize the code for the VAX.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/README
--- a/head/usr.bin/yacc/README	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-    Berkeley Yacc is an LALR(1) parser generator.  Berkeley Yacc has been made
-as compatible as possible with AT&T Yacc.  Berkeley Yacc can accept any input
-specification that conforms to the AT&T Yacc documentation.  Specifications
-that take advantage of undocumented features of AT&T Yacc will probably be
-rejected.
-
-    Berkeley Yacc is distributed with no warranty whatever.  The code is certain
-to contain errors.  Neither the author nor any contributor takes responsibility
-for any consequences of its use.
-
-    Berkeley Yacc is in the public domain.  The data structures and algorithms
-used in Berkeley Yacc are all either taken from documents available to the
-general public or are inventions of the author.  Anyone may freely distribute
-source or binary forms of Berkeley Yacc whether unchanged or modified.
-Distributers may charge whatever fees they can obtain for Berkeley Yacc.
-Programs generated by Berkeley Yacc may be distributed freely.
-
-    Please report bugs to
-
-			robert.corbett at eng.Sun.COM
-
-Include a small example if possible.  Please include the banner string from
-skeleton.c with the bug report.  Do not expect rapid responses.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/closure.c
--- a/head/usr.bin/yacc/closure.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,306 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)closure.c	5.3 (Berkeley) 5/24/93";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdlib.h>
-#include "defs.h"
-
-short *itemset;
-short *itemsetend;
-unsigned *ruleset;
-
-static void set_EFF(void);
-#ifdef DEBUG
-static void print_closure(int);
-static void print_EFF();
-static void print_first_derives();
-#endif
-
-static unsigned *first_derives;
-static unsigned *EFF;
-
-
-static void
-set_EFF(void)
-{
-    unsigned *row;
-    int symbol;
-    short *sp;
-    int rowsize;
-    int i;
-    int rule;
-
-    rowsize = WORDSIZE(nvars);
-    EFF = NEW2(nvars * rowsize, unsigned);
-
-    row = EFF;
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	sp = derives[i];
-	for (rule = *sp; rule > 0; rule = *++sp)
-	{
-	    symbol = ritem[rrhs[rule]];
-	    if (ISVAR(symbol))
-	    {
-		symbol -= start_symbol;
-		SETBIT(row, symbol);
-	    }
-	}
-	row += rowsize;
-    }
-
-    reflexive_transitive_closure(EFF, nvars);
-
-#ifdef	DEBUG
-    print_EFF();
-#endif
-}
-
-
-void
-set_first_derives(void)
-{
-    unsigned *rrow;
-    unsigned *vrow;
-    int j;
-    unsigned k;
-    unsigned cword = 0;
-    short *rp;
-
-    int rule;
-    int i;
-    int rulesetsize;
-    int varsetsize;
-
-    rulesetsize = WORDSIZE(nrules);
-    varsetsize = WORDSIZE(nvars);
-    first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
-
-    set_EFF();
-
-    rrow = first_derives + ntokens * rulesetsize;
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	vrow = EFF + ((i - ntokens) * varsetsize);
-	k = BITS_PER_WORD;
-	for (j = start_symbol; j < nsyms; k++, j++)
-	{
-	    if (k >= BITS_PER_WORD)
-	    {
-		cword = *vrow++;
-		k = 0;
-	    }
-
-	    if (cword & (1 << k))
-	    {
-		rp = derives[j];
-		while ((rule = *rp++) >= 0)
-		{
-		    SETBIT(rrow, rule);
-		}
-	    }
-	}
-
-	rrow += rulesetsize;
-    }
-
-#ifdef	DEBUG
-    print_first_derives();
-#endif
-
-    free(EFF);
-}
-
-
-void
-closure(short *nucleus, int n)
-{
-    int ruleno;
-    unsigned word;
-    unsigned i;
-    short *csp;
-    unsigned *dsp;
-    unsigned *rsp;
-    int rulesetsize;
-
-    short *csend;
-    unsigned *rsend;
-    int symbol;
-    int itemno;
-
-    rulesetsize = WORDSIZE(nrules);
-    rsend = ruleset + rulesetsize;
-    for (rsp = ruleset; rsp < rsend; rsp++)
-	*rsp = 0;
-
-    csend = nucleus + n;
-    for (csp = nucleus; csp < csend; ++csp)
-    {
-	symbol = ritem[*csp];
-	if (ISVAR(symbol))
-	{
-	    dsp = first_derives + symbol * rulesetsize;
-	    rsp = ruleset;
-	    while (rsp < rsend)
-		*rsp++ |= *dsp++;
-	}
-    }
-
-    ruleno = 0;
-    itemsetend = itemset;
-    csp = nucleus;
-    for (rsp = ruleset; rsp < rsend; ++rsp)
-    {
-	word = *rsp;
-	if (word)
-	{
-	    for (i = 0; i < BITS_PER_WORD; ++i)
-	    {
-		if (word & (1 << i))
-		{
-		    itemno = rrhs[ruleno+i];
-		    while (csp < csend && *csp < itemno)
-			*itemsetend++ = *csp++;
-		    *itemsetend++ = itemno;
-		    while (csp < csend && *csp == itemno)
-			++csp;
-		}
-	    }
-	}
-	ruleno += BITS_PER_WORD;
-    }
-
-    while (csp < csend)
-	*itemsetend++ = *csp++;
-
-#ifdef	DEBUG
-  print_closure(n);
-#endif
-}
-
-
-
-void
-finalize_closure(void)
-{
-  free(itemset);
-  free(ruleset);
-  free(first_derives + ntokens * WORDSIZE(nrules));
-}
-
-
-#ifdef	DEBUG
-
-static void
-print_closure(int n)
-{
-  short *isp;
-
-  printf("\n\nn = %d\n\n", n);
-  for (isp = itemset; isp < itemsetend; isp++)
-    printf("   %d\n", *isp);
-}
-
-
-static void
-print_EFF(void)
-{
-    int i, j;
-    unsigned *rowp;
-    unsigned word;
-    unsigned k;
-
-    printf("\n\nEpsilon Free Firsts\n");
-
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	printf("\n%s", symbol_name[i]);
-	rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars));
-	word = *rowp++;
-
-	k = BITS_PER_WORD;
-	for (j = 0; j < nvars; k++, j++)
-	{
-	    if (k >= BITS_PER_WORD)
-	    {
-		word = *rowp++;
-		k = 0;
-	    }
-
-	    if (word & (1 << k))
-		printf("  %s", symbol_name[start_symbol + j]);
-	}
-    }
-}
-
-
-static void
-print_first_derives(void)
-{
-    int i;
-    int j;
-    unsigned *rp;
-    unsigned cword;
-    unsigned k;
-
-    printf("\n\n\nFirst Derives\n");
-
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	printf("\n%s derives\n", symbol_name[i]);
-	rp = first_derives + i * WORDSIZE(nrules);
-	k = BITS_PER_WORD;
-	for (j = 0; j <= nrules; k++, j++)
-        {
-	  if (k >= BITS_PER_WORD)
-	  {
-	      cword = *rp++;
-	      k = 0;
-	  }
-
-	  if (cword & (1 << k))
-	    printf("   %d\n", j);
-	}
-    }
-
-  fflush(stdout);
-}
-
-#endif
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/defs.h
--- a/head/usr.bin/yacc/defs.h	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,348 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)defs.h	5.6 (Berkeley) 5/24/93
- * $FreeBSD$
- */
-
-#include <assert.h>
-#include <ctype.h>
-#include <err.h>
-#include <stdio.h>
-
-
-/*  machine-dependent definitions			*/
-/*  the following definitions are for the Tahoe		*/
-/*  they might have to be changed for other machines	*/
-
-/*  MAXTABLE is the maximum table size			*/
-/*  BITS_PER_WORD is the number of bits in a C unsigned	*/
-/*  WORDSIZE computes the number of words needed to	*/
-/*	store n bits					*/
-/*  BIT returns the value of the n-th bit starting	*/
-/*	from r (0-indexed)				*/
-/*  SETBIT sets the n-th bit starting from r		*/
-
-#define MAXTABLE	32500
-#define BITS_PER_WORD	32
-#define	WORDSIZE(n)	(((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
-#define	BIT(r, n)	((((r)[(n)>>5])>>((n)&31))&1)
-#define	SETBIT(r, n)	((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
-
-
-/*  character names  */
-
-#define	NUL		'\0'    /*  the null character  */
-#define	NEWLINE		'\n'    /*  line feed  */
-#define	SP		' '     /*  space  */
-#define	BS		'\b'    /*  backspace  */
-#define	HT		'\t'    /*  horizontal tab  */
-#define	VT		'\013'  /*  vertical tab  */
-#define	CR		'\r'    /*  carriage return  */
-#define	FF		'\f'    /*  form feed  */
-#define	QUOTE		'\''    /*  single quote  */
-#define	DOUBLE_QUOTE	'\"'    /*  double quote  */
-#define	BACKSLASH	'\\'    /*  backslash  */
-
-
-/* defines for constructing filenames */
-
-#define CODE_SUFFIX	".code.c"
-#define	DEFINES_SUFFIX	".tab.h"
-#define	OUTPUT_SUFFIX	".tab.c"
-#define	VERBOSE_SUFFIX	".output"
-
-
-/* keyword codes */
-
-#define TOKEN 0
-#define LEFT 1
-#define RIGHT 2
-#define NONASSOC 3
-#define MARK 4
-#define TEXT 5
-#define TYPE 6
-#define START 7
-#define UNION 8
-#define IDENT 9
-#define EXPECT 10
-
-
-/*  symbol classes  */
-
-#define UNKNOWN 0
-#define TERM 1
-#define NONTERM 2
-
-
-/*  the undefined value  */
-
-#define UNDEFINED (-1)
-
-
-/*  action codes  */
-
-#define SHIFT 1
-#define REDUCE 2
-
-
-/*  character macros  */
-
-#define IS_IDENT(c)	(isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
-#define	IS_OCTAL(c)	((c) >= '0' && (c) <= '7')
-#define	NUMERIC_VALUE(c)	((c) - '0')
-
-
-/*  symbol macros  */
-
-#define ISTOKEN(s)	((s) < start_symbol)
-#define ISVAR(s)	((s) >= start_symbol)
-
-
-/*  storage allocation macros  */
-
-#define	NEW(t)		((t*)allocate(sizeof(t)))
-#define	NEW2(n,t)	((t*)allocate((n)*sizeof(t)))
-
-
-/*  the structure of a symbol table entry  */
-
-typedef struct bucket bucket;
-struct bucket
-{
-    struct bucket *link;
-    struct bucket *next;
-    char *name;
-    char *tag;
-    short value;
-    short index;
-    short prec;
-    char class;
-    char assoc;
-};
-
-
-/*  the structure of the LR(0) state machine  */
-
-typedef struct core core;
-struct core
-{
-    struct core *next;
-    struct core *link;
-    short number;
-    short accessing_symbol;
-    short nitems;
-    short items[1];
-};
-
-
-/*  the structure used to record shifts  */
-
-typedef struct shifts shifts;
-struct shifts
-{
-    struct shifts *next;
-    short number;
-    short nshifts;
-    short shift[1];
-};
-
-
-/*  the structure used to store reductions  */
-
-typedef struct reductions reductions;
-struct reductions
-{
-    struct reductions *next;
-    short number;
-    short nreds;
-    short rules[1];
-};
-
-
-/*  the structure used to represent parser actions  */
-
-typedef struct action action;
-struct action
-{
-    struct action *next;
-    short symbol;
-    short number;
-    short prec;
-    char action_code;
-    char assoc;
-    char suppressed;
-};
-
-
-/* global variables */
-
-extern char dflag;
-extern char lflag;
-extern char rflag;
-extern char tflag;
-extern char vflag;
-extern const char *symbol_prefix;
-
-extern char *cptr;
-extern char *line;
-extern int lineno;
-extern int outline;
-
-extern const char *banner[];
-extern const char *tables[];
-extern const char *header[];
-extern const char *body[];
-extern const char *trailer[];
-
-extern char *action_file_name;
-extern char *code_file_name;
-extern char *defines_file_name;
-extern const char *input_file_name;
-extern char *output_file_name;
-extern char *text_file_name;
-extern char *union_file_name;
-extern char *verbose_file_name;
-
-extern FILE *action_file;
-extern FILE *code_file;
-extern FILE *defines_file;
-extern FILE *input_file;
-extern FILE *output_file;
-extern FILE *text_file;
-extern FILE *union_file;
-extern FILE *verbose_file;
-
-extern int nitems;
-extern int nrules;
-extern int nsyms;
-extern int ntokens;
-extern int nvars;
-extern int ntags;
-
-extern char unionized;
-
-extern int   start_symbol;
-extern char  **symbol_name;
-extern short *symbol_value;
-extern short *symbol_prec;
-extern char  *symbol_assoc;
-
-extern short *ritem;
-extern short *rlhs;
-extern short *rrhs;
-extern short *rprec;
-extern char  *rassoc;
-
-extern short **derives;
-extern char *nullable;
-
-extern bucket *first_symbol;
-extern bucket *last_symbol;
-
-extern int nstates;
-extern core *first_state;
-extern shifts *first_shift;
-extern reductions *first_reduction;
-extern short *accessing_symbol;
-extern core **state_table;
-extern shifts **shift_table;
-extern reductions **reduction_table;
-extern unsigned *LA;
-extern short *LAruleno;
-extern short *lookaheads;
-extern short *goto_map;
-extern short *from_state;
-extern short *to_state;
-
-extern action **parser;
-extern int SRexpect;
-extern int SRtotal;
-extern int RRtotal;
-extern short *SRconflicts;
-extern short *RRconflicts;
-extern short *defred;
-extern short *rules_used;
-extern short nunused;
-extern short final_state;
-
-/* global functions */
-
-void *allocate(size_t);
-void closure(short *, int);
-void create_symbol_table(void);
-void default_action_warning(void);
-void dollar_error(int, char *, char *) __dead2;
-void dollar_warning(int, int);
-void done(int) __dead2;
-void fatal(const char *msg) __dead2;
-void finalize_closure(void);
-void free_parser(void);
-void free_symbols(void);
-void free_symbol_table(void);
-void illegal_character(char *) __dead2;
-void illegal_tag(int, char *, char *) __dead2;
-void lalr(void);
-bucket *lookup(char *);
-void lr0(void);
-bucket *make_bucket(const char *);
-void make_parser(void);
-void no_grammar(void) __dead2;
-void no_space(void) __dead2;
-void open_error(const char *) __dead2;
-void output(void);
-void over_unionized(char *) __dead2;
-void prec_redeclared(void);
-void reader(void);
-void reflexive_transitive_closure(unsigned *, int);
-void reprec_warning(char *);
-void restarted_warning(void);
-void retyped_warning(char *);
-void revalued_warning(char *);
-void set_first_derives(void);
-void syntax_error(int, char *, char *) __dead2;
-void terminal_lhs(int) __dead2;
-void terminal_start(char *) __dead2;
-void tokenized_start(char *) __dead2;
-void undefined_goal(char *) __dead2;
-void undefined_symbol_warning(char *);
-void unexpected_EOF(void) __dead2;
-void unknown_rhs(int) __dead2;
-void unterminated_action(int, char *, char *) __dead2;
-void unterminated_comment(int, char *, char *) __dead2;
-void unterminated_string(int, char *, char *) __dead2;
-void unterminated_text(int, char *, char *) __dead2;
-void unterminated_union(int, char *, char *) __dead2;
-void untyped_lhs(void) __dead2;
-void untyped_rhs(int, char *) __dead2;
-void used_reserved(char *) __dead2;
-void verbose(void);
-void write_section(const char **);
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/error.c
--- a/head/usr.bin/yacc/error.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,341 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)error.c	5.3 (Berkeley) 6/1/90";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* routines for printing error messages  */
-
-#include "defs.h"
-
-static void print_pos(char *, char *);
-
-void
-fatal(const char *msg)
-{
-    warnx("f - %s", msg);
-    done(2);
-}
-
-
-void
-no_space(void)
-{
-    warnx("f - out of space");
-    done(2);
-}
-
-
-void
-open_error(const char *filename)
-{
-    warnx("f - cannot open \"%s\"", filename);
-    done(2);
-}
-
-
-void
-unexpected_EOF(void)
-{
-    warnx("e - line %d of \"%s\", unexpected end-of-file",
-	    lineno, input_file_name);
-    done(1);
-}
-
-
-static void
-print_pos(char *st_line, char *st_cptr)
-{
-    char *s;
-
-    if (st_line == 0) return;
-    for (s = st_line; *s != '\n'; ++s)
-    {
-	if (isprint(*s) || *s == '\t')
-	    putc(*s, stderr);
-	else
-	    putc('?', stderr);
-    }
-    putc('\n', stderr);
-    for (s = st_line; s < st_cptr; ++s)
-    {
-	if (*s == '\t')
-	    putc('\t', stderr);
-	else
-	    putc(' ', stderr);
-    }
-    putc('^', stderr);
-    putc('\n', stderr);
-}
-
-
-void
-syntax_error(int st_lineno, char *st_line, char *st_cptr)
-{
-    warnx("e - line %d of \"%s\", syntax error",
-	    st_lineno, input_file_name);
-    print_pos(st_line, st_cptr);
-    done(1);
-}
-
-
-void
-unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
-{
-    warnx("e - line %d of \"%s\", unmatched /*",
-	    c_lineno, input_file_name);
-    print_pos(c_line, c_cptr);
-    done(1);
-}
-
-
-void
-unterminated_string(int s_lineno, char *s_line, char *s_cptr)
-{
-    warnx("e - line %d of \"%s\", unterminated string",
-	    s_lineno, input_file_name);
-    print_pos(s_line, s_cptr);
-    done(1);
-}
-
-
-void
-unterminated_text(int t_lineno, char *t_line, char *t_cptr)
-{
-    warnx("e - line %d of \"%s\", unmatched %%{",
-	    t_lineno, input_file_name);
-    print_pos(t_line, t_cptr);
-    done(1);
-}
-
-
-void
-unterminated_union(int u_lineno, char *u_line, char *u_cptr)
-{
-    warnx("e - line %d of \"%s\", unterminated %%union declaration",
-		u_lineno, input_file_name);
-    print_pos(u_line, u_cptr);
-    done(1);
-}
-
-
-void
-over_unionized(char *u_cptr)
-{
-    warnx("e - line %d of \"%s\", too many %%union declarations",
-		lineno, input_file_name);
-    print_pos(line, u_cptr);
-    done(1);
-}
-
-
-void
-illegal_tag(int t_lineno, char *t_line, char *t_cptr)
-{
-    warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
-    print_pos(t_line, t_cptr);
-    done(1);
-}
-
-
-void
-illegal_character(char *c_cptr)
-{
-    warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
-    print_pos(line, c_cptr);
-    done(1);
-}
-
-
-void
-used_reserved(char *s)
-{
-    warnx("e - line %d of \"%s\", illegal use of reserved symbol %s",
-		lineno, input_file_name, s);
-    done(1);
-}
-
-
-void
-tokenized_start(char *s)
-{
-     warnx("e - line %d of \"%s\", the start symbol %s cannot be \
-declared to be a token", lineno, input_file_name, s);
-     done(1);
-}
-
-
-void
-retyped_warning(char *s)
-{
-    warnx("w - line %d of \"%s\", the type of %s has been redeclared",
-		lineno, input_file_name, s);
-}
-
-
-void
-reprec_warning(char *s)
-{
-    warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
-		lineno, input_file_name, s);
-}
-
-
-void
-revalued_warning(char *s)
-{
-    warnx("w - line %d of \"%s\", the value of %s has been redeclared",
-		lineno, input_file_name, s);
-}
-
-
-void
-terminal_start(char *s)
-{
-    warnx("e - line %d of \"%s\", the start symbol %s is a token",
-		lineno, input_file_name, s);
-    done(1);
-}
-
-
-void
-restarted_warning(void)
-{
-    warnx("w - line %d of \"%s\", the start symbol has been redeclared",
-		lineno, input_file_name);
-}
-
-
-void
-no_grammar(void)
-{
-    warnx("e - line %d of \"%s\", no grammar has been specified",
-		lineno, input_file_name);
-    done(1);
-}
-
-
-void
-terminal_lhs(int s_lineno)
-{
-    warnx("e - line %d of \"%s\", a token appears on the lhs of a production",
-		s_lineno, input_file_name);
-    done(1);
-}
-
-
-void
-prec_redeclared(void)
-{
-    warnx("w - line %d of  \"%s\", conflicting %%prec specifiers",
-		lineno, input_file_name);
-}
-
-
-void
-unterminated_action(int a_lineno, char *a_line, char *a_cptr)
-{
-    warnx("e - line %d of \"%s\", unterminated action",
-	    a_lineno, input_file_name);
-    print_pos(a_line, a_cptr);
-    done(1);
-}
-
-
-void
-dollar_warning(int a_lineno, int i)
-{
-    warnx("w - line %d of \"%s\", $%d references beyond the \
-end of the current rule", a_lineno, input_file_name, i);
-}
-
-
-void
-dollar_error(int a_lineno, char *a_line, char *a_cptr)
-{
-    warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
-    print_pos(a_line, a_cptr);
-    done(1);
-}
-
-
-void
-untyped_lhs(void)
-{
-    warnx("e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
-    done(1);
-}
-
-
-void
-untyped_rhs(int i, char *s)
-{
-    warnx("e - line %d of \"%s\", $%d (%s) is untyped",
-	    lineno, input_file_name, i, s);
-    done(1);
-}
-
-
-void
-unknown_rhs(int i)
-{
-    warnx("e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
-    done(1);
-}
-
-
-void
-default_action_warning(void)
-{
-    warnx("w - line %d of \"%s\", the default action assigns an \
-undefined value to $$", lineno, input_file_name);
-}
-
-
-void
-undefined_goal(char *s)
-{
-    warnx("e - the start symbol %s is undefined", s);
-    done(1);
-}
-
-
-void
-undefined_symbol_warning(char *s)
-{
-    warnx("w - the symbol %s is undefined", s);
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/lalr.c
--- a/head/usr.bin/yacc/lalr.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,701 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)lalr.c	5.3 (Berkeley) 6/1/90";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <limits.h>
-#include <stdlib.h>
-#include "defs.h"
-
-typedef
-  struct shorts
-    {
-      struct shorts *next;
-      short value;
-    }
-  shorts;
-
-int tokensetsize;
-short *lookaheads;
-short *LAruleno;
-unsigned *LA;
-short *accessing_symbol;
-core **state_table;
-shifts **shift_table;
-reductions **reduction_table;
-short *goto_map;
-short *from_state;
-short *to_state;
-
-static void add_lookback_edge(int, int, int);
-static void build_relations(void);
-static void compute_FOLLOWS(void);
-static void compute_lookaheads(void);
-static void digraph(short **);
-static void initialize_F(void);
-static void initialize_LA(void);
-static int map_goto(int, int);
-static void set_accessing_symbol(void);
-static void set_goto_map(void);
-static void set_maxrhs(void);
-static void set_reduction_table(void);
-static void set_shift_table(void);
-static void set_state_table(void);
-static short **transpose(short **, int);
-static void traverse(int, short **);
-
-static int infinity;
-static int maxrhs;
-static int ngotos;
-static unsigned *F;
-static short **includes;
-static shorts **lookback;
-static short *INDEX;
-static short *VERTICES;
-static int top;
-
-
-void
-lalr(void)
-{
-    tokensetsize = WORDSIZE(ntokens);
-
-    set_state_table();
-    set_accessing_symbol();
-    set_shift_table();
-    set_reduction_table();
-    set_maxrhs();
-    initialize_LA();
-    set_goto_map();
-    initialize_F();
-    build_relations();
-    compute_FOLLOWS();
-    compute_lookaheads();
-}
-
-
-
-static void
-set_state_table(void)
-{
-    core *sp;
-
-    state_table = NEW2(nstates, core *);
-    for (sp = first_state; sp; sp = sp->next)
-	state_table[sp->number] = sp;
-}
-
-
-
-static void
-set_accessing_symbol(void)
-{
-    core *sp;
-
-    accessing_symbol = NEW2(nstates, short);
-    for (sp = first_state; sp; sp = sp->next)
-	accessing_symbol[sp->number] = sp->accessing_symbol;
-}
-
-
-
-static void
-set_shift_table(void)
-{
-    shifts *sp;
-
-    shift_table = NEW2(nstates, shifts *);
-    for (sp = first_shift; sp; sp = sp->next)
-	shift_table[sp->number] = sp;
-}
-
-
-
-static void
-set_reduction_table(void)
-{
-    reductions *rp;
-
-    reduction_table = NEW2(nstates, reductions *);
-    for (rp = first_reduction; rp; rp = rp->next)
-	reduction_table[rp->number] = rp;
-}
-
-
-
-static void
-set_maxrhs(void)
-{
-  short *itemp;
-  short *item_end;
-  int length;
-  int max;
-
-  length = 0;
-  max = 0;
-  item_end = ritem + nitems;
-  for (itemp = ritem; itemp < item_end; itemp++)
-    {
-      if (*itemp >= 0)
-	{
-	  length++;
-	}
-      else
-	{
-	  if (length > max) max = length;
-	  length = 0;
-	}
-    }
-
-  maxrhs = max;
-}
-
-
-
-static void
-initialize_LA(void)
-{
-  int i, j, k;
-  reductions *rp;
-
-  lookaheads = NEW2(nstates + 1, short);
-
-  k = 0;
-  for (i = 0; i < nstates; i++)
-    {
-      lookaheads[i] = k;
-      rp = reduction_table[i];
-      if (rp)
-	k += rp->nreds;
-    }
-  lookaheads[nstates] = k;
-
-  LA = NEW2(k * tokensetsize, unsigned);
-  LAruleno = NEW2(k, short);
-  lookback = NEW2(k, shorts *);
-
-  k = 0;
-  for (i = 0; i < nstates; i++)
-    {
-      rp = reduction_table[i];
-      if (rp)
-	{
-	  for (j = 0; j < rp->nreds; j++)
-	    {
-	      LAruleno[k] = rp->rules[j];
-	      k++;
-	    }
-	}
-    }
-}
-
-
-static void
-set_goto_map(void)
-{
-  shifts *sp;
-  int i;
-  int symbol;
-  int k;
-  short *temp_map;
-  int state2;
-  int state1;
-
-  goto_map = NEW2(nvars + 1, short) - ntokens;
-  temp_map = NEW2(nvars + 1, short) - ntokens;
-
-  ngotos = 0;
-  for (sp = first_shift; sp; sp = sp->next)
-    {
-      for (i = sp->nshifts - 1; i >= 0; i--)
-	{
-	  symbol = accessing_symbol[sp->shift[i]];
-
-	  if (ISTOKEN(symbol)) break;
-
-	  if (ngotos == SHRT_MAX)
-	    fatal("too many gotos");
-
-	  ngotos++;
-	  goto_map[symbol]++;
-        }
-    }
-
-  k = 0;
-  for (i = ntokens; i < nsyms; i++)
-    {
-      temp_map[i] = k;
-      k += goto_map[i];
-    }
-
-  for (i = ntokens; i < nsyms; i++)
-    goto_map[i] = temp_map[i];
-
-  goto_map[nsyms] = ngotos;
-  temp_map[nsyms] = ngotos;
-
-  from_state = NEW2(ngotos, short);
-  to_state = NEW2(ngotos, short);
-
-  for (sp = first_shift; sp; sp = sp->next)
-    {
-      state1 = sp->number;
-      for (i = sp->nshifts - 1; i >= 0; i--)
-	{
-	  state2 = sp->shift[i];
-	  symbol = accessing_symbol[state2];
-
-	  if (ISTOKEN(symbol)) break;
-
-	  k = temp_map[symbol]++;
-	  from_state[k] = state1;
-	  to_state[k] = state2;
-	}
-    }
-
-  free(temp_map + ntokens);
-}
-
-
-
-/*  Map_goto maps a state/symbol pair into its numeric representation.	*/
-
-static int
-map_goto(int state, int symbol)
-{
-    int high;
-    int low;
-    int middle;
-    int s;
-
-    low = goto_map[symbol];
-    high = goto_map[symbol + 1];
-
-    for (;;)
-    {
-	assert(low <= high);
-	middle = (low + high) >> 1;
-	s = from_state[middle];
-	if (s == state)
-	    return (middle);
-	else if (s < state)
-	    low = middle + 1;
-	else
-	    high = middle - 1;
-    }
-}
-
-
-
-static void
-initialize_F(void)
-{
-  int i;
-  int j;
-  int k;
-  shifts *sp;
-  short *edge;
-  unsigned *rowp;
-  short *rp;
-  short **reads;
-  int nedges;
-  int stateno;
-  int symbol;
-  int nwords;
-
-  nwords = ngotos * tokensetsize;
-  F = NEW2(nwords, unsigned);
-
-  reads = NEW2(ngotos, short *);
-  edge = NEW2(ngotos + 1, short);
-  nedges = 0;
-
-  rowp = F;
-  for (i = 0; i < ngotos; i++)
-    {
-      stateno = to_state[i];
-      sp = shift_table[stateno];
-
-      if (sp)
-	{
-	  k = sp->nshifts;
-
-	  for (j = 0; j < k; j++)
-	    {
-	      symbol = accessing_symbol[sp->shift[j]];
-	      if (ISVAR(symbol))
-		break;
-	      SETBIT(rowp, symbol);
-	    }
-
-	  for (; j < k; j++)
-	    {
-	      symbol = accessing_symbol[sp->shift[j]];
-	      if (nullable[symbol])
-		edge[nedges++] = map_goto(stateno, symbol);
-	    }
-
-	  if (nedges)
-	    {
-	      reads[i] = rp = NEW2(nedges + 1, short);
-
-	      for (j = 0; j < nedges; j++)
-		rp[j] = edge[j];
-
-	      rp[nedges] = -1;
-	      nedges = 0;
-	    }
-	}
-
-      rowp += tokensetsize;
-    }
-
-  SETBIT(F, 0);
-  digraph(reads);
-
-  for (i = 0; i < ngotos; i++)
-    {
-      if (reads[i])
-	free(reads[i]);
-    }
-
-  free(reads);
-  free(edge);
-}
-
-
-
-static void
-build_relations(void)
-{
-  int i;
-  int j;
-  int k;
-  short *rulep;
-  short *rp;
-  shifts *sp;
-  int length;
-  int nedges;
-  int done1;
-  int state1;
-  int stateno;
-  int symbol1;
-  int symbol2;
-  short *shortp;
-  short *edge;
-  short *states;
-  short **new_includes;
-
-  includes = NEW2(ngotos, short *);
-  edge = NEW2(ngotos + 1, short);
-  states = NEW2(maxrhs + 1, short);
-
-  for (i = 0; i < ngotos; i++)
-    {
-      nedges = 0;
-      state1 = from_state[i];
-      symbol1 = accessing_symbol[to_state[i]];
-
-      for (rulep = derives[symbol1]; *rulep >= 0; rulep++)
-	{
-	  length = 1;
-	  states[0] = state1;
-	  stateno = state1;
-
-	  for (rp = ritem + rrhs[*rulep]; *rp >= 0; rp++)
-	    {
-	      symbol2 = *rp;
-	      sp = shift_table[stateno];
-	      k = sp->nshifts;
-
-	      for (j = 0; j < k; j++)
-		{
-		  stateno = sp->shift[j];
-		  if (accessing_symbol[stateno] == symbol2) break;
-		}
-
-	      states[length++] = stateno;
-	    }
-
-	  add_lookback_edge(stateno, *rulep, i);
-
-	  length--;
-	  done1 = 0;
-	  while (!done1)
-	    {
-	      done1 = 1;
-	      rp--;
-	      if (ISVAR(*rp))
-		{
-		  stateno = states[--length];
-		  edge[nedges++] = map_goto(stateno, *rp);
-		  if (nullable[*rp] && length > 0) done1 = 0;
-		}
-	    }
-	}
-
-      if (nedges)
-	{
-	  includes[i] = shortp = NEW2(nedges + 1, short);
-	  for (j = 0; j < nedges; j++)
-	    shortp[j] = edge[j];
-	  shortp[nedges] = -1;
-	}
-    }
-
-  new_includes = transpose(includes, ngotos);
-
-  for (i = 0; i < ngotos; i++)
-    if (includes[i])
-      free(includes[i]);
-
-  free(includes);
-
-  includes = new_includes;
-
-  free(edge);
-  free(states);
-}
-
-
-static void
-add_lookback_edge(int stateno, int ruleno, int gotono)
-{
-    int i, k;
-    int found;
-    shorts *sp;
-
-    i = lookaheads[stateno];
-    k = lookaheads[stateno + 1];
-    found = 0;
-    while (!found && i < k)
-    {
-	if (LAruleno[i] == ruleno)
-	    found = 1;
-	else
-	    ++i;
-    }
-    assert(found);
-
-    sp = NEW(shorts);
-    sp->next = lookback[i];
-    sp->value = gotono;
-    lookback[i] = sp;
-}
-
-
-
-static short **
-transpose(short **R, int n)
-{
-  short **new_R;
-  short **temp_R;
-  short *nedges;
-  short *sp;
-  int i;
-  int k;
-
-  nedges = NEW2(n, short);
-
-  for (i = 0; i < n; i++)
-    {
-      sp = R[i];
-      if (sp)
-	{
-	  while (*sp >= 0)
-	    nedges[*sp++]++;
-	}
-    }
-
-  new_R = NEW2(n, short *);
-  temp_R = NEW2(n, short *);
-
-  for (i = 0; i < n; i++)
-    {
-      k = nedges[i];
-      if (k > 0)
-	{
-	  sp = NEW2(k + 1, short);
-	  new_R[i] = sp;
-	  temp_R[i] = sp;
-	  sp[k] = -1;
-	}
-    }
-
-  free(nedges);
-
-  for (i = 0; i < n; i++)
-    {
-      sp = R[i];
-      if (sp)
-	{
-	  while (*sp >= 0)
-	    *temp_R[*sp++]++ = i;
-	}
-    }
-
-  free(temp_R);
-
-  return (new_R);
-}
-
-
-
-static void
-compute_FOLLOWS(void)
-{
-  digraph(includes);
-}
-
-
-static void
-compute_lookaheads(void)
-{
-  int i, n;
-  unsigned *fp1, *fp2, *fp3;
-  shorts *sp, *next;
-  unsigned *rowp;
-
-  rowp = LA;
-  n = lookaheads[nstates];
-  for (i = 0; i < n; i++)
-    {
-      fp3 = rowp + tokensetsize;
-      for (sp = lookback[i]; sp; sp = sp->next)
-	{
-	  fp1 = rowp;
-	  fp2 = F + tokensetsize * sp->value;
-	  while (fp1 < fp3)
-	    *fp1++ |= *fp2++;
-	}
-      rowp = fp3;
-    }
-
-  for (i = 0; i < n; i++)
-    for (sp = lookback[i]; sp; sp = next)
-      {
-        next = sp->next;
-        free(sp);
-      }
-
-  free(lookback);
-  free(F);
-}
-
-
-static void
-digraph(short **relation)
-{
-  int i;
-
-  infinity = ngotos + 2;
-  INDEX = NEW2(ngotos + 1, short);
-  VERTICES = NEW2(ngotos + 1, short);
-  top = 0;
-
-  for (i = 0; i < ngotos; i++)
-    INDEX[i] = 0;
-
-  for (i = 0; i < ngotos; i++)
-    {
-      if (INDEX[i] == 0 && relation[i])
-	traverse(i, relation);
-    }
-
-  free(INDEX);
-  free(VERTICES);
-}
-
-
-
-static void
-traverse(int i, short **R)
-{
-  unsigned *fp1;
-  unsigned *fp2;
-  unsigned *fp3;
-  int j;
-  short *rp;
-
-  int height;
-  unsigned *base;
-
-  VERTICES[++top] = i;
-  INDEX[i] = height = top;
-
-  base = F + i * tokensetsize;
-  fp3 = base + tokensetsize;
-
-  rp = R[i];
-  if (rp)
-    {
-      while ((j = *rp++) >= 0)
-	{
-	  if (INDEX[j] == 0)
-	    traverse(j, R);
-
-	  if (INDEX[i] > INDEX[j])
-	    INDEX[i] = INDEX[j];
-
-	  fp1 = base;
-	  fp2 = F + j * tokensetsize;
-
-	  while (fp1 < fp3)
-	    *fp1++ |= *fp2++;
-	}
-    }
-
-  if (INDEX[i] == height)
-    {
-      for (;;)
-	{
-	  j = VERTICES[top--];
-	  INDEX[j] = infinity;
-
-	  if (i == j)
-	    break;
-
-	  fp1 = base;
-	  fp2 = F + j * tokensetsize;
-
-	  while (fp1 < fp3)
-	    *fp2++ = *fp1++;
-	}
-    }
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/lr0.c
--- a/head/usr.bin/yacc/lr0.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,671 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)lr0.c	5.3 (Berkeley) 1/20/91";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <limits.h>
-#include <stdlib.h>
-#include "defs.h"
-
-extern short *itemset;
-extern short *itemsetend;
-extern unsigned *ruleset;
-
-int nstates;
-core *first_state;
-shifts *first_shift;
-reductions *first_reduction;
-
-static void allocate_itemsets(void);
-static void allocate_storage(void);
-static void append_states(void);
-static void free_storage(void);
-static void generate_states(void);
-static int get_state(int);
-static void initialize_states(void);
-static void new_itemsets(void);
-static core *new_state(int);
-#ifdef DEBUG
-static void print_derives(void);
-#endif
-static void save_reductions(void);
-static void save_shifts(void);
-static void set_derives(void);
-static void set_nullable(void);
-
-static core **state_set;
-static core *this_state;
-static core *last_state;
-static shifts *last_shift;
-static reductions *last_reduction;
-
-static int nshifts;
-static short *shift_symbol;
-
-static short *redset;
-static short *shiftset;
-
-static short **kernel_base;
-static short **kernel_end;
-static short *kernel_items;
-
-
-static void
-allocate_itemsets(void)
-{
-    short *itemp;
-    short *item_end;
-    int symbol;
-    int i;
-    int count;
-    int max;
-    short *symbol_count;
-
-    count = 0;
-    symbol_count = NEW2(nsyms, short);
-
-    item_end = ritem + nitems;
-    for (itemp = ritem; itemp < item_end; itemp++)
-    {
-	symbol = *itemp;
-	if (symbol >= 0)
-	{
-	    count++;
-	    symbol_count[symbol]++;
-	}
-    }
-
-    kernel_base = NEW2(nsyms, short *);
-    kernel_items = NEW2(count, short);
-
-    count = 0;
-    max = 0;
-    for (i = 0; i < nsyms; i++)
-    {
-	kernel_base[i] = kernel_items + count;
-	count += symbol_count[i];
-	if (max < symbol_count[i])
-	    max = symbol_count[i];
-    }
-
-    shift_symbol = symbol_count;
-    kernel_end = NEW2(nsyms, short *);
-}
-
-
-static void
-allocate_storage(void)
-{
-    allocate_itemsets();
-    shiftset = NEW2(nsyms, short);
-    redset = NEW2(nrules + 1, short);
-    state_set = NEW2(nitems, core *);
-}
-
-
-static void
-append_states(void)
-{
-    int i;
-    int j;
-    int symbol;
-
-#ifdef	TRACE
-    fprintf(stderr, "Entering append_states()\n");
-#endif
-    for (i = 1; i < nshifts; i++)
-    {
-	symbol = shift_symbol[i];
-	j = i;
-	while (j > 0 && shift_symbol[j - 1] > symbol)
-	{
-	    shift_symbol[j] = shift_symbol[j - 1];
-	    j--;
-	}
-	shift_symbol[j] = symbol;
-    }
-
-    for (i = 0; i < nshifts; i++)
-    {
-	symbol = shift_symbol[i];
-	shiftset[i] = get_state(symbol);
-    }
-}
-
-
-static void
-free_storage(void)
-{
-    free(shift_symbol);
-    free(redset);
-    free(shiftset);
-    free(kernel_base);
-    free(kernel_end);
-    free(kernel_items);
-    free(state_set);
-}
-
-
-
-static void
-generate_states(void)
-{
-    allocate_storage();
-    itemset = NEW2(nitems, short);
-    ruleset = NEW2(WORDSIZE(nrules), unsigned);
-    set_first_derives();
-    initialize_states();
-
-    while (this_state)
-    {
-	closure(this_state->items, this_state->nitems);
-	save_reductions();
-	new_itemsets();
-	append_states();
-
-	if (nshifts > 0)
-	    save_shifts();
-
-	this_state = this_state->next;
-    }
-
-    finalize_closure();
-    free_storage();
-}
-
-
-
-static int
-get_state(int symbol)
-{
-    int key;
-    short *isp1;
-    short *isp2;
-    short *iend;
-    core *sp;
-    int found;
-    int n;
-
-#ifdef	TRACE
-    fprintf(stderr, "Entering get_state(%d)\n", symbol);
-#endif
-
-    isp1 = kernel_base[symbol];
-    iend = kernel_end[symbol];
-    n = iend - isp1;
-
-    key = *isp1;
-    assert(0 <= key && key < nitems);
-    sp = state_set[key];
-    if (sp)
-    {
-	found = 0;
-	while (!found)
-	{
-	    if (sp->nitems == n)
-	    {
-		found = 1;
-		isp1 = kernel_base[symbol];
-		isp2 = sp->items;
-
-		while (found && isp1 < iend)
-		{
-		    if (*isp1++ != *isp2++)
-			found = 0;
-		}
-	    }
-
-	    if (!found)
-	    {
-		if (sp->link)
-		{
-		    sp = sp->link;
-		}
-		else
-		{
-		    sp = sp->link = new_state(symbol);
-		    found = 1;
-		}
-	    }
-	}
-    }
-    else
-    {
-	state_set[key] = sp = new_state(symbol);
-    }
-
-    return (sp->number);
-}
-
-
-
-static void
-initialize_states(void)
-{
-    int i;
-    short *start_derives;
-    core *p;
-
-    start_derives = derives[start_symbol];
-    for (i = 0; start_derives[i] >= 0; ++i)
-	continue;
-
-    p = malloc(sizeof(core) + i*sizeof(short));
-    if (p == 0) no_space();
-
-    p->next = 0;
-    p->link = 0;
-    p->number = 0;
-    p->accessing_symbol = 0;
-    p->nitems = i;
-
-    for (i = 0;  start_derives[i] >= 0; ++i)
-	p->items[i] = rrhs[start_derives[i]];
-
-    first_state = last_state = this_state = p;
-    nstates = 1;
-}
-
-
-static void
-new_itemsets(void)
-{
-    int i;
-    int shiftcount;
-    short *isp;
-    short *ksp;
-    int symbol;
-
-    for (i = 0; i < nsyms; i++)
-	kernel_end[i] = 0;
-
-    shiftcount = 0;
-    isp = itemset;
-    while (isp < itemsetend)
-    {
-	i = *isp++;
-	symbol = ritem[i];
-	if (symbol > 0)
-	{
-	    ksp = kernel_end[symbol];
-	    if (!ksp)
-	    {
-		shift_symbol[shiftcount++] = symbol;
-		ksp = kernel_base[symbol];
-	    }
-
-	    *ksp++ = i + 1;
-	    kernel_end[symbol] = ksp;
-	}
-    }
-
-    nshifts = shiftcount;
-}
-
-
-
-static core *
-new_state(int symbol)
-{
-    int n;
-    core *p;
-    short *isp1;
-    short *isp2;
-    short *iend;
-
-#ifdef	TRACE
-    fprintf(stderr, "Entering new_state(%d)\n", symbol);
-#endif
-
-    if (nstates >= SHRT_MAX)
-	fatal("too many states");
-
-    isp1 = kernel_base[symbol];
-    iend = kernel_end[symbol];
-    n = iend - isp1;
-
-    p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
-    p->accessing_symbol = symbol;
-    p->number = nstates;
-    p->nitems = n;
-
-    isp2 = p->items;
-    while (isp1 < iend)
-	*isp2++ = *isp1++;
-
-    last_state->next = p;
-    last_state = p;
-
-    nstates++;
-
-    return (p);
-}
-
-
-#if 0
-/* show_cores is used for debugging */
-
-show_cores(void)
-{
-    core *p;
-    int i, j, k, n;
-    int itemno;
-
-    k = 0;
-    for (p = first_state; p; ++k, p = p->next)
-    {
-	if (k) printf("\n");
-	printf("state %d, number = %d, accessing symbol = %s\n",
-		k, p->number, symbol_name[p->accessing_symbol]);
-	n = p->nitems;
-	for (i = 0; i < n; ++i)
-	{
-	    itemno = p->items[i];
-	    printf("%4d  ", itemno);
-	    j = itemno;
-	    while (ritem[j] >= 0) ++j;
-	    printf("%s :", symbol_name[rlhs[-ritem[j]]]);
-	    j = rrhs[-ritem[j]];
-	    while (j < itemno)
-		printf(" %s", symbol_name[ritem[j++]]);
-	    printf(" .");
-	    while (ritem[j] >= 0)
-		printf(" %s", symbol_name[ritem[j++]]);
-	    printf("\n");
-	    fflush(stdout);
-	}
-    }
-}
-
-
-/* show_ritems is used for debugging */
-
-show_ritems(void)
-{
-    int i;
-
-    for (i = 0; i < nitems; ++i)
-	printf("ritem[%d] = %d\n", i, ritem[i]);
-}
-
-
-/* show_rrhs is used for debugging */
-show_rrhs(void)
-{
-    int i;
-
-    for (i = 0; i < nrules; ++i)
-	printf("rrhs[%d] = %d\n", i, rrhs[i]);
-}
-
-
-/* show_shifts is used for debugging */
-
-show_shifts(void)
-{
-    shifts *p;
-    int i, j, k;
-
-    k = 0;
-    for (p = first_shift; p; ++k, p = p->next)
-    {
-	if (k) printf("\n");
-	printf("shift %d, number = %d, nshifts = %d\n", k, p->number,
-		p->nshifts);
-	j = p->nshifts;
-	for (i = 0; i < j; ++i)
-	    printf("\t%d\n", p->shift[i]);
-    }
-}
-#endif
-
-
-static void
-save_shifts(void)
-{
-    shifts *p;
-    short *sp1;
-    short *sp2;
-    short *send;
-
-    p = (shifts *) allocate((unsigned) (sizeof(shifts) +
-			(nshifts - 1) * sizeof(short)));
-
-    p->number = this_state->number;
-    p->nshifts = nshifts;
-
-    sp1 = shiftset;
-    sp2 = p->shift;
-    send = shiftset + nshifts;
-
-    while (sp1 < send)
-	*sp2++ = *sp1++;
-
-    if (last_shift)
-    {
-	last_shift->next = p;
-	last_shift = p;
-    }
-    else
-    {
-	first_shift = p;
-	last_shift = p;
-    }
-}
-
-
-
-static void
-save_reductions(void)
-{
-    short *isp;
-    short *rp1;
-    short *rp2;
-    int item;
-    int count;
-    reductions *p;
-    short *rend;
-
-    count = 0;
-    for (isp = itemset; isp < itemsetend; isp++)
-    {
-	item = ritem[*isp];
-	if (item < 0)
-	{
-	    redset[count++] = -item;
-	}
-    }
-
-    if (count)
-    {
-	p = (reductions *) allocate((unsigned) (sizeof(reductions) +
-					(count - 1) * sizeof(short)));
-
-	p->number = this_state->number;
-	p->nreds = count;
-
-	rp1 = redset;
-	rp2 = p->rules;
-	rend = rp1 + count;
-
-	while (rp1 < rend)
-	    *rp2++ = *rp1++;
-
-	if (last_reduction)
-	{
-	    last_reduction->next = p;
-	    last_reduction = p;
-	}
-	else
-	{
-	    first_reduction = p;
-	    last_reduction = p;
-	}
-    }
-}
-
-
-static void
-set_derives(void)
-{
-    int i, k;
-    int lhs;
-    short *rules;
-
-    derives = NEW2(nsyms, short *);
-    rules = NEW2(nvars + nrules, short);
-
-    k = 0;
-    for (lhs = start_symbol; lhs < nsyms; lhs++)
-    {
-	derives[lhs] = rules + k;
-	for (i = 0; i < nrules; i++)
-	{
-	    if (rlhs[i] == lhs)
-	    {
-		rules[k] = i;
-		k++;
-	    }
-	}
-	rules[k] = -1;
-	k++;
-    }
-
-#ifdef	DEBUG
-    print_derives();
-#endif
-}
-
-#if 0
-free_derives()
-{
-    free(derives[start_symbol]);
-    free(derives);
-}
-#endif
-
-#ifdef	DEBUG
-static void
-print_derives(void)
-{
-    int i;
-    short *sp;
-
-    printf("\nDERIVES\n\n");
-
-    for (i = start_symbol; i < nsyms; i++)
-    {
-	printf("%s derives ", symbol_name[i]);
-	for (sp = derives[i]; *sp >= 0; sp++)
-	{
-	    printf("  %d", *sp);
-	}
-	putchar('\n');
-    }
-
-    putchar('\n');
-}
-#endif
-
-
-static void
-set_nullable(void)
-{
-    int i, j;
-    int empty;
-    int done1;
-
-    nullable = malloc(nsyms);
-    if (nullable == 0) no_space();
-
-    for (i = 0; i < nsyms; ++i)
-	nullable[i] = 0;
-
-    done1 = 0;
-    while (!done1)
-    {
-	done1 = 1;
-	for (i = 1; i < nitems; i++)
-	{
-	    empty = 1;
-	    while ((j = ritem[i]) >= 0)
-	    {
-		if (!nullable[j])
-		    empty = 0;
-		++i;
-	    }
-	    if (empty)
-	    {
-		j = rlhs[-j];
-		if (!nullable[j])
-		{
-		    nullable[j] = 1;
-		    done1 = 0;
-		}
-	    }
-	}
-    }
-
-#ifdef DEBUG
-    for (i = 0; i < nsyms; i++)
-    {
-	if (nullable[i])
-	    printf("%s is nullable\n", symbol_name[i]);
-	else
-	    printf("%s is not nullable\n", symbol_name[i]);
-    }
-#endif
-}
-
-
-#if 0
-free_nullable(void)
-{
-    free(nullable);
-}
-#endif
-
-
-void
-lr0(void)
-{
-    set_derives();
-    set_nullable();
-    generate_states();
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/main.c
--- a/head/usr.bin/yacc/main.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,438 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)main.c	5.5 (Berkeley) 5/24/93";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <paths.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "defs.h"
-
-char dflag;
-char lflag;
-char rflag;
-char tflag;
-char vflag;
-
-const char *symbol_prefix;
-const char *file_prefix = "y";
-char temp_form[] = "yacc.XXXXXXXXXXX";
-
-int lineno;
-int outline;
-
-char *action_file_name;
-char *code_file_name;
-char *defines_file_name;
-const char *input_file_name = "";
-char *output_file_name;
-char *text_file_name;
-char *union_file_name;
-char *verbose_file_name;
-
-FILE *action_file;	/*  a temp file, used to save actions associated    */
-			/*  with rules until the parser is written	    */
-FILE *code_file;	/*  y.code.c (used when the -r option is specified) */
-FILE *defines_file;	/*  y.tab.h					    */
-FILE *input_file;	/*  the input file				    */
-FILE *output_file;	/*  y.tab.c					    */
-FILE *text_file;	/*  a temp file, used to save text until all	    */
-			/*  symbols have been defined			    */
-FILE *union_file;	/*  a temp file, used to save the union		    */
-			/*  definition until all symbol have been	    */
-			/*  defined					    */
-FILE *verbose_file;	/*  y.output					    */
-
-int nitems;
-int nrules;
-int nsyms;
-int ntokens;
-int nvars;
-
-int   start_symbol;
-char  **symbol_name;
-short *symbol_value;
-short *symbol_prec;
-char  *symbol_assoc;
-
-short *ritem;
-short *rlhs;
-short *rrhs;
-short *rprec;
-char  *rassoc;
-short **derives;
-char *nullable;
-
-static void create_file_names(void);
-static void getargs(int, char **);
-static void onintr(int);
-static void open_files(void);
-static void set_signals(void);
-static void usage(void);
-
-volatile sig_atomic_t sigdie;
-
-__dead2 void
-done(int k)
-{
-    if (action_file) { fclose(action_file); unlink(action_file_name); }
-    if (text_file) { fclose(text_file); unlink(text_file_name); }
-    if (union_file) { fclose(union_file); unlink(union_file_name); }
-    if (sigdie) { _exit(k); }
-    exit(k);
-}
-
-
-static void
-onintr(int signo __unused)
-{
-    sigdie = 1;
-    done(1);
-}
-
-
-static void
-set_signals(void)
-{
-#ifdef SIGINT
-    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-	signal(SIGINT, onintr);
-#endif
-#ifdef SIGTERM
-    if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
-	signal(SIGTERM, onintr);
-#endif
-#ifdef SIGHUP
-    if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
-	signal(SIGHUP, onintr);
-#endif
-}
-
-
-static void
-usage(void)
-{
-    fprintf(stderr, "%s\n%s\n",
-		"usage: yacc [-dlrtv] [-b file_prefix] [-o output_filename]",
-		"            [-p symbol_prefix] filename");
-    exit(1);
-}
-
-
-static void
-getargs(int argc, char *argv[])
-{
-    int ch;
-
-    while ((ch = getopt(argc, argv, "b:dlo:p:rtvy")) != -1)
-    {
-	switch (ch)
-	{
-	case 'b':
-	    file_prefix = optarg;
-	    break;
-
-	case 'd':
-	    dflag = 1;
-	    break;
-
-	case 'l':
-	    lflag = 1;
-	    break;
-
-	case 'o':
-	    output_file_name = optarg;
-	    break;
-
-	case 'p':
-	    symbol_prefix = optarg;
-	    break;
-
-	case 'r':
-	    rflag = 1;
-	    break;
-
-	case 't':
-	    tflag = 1;
-	    break;
-
-	case 'v':
-	    vflag = 1;
-	    break;
-
-	case 'y':
-	    /* for bison compatibility -- byacc is already POSIX compatible */
-	    break;
-
-	default:
-	    usage();
-	}
-    }
-
-    if (optind + 1 != argc)
-	usage();
-    if (strcmp(argv[optind], "-") == 0)
-	input_file = stdin;
-    else
-	input_file_name = argv[optind];
-}
-
-
-void *
-allocate(size_t n)
-{
-    void *p;
-
-    p = NULL;
-    if (n)
-    {
-	p = calloc(1, n);
-	if (!p) no_space();
-    }
-    return (p);
-}
-
-
-static void
-create_file_names(void)
-{
-    int i, len;
-    const char *tmpdir;
-
-    if (!(tmpdir = getenv("TMPDIR")))
-	tmpdir = _PATH_TMP;
-
-    len = strlen(tmpdir);
-    i = len + strlen(temp_form) + 1;
-    if (len && tmpdir[len-1] != '/')
-	++i;
-
-    action_file_name = malloc(i);
-    if (action_file_name == 0) no_space();
-    text_file_name = malloc(i);
-    if (text_file_name == 0) no_space();
-    union_file_name = malloc(i);
-    if (union_file_name == 0) no_space();
-
-    strcpy(action_file_name, tmpdir);
-    strcpy(text_file_name, tmpdir);
-    strcpy(union_file_name, tmpdir);
-
-    if (len && tmpdir[len - 1] != '/')
-    {
-	action_file_name[len] = '/';
-	text_file_name[len] = '/';
-	union_file_name[len] = '/';
-	++len;
-    }
-
-    strcpy(action_file_name + len, temp_form);
-    strcpy(text_file_name + len, temp_form);
-    strcpy(union_file_name + len, temp_form);
-
-    action_file_name[len + 5] = 'a';
-    text_file_name[len + 5] = 't';
-    union_file_name[len + 5] = 'u';
-
-    if (output_file_name != 0)
-    {
-	file_prefix = output_file_name;
-	len = strlen(file_prefix);
-    }
-    else
-    {
-	len = strlen(file_prefix);
-	output_file_name = malloc(len + 7);
-	if (output_file_name == 0)
-	    no_space();
-	strcpy(output_file_name, file_prefix);
-	strcpy(output_file_name + len, OUTPUT_SUFFIX);
-    }
-
-    if (rflag)
-    {
-	code_file_name = malloc(len + 8);
-	if (code_file_name == 0)
-	    no_space();
-	strcpy(code_file_name, file_prefix);
-	if (file_prefix == output_file_name)
-	{
-	    /*
-	     * XXX ".tab.c" here is OUTPUT_SUFFIX, but since its length is
-	     * in various magic numbers, don't bother using the macro.
-	     */
-	    if (len >= 6 && strcmp(code_file_name + len - 6, ".tab.c") == 0)
-		strcpy(code_file_name + len - 6, CODE_SUFFIX);
-	    else if (len >= 2 && strcmp(code_file_name + len - 2, ".c") == 0)
-		strcpy(code_file_name + len - 2, CODE_SUFFIX);
-	    else
-		strcpy(code_file_name + len, CODE_SUFFIX);
-	}
-	else
-	    strcpy(code_file_name + len, CODE_SUFFIX);
-    }
-    else
-	code_file_name = output_file_name;
-
-    if (dflag)
-    {
-	defines_file_name = malloc(len + 7);
-	if (defines_file_name == 0)
-	    no_space();
-	strcpy(defines_file_name, file_prefix);
-	if (file_prefix == output_file_name)
-	{
-#define BISON_DEFINES_SUFFIX  ".h"
-	    if (len >= 2 && strcmp(defines_file_name + len - 2, ".c") == 0)
-		strcpy(defines_file_name + len - 2, BISON_DEFINES_SUFFIX);
-	    else
-		strcpy(defines_file_name + len, BISON_DEFINES_SUFFIX);
-	}
-	else
-	    strcpy(defines_file_name + len, DEFINES_SUFFIX);
-    }
-
-    if (vflag)
-    {
-	verbose_file_name = malloc(len + 8);
-	if (verbose_file_name == 0)
-	    no_space();
-	strcpy(verbose_file_name, file_prefix);
-	if (file_prefix == output_file_name)
-	{
-	    if (len >= 6 && strcmp(verbose_file_name + len - 6, ".tab.c") == 0)
-		strcpy(verbose_file_name + len - 6, VERBOSE_SUFFIX);
-	    else if (len >= 2 && strcmp(verbose_file_name + len - 2, ".c") == 0)
-		strcpy(verbose_file_name + len - 2, VERBOSE_SUFFIX);
-	    else
-		strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
-	}
-	else
-	    strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
-    }
-}
-
-
-static void
-open_files(void)
-{
-    int fd;
-
-    create_file_names();
-
-    if (input_file == 0)
-    {
-	input_file = fopen(input_file_name, "r");
-	if (input_file == 0)
-	    open_error(input_file_name);
-    }
-
-    fd = mkstemp(action_file_name);
-    if (fd < 0 || (action_file = fdopen(fd, "w")) == NULL) {
-        if (fd >= 0)
-	    close(fd);
-	open_error(action_file_name);
-    }
-    fd = mkstemp(text_file_name);
-    if (fd < 0 || (text_file = fdopen(fd, "w")) == NULL) {
-        if (fd >= 0)
-	    close(fd);
-	open_error(text_file_name);
-    }
-    fd = mkstemp(union_file_name);
-    if (fd < 0 || (union_file = fdopen(fd, "w")) == NULL) {
-        if (fd >= 0)
-	    close(fd);
-	open_error(union_file_name);
-    }
-
-    text_file = fopen(text_file_name, "w");
-    if (text_file == 0)
-	open_error(text_file_name);
-
-    if (vflag)
-    {
-	verbose_file = fopen(verbose_file_name, "w");
-	if (verbose_file == 0)
-	    open_error(verbose_file_name);
-    }
-
-    if (dflag)
-    {
-	defines_file = fopen(defines_file_name, "w");
-	if (defines_file == 0)
-	    open_error(defines_file_name);
-	union_file = fopen(union_file_name, "w");
-	if (union_file ==  0)
-	    open_error(union_file_name);
-    }
-
-    output_file = fopen(output_file_name, "w");
-    if (output_file == 0)
-	open_error(output_file_name);
-
-    if (rflag)
-    {
-	code_file = fopen(code_file_name, "w");
-	if (code_file == 0)
-	    open_error(code_file_name);
-    }
-    else
-	code_file = output_file;
-}
-
-
-int
-main(int argc, char *argv[])
-{
-    set_signals();
-    getargs(argc, argv);
-    open_files();
-    reader();
-    lr0();
-    lalr();
-    make_parser();
-    verbose();
-    output();
-    done(0);
-    /*NOTREACHED*/
-    return (0);
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/mkpar.c
--- a/head/usr.bin/yacc/mkpar.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,404 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)mkpar.c	5.3 (Berkeley) 1/20/91";
-#endif
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdlib.h>
-#include "defs.h"
-
-action **parser;
-int SRexpect;
-int SRtotal;
-int RRtotal;
-short *SRconflicts;
-short *RRconflicts;
-short *defred;
-short *rules_used;
-short nunused;
-short final_state;
-
-static int SRcount;
-static int RRcount;
-
-static action *add_reduce(action *, int, int);
-static action *add_reductions(int, action *);
-static void defreds(void);
-static void find_final_state(void);
-static void free_action_row(action *);
-static action *get_shifts(int);
-static action *parse_actions(int);
-static void remove_conflicts(void);
-static int sole_reduction(int);
-static void total_conflicts(void);
-static void unused_rules(void);
-
-
-void
-make_parser(void)
-{
-    int i;
-
-    parser = NEW2(nstates, action *);
-    for (i = 0; i < nstates; i++)
-	parser[i] = parse_actions(i);
-
-    find_final_state();
-    remove_conflicts();
-    unused_rules();
-    if (SRtotal + RRtotal > 0) total_conflicts();
-    defreds();
-}
-
-
-static action *
-parse_actions(int stateno)
-{
-    action *actions;
-
-    actions = get_shifts(stateno);
-    actions = add_reductions(stateno, actions);
-    return (actions);
-}
-
-
-static action *
-get_shifts(int stateno)
-{
-    action *actions, *temp;
-    shifts *sp;
-    short *tostate;
-    int i, k;
-    int symbol;
-
-    actions = 0;
-    sp = shift_table[stateno];
-    if (sp)
-    {
-	tostate = sp->shift;
-	for (i = sp->nshifts - 1; i >= 0; i--)
-	{
-	    k = tostate[i];
-	    symbol = accessing_symbol[k];
-	    if (ISTOKEN(symbol))
-	    {
-		temp = NEW(action);
-		temp->next = actions;
-		temp->symbol = symbol;
-		temp->number = k;
-		temp->prec = symbol_prec[symbol];
-		temp->action_code = SHIFT;
-		temp->assoc = symbol_assoc[symbol];
-		actions = temp;
-	    }
-	}
-    }
-    return (actions);
-}
-
-static action *
-add_reductions(int stateno, action *actions)
-{
-    int i, j, m, n;
-    int ruleno, tokensetsize;
-    unsigned *rowp;
-
-    tokensetsize = WORDSIZE(ntokens);
-    m = lookaheads[stateno];
-    n = lookaheads[stateno + 1];
-    for (i = m; i < n; i++)
-    {
-	ruleno = LAruleno[i];
-	rowp = LA + i * tokensetsize;
-	for (j = ntokens - 1; j >= 0; j--)
-	{
-	    if (BIT(rowp, j))
-		actions = add_reduce(actions, ruleno, j);
-	}
-    }
-    return (actions);
-}
-
-
-static action *
-add_reduce(action *actions, int ruleno, int symbol)
-{
-    action *temp, *prev, *next;
-
-    prev = 0;
-    for (next = actions; next && next->symbol < symbol; next = next->next)
-	prev = next;
-
-    while (next && next->symbol == symbol && next->action_code == SHIFT)
-    {
-	prev = next;
-	next = next->next;
-    }
-
-    while (next && next->symbol == symbol &&
-	    next->action_code == REDUCE && next->number < ruleno)
-    {
-	prev = next;
-	next = next->next;
-    }
-
-    temp = NEW(action);
-    temp->next = next;
-    temp->symbol = symbol;
-    temp->number = ruleno;
-    temp->prec = rprec[ruleno];
-    temp->action_code = REDUCE;
-    temp->assoc = rassoc[ruleno];
-
-    if (prev)
-	prev->next = temp;
-    else
-	actions = temp;
-
-    return (actions);
-}
-
-
-static void
-find_final_state(void)
-{
-    int goal, i;
-    short *tostate;
-    shifts *p;
-
-    p = shift_table[0];
-    tostate = p->shift;
-    goal = ritem[1];
-    for (i = p->nshifts - 1; i >= 0; --i)
-    {
-	final_state = tostate[i];
-	if (accessing_symbol[final_state] == goal) break;
-    }
-}
-
-
-static void
-unused_rules(void)
-{
-    int i;
-    action *p;
-
-    rules_used = malloc(nrules*sizeof(short));
-    if (rules_used == 0) no_space();
-
-    for (i = 0; i < nrules; ++i)
-	rules_used[i] = 0;
-
-    for (i = 0; i < nstates; ++i)
-    {
-	for (p = parser[i]; p; p = p->next)
-	{
-	    if (p->action_code == REDUCE && p->suppressed == 0)
-		rules_used[p->number] = 1;
-	}
-    }
-
-    nunused = 0;
-    for (i = 3; i < nrules; ++i)
-	if (!rules_used[i]) ++nunused;
-
-    if (nunused) {
-	if (nunused == 1)
-	    warnx("1 rule never reduced");
-	else
-	    warnx("%d rules never reduced", nunused);
-    }
-}
-
-
-static void
-remove_conflicts(void)
-{
-    int i;
-    int symbol;
-    action *p, *pref;
-
-    pref = NULL;
-    SRtotal = 0;
-    RRtotal = 0;
-    SRconflicts = NEW2(nstates, short);
-    RRconflicts = NEW2(nstates, short);
-    for (i = 0; i < nstates; i++)
-    {
-	SRcount = 0;
-	RRcount = 0;
-	symbol = -1;
-	for (p = parser[i]; p; p = p->next)
-	{
-	    if (p->symbol != symbol)
-	    {
-		pref = p;
-		symbol = p->symbol;
-	    }
-	    else if (i == final_state && symbol == 0)
-	    {
-		SRcount++;
-		p->suppressed = 1;
-	    }
-	    else if (pref->action_code == SHIFT)
-	    {
-		if (pref->prec > 0 && p->prec > 0)
-		{
-		    if (pref->prec < p->prec)
-		    {
-			pref->suppressed = 2;
-			pref = p;
-		    }
-		    else if (pref->prec > p->prec)
-		    {
-			p->suppressed = 2;
-		    }
-		    else if (pref->assoc == LEFT)
-		    {
-			pref->suppressed = 2;
-			pref = p;
-		    }
-		    else if (pref->assoc == RIGHT)
-		    {
-			p->suppressed = 2;
-		    }
-		    else
-		    {
-			pref->suppressed = 2;
-			p->suppressed = 2;
-		    }
-		}
-		else
-		{
-		    SRcount++;
-		    p->suppressed = 1;
-		}
-	    }
-	    else
-	    {
-		RRcount++;
-		p->suppressed = 1;
-	    }
-	}
-	SRtotal += SRcount;
-	RRtotal += RRcount;
-	SRconflicts[i] = SRcount;
-	RRconflicts[i] = RRcount;
-    }
-}
-
-
-static void
-total_conflicts(void)
-{
-    /* Warn if s/r != expect or if any r/r */
-    if ((SRtotal != SRexpect) || RRtotal)
-    {
-	    if (SRtotal == 1)
-	    warnx("1 shift/reduce conflict");
-	    else if (SRtotal > 1)
-	    warnx("%d shift/reduce conflicts", SRtotal);
-    }
-
-    if (RRtotal == 1)
-	warnx("1 reduce/reduce conflict");
-    else if (RRtotal > 1)
-	warnx("%d reduce/reduce conflicts", RRtotal);
-}
-
-
-static int
-sole_reduction(int stateno)
-{
-    int count, ruleno;
-    action *p;
-
-    count = 0;
-    ruleno = 0;
-    for (p = parser[stateno]; p; p = p->next)
-    {
-	if (p->action_code == SHIFT && p->suppressed == 0)
-	    return (0);
-	else if (p->action_code == REDUCE && p->suppressed == 0)
-	{
-	    if (ruleno > 0 && p->number != ruleno)
-		return (0);
-	    if (p->symbol != 1)
-		++count;
-	    ruleno = p->number;
-	}
-    }
-
-    if (count == 0)
-	return (0);
-    return (ruleno);
-}
-
-
-static void
-defreds(void)
-{
-    int i;
-
-    defred = NEW2(nstates, short);
-    for (i = 0; i < nstates; i++)
-	defred[i] = sole_reduction(i);
-}
-
-static void
-free_action_row(action *p)
-{
-  action *q;
-
-  while (p)
-    {
-      q = p->next;
-      free(p);
-      p = q;
-    }
-}
-
-void
-free_parser(void)
-{
-  int i;
-
-  for (i = 0; i < nstates; i++)
-    free_action_row(parser[i]);
-
-  free(parser);
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/output.c
--- a/head/usr.bin/yacc/output.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1342 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)output.c	5.7 (Berkeley) 5/24/93";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include "defs.h"
-
-static int nvectors;
-static int nentries;
-static short **froms;
-static short **tos;
-static short *tally;
-static short *width;
-static short *state_count;
-static short *order;
-static short *base;
-static short *pos;
-static int maxtable;
-static short *table;
-static short *check;
-static int lowzero;
-static int high;
-
-static int default_goto(int);
-static void free_itemsets(void);
-static void free_reductions(void);
-static void free_shifts(void);
-static void goto_actions(void);
-static int is_C_identifier(char *);
-static int matching_vector(int);
-static void output_actions(void);
-static void output_base(void);
-static void output_check(void);
-static void output_debug(void);
-static void output_defines(void);
-static void output_prefix(void);
-static void output_rule_data(void);
-static void output_semantic_actions(void);
-static void output_stored_text(void);
-static void output_stype(void);
-static void output_table(void);
-static void output_trailing_text(void);
-static void output_yydefred(void);
-static void pack_table(void);
-static int pack_vector(int);
-static void save_column(int, int);
-static void sort_actions(void);
-static void token_actions(void);
-static int increase_maxtable(int);
-
-static const char line_format[] = "#line %d \"%s\"\n";
-
-
-void
-output(void)
-{
-    free_itemsets();
-    free_shifts();
-    free_reductions();
-    output_prefix();
-    output_stored_text();
-    output_defines();
-    output_rule_data();
-    output_yydefred();
-    output_actions();
-    free_parser();
-    output_debug();
-    output_stype();
-    if (rflag) write_section(tables);
-    write_section(header);
-    output_trailing_text();
-    write_section(body);
-    output_semantic_actions();
-    write_section(trailer);
-}
-
-
-static void
-output_prefix(void)
-{
-    if (symbol_prefix == NULL)
-	symbol_prefix = "yy";
-    else
-    {
-	++outline;
-	fprintf(code_file, "#define yyparse %sparse\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylex %slex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyerror %serror\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yychar %schar\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyval %sval\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylval %slval\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yydebug %sdebug\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yynerrs %snerrs\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyerrflag %serrflag\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyss %sss\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyssp %sssp\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyvs %svs\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyvsp %svsp\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylhs %slhs\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yylen %slen\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yydefred %sdefred\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yydgoto %sdgoto\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yysindex %ssindex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyrindex %srindex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yygindex %sgindex\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yytable %stable\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yycheck %scheck\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyname %sname\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yyrule %srule\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yysslim %ssslim\n", symbol_prefix);
-	++outline;
-	fprintf(code_file, "#define yystacksize %sstacksize\n", symbol_prefix);
-    }
-    ++outline;
-    fprintf(code_file, "#define YYPREFIX \"%s\"\n", symbol_prefix);
-}
-
-
-static void
-output_rule_data(void)
-{
-    int i;
-    int j;
-
-
-    fprintf(output_file, "const short %slhs[] = {%42d,", symbol_prefix,
-	    symbol_value[start_symbol]);
-
-    j = 10;
-    for (i = 3; i < nrules; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-        else
-	    ++j;
-
-        fprintf(output_file, "%5d,", symbol_value[rlhs[i]]);
-    }
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-
-    fprintf(output_file, "const short %slen[] = {%42d,", symbol_prefix, 2);
-
-    j = 10;
-    for (i = 3; i < nrules; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	  j++;
-
-        fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1);
-    }
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-}
-
-
-static void
-output_yydefred(void)
-{
-    int i, j;
-
-    fprintf(output_file, "const short %sdefred[] = {%39d,", symbol_prefix,
-	    (defred[0] ? defred[0] - 2 : 0));
-
-    j = 10;
-    for (i = 1; i < nstates; i++)
-    {
-	if (j < 10)
-	    ++j;
-	else
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-
-	fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0));
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-}
-
-
-static void
-output_actions(void)
-{
-    nvectors = 2*nstates + nvars;
-
-    froms = NEW2(nvectors, short *);
-    tos = NEW2(nvectors, short *);
-    tally = NEW2(nvectors, short);
-    width = NEW2(nvectors, short);
-
-    token_actions();
-    free(lookaheads);
-    free(LA);
-    free(LAruleno);
-    free(accessing_symbol);
-
-    goto_actions();
-    free(goto_map + ntokens);
-    free(from_state);
-    free(to_state);
-
-    sort_actions();
-    pack_table();
-    output_base();
-    output_table();
-    output_check();
-}
-
-
-static void
-token_actions(void)
-{
-    int i, j;
-    int shiftcount, reducecount;
-    int max, min;
-    short *actionrow, *r, *s;
-    action *p;
-
-    actionrow = NEW2(2*ntokens, short);
-    for (i = 0; i < nstates; ++i)
-    {
-	if (parser[i])
-	{
-	    for (j = 0; j < 2*ntokens; ++j)
-	    actionrow[j] = 0;
-
-	    shiftcount = 0;
-	    reducecount = 0;
-	    for (p = parser[i]; p; p = p->next)
-	    {
-		if (p->suppressed == 0)
-		{
-		    if (p->action_code == SHIFT)
-		    {
-			++shiftcount;
-			actionrow[p->symbol] = p->number;
-		    }
-		    else if (p->action_code == REDUCE && p->number != defred[i])
-		    {
-			++reducecount;
-			actionrow[p->symbol + ntokens] = p->number;
-		    }
-		}
-	    }
-
-	    tally[i] = shiftcount;
-	    tally[nstates+i] = reducecount;
-	    width[i] = 0;
-	    width[nstates+i] = 0;
-	    if (shiftcount > 0)
-	    {
-		froms[i] = r = NEW2(shiftcount, short);
-		tos[i] = s = NEW2(shiftcount, short);
-		min = SHRT_MAX;
-		max = 0;
-		for (j = 0; j < ntokens; ++j)
-		{
-		    if (actionrow[j])
-		    {
-			if (min > symbol_value[j])
-			    min = symbol_value[j];
-			if (max < symbol_value[j])
-			    max = symbol_value[j];
-			*r++ = symbol_value[j];
-			*s++ = actionrow[j];
-		    }
-		}
-		width[i] = max - min + 1;
-	    }
-	    if (reducecount > 0)
-	    {
-		froms[nstates+i] = r = NEW2(reducecount, short);
-		tos[nstates+i] = s = NEW2(reducecount, short);
-		min = SHRT_MAX;
-		max = 0;
-		for (j = 0; j < ntokens; ++j)
-		{
-		    if (actionrow[ntokens+j])
-		    {
-			if (min > symbol_value[j])
-			    min = symbol_value[j];
-			if (max < symbol_value[j])
-			    max = symbol_value[j];
-			*r++ = symbol_value[j];
-			*s++ = actionrow[ntokens+j] - 2;
-		    }
-		}
-		width[nstates+i] = max - min + 1;
-	    }
-	}
-    }
-    free(actionrow);
-}
-
-static void
-goto_actions(void)
-{
-    int i, j, k;
-
-    state_count = NEW2(nstates, short);
-
-    k = default_goto(start_symbol + 1);
-    fprintf(output_file, "const short %sdgoto[] = {%40d,", symbol_prefix, k);
-    save_column(start_symbol + 1, k);
-
-    j = 10;
-    for (i = start_symbol + 2; i < nsyms; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	k = default_goto(i);
-	fprintf(output_file, "%5d,", k);
-	save_column(i, k);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    free(state_count);
-}
-
-static int
-default_goto(int symbol)
-{
-    int i;
-    int m;
-    int n;
-    int default_state;
-    int max;
-
-    m = goto_map[symbol];
-    n = goto_map[symbol + 1];
-
-    if (m == n) return (0);
-
-    for (i = 0; i < nstates; i++)
-	state_count[i] = 0;
-
-    for (i = m; i < n; i++)
-	state_count[to_state[i]]++;
-
-    max = 0;
-    default_state = 0;
-    for (i = 0; i < nstates; i++)
-    {
-	if (state_count[i] > max)
-	{
-	    max = state_count[i];
-	    default_state = i;
-	}
-    }
-
-    return (default_state);
-}
-
-
-
-static void
-save_column(int symbol, int default_state)
-{
-    int i;
-    int m;
-    int n;
-    short *sp;
-    short *sp1;
-    short *sp2;
-    int count;
-    int symno;
-
-    m = goto_map[symbol];
-    n = goto_map[symbol + 1];
-
-    count = 0;
-    for (i = m; i < n; i++)
-    {
-	if (to_state[i] != default_state)
-	    ++count;
-    }
-    if (count == 0) return;
-
-    symno = symbol_value[symbol] + 2*nstates;
-
-    froms[symno] = sp1 = sp = NEW2(count, short);
-    tos[symno] = sp2 = NEW2(count, short);
-
-    for (i = m; i < n; i++)
-    {
-	if (to_state[i] != default_state)
-	{
-	    *sp1++ = from_state[i];
-	    *sp2++ = to_state[i];
-	}
-    }
-
-    tally[symno] = count;
-    width[symno] = sp1[-1] - sp[0] + 1;
-}
-
-static void
-sort_actions(void)
-{
-  int i;
-  int j;
-  int k;
-  int t;
-  int w;
-
-  order = NEW2(nvectors, short);
-  nentries = 0;
-
-  for (i = 0; i < nvectors; i++)
-    {
-      if (tally[i] > 0)
-	{
-	  t = tally[i];
-	  w = width[i];
-	  j = nentries - 1;
-
-	  while (j >= 0 && (width[order[j]] < w))
-	    j--;
-
-	  while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
-	    j--;
-
-	  for (k = nentries - 1; k > j; k--)
-	    order[k + 1] = order[k];
-
-	  order[j + 1] = i;
-	  nentries++;
-	}
-    }
-}
-
-
-static void
-pack_table(void)
-{
-    int i;
-    int place;
-    int state;
-
-    base = NEW2(nvectors, short);
-    pos = NEW2(nentries, short);
-
-    maxtable = 10000;
-    table = NEW2(maxtable, short);
-    check = NEW2(maxtable, short);
-
-    lowzero = 0;
-    high = 0;
-
-    for (i = 0; i < maxtable; i++)
-	check[i] = -1;
-
-    for (i = 0; i < nentries; i++)
-    {
-	state = matching_vector(i);
-
-	if (state < 0)
-	    place = pack_vector(i);
-	else
-	    place = base[state];
-
-	pos[i] = place;
-	base[order[i]] = place;
-    }
-
-    for (i = 0; i < nvectors; i++)
-    {
-	if (froms[i])
-	    free(froms[i]);
-	if (tos[i])
-	    free(tos[i]);
-    }
-
-    free(froms);
-    free(tos);
-    free(pos);
-}
-
-
-/*  The function matching_vector determines if the vector specified by	*/
-/*  the input parameter matches a previously considered	vector.  The	*/
-/*  test at the start of the function checks if the vector represents	*/
-/*  a row of shifts over terminal symbols or a row of reductions, or a	*/
-/*  column of shifts over a nonterminal symbol.  Berkeley Yacc does not	*/
-/*  check if a column of shifts over a nonterminal symbols matches a	*/
-/*  previously considered vector.  Because of the nature of LR parsing	*/
-/*  tables, no two columns can match.  Therefore, the only possible	*/
-/*  match would be between a row and a column.  Such matches are	*/
-/*  unlikely.  Therefore, to save time, no attempt is made to see if a	*/
-/*  column matches a previously considered vector.			*/
-/*									*/
-/*  Matching_vector is poorly designed.  The test could easily be made	*/
-/*  faster.  Also, it depends on the vectors being in a specific	*/
-/*  order.								*/
-
-static int
-matching_vector(int vector)
-{
-    int i;
-    int j;
-    int k;
-    int t;
-    int w;
-    int match;
-    int prev;
-
-    i = order[vector];
-    if (i >= 2*nstates)
-	return (-1);
-
-    t = tally[i];
-    w = width[i];
-
-    for (prev = vector - 1; prev >= 0; prev--)
-    {
-	j = order[prev];
-	if (width[j] != w || tally[j] != t)
-	    return (-1);
-
-	match = 1;
-	for (k = 0; match && k < t; k++)
-	{
-	    if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
-		match = 0;
-	}
-
-	if (match)
-	    return (j);
-    }
-
-    return (-1);
-}
-
-
-
-static int
-pack_vector(int vector)
-{
-    int i, j, k;
-    int t;
-    int loc;
-    int ok;
-    short *from;
-    short *to;
-
-    loc = 0;
-    i = order[vector];
-    t = tally[i];
-    assert(t);
-
-    from = froms[i];
-    to = tos[i];
-
-    j = lowzero - from[0];
-    for (k = 1; k < t; ++k)
-	if (lowzero - from[k] > j)
-	    j = lowzero - from[k];
-    for (;; ++j)
-    {
-	if (j == 0)
-	    continue;
-	ok = 1;
-	for (k = 0; ok && k < t; k++)
-	{
-	    loc = j + from[k];
-	    if (loc >= maxtable)
-	    {
-		if (loc >= MAXTABLE)
-		    fatal("maximum table size exceeded");
-		maxtable = increase_maxtable(loc);
-	    }
-
-	    if (check[loc] != -1)
-		ok = 0;
-	}
-	for (k = 0; ok && k < vector; k++)
-	{
-	    if (pos[k] == j)
-		ok = 0;
-	}
-	if (ok)
-	{
-	    for (k = 0; k < t; k++)
-	    {
-		loc = j + from[k];
-		table[loc] = to[k];
-		check[loc] = from[k];
-		if (loc > high) high = loc;
-	    }
-
-	    while (check[lowzero] != -1)
-	    {
-		if (lowzero >= maxtable)
-		{
-		    if (lowzero >= MAXTABLE)
-		    {
-		      fatal("maximum table size exceeded in check\n");
-		    }
-
-		    maxtable = increase_maxtable(loc);
-		}
-
-		++lowzero;
-	    }
-
-	    return (j);
-	}
-    }
-}
-
-
-
-static void
-output_base(void)
-{
-    int i, j;
-
-    fprintf(output_file, "const short %ssindex[] = {%39d,", symbol_prefix,
-	    base[0]);
-
-    j = 10;
-    for (i = 1; i < nstates; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", base[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\nconst short %srindex[] = {%39d,", symbol_prefix,
-	    base[nstates]);
-
-    j = 10;
-    for (i = nstates + 1; i < 2*nstates; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", base[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\nconst short %sgindex[] = {%39d,", symbol_prefix,
-	    base[2*nstates]);
-
-    j = 10;
-    for (i = 2*nstates + 1; i < nvectors - 1; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", base[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    free(base);
-}
-
-
-
-static void
-output_table(void)
-{
-    int i;
-    int j;
-
-    ++outline;
-    fprintf(code_file, "#define YYTABLESIZE %d\n", high);
-    fprintf(output_file, "const short %stable[] = {%40d,", symbol_prefix,
-	    table[0]);
-
-    j = 10;
-    for (i = 1; i <= high; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", table[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    free(table);
-}
-
-
-
-static void
-output_check(void)
-{
-    int i;
-    int j;
-
-    fprintf(output_file, "const short %scheck[] = {%40d,", symbol_prefix,
-	    check[0]);
-
-    j = 10;
-    for (i = 1; i <= high; i++)
-    {
-	if (j >= 10)
-	{
-	    if (!rflag) ++outline;
-	    putc('\n', output_file);
-	    j = 1;
-	}
-	else
-	    ++j;
-
-	fprintf(output_file, "%5d,", check[i]);
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    free(check);
-}
-
-
-static int
-is_C_identifier(char *name)
-{
-    char *s;
-    int c;
-
-    s = name;
-    c = *s;
-    if (c == '"')
-    {
-	c = *++s;
-	if (!isalpha(c) && c != '_' && c != '$')
-	    return (0);
-	while ((c = *++s) != '"')
-	{
-	    if (!isalnum(c) && c != '_' && c != '$')
-		return (0);
-	}
-	return (1);
-    }
-
-    if (!isalpha(c) && c != '_' && c != '$')
-	return (0);
-    while ((c = *++s))
-    {
-	if (!isalnum(c) && c != '_' && c != '$')
-	    return (0);
-    }
-    return (1);
-}
-
-
-static void
-output_defines(void)
-{
-    int c, i;
-    char *s;
-
-    ++outline;
-    fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]);
-
-    if(dflag)
-    {
-        fprintf(defines_file, "#ifndef YYERRCODE\n");
-        fprintf(defines_file, "#define YYERRCODE %d\n", symbol_value[1]);
-        fprintf(defines_file, "#endif\n\n");
-    }
-    for (i = 2; i < ntokens; ++i)
-    {
-	s = symbol_name[i];
-	if (is_C_identifier(s))
-	{
-	    fprintf(code_file, "#define ");
-	    if (dflag) fprintf(defines_file, "#define ");
-	    c = *s;
-	    if (c == '"')
-	    {
-		while ((c = *++s) != '"')
-		{
-		    putc(c, code_file);
-		    if (dflag) putc(c, defines_file);
-		}
-	    }
-	    else
-	    {
-		do
-		{
-		    putc(c, code_file);
-		    if (dflag) putc(c, defines_file);
-		}
-		while ((c = *++s));
-	    }
-	    ++outline;
-	    fprintf(code_file, " %d\n", symbol_value[i]);
-	    if (dflag) fprintf(defines_file, " %d\n", symbol_value[i]);
-	}
-    }
-
-    if (dflag && unionized)
-    {
-	fclose(union_file);
-	union_file = fopen(union_file_name, "r");
-	if (union_file == NULL) open_error(union_file_name);
-	while ((c = getc(union_file)) != EOF)
-	    putc(c, defines_file);
-	fprintf(defines_file, " YYSTYPE;\nextern YYSTYPE %slval;\n",
-		symbol_prefix);
-    }
-}
-
-
-static void
-output_stored_text(void)
-{
-    int c;
-    FILE *in, *out;
-
-    fclose(text_file);
-    text_file = fopen(text_file_name, "r");
-    if (text_file == NULL)
-	open_error(text_file_name);
-    in = text_file;
-    if ((c = getc(in)) == EOF)
-	return;
-    out = code_file;
-    if (c ==  '\n')
-	++outline;
-    putc(c, out);
-    while ((c = getc(in)) != EOF)
-    {
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-    }
-    if (!lflag)
-	fprintf(out, line_format, ++outline + 1, code_file_name);
-}
-
-
-static void
-output_debug(void)
-{
-    int i, j, k, max;
-    char **symnam, *s;
-    static char eof[] = "end-of-file";
-
-    ++outline;
-    fprintf(code_file, "#define YYFINAL %d\n", final_state);
-    outline += 3;
-    fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
-	    tflag);
-    if (rflag)
-	fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
-		tflag);
-
-    max = 0;
-    for (i = 2; i < ntokens; ++i)
-	if (symbol_value[i] > max)
-	    max = symbol_value[i];
-    ++outline;
-    fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
-
-    symnam = malloc((max+1)*sizeof(char *));
-    if (symnam == 0) no_space();
-
-    /* Note that it is  not necessary to initialize the element		*/
-    /* symnam[max].							*/
-    for (i = 0; i < max; ++i)
-	symnam[i] = 0;
-    for (i = ntokens - 1; i >= 2; --i)
-	symnam[symbol_value[i]] = symbol_name[i];
-    symnam[0] = eof;
-
-    if (!rflag) ++outline;
-    fprintf(output_file, "#if YYDEBUG\n");
-    fprintf(output_file, "const char * const %sname[] = {", symbol_prefix);
-    j = 80;
-    for (i = 0; i <= max; ++i)
-    {
-	if ((s = symnam[i]))
-	{
-	    if (s[0] == '"')
-	    {
-		k = 7;
-		while (*++s != '"')
-		{
-		    ++k;
-		    if (*s == '\\')
-		    {
-			k += 2;
-			if (*++s == '\\')
-			    ++k;
-		    }
-		}
-		j += k;
-		if (j > 80)
-		{
-		    if (!rflag) ++outline;
-		    putc('\n', output_file);
-		    j = k;
-		}
-		fprintf(output_file, "\"\\\"");
-		s = symnam[i];
-		while (*++s != '"')
-		{
-		    if (*s == '\\')
-		    {
-			fprintf(output_file, "\\\\");
-			if (*++s == '\\')
-			    fprintf(output_file, "\\\\");
-			else
-			    putc(*s, output_file);
-		    }
-		    else
-			putc(*s, output_file);
-		}
-		fprintf(output_file, "\\\"\",");
-	    }
-	    else if (s[0] == '\'')
-	    {
-		if (s[1] == '"')
-		{
-		    j += 7;
-		    if (j > 80)
-		    {
-			if (!rflag) ++outline;
-			putc('\n', output_file);
-			j = 7;
-		    }
-		    fprintf(output_file, "\"'\\\"'\",");
-		}
-		else
-		{
-		    k = 5;
-		    while (*++s != '\'')
-		    {
-			++k;
-			if (*s == '\\')
-			{
-			    k += 2;
-			    if (*++s == '\\')
-				++k;
-			}
-		    }
-		    j += k;
-		    if (j > 80)
-		    {
-			if (!rflag) ++outline;
-			putc('\n', output_file);
-			j = k;
-		    }
-		    fprintf(output_file, "\"'");
-		    s = symnam[i];
-		    while (*++s != '\'')
-		    {
-			if (*s == '\\')
-			{
-			    fprintf(output_file, "\\\\");
-			    if (*++s == '\\')
-				fprintf(output_file, "\\\\");
-			    else
-				putc(*s, output_file);
-			}
-			else
-			    putc(*s, output_file);
-		    }
-		    fprintf(output_file, "'\",");
-		}
-	    }
-	    else
-	    {
-		k = strlen(s) + 3;
-		j += k;
-		if (j > 80)
-		{
-		    if (!rflag) ++outline;
-		    putc('\n', output_file);
-		    j = k;
-		}
-		putc('"', output_file);
-		do { putc(*s, output_file); } while (*++s);
-		fprintf(output_file, "\",");
-	    }
-	}
-	else
-	{
-	    j += 2;
-	    if (j > 80)
-	    {
-		if (!rflag) ++outline;
-		putc('\n', output_file);
-		j = 2;
-	    }
-	    fprintf(output_file, "0,");
-	}
-    }
-    if (!rflag) outline += 2;
-    fprintf(output_file, "\n};\n");
-    free(symnam);
-
-    if (!rflag) ++outline;
-    fprintf(output_file, "const char * const %srule[] = {\n", symbol_prefix);
-    for (i = 2; i < nrules; ++i)
-    {
-	fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
-	for (j = rrhs[i]; ritem[j] > 0; ++j)
-	{
-	    s = symbol_name[ritem[j]];
-	    if (s[0] == '"')
-	    {
-		fprintf(output_file, " \\\"");
-		while (*++s != '"')
-		{
-		    if (*s == '\\')
-		    {
-			if (s[1] == '\\')
-			    fprintf(output_file, "\\\\\\\\");
-			else
-			    fprintf(output_file, "\\\\%c", s[1]);
-			++s;
-		    }
-		    else
-			putc(*s, output_file);
-		}
-		fprintf(output_file, "\\\"");
-	    }
-	    else if (s[0] == '\'')
-	    {
-		if (s[1] == '"')
-		    fprintf(output_file, " '\\\"'");
-		else if (s[1] == '\\')
-		{
-		    if (s[2] == '\\')
-			fprintf(output_file, " '\\\\\\\\");
-		    else
-			fprintf(output_file, " '\\\\%c", s[2]);
-		    s += 2;
-		    while (*++s != '\'')
-			putc(*s, output_file);
-		    putc('\'', output_file);
-		}
-		else
-		    fprintf(output_file, " '%c'", s[1]);
-	    }
-	    else
-		fprintf(output_file, " %s", s);
-	}
-	if (!rflag) ++outline;
-	fprintf(output_file, "\",\n");
-    }
-
-    if (!rflag) outline += 2;
-    fprintf(output_file, "};\n#endif\n");
-}
-
-
-static void
-output_stype(void)
-{
-    if (!unionized && ntags == 0)
-    {
-	outline += 3;
-	fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
-    }
-}
-
-
-static void
-output_trailing_text(void)
-{
-    int c, last;
-    FILE *in, *out;
-
-    if (line == 0)
-	return;
-
-    in = input_file;
-    out = code_file;
-    c = *cptr;
-    if (c == '\n')
-    {
-	++lineno;
-	if ((c = getc(in)) == EOF)
-	    return;
-	if (!lflag)
-	{
-	    ++outline;
-	    fprintf(out, line_format, lineno, input_file_name);
-	}
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-	last = c;
-    }
-    else
-    {
-	if (!lflag)
-	{
-	    ++outline;
-	    fprintf(out, line_format, lineno, input_file_name);
-	}
-	do { putc(c, out); } while ((c = *++cptr) != '\n');
-	++outline;
-	putc('\n', out);
-	last = '\n';
-    }
-
-    while ((c = getc(in)) != EOF)
-    {
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-	last = c;
-    }
-
-    if (last != '\n')
-    {
-	++outline;
-	putc('\n', out);
-    }
-    if (!lflag)
-	fprintf(out, line_format, ++outline + 1, code_file_name);
-}
-
-
-static void
-output_semantic_actions(void)
-{
-    int c, last;
-    FILE *out;
-
-    fclose(action_file);
-    action_file = fopen(action_file_name, "r");
-    if (action_file == NULL)
-	open_error(action_file_name);
-
-    if ((c = getc(action_file)) == EOF)
-	return;
-
-    out = code_file;
-    last = c;
-    if (c == '\n')
-	++outline;
-    putc(c, out);
-    while ((c = getc(action_file)) != EOF)
-    {
-	if (c == '\n')
-	    ++outline;
-	putc(c, out);
-	last = c;
-    }
-
-    if (last != '\n')
-    {
-	++outline;
-	putc('\n', out);
-    }
-
-    if (!lflag)
-	fprintf(out, line_format, ++outline + 1, code_file_name);
-}
-
-
-static void
-free_itemsets(void)
-{
-    core *cp, *next;
-
-    free(state_table);
-    for (cp = first_state; cp; cp = next)
-    {
-	next = cp->next;
-	free(cp);
-    }
-}
-
-
-static void
-free_shifts(void)
-{
-    shifts *sp, *next;
-
-    free(shift_table);
-    for (sp = first_shift; sp; sp = next)
-    {
-	next = sp->next;
-	free(sp);
-    }
-}
-
-
-
-static void
-free_reductions(void)
-{
-    reductions *rp, *next;
-
-    free(reduction_table);
-    for (rp = first_reduction; rp; rp = next)
-    {
-	next = rp->next;
-	free(rp);
-    }
-}
-
-/*
- * increase_maxtable
- *
- * inputs	- loc location in table
- * output	- size increased to
- * side effects	- table is increase by at least 200 short words
- */
-
-static int
-increase_maxtable(int loc)
-{
-    int newmax;
-    int l;
-
-    newmax = maxtable;
-
-    do { newmax += 200; } while (newmax <= loc);
-    table = realloc(table, newmax*sizeof(short));
-	if (table == 0) no_space();
-	check = realloc(check, newmax*sizeof(short));
-	if (check == 0) no_space();
-	for (l  = maxtable; l < newmax; ++l)
-	{
-	    table[l] = 0;
-	    check[l] = -1;
-	}
-
-    return(newmax);
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/reader.c
--- a/head/usr.bin/yacc/reader.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1924 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)reader.c	5.7 (Berkeley) 1/20/91";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/yacc/reader.c 228992 2011-12-30 11:02:40Z uqs $");
-
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include "defs.h"
-
-/*  The line size must be a positive integer.  One hundred was chosen	*/
-/*  because few lines in Yacc input grammars exceed 100 characters.	*/
-/*  Note that if a line exceeds LINESIZE characters, the line buffer	*/
-/*  will be expanded to accommodate it.					*/
-
-#define LINESIZE 100
-
-char *cache;
-int cinc, cache_size;
-
-int ntags, tagmax;
-char **tag_table;
-
-char saw_eof, unionized;
-char *cptr, *line;
-int linesize;
-
-bucket *goal;
-int prec;
-int gensym;
-char last_was_action;
-
-int maxitems;
-bucket **pitem;
-
-int maxrules;
-bucket **plhs;
-
-int name_pool_size;
-char *name_pool;
-
-static const char line_format[] = "#line %d \"%s\"\n";
-
-static void add_symbol(void);
-static void advance_to_start(void);
-static void cachec(int);
-static void check_symbols(void);
-static void copy_action(void);
-static void copy_ident(void);
-static void copy_text(void);
-static void copy_union(void);
-static void declare_expect(int);
-static void declare_start(void);
-static void declare_tokens(int);
-static void declare_types(void);
-static char *dup_line(void);
-static void end_rule(void);
-static void expand_items(void);
-static void expand_rules(void);
-static void free_tags(void);
-static void get_line(void);
-static bucket *get_literal(void);
-static bucket *get_name(void);
-static int get_number(void);
-static char *get_tag(void);
-static int hexval(int);
-static void initialize_grammar(void);
-static void insert_empty_rule(void);
-static int is_reserved(char *);
-static int keyword(void);
-static int mark_symbol(void);
-static int nextc(void);
-static void pack_grammar(void);
-static void pack_names(void);
-static void pack_symbols(void);
-static void print_grammar(void);
-static void read_declarations(void);
-static void read_grammar(void);
-static void skip_comment(void);
-static void start_rule(bucket *, int);
-
-static void
-cachec(int c)
-{
-    assert(cinc >= 0);
-    if (cinc >= cache_size)
-    {
-	cache_size += 256;
-	cache = realloc(cache, cache_size);
-	if (cache == 0) no_space();
-    }
-    cache[cinc] = c;
-    ++cinc;
-}
-
-
-static void
-get_line(void)
-{
-    FILE *f = input_file;
-    int c;
-    int i;
-
-    if (saw_eof || (c = getc(f)) == EOF)
-    {
-	if (line) { free(line); line = 0; }
-	cptr = 0;
-	saw_eof = 1;
-	return;
-    }
-
-    if (line == 0 || linesize != (LINESIZE + 1))
-    {
-	if (line) free(line);
-	linesize = LINESIZE + 1;
-	line = malloc(linesize);
-	if (line == 0) no_space();
-    }
-
-    i = 0;
-    ++lineno;
-    for (;;)
-    {
-	line[i]  =  c;
-	if (c == '\n') { cptr = line; return; }
-	if (++i >= linesize)
-	{
-	    linesize += LINESIZE;
-	    line = realloc(line, linesize);
-	    if (line ==  0) no_space();
-	}
-	c = getc(f);
-	if (c ==  EOF)
-	{
-	    line[i] = '\n';
-	    saw_eof = 1;
-	    cptr = line;
-	    return;
-	}
-    }
-}
-
-
-static char *
-dup_line(void)
-{
-    char *p, *s, *t;
-
-    if (line == 0) return (0);
-    s = line;
-    while (*s != '\n') ++s;
-    p = malloc(s - line + 1);
-    if (p == 0) no_space();
-
-    s = line;
-    t = p;
-    while ((*t++ = *s++) != '\n') continue;
-    return (p);
-}
-
-
-static void
-skip_comment(void)
-{
-    char *s;
-
-    int st_lineno = lineno;
-    char *st_line = dup_line();
-    char *st_cptr = st_line + (cptr - line);
-
-    s = cptr + 2;
-    for (;;)
-    {
-	if (*s == '*' && s[1] == '/')
-	{
-	    cptr = s + 2;
-	    free(st_line);
-	    return;
-	}
-	if (*s == '\n')
-	{
-	    get_line();
-	    if (line == 0)
-		unterminated_comment(st_lineno, st_line, st_cptr);
-	    s = cptr;
-	}
-	else
-	    ++s;
-    }
-}
-
-
-static int
-nextc(void)
-{
-    char *s;
-
-    if (line == 0)
-    {
-	get_line();
-	if (line == 0)
-	    return (EOF);
-    }
-
-    s = cptr;
-    for (;;)
-    {
-	switch (*s)
-	{
-	case '\n':
-	    get_line();
-	    if (line == 0) return (EOF);
-	    s = cptr;
-	    break;
-
-	case ' ':
-	case '\t':
-	case '\f':
-	case '\r':
-	case '\v':
-	case ',':
-	case ';':
-	    ++s;
-	    break;
-
-	case '\\':
-	    cptr = s;
-	    return ('%');
-
-	case '/':
-	    if (s[1] == '*')
-	    {
-		cptr = s;
-		skip_comment();
-		s = cptr;
-		break;
-	    }
-	    else if (s[1] == '/')
-	    {
-		get_line();
-		if (line == 0) return (EOF);
-		s = cptr;
-		break;
-	    }
-	    /* FALLTHROUGH */
-
-	default:
-	    cptr = s;
-	    return (*s);
-	}
-    }
-}
-
-
-static int
-keyword(void)
-{
-    int c;
-    char *t_cptr = cptr;
-
-    c = *++cptr;
-    if (isalpha(c))
-    {
-	cinc = 0;
-	for (;;)
-	{
-	    if (isalpha(c))
-	    {
-		if (isupper(c)) c = tolower(c);
-		cachec(c);
-	    }
-	    else if (isdigit(c) || c == '_' || c == '.' || c == '$')
-		cachec(c);
-	    else
-		break;
-	    c = *++cptr;
-	}
-	cachec(NUL);
-
-	if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0)
-	    return (TOKEN);
-	if (strcmp(cache, "type") == 0)
-	    return (TYPE);
-	if (strcmp(cache, "left") == 0)
-	    return (LEFT);
-	if (strcmp(cache, "right") == 0)
-	    return (RIGHT);
-	if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0)
-	    return (NONASSOC);
-	if (strcmp(cache, "start") == 0)
-	    return (START);
-	if (strcmp(cache, "union") == 0)
-	    return (UNION);
-	if (strcmp(cache, "ident") == 0)
-	    return (IDENT);
-	if (strcmp(cache, "expect") == 0)
-	    return (EXPECT);
-    }
-    else
-    {
-	++cptr;
-	if (c == '{')
-	    return (TEXT);
-	if (c == '%' || c == '\\')
-	    return (MARK);
-	if (c == '<')
-	    return (LEFT);
-	if (c == '>')
-	    return (RIGHT);
-	if (c == '0')
-	    return (TOKEN);
-	if (c == '2')
-	    return (NONASSOC);
-    }
-    syntax_error(lineno, line, t_cptr);
-    /*NOTREACHED*/
-    return (0);
-}
-
-
-static void
-copy_ident(void)
-{
-    int c;
-    FILE *f = output_file;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != '"') syntax_error(lineno, line, cptr);
-    ++outline;
-    fprintf(f, "#ident \"");
-    for (;;)
-    {
-	c = *++cptr;
-	if (c == '\n')
-	{
-	    fprintf(f, "\"\n");
-	    return;
-	}
-	putc(c, f);
-	if (c == '"')
-	{
-	    putc('\n', f);
-	    ++cptr;
-	    return;
-	}
-    }
-}
-
-
-static void
-copy_text(void)
-{
-    int c;
-    int quote;
-    FILE *f = text_file;
-    int need_newline = 0;
-    int t_lineno = lineno;
-    char *t_line = dup_line();
-    char *t_cptr = t_line + (cptr - line - 2);
-
-    if (*cptr == '\n')
-    {
-	get_line();
-	if (line == 0)
-	    unterminated_text(t_lineno, t_line, t_cptr);
-    }
-    if (!lflag) fprintf(f, line_format, lineno, input_file_name);
-
-loop:
-    c = *cptr++;
-    switch (c)
-    {
-    case '\n':
-    next_line:
-	putc('\n', f);
-	need_newline = 0;
-	get_line();
-	if (line) goto loop;
-	unterminated_text(t_lineno, t_line, t_cptr);
-
-    case '\'':
-    case '"':
-	{
-	    int s_lineno = lineno;
-	    char *s_line = dup_line();
-	    char *s_cptr = s_line + (cptr - line - 1);
-
-	    quote = c;
-	    putc(c, f);
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == quote)
-		{
-		    need_newline = 1;
-		    free(s_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		    unterminated_string(s_lineno, s_line, s_cptr);
-		if (c == '\\')
-		{
-		    c = *cptr++;
-		    putc(c, f);
-		    if (c == '\n')
-		    {
-			get_line();
-			if (line == 0)
-			    unterminated_string(s_lineno, s_line, s_cptr);
-		    }
-		}
-	    }
-	}
-
-    case '/':
-	putc(c, f);
-	need_newline = 1;
-	c = *cptr;
-	if (c == '/')
-	{
-	    putc('*', f);
-	    while ((c = *++cptr) != '\n')
-	    {
-		if (c == '*' && cptr[1] == '/')
-		    fprintf(f, "* ");
-		else
-		    putc(c, f);
-	    }
-	    fprintf(f, "*/");
-	    goto next_line;
-	}
-	if (c == '*')
-	{
-	    int c_lineno = lineno;
-	    char *c_line = dup_line();
-	    char *c_cptr = c_line + (cptr - line - 1);
-
-	    putc('*', f);
-	    ++cptr;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == '*' && *cptr == '/')
-		{
-		    putc('/', f);
-		    ++cptr;
-		    free(c_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		{
-		    get_line();
-		    if (line == 0)
-			unterminated_comment(c_lineno, c_line, c_cptr);
-		}
-	    }
-	}
-	need_newline = 1;
-	goto loop;
-
-    case '%':
-    case '\\':
-	if (*cptr == '}')
-	{
-	    if (need_newline) putc('\n', f);
-	    ++cptr;
-	    free(t_line);
-	    return;
-	}
-	/* FALLTHROUGH */
-
-    default:
-	putc(c, f);
-	need_newline = 1;
-	goto loop;
-    }
-}
-
-
-static void
-copy_union(void)
-{
-    int c;
-    int quote;
-    int depth;
-    int u_lineno = lineno;
-    char *u_line = dup_line();
-    char *u_cptr = u_line + (cptr - line - 6);
-
-    if (unionized) over_unionized(cptr - 6);
-    unionized = 1;
-
-    if (!lflag)
-	fprintf(text_file, line_format, lineno, input_file_name);
-
-    fprintf(text_file, "typedef union");
-    if (dflag) fprintf(union_file, "typedef union");
-
-    depth = 0;
-loop:
-    c = *cptr++;
-    putc(c, text_file);
-    if (dflag) putc(c, union_file);
-    switch (c)
-    {
-    case '\n':
-    next_line:
-	get_line();
-	if (line == 0) unterminated_union(u_lineno, u_line, u_cptr);
-	goto loop;
-
-    case '{':
-	++depth;
-	goto loop;
-
-    case '}':
-	if (--depth == 0)
-	{
-	    fprintf(text_file, " YYSTYPE;\n");
-	    free(u_line);
-	    return;
-	}
-	goto loop;
-
-    case '\'':
-    case '"':
-	{
-	    int s_lineno = lineno;
-	    char *s_line = dup_line();
-	    char *s_cptr = s_line + (cptr - line - 1);
-
-	    quote = c;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, text_file);
-		if (dflag) putc(c, union_file);
-		if (c == quote)
-		{
-		    free(s_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		    unterminated_string(s_lineno, s_line, s_cptr);
-		if (c == '\\')
-		{
-		    c = *cptr++;
-		    putc(c, text_file);
-		    if (dflag) putc(c, union_file);
-		    if (c == '\n')
-		    {
-			get_line();
-			if (line == 0)
-			    unterminated_string(s_lineno, s_line, s_cptr);
-		    }
-		}
-	    }
-	}
-
-    case '/':
-	c = *cptr;
-	if (c == '/')
-	{
-	    putc('*', text_file);
-	    if (dflag) putc('*', union_file);
-	    while ((c = *++cptr) != '\n')
-	    {
-		if (c == '*' && cptr[1] == '/')
-		{
-		    fprintf(text_file, "* ");
-		    if (dflag) fprintf(union_file, "* ");
-		}
-		else
-		{
-		    putc(c, text_file);
-		    if (dflag) putc(c, union_file);
-		}
-	    }
-	    fprintf(text_file, "*/\n");
-	    if (dflag) fprintf(union_file, "*/\n");
-	    goto next_line;
-	}
-	if (c == '*')
-	{
-	    int c_lineno = lineno;
-	    char *c_line = dup_line();
-	    char *c_cptr = c_line + (cptr - line - 1);
-
-	    putc('*', text_file);
-	    if (dflag) putc('*', union_file);
-	    ++cptr;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, text_file);
-		if (dflag) putc(c, union_file);
-		if (c == '*' && *cptr == '/')
-		{
-		    putc('/', text_file);
-		    if (dflag) putc('/', union_file);
-		    ++cptr;
-		    free(c_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		{
-		    get_line();
-		    if (line == 0)
-			unterminated_comment(c_lineno, c_line, c_cptr);
-		}
-	    }
-	}
-	goto loop;
-
-    default:
-	goto loop;
-    }
-}
-
-
-static int
-hexval(int c)
-{
-    if (c >= '0' && c <= '9')
-	return (c - '0');
-    if (c >= 'A' && c <= 'F')
-	return (c - 'A' + 10);
-    if (c >= 'a' && c <= 'f')
-	return (c - 'a' + 10);
-    return (-1);
-}
-
-
-static bucket *
-get_literal(void)
-{
-    int c, quote;
-    int i;
-    int n;
-    char *s;
-    bucket *bp;
-    int s_lineno = lineno;
-    char *s_line = dup_line();
-    char *s_cptr = s_line + (cptr - line);
-
-    quote = *cptr++;
-    cinc = 0;
-    for (;;)
-    {
-	c = *cptr++;
-	if (c == quote) break;
-	if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr);
-	if (c == '\\')
-	{
-	    char *c_cptr = cptr - 1;
-
-	    c = *cptr++;
-	    switch (c)
-	    {
-	    case '\n':
-		get_line();
-		if (line == 0) unterminated_string(s_lineno, s_line, s_cptr);
-		continue;
-
-	    case '0': case '1': case '2': case '3':
-	    case '4': case '5': case '6': case '7':
-		n = c - '0';
-		c = *cptr;
-		if (IS_OCTAL(c))
-		{
-		    n = (n << 3) + (c - '0');
-		    c = *++cptr;
-		    if (IS_OCTAL(c))
-		    {
-			n = (n << 3) + (c - '0');
-			++cptr;
-		    }
-		}
-		if (n > (int)UCHAR_MAX) illegal_character(c_cptr);
-		c = n;
-	    	break;
-
-	    case 'x':
-		c = *cptr++;
-		n = hexval(c);
-		if (n < 0 || n >= 16)
-		    illegal_character(c_cptr);
-		for (;;)
-		{
-		    c = *cptr;
-		    i = hexval(c);
-		    if (i < 0 || i >= 16) break;
-		    ++cptr;
-		    n = (n << 4) + i;
-		    if (n > (int)UCHAR_MAX) illegal_character(c_cptr);
-		}
-		c = n;
-		break;
-
-	    case 'a': c = 7; break;
-	    case 'b': c = '\b'; break;
-	    case 'f': c = '\f'; break;
-	    case 'n': c = '\n'; break;
-	    case 'r': c = '\r'; break;
-	    case 't': c = '\t'; break;
-	    case 'v': c = '\v'; break;
-	    }
-	}
-	cachec(c);
-    }
-    free(s_line);
-
-    n = cinc;
-    s = malloc(n);
-    if (s == 0) no_space();
-
-    for (i = 0; i < n; ++i)
-	s[i] = cache[i];
-
-    cinc = 0;
-    if (n == 1)
-	cachec('\'');
-    else
-	cachec('"');
-
-    for (i = 0; i < n; ++i)
-    {
-	c = ((unsigned char *)s)[i];
-	if (c == '\\' || c == cache[0])
-	{
-	    cachec('\\');
-	    cachec(c);
-	}
-	else if (isprint(c))
-	    cachec(c);
-	else
-	{
-	    cachec('\\');
-	    switch (c)
-	    {
-	    case 7: cachec('a'); break;
-	    case '\b': cachec('b'); break;
-	    case '\f': cachec('f'); break;
-	    case '\n': cachec('n'); break;
-	    case '\r': cachec('r'); break;
-	    case '\t': cachec('t'); break;
-	    case '\v': cachec('v'); break;
-	    default:
-		cachec(((c >> 6) & 7) + '0');
-		cachec(((c >> 3) & 7) + '0');
-		cachec((c & 7) + '0');
-		break;
-	    }
-	}
-    }
-
-    if (n == 1)
-	cachec('\'');
-    else
-	cachec('"');
-
-    cachec(NUL);
-    bp = lookup(cache);
-    bp->class = TERM;
-    if (n == 1 && bp->value == UNDEFINED)
-	bp->value = *(unsigned char *)s;
-    free(s);
-
-    return (bp);
-}
-
-
-static int
-is_reserved(char *name)
-{
-    char *s;
-
-    if (strcmp(name, ".") == 0 ||
-	    strcmp(name, "$accept") == 0 ||
-	    strcmp(name, "$end") == 0)
-	return (1);
-
-    if (name[0] == '$' && name[1] == '$' && isdigit(name[2]))
-    {
-	s = name + 3;
-	while (isdigit(*s)) ++s;
-	if (*s == NUL) return (1);
-    }
-
-    return (0);
-}
-
-
-static bucket *
-get_name(void)
-{
-    int c;
-
-    cinc = 0;
-    for (c = *cptr; IS_IDENT(c); c = *++cptr)
-	cachec(c);
-    cachec(NUL);
-
-    if (is_reserved(cache)) used_reserved(cache);
-
-    return (lookup(cache));
-}
-
-
-static int
-get_number(void)
-{
-    int c;
-    int n;
-
-    n = 0;
-    for (c = *cptr; isdigit(c); c = *++cptr)
-	n = 10*n + (c - '0');
-
-    return (n);
-}
-
-
-static char *
-get_tag(void)
-{
-    int c;
-    int i;
-    char *s;
-    int t_lineno = lineno;
-    char *t_line = dup_line();
-    char *t_cptr = t_line + (cptr - line);
-
-    ++cptr;
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (!isalpha(c) && c != '_' && c != '$')
-	illegal_tag(t_lineno, t_line, t_cptr);
-
-    cinc = 0;
-    do { cachec(c); c = *++cptr; } while (IS_IDENT(c));
-    cachec(NUL);
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != '>')
-	illegal_tag(t_lineno, t_line, t_cptr);
-    ++cptr;
-
-    for (i = 0; i < ntags; ++i)
-    {
-	if (strcmp(cache, tag_table[i]) == 0)
-	    return (tag_table[i]);
-    }
-
-    if (ntags >= tagmax)
-    {
-	tagmax += 16;
-	tag_table = (char **)
-			(tag_table ? realloc(tag_table, tagmax*sizeof(char *))
-				   : malloc(tagmax*sizeof(char *)));
-	if (tag_table == 0) no_space();
-    }
-
-    s = malloc(cinc);
-    if  (s == 0) no_space();
-    strcpy(s, cache);
-    tag_table[ntags] = s;
-    ++ntags;
-    free(t_line);
-    return (s);
-}
-
-
-static void
-declare_tokens(int assoc)
-{
-    int c;
-    bucket *bp;
-    int value;
-    char *tag = 0;
-
-    if (assoc != TOKEN) ++prec;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c == '<')
-    {
-	tag = get_tag();
-	c = nextc();
-	if (c == EOF) unexpected_EOF();
-    }
-
-    for (;;)
-    {
-	if (isalpha(c) || c == '_' || c == '.' || c == '$')
-	    bp = get_name();
-	else if (c == '\'' || c == '"')
-	    bp = get_literal();
-	else
-	    return;
-
-	if (bp == goal) tokenized_start(bp->name);
-	bp->class = TERM;
-
-	if (tag)
-	{
-	    if (bp->tag && tag != bp->tag)
-		retyped_warning(bp->name);
-	    bp->tag = tag;
-	}
-
-	if (assoc != TOKEN)
-	{
-	    if (bp->prec && prec != bp->prec)
-		reprec_warning(bp->name);
-	    bp->assoc = assoc;
-	    bp->prec = prec;
-	}
-
-	c = nextc();
-	if (c == EOF) unexpected_EOF();
-	value = UNDEFINED;
-	if (isdigit(c))
-	{
-	    value = get_number();
-	    if (bp->value != UNDEFINED && value != bp->value)
-		revalued_warning(bp->name);
-	    bp->value = value;
-	    c = nextc();
-	    if (c == EOF) unexpected_EOF();
-	}
-    }
-}
-
-
-/*
- * %expect requires special handling
- * as it really isn't part of the yacc
- * grammar only a flag for yacc proper.
- */
-static void
-declare_expect(int assoc)
-{
-    int c;
-
-    if (assoc != EXPECT) ++prec;
-
-    /*
-     * Stay away from nextc - doesn't
-     * detect EOL and will read to EOF.
-     */
-    c = *++cptr;
-    if (c == EOF) unexpected_EOF();
-
-    for(;;)
-    {
-	if (isdigit(c))
-	{
-	    SRexpect = get_number();
-	    break;
-	}
-	/*
-	 * Looking for number before EOL.
-	 * Spaces, tabs, and numbers are ok,
-	 * words, punc., etc. are syntax errors.
-	 */
-	else if (c == '\n' || isalpha(c) || !isspace(c))
-	{
-	    syntax_error(lineno, line, cptr);
-	}
-	else
-	{
-	    c = *++cptr;
-	    if (c == EOF) unexpected_EOF();
-	}
-    }
-}
-
-
-static void
-declare_types(void)
-{
-    int c;
-    bucket *bp;
-    char *tag;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != '<') syntax_error(lineno, line, cptr);
-    tag = get_tag();
-
-    for (;;)
-    {
-	c = nextc();
-	if (isalpha(c) || c == '_' || c == '.' || c == '$')
-	    bp = get_name();
-	else if (c == '\'' || c == '"')
-	    bp = get_literal();
-	else
-	    return;
-
-	if (bp->tag && tag != bp->tag)
-	    retyped_warning(bp->name);
-	bp->tag = tag;
-    }
-}
-
-
-static void
-declare_start(void)
-{
-    int c;
-    bucket *bp;
-
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (!isalpha(c) && c != '_' && c != '.' && c != '$')
-	syntax_error(lineno, line, cptr);
-    bp = get_name();
-    if (bp->class == TERM)
-	terminal_start(bp->name);
-    if (goal && goal != bp)
-	restarted_warning();
-    goal = bp;
-}
-
-
-static void
-read_declarations(void)
-{
-    int c, k;
-
-    cache_size = 256;
-    cache = malloc(cache_size);
-    if (cache == 0) no_space();
-
-    for (;;)
-    {
-	c = nextc();
-	if (c == EOF) unexpected_EOF();
-	if (c != '%') syntax_error(lineno, line, cptr);
-	switch (k = keyword())
-	{
-	case MARK:
-	    return;
-
-	case IDENT:
-	    copy_ident();
-	    break;
-
-	case TEXT:
-	    copy_text();
-	    break;
-
-	case UNION:
-	    copy_union();
-	    break;
-
-	case TOKEN:
-	case LEFT:
-	case RIGHT:
-	case NONASSOC:
-	    declare_tokens(k);
-	    break;
-
-	case EXPECT:
-	    declare_expect(k);
-	    break;
-
-	case TYPE:
-	    declare_types();
-	    break;
-
-	case START:
-	    declare_start();
-	    break;
-	}
-    }
-}
-
-
-static void
-initialize_grammar(void)
-{
-    nitems = 4;
-    maxitems = 300;
-    pitem = malloc(maxitems*sizeof(bucket *));
-    if (pitem == 0) no_space();
-    pitem[0] = 0;
-    pitem[1] = 0;
-    pitem[2] = 0;
-    pitem[3] = 0;
-
-    nrules = 3;
-    maxrules = 100;
-    plhs = malloc(maxrules*sizeof(bucket *));
-    if (plhs == 0) no_space();
-    plhs[0] = 0;
-    plhs[1] = 0;
-    plhs[2] = 0;
-    rprec = malloc(maxrules*sizeof(short));
-    if (rprec == 0) no_space();
-    rprec[0] = 0;
-    rprec[1] = 0;
-    rprec[2] = 0;
-    rassoc = malloc(maxrules*sizeof(char));
-    if (rassoc == 0) no_space();
-    rassoc[0] = TOKEN;
-    rassoc[1] = TOKEN;
-    rassoc[2] = TOKEN;
-}
-
-
-static void
-expand_items(void)
-{
-    maxitems += 300;
-    pitem = realloc(pitem, maxitems*sizeof(bucket *));
-    if (pitem == 0) no_space();
-}
-
-
-static void
-expand_rules(void)
-{
-    maxrules += 100;
-    plhs = realloc(plhs, maxrules*sizeof(bucket *));
-    if (plhs == 0) no_space();
-    rprec = realloc(rprec, maxrules*sizeof(short));
-    if (rprec == 0) no_space();
-    rassoc = realloc(rassoc, maxrules*sizeof(char));
-    if (rassoc == 0) no_space();
-}
-
-
-static void
-advance_to_start(void)
-{
-    int c;
-    bucket *bp;
-    char *s_cptr;
-    int s_lineno;
-
-    for (;;)
-    {
-	c = nextc();
-	if (c != '%') break;
-	s_cptr = cptr;
-	switch (keyword())
-	{
-	case MARK:
-	    no_grammar();
-
-	case TEXT:
-	    copy_text();
-	    break;
-
-	case START:
-	    declare_start();
-	    break;
-
-	default:
-	    syntax_error(lineno, line, s_cptr);
-	}
-    }
-
-    c = nextc();
-    if (!isalpha(c) && c != '_' && c != '.' && c != '_')
-	syntax_error(lineno, line, cptr);
-    bp = get_name();
-    if (goal == 0)
-    {
-	if (bp->class == TERM)
-	    terminal_start(bp->name);
-	goal = bp;
-    }
-
-    s_lineno = lineno;
-    c = nextc();
-    if (c == EOF) unexpected_EOF();
-    if (c != ':') syntax_error(lineno, line, cptr);
-    start_rule(bp, s_lineno);
-    ++cptr;
-}
-
-
-static void
-start_rule(bucket *bp, int s_lineno)
-{
-    if (bp->class == TERM)
-	terminal_lhs(s_lineno);
-    bp->class = NONTERM;
-    if (nrules >= maxrules)
-	expand_rules();
-    plhs[nrules] = bp;
-    rprec[nrules] = UNDEFINED;
-    rassoc[nrules] = TOKEN;
-}
-
-
-static void
-end_rule(void)
-{
-    int i;
-
-    if (!last_was_action && plhs[nrules]->tag)
-    {
-	for (i = nitems - 1; pitem[i]; --i) continue;
-	if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[nrules]->tag)
-	    default_action_warning();
-    }
-
-    last_was_action = 0;
-    if (nitems >= maxitems) expand_items();
-    pitem[nitems] = 0;
-    ++nitems;
-    ++nrules;
-}
-
-
-static void
-insert_empty_rule(void)
-{
-    bucket *bp, **bpp;
-
-    assert(cache);
-    sprintf(cache, "$$%d", ++gensym);
-    bp = make_bucket(cache);
-    last_symbol->next = bp;
-    last_symbol = bp;
-    bp->tag = plhs[nrules]->tag;
-    bp->class = NONTERM;
-
-    if ((nitems += 2) > maxitems)
-	expand_items();
-    bpp = pitem + nitems - 1;
-    *bpp-- = bp;
-    while ((bpp[0] = bpp[-1])) --bpp;
-
-    if (++nrules >= maxrules)
-	expand_rules();
-    plhs[nrules] = plhs[nrules-1];
-    plhs[nrules-1] = bp;
-    rprec[nrules] = rprec[nrules-1];
-    rprec[nrules-1] = 0;
-    rassoc[nrules] = rassoc[nrules-1];
-    rassoc[nrules-1] = TOKEN;
-}
-
-
-static void
-add_symbol(void)
-{
-    int c;
-    bucket *bp;
-    int s_lineno = lineno;
-
-    c = *cptr;
-    if (c == '\'' || c == '"')
-	bp = get_literal();
-    else
-	bp = get_name();
-
-    c = nextc();
-    if (c == ':')
-    {
-	end_rule();
-	start_rule(bp, s_lineno);
-	++cptr;
-	return;
-    }
-
-    if (last_was_action)
-	insert_empty_rule();
-    last_was_action = 0;
-
-    if (++nitems > maxitems)
-	expand_items();
-    pitem[nitems-1] = bp;
-}
-
-
-static void
-copy_action(void)
-{
-    int c;
-    int i, n;
-    int depth;
-    int quote;
-    char *tag;
-    FILE *f = action_file;
-    int a_lineno = lineno;
-    char *a_line = dup_line();
-    char *a_cptr = a_line + (cptr - line);
-
-    if (last_was_action)
-	insert_empty_rule();
-    last_was_action = 1;
-
-    fprintf(f, "case %d:\n", nrules - 2);
-    if (!lflag)
-	fprintf(f, line_format, lineno, input_file_name);
-    if (*cptr == '=') ++cptr;
-
-    n = 0;
-    for (i = nitems - 1; pitem[i]; --i) ++n;
-
-    depth = 0;
-loop:
-    c = *cptr;
-    if (c == '$')
-    {
-	if (cptr[1] == '<')
-	{
-	    int d_lineno = lineno;
-	    char *d_line = dup_line();
-	    char *d_cptr = d_line + (cptr - line);
-
-	    ++cptr;
-	    tag = get_tag();
-	    c = *cptr;
-	    if (c == '$')
-	    {
-		fprintf(f, "yyval.%s", tag);
-		++cptr;
-		free(d_line);
-		goto loop;
-	    }
-	    else if (isdigit(c))
-	    {
-		i = get_number();
-		if (i > n) dollar_warning(d_lineno, i);
-		fprintf(f, "yyvsp[%d].%s", i - n, tag);
-		free(d_line);
-		goto loop;
-	    }
-	    else if (c == '-' && isdigit(cptr[1]))
-	    {
-		++cptr;
-		i = -get_number() - n;
-		fprintf(f, "yyvsp[%d].%s", i, tag);
-		free(d_line);
-		goto loop;
-	    }
-	    else
-		dollar_error(d_lineno, d_line, d_cptr);
-	}
-	else if (cptr[1] == '$')
-	{
-	    if (ntags)
-	    {
-		tag = plhs[nrules]->tag;
-		if (tag == 0) untyped_lhs();
-		fprintf(f, "yyval.%s", tag);
-	    }
-	    else
-		fprintf(f, "yyval");
-	    cptr += 2;
-	    goto loop;
-	}
-	else if (isdigit(cptr[1]))
-	{
-	    ++cptr;
-	    i = get_number();
-	    if (ntags)
-	    {
-		if (i <= 0 || i > n)
-		    unknown_rhs(i);
-		tag = pitem[nitems + i - n - 1]->tag;
-		if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name);
-		fprintf(f, "yyvsp[%d].%s", i - n, tag);
-	    }
-	    else
-	    {
-		if (i > n)
-		    dollar_warning(lineno, i);
-		fprintf(f, "yyvsp[%d]", i - n);
-	    }
-	    goto loop;
-	}
-	else if (cptr[1] == '-')
-	{
-	    cptr += 2;
-	    i = get_number();
-	    if (ntags)
-		unknown_rhs(-i);
-	    fprintf(f, "yyvsp[%d]", -i - n);
-	    goto loop;
-	}
-    }
-    if (isalpha(c) || c == '_' || c == '$')
-    {
-	do
-	{
-	    putc(c, f);
-	    c = *++cptr;
-	} while (isalnum(c) || c == '_' || c == '$');
-	goto loop;
-    }
-    putc(c, f);
-    ++cptr;
-    switch (c)
-    {
-    case '\n':
-    next_line:
-	get_line();
-	if (line) goto loop;
-	unterminated_action(a_lineno, a_line, a_cptr);
-
-    case ';':
-	if (depth > 0) goto loop;
-	fprintf(f, "\nbreak;\n");
-	return;
-
-    case '{':
-	++depth;
-	goto loop;
-
-    case '}':
-	if (--depth > 0) goto loop;
-	fprintf(f, "\nbreak;\n");
-	return;
-
-    case '\'':
-    case '"':
-	{
-	    int s_lineno = lineno;
-	    char *s_line = dup_line();
-	    char *s_cptr = s_line + (cptr - line - 1);
-
-	    quote = c;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == quote)
-		{
-		    free(s_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		    unterminated_string(s_lineno, s_line, s_cptr);
-		if (c == '\\')
-		{
-		    c = *cptr++;
-		    putc(c, f);
-		    if (c == '\n')
-		    {
-			get_line();
-			if (line == 0)
-			    unterminated_string(s_lineno, s_line, s_cptr);
-		    }
-		}
-	    }
-	}
-
-    case '/':
-	c = *cptr;
-	if (c == '/')
-	{
-	    putc('*', f);
-	    while ((c = *++cptr) != '\n')
-	    {
-		if (c == '*' && cptr[1] == '/')
-		    fprintf(f, "* ");
-		else
-		    putc(c, f);
-	    }
-	    fprintf(f, "*/\n");
-	    goto next_line;
-	}
-	if (c == '*')
-	{
-	    int c_lineno = lineno;
-	    char *c_line = dup_line();
-	    char *c_cptr = c_line + (cptr - line - 1);
-
-	    putc('*', f);
-	    ++cptr;
-	    for (;;)
-	    {
-		c = *cptr++;
-		putc(c, f);
-		if (c == '*' && *cptr == '/')
-		{
-		    putc('/', f);
-		    ++cptr;
-		    free(c_line);
-		    goto loop;
-		}
-		if (c == '\n')
-		{
-		    get_line();
-		    if (line == 0)
-			unterminated_comment(c_lineno, c_line, c_cptr);
-		}
-	    }
-	}
-	goto loop;
-
-    default:
-	goto loop;
-    }
-}
-
-
-static int
-mark_symbol(void)
-{
-    int c;
-    bucket *bp = NULL;
-
-    c = cptr[1];
-    if (c == '%' || c == '\\')
-    {
-	cptr += 2;
-	return (1);
-    }
-
-    if (c == '=')
-	cptr += 2;
-    else if ((c == 'p' || c == 'P') &&
-	     ((c = cptr[2]) == 'r' || c == 'R') &&
-	     ((c = cptr[3]) == 'e' || c == 'E') &&
-	     ((c = cptr[4]) == 'c' || c == 'C') &&
-	     ((c = cptr[5], !IS_IDENT(c))))
-	cptr += 5;
-    else
-	syntax_error(lineno, line, cptr);
-
-    c = nextc();
-    if (isalpha(c) || c == '_' || c == '.' || c == '$')
-	bp = get_name();
-    else if (c == '\'' || c == '"')
-	bp = get_literal();
-    else
-    {
-	syntax_error(lineno, line, cptr);
-	/*NOTREACHED*/
-    }
-
-    if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules])
-	prec_redeclared();
-
-    rprec[nrules] = bp->prec;
-    rassoc[nrules] = bp->assoc;
-    return (0);
-}
-
-
-static void
-read_grammar(void)
-{
-    int c;
-
-    initialize_grammar();
-    advance_to_start();
-
-    for (;;)
-    {
-	c = nextc();
-	if (c == EOF) break;
-	if (isalpha(c) || c == '_' || c == '.' || c == '$' || c == '\'' ||
-		c == '"')
-	    add_symbol();
-	else if (c == '{' || c == '=')
-	    copy_action();
-	else if (c == '|')
-	{
-	    end_rule();
-	    start_rule(plhs[nrules-1], 0);
-	    ++cptr;
-	}
-	else if (c == '%')
-	{
-	    if (mark_symbol()) break;
-	}
-	else
-	    syntax_error(lineno, line, cptr);
-    }
-    end_rule();
-}
-
-
-static void
-free_tags(void)
-{
-    int i;
-
-    if (tag_table == 0) return;
-
-    for (i = 0; i < ntags; ++i)
-    {
-	assert(tag_table[i]);
-	free(tag_table[i]);
-    }
-    free(tag_table);
-}
-
-
-static void
-pack_names(void)
-{
-    bucket *bp;
-    char *p, *s, *t;
-
-    name_pool_size = 13;  /* 13 == sizeof("$end") + sizeof("$accept") */
-    for (bp = first_symbol; bp; bp = bp->next)
-	name_pool_size += strlen(bp->name) + 1;
-    name_pool = malloc(name_pool_size);
-    if (name_pool == 0) no_space();
-
-    strcpy(name_pool, "$accept");
-    strcpy(name_pool+8, "$end");
-    t = name_pool + 13;
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	p = t;
-	s = bp->name;
-	while ((*t++ = *s++)) continue;
-	free(bp->name);
-	bp->name = p;
-    }
-}
-
-
-static void
-check_symbols(void)
-{
-    bucket *bp;
-
-    if (goal->class == UNKNOWN)
-	undefined_goal(goal->name);
-
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	if (bp->class == UNKNOWN)
-	{
-	    undefined_symbol_warning(bp->name);
-	    bp->class = TERM;
-	}
-    }
-}
-
-
-static void
-pack_symbols(void)
-{
-    bucket *bp;
-    bucket **v;
-    int i, j, k, n;
-
-    nsyms = 2;
-    ntokens = 1;
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	++nsyms;
-	if (bp->class == TERM) ++ntokens;
-    }
-    start_symbol = ntokens;
-    nvars = nsyms - ntokens;
-
-    symbol_name = malloc(nsyms*sizeof(char *));
-    if (symbol_name == 0) no_space();
-    symbol_value = malloc(nsyms*sizeof(short));
-    if (symbol_value == 0) no_space();
-    symbol_prec = malloc(nsyms*sizeof(short));
-    if (symbol_prec == 0) no_space();
-    symbol_assoc = malloc(nsyms);
-    if (symbol_assoc == 0) no_space();
-
-    v = malloc(nsyms*sizeof(bucket *));
-    if (v == 0) no_space();
-
-    v[0] = 0;
-    v[start_symbol] = 0;
-
-    i = 1;
-    j = start_symbol + 1;
-    for (bp = first_symbol; bp; bp = bp->next)
-    {
-	if (bp->class == TERM)
-	    v[i++] = bp;
-	else
-	    v[j++] = bp;
-    }
-    assert(i == ntokens && j == nsyms);
-
-    for (i = 1; i < ntokens; ++i)
-	v[i]->index = i;
-
-    goal->index = start_symbol + 1;
-    k = start_symbol + 2;
-    while (++i < nsyms)
-	if (v[i] != goal)
-	{
-	    v[i]->index = k;
-	    ++k;
-	}
-
-    goal->value = 0;
-    k = 1;
-    for (i = start_symbol + 1; i < nsyms; ++i)
-    {
-	if (v[i] != goal)
-	{
-	    v[i]->value = k;
-	    ++k;
-	}
-    }
-
-    k = 0;
-    for (i = 1; i < ntokens; ++i)
-    {
-	n = v[i]->value;
-	if (n > 256)
-	{
-	    for (j = k++; j > 0 && symbol_value[j-1] > n; --j)
-		symbol_value[j] = symbol_value[j-1];
-	    symbol_value[j] = n;
-	}
-    }
-
-    if (v[1]->value == UNDEFINED)
-	v[1]->value = 256;
-
-    j = 0;
-    n = 257;
-    for (i = 2; i < ntokens; ++i)
-    {
-	if (v[i]->value == UNDEFINED)
-	{
-	    while (j < k && n == symbol_value[j])
-	    {
-		while (++j < k && n == symbol_value[j]) continue;
-		++n;
-	    }
-	    v[i]->value = n;
-	    ++n;
-	}
-    }
-
-    symbol_name[0] = name_pool + 8;
-    symbol_value[0] = 0;
-    symbol_prec[0] = 0;
-    symbol_assoc[0] = TOKEN;
-    for (i = 1; i < ntokens; ++i)
-    {
-	symbol_name[i] = v[i]->name;
-	symbol_value[i] = v[i]->value;
-	symbol_prec[i] = v[i]->prec;
-	symbol_assoc[i] = v[i]->assoc;
-    }
-    symbol_name[start_symbol] = name_pool;
-    symbol_value[start_symbol] = -1;
-    symbol_prec[start_symbol] = 0;
-    symbol_assoc[start_symbol] = TOKEN;
-    for (++i; i < nsyms; ++i)
-    {
-	k = v[i]->index;
-	symbol_name[k] = v[i]->name;
-	symbol_value[k] = v[i]->value;
-	symbol_prec[k] = v[i]->prec;
-	symbol_assoc[k] = v[i]->assoc;
-    }
-
-    free(v);
-}
-
-
-static void
-pack_grammar(void)
-{
-    int i, j;
-    int assoc, preced;
-
-    ritem = malloc(nitems*sizeof(short));
-    if (ritem == 0) no_space();
-    rlhs = malloc(nrules*sizeof(short));
-    if (rlhs == 0) no_space();
-    rrhs = malloc((nrules+1)*sizeof(short));
-    if (rrhs == 0) no_space();
-    rprec = realloc(rprec, nrules*sizeof(short));
-    if (rprec == 0) no_space();
-    rassoc = realloc(rassoc, nrules);
-    if (rassoc == 0) no_space();
-
-    ritem[0] = -1;
-    ritem[1] = goal->index;
-    ritem[2] = 0;
-    ritem[3] = -2;
-    rlhs[0] = 0;
-    rlhs[1] = 0;
-    rlhs[2] = start_symbol;
-    rrhs[0] = 0;
-    rrhs[1] = 0;
-    rrhs[2] = 1;
-
-    j = 4;
-    for (i = 3; i < nrules; ++i)
-    {
-	rlhs[i] = plhs[i]->index;
-	rrhs[i] = j;
-	assoc = TOKEN;
-	preced = 0;
-	while (pitem[j])
-	{
-	    ritem[j] = pitem[j]->index;
-	    if (pitem[j]->class == TERM)
-	    {
-		preced = pitem[j]->prec;
-		assoc = pitem[j]->assoc;
-	    }
-	    ++j;
-	}
-	ritem[j] = -i;
-	++j;
-	if (rprec[i] == UNDEFINED)
-	{
-	    rprec[i] = preced;
-	    rassoc[i] = assoc;
-	}
-    }
-    rrhs[i] = j;
-
-    free(plhs);
-    free(pitem);
-}
-
-
-static void
-print_grammar(void)
-{
-    int i, j, k;
-    int spacing;
-    FILE *f = verbose_file;
-
-    if (!vflag) return;
-
-    k = 1;
-    spacing = 0;
-    for (i = 2; i < nrules; ++i)
-    {
-	if (rlhs[i] != rlhs[i-1])
-	{
-	    if (i != 2) fprintf(f, "\n");
-	    fprintf(f, "%4d  %s :", i - 2, symbol_name[rlhs[i]]);
-	    spacing = strlen(symbol_name[rlhs[i]]) + 1;
-	}
-	else
-	{
-	    fprintf(f, "%4d  ", i - 2);
-	    j = spacing;
-	    while (--j >= 0) putc(' ', f);
-	    putc('|', f);
-	}
-
-	while (ritem[k] >= 0)
-	{
-	    fprintf(f, " %s", symbol_name[ritem[k]]);
-	    ++k;
-	}
-	++k;
-	putc('\n', f);
-    }
-}
-
-
-void
-reader(void)
-{
-    write_section(banner);
-    create_symbol_table();
-    read_declarations();
-    read_grammar();
-    free_symbol_table();
-    free_tags();
-    pack_names();
-    check_symbols();
-    pack_symbols();
-    pack_grammar();
-    free_symbols();
-    print_grammar();
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/skeleton.c
--- a/head/usr.bin/yacc/skeleton.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,426 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)skeleton.c	5.8 (Berkeley) 4/29/95";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "defs.h"
-
-/*  The definition of yysccsid in the banner should be replaced with	*/
-/*  a #pragma ident directive if the target C compiler supports		*/
-/*  #pragma ident directives.						*/
-/*									*/
-/*  If the skeleton is changed, the banner should be changed so that	*/
-/*  the altered version can be easily distinguished from the original.	*/
-/*									*/
-/*  The #defines included with the banner are there because they are	*/
-/*  useful in subsequent code.  The macros #defined in the header or	*/
-/*  the body either are not useful outside of semantic actions or	*/
-/*  are conditional.							*/
-
-const char *banner[] =
-{
-    "#include <stdlib.h>",
-    "#include <string.h>",
-    "#ifndef lint",
-    "#ifdef __unused",
-    "__unused",
-    "#endif",
-    "static char const ",
-    "yyrcsid[] = \"$FreeBSD$\";",
-    "#endif",
-    "#define YYBYACC 1",
-    "#define YYMAJOR 1",
-    "#define YYMINOR 9",
-    "#define YYLEX yylex()",
-    "#define YYEMPTY -1",
-    "#define yyclearin (yychar=(YYEMPTY))",
-    "#define yyerrok (yyerrflag=0)",
-    "#define YYRECOVERING() (yyerrflag!=0)",
-    "#if defined(__cplusplus) || __STDC__",
-    "static int yygrowstack(void);",
-    "#else",
-    "static int yygrowstack();",
-    "#endif",
-    0
-};
-
-
-const char *tables[] =
-{
-    "extern const short yylhs[];",
-    "extern const short yylen[];",
-    "extern const short yydefred[];",
-    "extern const short yydgoto[];",
-    "extern const short yysindex[];",
-    "extern const short yyrindex[];",
-    "extern const short yygindex[];",
-    "extern const short yytable[];",
-    "extern const short yycheck[];",
-    "#if YYDEBUG",
-    "extern char *yyname[];",
-    "extern char *yyrule[];",
-    "#endif",
-    0
-};
-
-
-const char *header[] =
-{
-    "#if YYDEBUG",
-    "#include <stdio.h>",
-    "#endif",
-    "#ifdef YYSTACKSIZE",
-    "#undef YYMAXDEPTH",
-    "#define YYMAXDEPTH YYSTACKSIZE",
-    "#else",
-    "#ifdef YYMAXDEPTH",
-    "#define YYSTACKSIZE YYMAXDEPTH",
-    "#else",
-    "#define YYSTACKSIZE 10000",
-    "#define YYMAXDEPTH 10000",
-    "#endif",
-    "#endif",
-    "#define YYINITSTACKSIZE 200",
-    "int yydebug;",
-    "int yynerrs;",
-    "int yyerrflag;",
-    "int yychar;",
-    "short *yyssp;",
-    "YYSTYPE *yyvsp;",
-    "YYSTYPE yyval;",
-    "YYSTYPE yylval;",
-    "short *yyss;",
-    "short *yysslim;",
-    "YYSTYPE *yyvs;",
-    "int yystacksize;",
-    0
-};
-
-
-const char *body[] =
-{
-    "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
-    "#if defined(__cplusplus) || __STDC__",
-    "static int yygrowstack(void)",
-    "#else",
-    "static int yygrowstack()",
-    "#endif",
-    "{",
-    "    int newsize, i;",
-    "    short *newss;",
-    "    YYSTYPE *newvs;",
-    "",
-    "    if ((newsize = yystacksize) == 0)",
-    "        newsize = YYINITSTACKSIZE;",
-    "    else if (newsize >= YYMAXDEPTH)",
-    "        return -1;",
-    "    else if ((newsize *= 2) > YYMAXDEPTH)",
-    "        newsize = YYMAXDEPTH;",
-    "    i = yyssp - yyss;",
-    "    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
-    "      (short *)malloc(newsize * sizeof *newss);",
-    "    if (newss == NULL)",
-    "        return -1;",
-    "    yyss = newss;",
-    "    yyssp = newss + i;",
-    "    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
-    "      (YYSTYPE *)malloc(newsize * sizeof *newvs);",
-    "    if (newvs == NULL)",
-    "        return -1;",
-    "    yyvs = newvs;",
-    "    yyvsp = newvs + i;",
-    "    yystacksize = newsize;",
-    "    yysslim = yyss + newsize - 1;",
-    "    return 0;",
-    "}",
-    "",
-    "#define YYABORT goto yyabort",
-    "#define YYREJECT goto yyabort",
-    "#define YYACCEPT goto yyaccept",
-    "#define YYERROR goto yyerrlab",
-    "",
-    "#ifndef YYPARSE_PARAM",
-    "#if defined(__cplusplus) || __STDC__",
-    "#define YYPARSE_PARAM_ARG void",
-    "#define YYPARSE_PARAM_DECL",
-    "#else	/* ! ANSI-C/C++ */",
-    "#define YYPARSE_PARAM_ARG",
-    "#define YYPARSE_PARAM_DECL",
-    "#endif	/* ANSI-C/C++ */",
-    "#else	/* YYPARSE_PARAM */",
-    "#ifndef YYPARSE_PARAM_TYPE",
-    "#define YYPARSE_PARAM_TYPE void *",
-    "#endif",
-    "#if defined(__cplusplus) || __STDC__",
-    "#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM",
-    "#define YYPARSE_PARAM_DECL",
-    "#else	/* ! ANSI-C/C++ */",
-    "#define YYPARSE_PARAM_ARG YYPARSE_PARAM",
-    "#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;",
-    "#endif	/* ANSI-C/C++ */",
-    "#endif	/* ! YYPARSE_PARAM */",
-    "",
-    "int",
-    "yyparse (YYPARSE_PARAM_ARG)",
-    "    YYPARSE_PARAM_DECL",
-    "{",
-    "    int yym, yyn, yystate;",
-    "#if YYDEBUG",
-    "    const char *yys;",
-    "",
-    "    if ((yys = getenv(\"YYDEBUG\")))",
-    "    {",
-    "        yyn = *yys;",
-    "        if (yyn >= '0' && yyn <= '9')",
-    "            yydebug = yyn - '0';",
-    "    }",
-    "#endif",
-    "",
-    "    yynerrs = 0;",
-    "    yyerrflag = 0;",
-    "    yychar = (-1);",
-    "",
-    "    if (yyss == NULL && yygrowstack()) goto yyoverflow;",
-    "    yyssp = yyss;",
-    "    yyvsp = yyvs;",
-    "    *yyssp = yystate = 0;",
-    "",
-    "yyloop:",
-    "    if ((yyn = yydefred[yystate])) goto yyreduce;",
-    "    if (yychar < 0)",
-    "    {",
-    "        if ((yychar = yylex()) < 0) yychar = 0;",
-    "#if YYDEBUG",
-    "        if (yydebug)",
-    "        {",
-    "            yys = 0;",
-    "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
-    "            if (!yys) yys = \"illegal-symbol\";",
-    "            printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
-    "                    YYPREFIX, yystate, yychar, yys);",
-    "        }",
-    "#endif",
-    "    }",
-    "    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
-    "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
-    "    {",
-    "#if YYDEBUG",
-    "        if (yydebug)",
-    "            printf(\"%sdebug: state %d, shifting to state %d\\n\",",
-    "                    YYPREFIX, yystate, yytable[yyn]);",
-    "#endif",
-    "        if (yyssp >= yysslim && yygrowstack())",
-    "        {",
-    "            goto yyoverflow;",
-    "        }",
-    "        *++yyssp = yystate = yytable[yyn];",
-    "        *++yyvsp = yylval;",
-    "        yychar = (-1);",
-    "        if (yyerrflag > 0)  --yyerrflag;",
-    "        goto yyloop;",
-    "    }",
-    "    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
-    "            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
-    "    {",
-    "        yyn = yytable[yyn];",
-    "        goto yyreduce;",
-    "    }",
-    "    if (yyerrflag) goto yyinrecovery;",
-    "#if defined(lint) || defined(__GNUC__)",
-    "    goto yynewerror;",
-    "#endif",
-    "yynewerror:",
-    "    yyerror(\"syntax error\");",
-    "#if defined(lint) || defined(__GNUC__)",
-    "    goto yyerrlab;",
-    "#endif",
-    "yyerrlab:",
-    "    ++yynerrs;",
-    "yyinrecovery:",
-    "    if (yyerrflag < 3)",
-    "    {",
-    "        yyerrflag = 3;",
-    "        for (;;)",
-    "        {",
-    "            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
-    "                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
-    "            {",
-    "#if YYDEBUG",
-    "                if (yydebug)",
-    "                    printf(\"%sdebug: state %d, error recovery shifting\\",
-    " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
-    "#endif",
-    "                if (yyssp >= yysslim && yygrowstack())",
-    "                {",
-    "                    goto yyoverflow;",
-    "                }",
-    "                *++yyssp = yystate = yytable[yyn];",
-    "                *++yyvsp = yylval;",
-    "                goto yyloop;",
-    "            }",
-    "            else",
-    "            {",
-    "#if YYDEBUG",
-    "                if (yydebug)",
-    "                    printf(\"%sdebug: error recovery discarding state %d\
-\\n\",",
-    "                            YYPREFIX, *yyssp);",
-    "#endif",
-    "                if (yyssp <= yyss) goto yyabort;",
-    "                --yyssp;",
-    "                --yyvsp;",
-    "            }",
-    "        }",
-    "    }",
-    "    else",
-    "    {",
-    "        if (yychar == 0) goto yyabort;",
-    "#if YYDEBUG",
-    "        if (yydebug)",
-    "        {",
-    "            yys = 0;",
-    "            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
-    "            if (!yys) yys = \"illegal-symbol\";",
-    "            printf(\"%sdebug: state %d, error recovery discards token %d\
- (%s)\\n\",",
-    "                    YYPREFIX, yystate, yychar, yys);",
-    "        }",
-    "#endif",
-    "        yychar = (-1);",
-    "        goto yyloop;",
-    "    }",
-    "yyreduce:",
-    "#if YYDEBUG",
-    "    if (yydebug)",
-    "        printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
-    "                YYPREFIX, yystate, yyn, yyrule[yyn]);",
-    "#endif",
-    "    yym = yylen[yyn];",
-    "    if (yym)",
-    "        yyval = yyvsp[1-yym];",
-    "    else",
-    "        memset(&yyval, 0, sizeof yyval);",
-    "    switch (yyn)",
-    "    {",
-    0
-};
-
-
-const char *trailer[] =
-{
-    "    }",
-    "    yyssp -= yym;",
-    "    yystate = *yyssp;",
-    "    yyvsp -= yym;",
-    "    yym = yylhs[yyn];",
-    "    if (yystate == 0 && yym == 0)",
-    "    {",
-    "#if YYDEBUG",
-    "        if (yydebug)",
-    "            printf(\"%sdebug: after reduction, shifting from state 0 to\\",
-    " state %d\\n\", YYPREFIX, YYFINAL);",
-    "#endif",
-    "        yystate = YYFINAL;",
-    "        *++yyssp = YYFINAL;",
-    "        *++yyvsp = yyval;",
-    "        if (yychar < 0)",
-    "        {",
-    "            if ((yychar = yylex()) < 0) yychar = 0;",
-    "#if YYDEBUG",
-    "            if (yydebug)",
-    "            {",
-    "                yys = 0;",
-    "                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
-    "                if (!yys) yys = \"illegal-symbol\";",
-    "                printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
-    "                        YYPREFIX, YYFINAL, yychar, yys);",
-    "            }",
-    "#endif",
-    "        }",
-    "        if (yychar == 0) goto yyaccept;",
-    "        goto yyloop;",
-    "    }",
-    "    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
-    "            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
-    "        yystate = yytable[yyn];",
-    "    else",
-    "        yystate = yydgoto[yym];",
-    "#if YYDEBUG",
-    "    if (yydebug)",
-    "        printf(\"%sdebug: after reduction, shifting from state %d \\",
-    "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
-    "#endif",
-    "    if (yyssp >= yysslim && yygrowstack())",
-    "    {",
-    "        goto yyoverflow;",
-    "    }",
-    "    *++yyssp = yystate;",
-    "    *++yyvsp = yyval;",
-    "    goto yyloop;",
-    "yyoverflow:",
-    "    yyerror(\"yacc stack overflow\");",
-    "yyabort:",
-    "    return (1);",
-    "yyaccept:",
-    "    return (0);",
-    "}",
-    0
-};
-
-
-void
-write_section(const char *section[])
-{
-    int c;
-    int i;
-    const char *s;
-    FILE *f;
-
-    f = code_file;
-    for (i = 0; (s = section[i]); ++i)
-    {
-	++outline;
-	while ((c = *s))
-	{
-	    putc(c, f);
-	    ++s;
-	}
-	putc('\n', f);
-    }
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/symtab.c
--- a/head/usr.bin/yacc/symtab.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)symtab.c	5.3 (Berkeley) 6/1/90";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdlib.h>
-#include <string.h>
-#include "defs.h"
-
-/* TABLE_SIZE is the number of entries in the symbol table. */
-/* TABLE_SIZE must be a power of two.			    */
-
-#define	TABLE_SIZE 1024
-
-static int hash(const char *);
-
-bucket **symbol_table;
-bucket *first_symbol;
-bucket *last_symbol;
-
-
-static int
-hash(const char *name)
-{
-    const char *s;
-    int c, k;
-
-    assert(name && *name);
-    s = name;
-    k = *s;
-    while ((c = *++s))
-	k = (31*k + c) & (TABLE_SIZE - 1);
-
-    return (k);
-}
-
-
-bucket *
-make_bucket(const char *name)
-{
-    bucket *bp;
-
-    assert(name);
-    bp = malloc(sizeof(bucket));
-    if (bp == 0) no_space();
-    bp->link = 0;
-    bp->next = 0;
-    bp->name = malloc(strlen(name) + 1);
-    if (bp->name == 0) no_space();
-    bp->tag = 0;
-    bp->value = UNDEFINED;
-    bp->index = 0;
-    bp->prec = 0;
-    bp-> class = UNKNOWN;
-    bp->assoc = TOKEN;
-
-    if (bp->name == 0) no_space();
-    strcpy(bp->name, name);
-
-    return (bp);
-}
-
-
-bucket *
-lookup(char *name)
-{
-    bucket *bp, **bpp;
-
-    bpp = symbol_table + hash(name);
-    bp = *bpp;
-
-    while (bp)
-    {
-	if (strcmp(name, bp->name) == 0) return (bp);
-	bpp = &bp->link;
-	bp = *bpp;
-    }
-
-    *bpp = bp = make_bucket(name);
-    last_symbol->next = bp;
-    last_symbol = bp;
-
-    return (bp);
-}
-
-
-void
-create_symbol_table(void)
-{
-    int i;
-    bucket *bp;
-
-    symbol_table = malloc(TABLE_SIZE*sizeof(bucket *));
-    if (symbol_table == 0) no_space();
-    for (i = 0; i < TABLE_SIZE; i++)
-	symbol_table[i] = 0;
-
-    bp = make_bucket("error");
-    bp->index = 1;
-    bp->class = TERM;
-
-    first_symbol = bp;
-    last_symbol = bp;
-    symbol_table[hash("error")] = bp;
-}
-
-
-void
-free_symbol_table(void)
-{
-    free(symbol_table);
-    symbol_table = 0;
-}
-
-
-void
-free_symbols(void)
-{
-    bucket *p, *q;
-
-    for (p = first_symbol; p; p = q)
-    {
-	q = p->next;
-	free(p);
-    }
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/error.output
--- a/head/usr.bin/yacc/test/error.output	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-   0  $accept : S $end
-
-   1  S : error
-

-state 0
-	$accept : . S $end  (0)
-
-	error  shift 1
-	.  error
-
-	S  goto 2
-
-
-state 1
-	S : error .  (1)
-
-	.  reduce 1
-
-
-state 2
-	$accept : S . $end  (0)
-
-	$end  accept
-
-
-2 terminals, 2 nonterminals
-2 grammar rules, 3 states
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/error.tab.c
--- a/head/usr.bin/yacc/test/error.tab.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,317 +0,0 @@
-#ifndef lint
-static char const yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
-#endif
-#include <stdlib.h>
-#define YYBYACC 1
-#define YYMAJOR 1
-#define YYMINOR 9
-#define YYLEX yylex()
-#define YYEMPTY -1
-#define yyclearin (yychar=(YYEMPTY))
-#define yyerrok (yyerrflag=0)
-#define YYRECOVERING (yyerrflag!=0)
-#if defined(c_plusplus) || defined(__cplusplus)
-#include <stdlib.h>
-#else
-extern char *getenv();
-extern void *realloc();
-#endif
-static int yygrowstack();
-#define YYPREFIX "yy"
-#define YYERRCODE 256
-const short yylhs[] = {                                        -1,
-    0,
-};
-const short yylen[] = {                                         2,
-    1,
-};
-const short yydefred[] = {                                      0,
-    1,    0,
-};
-const short yydgoto[] = {                                       2,
-};
-const short yysindex[] = {                                   -256,
-    0,    0,
-};
-const short yyrindex[] = {                                      0,
-    0,    0,
-};
-const short yygindex[] = {                                      0,
-};
-#define YYTABLESIZE 0
-const short yytable[] = {                                       1,
-};
-const short yycheck[] = {                                     256,
-};
-#define YYFINAL 2
-#ifndef YYDEBUG
-#define YYDEBUG 0
-#elif YYDEBUG
-#include <stdio.h>
-#endif
-#define YYMAXTOKEN 0
-#if YYDEBUG
-const char * const yyname[] = {
-"end-of-file",
-};
-const char * const yyrule[] = {
-"$accept : S",
-"S : error",
-};
-#endif
-#ifndef YYSTYPE
-typedef int YYSTYPE;
-#endif
-#ifdef YYSTACKSIZE
-#undef YYMAXDEPTH
-#define YYMAXDEPTH YYSTACKSIZE
-#else
-#ifdef YYMAXDEPTH
-#define YYSTACKSIZE YYMAXDEPTH
-#else
-#define YYSTACKSIZE 10000
-#define YYMAXDEPTH 10000
-#endif
-#endif
-#define YYINITSTACKSIZE 200
-int yydebug;
-int yynerrs;
-int yyerrflag;
-int yychar;
-short *yyssp;
-YYSTYPE *yyvsp;
-YYSTYPE yyval;
-YYSTYPE yylval;
-short *yyss;
-short *yysslim;
-YYSTYPE *yyvs;
-int yystacksize;
-#line 4 "error.y"
-main(){printf("yyparse() = %d\n",yyparse());}
-yylex(){return-1;}
-yyerror(s)char*s;{printf("%s\n",s);}
-#line 92 "error.tab.c"
-/* allocate initial stack or double stack size, up to YYMAXDEPTH */
-static int yygrowstack()
-{
-    int newsize, i;
-    short *newss;
-    YYSTYPE *newvs;
-
-    if ((newsize = yystacksize) == 0)
-        newsize = YYINITSTACKSIZE;
-    else if (newsize >= YYMAXDEPTH)
-        return -1;
-    else if ((newsize *= 2) > YYMAXDEPTH)
-        newsize = YYMAXDEPTH;
-    i = yyssp - yyss;
-    if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)
-        return -1;
-    yyss = newss;
-    yyssp = newss + i;
-    if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)
-        return -1;
-    yyvs = newvs;
-    yyvsp = newvs + i;
-    yystacksize = newsize;
-    yysslim = yyss + newsize - 1;
-    return 0;
-}
-
-#define YYABORT goto yyabort
-#define YYREJECT goto yyabort
-#define YYACCEPT goto yyaccept
-#define YYERROR goto yyerrlab
-
-int
-yyparse()
-{
-    register int yym, yyn, yystate;
-#if YYDEBUG
-    register const char *yys;
-
-    if ((yys = getenv("YYDEBUG")))
-    {
-        yyn = *yys;
-        if (yyn >= '0' && yyn <= '9')
-            yydebug = yyn - '0';
-    }
-#endif
-
-    yynerrs = 0;
-    yyerrflag = 0;
-    yychar = (-1);
-
-    if (yyss == NULL && yygrowstack()) goto yyoverflow;
-    yyssp = yyss;
-    yyvsp = yyvs;
-    *yyssp = yystate = 0;
-
-yyloop:
-    if ((yyn = yydefred[yystate])) goto yyreduce;
-    if (yychar < 0)
-    {
-        if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
-        if (yydebug)
-        {
-            yys = 0;
-            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-            if (!yys) yys = "illegal-symbol";
-            printf("%sdebug: state %d, reading %d (%s)\n",
-                    YYPREFIX, yystate, yychar, yys);
-        }
-#endif
-    }
-    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
-    {
-#if YYDEBUG
-        if (yydebug)
-            printf("%sdebug: state %d, shifting to state %d\n",
-                    YYPREFIX, yystate, yytable[yyn]);
-#endif
-        if (yyssp >= yysslim && yygrowstack())
-        {
-            goto yyoverflow;
-        }
-        *++yyssp = yystate = yytable[yyn];
-        *++yyvsp = yylval;
-        yychar = (-1);
-        if (yyerrflag > 0)  --yyerrflag;
-        goto yyloop;
-    }
-    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
-    {
-        yyn = yytable[yyn];
-        goto yyreduce;
-    }
-    if (yyerrflag) goto yyinrecovery;
-#if defined(lint) || defined(__GNUC__)
-    goto yynewerror;
-#endif
-yynewerror:
-    yyerror("syntax error");
-#if defined(lint) || defined(__GNUC__)
-    goto yyerrlab;
-#endif
-yyerrlab:
-    ++yynerrs;
-yyinrecovery:
-    if (yyerrflag < 3)
-    {
-        yyerrflag = 3;
-        for (;;)
-        {
-            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
-                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
-            {
-#if YYDEBUG
-                if (yydebug)
-                    printf("%sdebug: state %d, error recovery shifting\
- to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
-#endif
-                if (yyssp >= yysslim && yygrowstack())
-                {
-                    goto yyoverflow;
-                }
-                *++yyssp = yystate = yytable[yyn];
-                *++yyvsp = yylval;
-                goto yyloop;
-            }
-            else
-            {
-#if YYDEBUG
-                if (yydebug)
-                    printf("%sdebug: error recovery discarding state %d\n",
-                            YYPREFIX, *yyssp);
-#endif
-                if (yyssp <= yyss) goto yyabort;
-                --yyssp;
-                --yyvsp;
-            }
-        }
-    }
-    else
-    {
-        if (yychar == 0) goto yyabort;
-#if YYDEBUG
-        if (yydebug)
-        {
-            yys = 0;
-            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-            if (!yys) yys = "illegal-symbol";
-            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
-                    YYPREFIX, yystate, yychar, yys);
-        }
-#endif
-        yychar = (-1);
-        goto yyloop;
-    }
-yyreduce:
-#if YYDEBUG
-    if (yydebug)
-        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
-                YYPREFIX, yystate, yyn, yyrule[yyn]);
-#endif
-    yym = yylen[yyn];
-    yyval = yyvsp[1-yym];
-    switch (yyn)
-    {
-    }
-    yyssp -= yym;
-    yystate = *yyssp;
-    yyvsp -= yym;
-    yym = yylhs[yyn];
-    if (yystate == 0 && yym == 0)
-    {
-#if YYDEBUG
-        if (yydebug)
-            printf("%sdebug: after reduction, shifting from state 0 to\
- state %d\n", YYPREFIX, YYFINAL);
-#endif
-        yystate = YYFINAL;
-        *++yyssp = YYFINAL;
-        *++yyvsp = yyval;
-        if (yychar < 0)
-        {
-            if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
-            if (yydebug)
-            {
-                yys = 0;
-                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-                if (!yys) yys = "illegal-symbol";
-                printf("%sdebug: state %d, reading %d (%s)\n",
-                        YYPREFIX, YYFINAL, yychar, yys);
-            }
-#endif
-        }
-        if (yychar == 0) goto yyaccept;
-        goto yyloop;
-    }
-    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
-        yystate = yytable[yyn];
-    else
-        yystate = yydgoto[yym];
-#if YYDEBUG
-    if (yydebug)
-        printf("%sdebug: after reduction, shifting from state %d \
-to state %d\n", YYPREFIX, *yyssp, yystate);
-#endif
-    if (yyssp >= yysslim && yygrowstack())
-    {
-        goto yyoverflow;
-    }
-    *++yyssp = yystate;
-    *++yyvsp = yyval;
-    goto yyloop;
-yyoverflow:
-    yyerror("yacc stack overflow");
-yyabort:
-    return (1);
-yyaccept:
-    return (0);
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/error.y
--- a/head/usr.bin/yacc/test/error.y	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-%%
-S: error
-%%
-main(){printf("yyparse() = %d\n",yyparse());}
-yylex(){return-1;}
-yyerror(s)char*s;{printf("%s\n",s);}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/ftp.output
--- a/head/usr.bin/yacc/test/ftp.output	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1625 +0,0 @@
-   0  $accept : cmd_list $end
-
-   1  cmd_list :
-   2           | cmd_list cmd
-   3           | cmd_list rcmd
-
-   4  cmd : USER SP username CRLF
-   5      | PASS SP password CRLF
-   6      | PORT SP host_port CRLF
-   7      | PASV CRLF
-   8      | TYPE SP type_code CRLF
-   9      | STRU SP struct_code CRLF
-  10      | MODE SP mode_code CRLF
-  11      | ALLO SP NUMBER CRLF
-  12      | ALLO SP NUMBER SP R SP NUMBER CRLF
-  13      | RETR check_login SP pathname CRLF
-  14      | STOR check_login SP pathname CRLF
-  15      | APPE check_login SP pathname CRLF
-  16      | NLST check_login CRLF
-  17      | NLST check_login SP STRING CRLF
-  18      | LIST check_login CRLF
-  19      | LIST check_login SP pathname CRLF
-  20      | STAT check_login SP pathname CRLF
-  21      | STAT CRLF
-  22      | DELE check_login SP pathname CRLF
-  23      | RNTO SP pathname CRLF
-  24      | ABOR CRLF
-  25      | CWD check_login CRLF
-  26      | CWD check_login SP pathname CRLF
-  27      | HELP CRLF
-  28      | HELP SP STRING CRLF
-  29      | NOOP CRLF
-  30      | MKD check_login SP pathname CRLF
-  31      | RMD check_login SP pathname CRLF
-  32      | PWD check_login CRLF
-  33      | CDUP check_login CRLF
-  34      | SITE SP HELP CRLF
-  35      | SITE SP HELP SP STRING CRLF
-  36      | SITE SP UMASK check_login CRLF
-  37      | SITE SP UMASK check_login SP octal_number CRLF
-  38      | SITE SP CHMOD check_login SP octal_number SP pathname CRLF
-  39      | SITE SP IDLE CRLF
-  40      | SITE SP IDLE SP NUMBER CRLF
-  41      | STOU check_login SP pathname CRLF
-  42      | SYST CRLF
-  43      | SIZE check_login SP pathname CRLF
-  44      | MDTM check_login SP pathname CRLF
-  45      | QUIT CRLF
-  46      | error CRLF
-
-  47  rcmd : RNFR check_login SP pathname CRLF
-
-  48  username : STRING
-
-  49  password :
-  50           | STRING
-
-  51  byte_size : NUMBER
-
-  52  host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER
-
-  53  form_code : N
-  54            | T
-  55            | C
-
-  56  type_code : A
-  57            | A SP form_code
-  58            | E
-  59            | E SP form_code
-  60            | I
-  61            | L
-  62            | L SP byte_size
-  63            | L byte_size
-
-  64  struct_code : F
-  65              | R
-  66              | P
-
-  67  mode_code : S
-  68            | B
-  69            | C
-
-  70  pathname : pathstring
-
-  71  pathstring : STRING
-
-  72  octal_number : NUMBER
-
-  73  check_login :
-

-state 0
-	$accept : . cmd_list $end  (0)
-	cmd_list : .  (1)
-
-	.  reduce 1
-
-	cmd_list  goto 1
-
-
-state 1
-	$accept : cmd_list . $end  (0)
-	cmd_list : cmd_list . cmd  (2)
-	cmd_list : cmd_list . rcmd  (3)
-
-	$end  accept
-	error  shift 2
-	USER  shift 3
-	PASS  shift 4
-	QUIT  shift 5
-	PORT  shift 6
-	PASV  shift 7
-	TYPE  shift 8
-	STRU  shift 9
-	MODE  shift 10
-	RETR  shift 11
-	STOR  shift 12
-	APPE  shift 13
-	ALLO  shift 14
-	RNFR  shift 15
-	RNTO  shift 16
-	ABOR  shift 17
-	DELE  shift 18
-	CWD  shift 19
-	LIST  shift 20
-	NLST  shift 21
-	SITE  shift 22
-	STAT  shift 23
-	HELP  shift 24
-	NOOP  shift 25
-	MKD  shift 26
-	RMD  shift 27
-	PWD  shift 28
-	CDUP  shift 29
-	STOU  shift 30
-	SYST  shift 31
-	SIZE  shift 32
-	MDTM  shift 33
-	.  error
-
-	cmd  goto 34
-	rcmd  goto 35
-
-
-state 2
-	cmd : error . CRLF  (46)
-
-	CRLF  shift 36
-	.  error
-
-
-state 3
-	cmd : USER . SP username CRLF  (4)
-
-	SP  shift 37
-	.  error
-
-
-state 4
-	cmd : PASS . SP password CRLF  (5)
-
-	SP  shift 38
-	.  error
-
-
-state 5
-	cmd : QUIT . CRLF  (45)
-
-	CRLF  shift 39
-	.  error
-
-
-state 6
-	cmd : PORT . SP host_port CRLF  (6)
-
-	SP  shift 40
-	.  error
-
-
-state 7
-	cmd : PASV . CRLF  (7)
-
-	CRLF  shift 41
-	.  error
-
-
-state 8
-	cmd : TYPE . SP type_code CRLF  (8)
-
-	SP  shift 42
-	.  error
-
-
-state 9
-	cmd : STRU . SP struct_code CRLF  (9)
-
-	SP  shift 43
-	.  error
-
-
-state 10
-	cmd : MODE . SP mode_code CRLF  (10)
-
-	SP  shift 44
-	.  error
-
-
-state 11
-	cmd : RETR . check_login SP pathname CRLF  (13)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 45
-
-
-state 12
-	cmd : STOR . check_login SP pathname CRLF  (14)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 46
-
-
-state 13
-	cmd : APPE . check_login SP pathname CRLF  (15)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 47
-
-
-state 14
-	cmd : ALLO . SP NUMBER CRLF  (11)
-	cmd : ALLO . SP NUMBER SP R SP NUMBER CRLF  (12)
-
-	SP  shift 48
-	.  error
-
-
-state 15
-	rcmd : RNFR . check_login SP pathname CRLF  (47)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 49
-
-
-state 16
-	cmd : RNTO . SP pathname CRLF  (23)
-
-	SP  shift 50
-	.  error
-
-
-state 17
-	cmd : ABOR . CRLF  (24)
-
-	CRLF  shift 51
-	.  error
-
-
-state 18
-	cmd : DELE . check_login SP pathname CRLF  (22)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 52
-
-
-state 19
-	cmd : CWD . check_login CRLF  (25)
-	cmd : CWD . check_login SP pathname CRLF  (26)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 53
-
-
-state 20
-	cmd : LIST . check_login CRLF  (18)
-	cmd : LIST . check_login SP pathname CRLF  (19)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 54
-
-
-state 21
-	cmd : NLST . check_login CRLF  (16)
-	cmd : NLST . check_login SP STRING CRLF  (17)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 55
-
-
-state 22
-	cmd : SITE . SP HELP CRLF  (34)
-	cmd : SITE . SP HELP SP STRING CRLF  (35)
-	cmd : SITE . SP UMASK check_login CRLF  (36)
-	cmd : SITE . SP UMASK check_login SP octal_number CRLF  (37)
-	cmd : SITE . SP CHMOD check_login SP octal_number SP pathname CRLF  (38)
-	cmd : SITE . SP IDLE CRLF  (39)
-	cmd : SITE . SP IDLE SP NUMBER CRLF  (40)
-
-	SP  shift 56
-	.  error
-
-
-state 23
-	cmd : STAT . check_login SP pathname CRLF  (20)
-	cmd : STAT . CRLF  (21)
-	check_login : .  (73)
-
-	CRLF  shift 57
-	SP  reduce 73
-
-	check_login  goto 58
-
-
-state 24
-	cmd : HELP . CRLF  (27)
-	cmd : HELP . SP STRING CRLF  (28)
-
-	SP  shift 59
-	CRLF  shift 60
-	.  error
-
-
-state 25
-	cmd : NOOP . CRLF  (29)
-
-	CRLF  shift 61
-	.  error
-
-
-state 26
-	cmd : MKD . check_login SP pathname CRLF  (30)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 62
-
-
-state 27
-	cmd : RMD . check_login SP pathname CRLF  (31)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 63
-
-
-state 28
-	cmd : PWD . check_login CRLF  (32)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 64
-
-
-state 29
-	cmd : CDUP . check_login CRLF  (33)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 65
-
-
-state 30
-	cmd : STOU . check_login SP pathname CRLF  (41)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 66
-
-
-state 31
-	cmd : SYST . CRLF  (42)
-
-	CRLF  shift 67
-	.  error
-
-
-state 32
-	cmd : SIZE . check_login SP pathname CRLF  (43)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 68
-
-
-state 33
-	cmd : MDTM . check_login SP pathname CRLF  (44)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 69
-
-
-state 34
-	cmd_list : cmd_list cmd .  (2)
-
-	.  reduce 2
-
-
-state 35
-	cmd_list : cmd_list rcmd .  (3)
-
-	.  reduce 3
-
-
-state 36
-	cmd : error CRLF .  (46)
-
-	.  reduce 46
-
-
-state 37
-	cmd : USER SP . username CRLF  (4)
-
-	STRING  shift 70
-	.  error
-
-	username  goto 71
-
-
-state 38
-	cmd : PASS SP . password CRLF  (5)
-	password : .  (49)
-
-	STRING  shift 72
-	CRLF  reduce 49
-
-	password  goto 73
-
-
-state 39
-	cmd : QUIT CRLF .  (45)
-
-	.  reduce 45
-
-
-state 40
-	cmd : PORT SP . host_port CRLF  (6)
-
-	NUMBER  shift 74
-	.  error
-
-	host_port  goto 75
-
-
-state 41
-	cmd : PASV CRLF .  (7)
-
-	.  reduce 7
-
-
-state 42
-	cmd : TYPE SP . type_code CRLF  (8)
-
-	A  shift 76
-	E  shift 77
-	I  shift 78
-	L  shift 79
-	.  error
-
-	type_code  goto 80
-
-
-state 43
-	cmd : STRU SP . struct_code CRLF  (9)
-
-	F  shift 81
-	P  shift 82
-	R  shift 83
-	.  error
-
-	struct_code  goto 84
-
-
-state 44
-	cmd : MODE SP . mode_code CRLF  (10)
-
-	B  shift 85
-	C  shift 86
-	S  shift 87
-	.  error
-
-	mode_code  goto 88
-
-
-state 45
-	cmd : RETR check_login . SP pathname CRLF  (13)
-
-	SP  shift 89
-	.  error
-
-
-state 46
-	cmd : STOR check_login . SP pathname CRLF  (14)
-
-	SP  shift 90
-	.  error
-
-
-state 47
-	cmd : APPE check_login . SP pathname CRLF  (15)
-
-	SP  shift 91
-	.  error
-
-
-state 48
-	cmd : ALLO SP . NUMBER CRLF  (11)
-	cmd : ALLO SP . NUMBER SP R SP NUMBER CRLF  (12)
-
-	NUMBER  shift 92
-	.  error
-
-
-state 49
-	rcmd : RNFR check_login . SP pathname CRLF  (47)
-
-	SP  shift 93
-	.  error
-
-
-state 50
-	cmd : RNTO SP . pathname CRLF  (23)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 95
-	pathstring  goto 96
-
-
-state 51
-	cmd : ABOR CRLF .  (24)
-
-	.  reduce 24
-
-
-state 52
-	cmd : DELE check_login . SP pathname CRLF  (22)
-
-	SP  shift 97
-	.  error
-
-
-state 53
-	cmd : CWD check_login . CRLF  (25)
-	cmd : CWD check_login . SP pathname CRLF  (26)
-
-	SP  shift 98
-	CRLF  shift 99
-	.  error
-
-
-state 54
-	cmd : LIST check_login . CRLF  (18)
-	cmd : LIST check_login . SP pathname CRLF  (19)
-
-	SP  shift 100
-	CRLF  shift 101
-	.  error
-
-
-state 55
-	cmd : NLST check_login . CRLF  (16)
-	cmd : NLST check_login . SP STRING CRLF  (17)
-
-	SP  shift 102
-	CRLF  shift 103
-	.  error
-
-
-state 56
-	cmd : SITE SP . HELP CRLF  (34)
-	cmd : SITE SP . HELP SP STRING CRLF  (35)
-	cmd : SITE SP . UMASK check_login CRLF  (36)
-	cmd : SITE SP . UMASK check_login SP octal_number CRLF  (37)
-	cmd : SITE SP . CHMOD check_login SP octal_number SP pathname CRLF  (38)
-	cmd : SITE SP . IDLE CRLF  (39)
-	cmd : SITE SP . IDLE SP NUMBER CRLF  (40)
-
-	HELP  shift 104
-	UMASK  shift 105
-	IDLE  shift 106
-	CHMOD  shift 107
-	.  error
-
-
-state 57
-	cmd : STAT CRLF .  (21)
-
-	.  reduce 21
-
-
-state 58
-	cmd : STAT check_login . SP pathname CRLF  (20)
-
-	SP  shift 108
-	.  error
-
-
-state 59
-	cmd : HELP SP . STRING CRLF  (28)
-
-	STRING  shift 109
-	.  error
-
-
-state 60
-	cmd : HELP CRLF .  (27)
-
-	.  reduce 27
-
-
-state 61
-	cmd : NOOP CRLF .  (29)
-
-	.  reduce 29
-
-
-state 62
-	cmd : MKD check_login . SP pathname CRLF  (30)
-
-	SP  shift 110
-	.  error
-
-
-state 63
-	cmd : RMD check_login . SP pathname CRLF  (31)
-
-	SP  shift 111
-	.  error
-
-
-state 64
-	cmd : PWD check_login . CRLF  (32)
-
-	CRLF  shift 112
-	.  error
-
-
-state 65
-	cmd : CDUP check_login . CRLF  (33)
-
-	CRLF  shift 113
-	.  error
-
-
-state 66
-	cmd : STOU check_login . SP pathname CRLF  (41)
-
-	SP  shift 114
-	.  error
-
-
-state 67
-	cmd : SYST CRLF .  (42)
-
-	.  reduce 42
-
-
-state 68
-	cmd : SIZE check_login . SP pathname CRLF  (43)
-
-	SP  shift 115
-	.  error
-
-
-state 69
-	cmd : MDTM check_login . SP pathname CRLF  (44)
-
-	SP  shift 116
-	.  error
-
-
-state 70
-	username : STRING .  (48)
-
-	.  reduce 48
-
-
-state 71
-	cmd : USER SP username . CRLF  (4)
-
-	CRLF  shift 117
-	.  error
-
-
-state 72
-	password : STRING .  (50)
-
-	.  reduce 50
-
-
-state 73
-	cmd : PASS SP password . CRLF  (5)
-
-	CRLF  shift 118
-	.  error
-
-
-state 74
-	host_port : NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER  (52)
-
-	COMMA  shift 119
-	.  error
-
-
-state 75
-	cmd : PORT SP host_port . CRLF  (6)
-
-	CRLF  shift 120
-	.  error
-
-
-state 76
-	type_code : A .  (56)
-	type_code : A . SP form_code  (57)
-
-	SP  shift 121
-	CRLF  reduce 56
-
-
-state 77
-	type_code : E .  (58)
-	type_code : E . SP form_code  (59)
-
-	SP  shift 122
-	CRLF  reduce 58
-
-
-state 78
-	type_code : I .  (60)
-
-	.  reduce 60
-
-
-state 79
-	type_code : L .  (61)
-	type_code : L . SP byte_size  (62)
-	type_code : L . byte_size  (63)
-
-	SP  shift 123
-	NUMBER  shift 124
-	CRLF  reduce 61
-
-	byte_size  goto 125
-
-
-state 80
-	cmd : TYPE SP type_code . CRLF  (8)
-
-	CRLF  shift 126
-	.  error
-
-
-state 81
-	struct_code : F .  (64)
-
-	.  reduce 64
-
-
-state 82
-	struct_code : P .  (66)
-
-	.  reduce 66
-
-
-state 83
-	struct_code : R .  (65)
-
-	.  reduce 65
-
-
-state 84
-	cmd : STRU SP struct_code . CRLF  (9)
-
-	CRLF  shift 127
-	.  error
-
-
-state 85
-	mode_code : B .  (68)
-
-	.  reduce 68
-
-
-state 86
-	mode_code : C .  (69)
-
-	.  reduce 69
-
-
-state 87
-	mode_code : S .  (67)
-
-	.  reduce 67
-
-
-state 88
-	cmd : MODE SP mode_code . CRLF  (10)
-
-	CRLF  shift 128
-	.  error
-
-
-state 89
-	cmd : RETR check_login SP . pathname CRLF  (13)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 129
-	pathstring  goto 96
-
-
-state 90
-	cmd : STOR check_login SP . pathname CRLF  (14)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 130
-	pathstring  goto 96
-
-
-state 91
-	cmd : APPE check_login SP . pathname CRLF  (15)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 131
-	pathstring  goto 96
-
-
-state 92
-	cmd : ALLO SP NUMBER . CRLF  (11)
-	cmd : ALLO SP NUMBER . SP R SP NUMBER CRLF  (12)
-
-	SP  shift 132
-	CRLF  shift 133
-	.  error
-
-
-state 93
-	rcmd : RNFR check_login SP . pathname CRLF  (47)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 134
-	pathstring  goto 96
-
-
-state 94
-	pathstring : STRING .  (71)
-
-	.  reduce 71
-
-
-state 95
-	cmd : RNTO SP pathname . CRLF  (23)
-
-	CRLF  shift 135
-	.  error
-
-
-state 96
-	pathname : pathstring .  (70)
-
-	.  reduce 70
-
-
-state 97
-	cmd : DELE check_login SP . pathname CRLF  (22)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 136
-	pathstring  goto 96
-
-
-state 98
-	cmd : CWD check_login SP . pathname CRLF  (26)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 137
-	pathstring  goto 96
-
-
-state 99
-	cmd : CWD check_login CRLF .  (25)
-
-	.  reduce 25
-
-
-state 100
-	cmd : LIST check_login SP . pathname CRLF  (19)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 138
-	pathstring  goto 96
-
-
-state 101
-	cmd : LIST check_login CRLF .  (18)
-
-	.  reduce 18
-
-
-state 102
-	cmd : NLST check_login SP . STRING CRLF  (17)
-
-	STRING  shift 139
-	.  error
-
-
-state 103
-	cmd : NLST check_login CRLF .  (16)
-
-	.  reduce 16
-
-
-state 104
-	cmd : SITE SP HELP . CRLF  (34)
-	cmd : SITE SP HELP . SP STRING CRLF  (35)
-
-	SP  shift 140
-	CRLF  shift 141
-	.  error
-
-
-state 105
-	cmd : SITE SP UMASK . check_login CRLF  (36)
-	cmd : SITE SP UMASK . check_login SP octal_number CRLF  (37)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 142
-
-
-state 106
-	cmd : SITE SP IDLE . CRLF  (39)
-	cmd : SITE SP IDLE . SP NUMBER CRLF  (40)
-
-	SP  shift 143
-	CRLF  shift 144
-	.  error
-
-
-state 107
-	cmd : SITE SP CHMOD . check_login SP octal_number SP pathname CRLF  (38)
-	check_login : .  (73)
-
-	.  reduce 73
-
-	check_login  goto 145
-
-
-state 108
-	cmd : STAT check_login SP . pathname CRLF  (20)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 146
-	pathstring  goto 96
-
-
-state 109
-	cmd : HELP SP STRING . CRLF  (28)
-
-	CRLF  shift 147
-	.  error
-
-
-state 110
-	cmd : MKD check_login SP . pathname CRLF  (30)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 148
-	pathstring  goto 96
-
-
-state 111
-	cmd : RMD check_login SP . pathname CRLF  (31)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 149
-	pathstring  goto 96
-
-
-state 112
-	cmd : PWD check_login CRLF .  (32)
-
-	.  reduce 32
-
-
-state 113
-	cmd : CDUP check_login CRLF .  (33)
-
-	.  reduce 33
-
-
-state 114
-	cmd : STOU check_login SP . pathname CRLF  (41)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 150
-	pathstring  goto 96
-
-
-state 115
-	cmd : SIZE check_login SP . pathname CRLF  (43)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 151
-	pathstring  goto 96
-
-
-state 116
-	cmd : MDTM check_login SP . pathname CRLF  (44)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 152
-	pathstring  goto 96
-
-
-state 117
-	cmd : USER SP username CRLF .  (4)
-
-	.  reduce 4
-
-
-state 118
-	cmd : PASS SP password CRLF .  (5)
-
-	.  reduce 5
-
-
-state 119
-	host_port : NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER  (52)
-
-	NUMBER  shift 153
-	.  error
-
-
-state 120
-	cmd : PORT SP host_port CRLF .  (6)
-
-	.  reduce 6
-
-
-state 121
-	type_code : A SP . form_code  (57)
-
-	C  shift 154
-	N  shift 155
-	T  shift 156
-	.  error
-
-	form_code  goto 157
-
-
-state 122
-	type_code : E SP . form_code  (59)
-
-	C  shift 154
-	N  shift 155
-	T  shift 156
-	.  error
-
-	form_code  goto 158
-
-
-state 123
-	type_code : L SP . byte_size  (62)
-
-	NUMBER  shift 124
-	.  error
-
-	byte_size  goto 159
-
-
-state 124
-	byte_size : NUMBER .  (51)
-
-	.  reduce 51
-
-
-state 125
-	type_code : L byte_size .  (63)
-
-	.  reduce 63
-
-
-state 126
-	cmd : TYPE SP type_code CRLF .  (8)
-
-	.  reduce 8
-
-
-state 127
-	cmd : STRU SP struct_code CRLF .  (9)
-
-	.  reduce 9
-
-
-state 128
-	cmd : MODE SP mode_code CRLF .  (10)
-
-	.  reduce 10
-
-
-state 129
-	cmd : RETR check_login SP pathname . CRLF  (13)
-
-	CRLF  shift 160
-	.  error
-
-
-state 130
-	cmd : STOR check_login SP pathname . CRLF  (14)
-
-	CRLF  shift 161
-	.  error
-
-
-state 131
-	cmd : APPE check_login SP pathname . CRLF  (15)
-
-	CRLF  shift 162
-	.  error
-
-
-state 132
-	cmd : ALLO SP NUMBER SP . R SP NUMBER CRLF  (12)
-
-	R  shift 163
-	.  error
-
-
-state 133
-	cmd : ALLO SP NUMBER CRLF .  (11)
-
-	.  reduce 11
-
-
-state 134
-	rcmd : RNFR check_login SP pathname . CRLF  (47)
-
-	CRLF  shift 164
-	.  error
-
-
-state 135
-	cmd : RNTO SP pathname CRLF .  (23)
-
-	.  reduce 23
-
-
-state 136
-	cmd : DELE check_login SP pathname . CRLF  (22)
-
-	CRLF  shift 165
-	.  error
-
-
-state 137
-	cmd : CWD check_login SP pathname . CRLF  (26)
-
-	CRLF  shift 166
-	.  error
-
-
-state 138
-	cmd : LIST check_login SP pathname . CRLF  (19)
-
-	CRLF  shift 167
-	.  error
-
-
-state 139
-	cmd : NLST check_login SP STRING . CRLF  (17)
-
-	CRLF  shift 168
-	.  error
-
-
-state 140
-	cmd : SITE SP HELP SP . STRING CRLF  (35)
-
-	STRING  shift 169
-	.  error
-
-
-state 141
-	cmd : SITE SP HELP CRLF .  (34)
-
-	.  reduce 34
-
-
-state 142
-	cmd : SITE SP UMASK check_login . CRLF  (36)
-	cmd : SITE SP UMASK check_login . SP octal_number CRLF  (37)
-
-	SP  shift 170
-	CRLF  shift 171
-	.  error
-
-
-state 143
-	cmd : SITE SP IDLE SP . NUMBER CRLF  (40)
-
-	NUMBER  shift 172
-	.  error
-
-
-state 144
-	cmd : SITE SP IDLE CRLF .  (39)
-
-	.  reduce 39
-
-
-state 145
-	cmd : SITE SP CHMOD check_login . SP octal_number SP pathname CRLF  (38)
-
-	SP  shift 173
-	.  error
-
-
-state 146
-	cmd : STAT check_login SP pathname . CRLF  (20)
-
-	CRLF  shift 174
-	.  error
-
-
-state 147
-	cmd : HELP SP STRING CRLF .  (28)
-
-	.  reduce 28
-
-
-state 148
-	cmd : MKD check_login SP pathname . CRLF  (30)
-
-	CRLF  shift 175
-	.  error
-
-
-state 149
-	cmd : RMD check_login SP pathname . CRLF  (31)
-
-	CRLF  shift 176
-	.  error
-
-
-state 150
-	cmd : STOU check_login SP pathname . CRLF  (41)
-
-	CRLF  shift 177
-	.  error
-
-
-state 151
-	cmd : SIZE check_login SP pathname . CRLF  (43)
-
-	CRLF  shift 178
-	.  error
-
-
-state 152
-	cmd : MDTM check_login SP pathname . CRLF  (44)
-
-	CRLF  shift 179
-	.  error
-
-
-state 153
-	host_port : NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER  (52)
-
-	COMMA  shift 180
-	.  error
-
-
-state 154
-	form_code : C .  (55)
-
-	.  reduce 55
-
-
-state 155
-	form_code : N .  (53)
-
-	.  reduce 53
-
-
-state 156
-	form_code : T .  (54)
-
-	.  reduce 54
-
-
-state 157
-	type_code : A SP form_code .  (57)
-
-	.  reduce 57
-
-
-state 158
-	type_code : E SP form_code .  (59)
-
-	.  reduce 59
-
-
-state 159
-	type_code : L SP byte_size .  (62)
-
-	.  reduce 62
-
-
-state 160
-	cmd : RETR check_login SP pathname CRLF .  (13)
-
-	.  reduce 13
-
-
-state 161
-	cmd : STOR check_login SP pathname CRLF .  (14)
-
-	.  reduce 14
-
-
-state 162
-	cmd : APPE check_login SP pathname CRLF .  (15)
-
-	.  reduce 15
-
-
-state 163
-	cmd : ALLO SP NUMBER SP R . SP NUMBER CRLF  (12)
-
-	SP  shift 181
-	.  error
-
-
-state 164
-	rcmd : RNFR check_login SP pathname CRLF .  (47)
-
-	.  reduce 47
-
-
-state 165
-	cmd : DELE check_login SP pathname CRLF .  (22)
-
-	.  reduce 22
-
-
-state 166
-	cmd : CWD check_login SP pathname CRLF .  (26)
-
-	.  reduce 26
-
-
-state 167
-	cmd : LIST check_login SP pathname CRLF .  (19)
-
-	.  reduce 19
-
-
-state 168
-	cmd : NLST check_login SP STRING CRLF .  (17)
-
-	.  reduce 17
-
-
-state 169
-	cmd : SITE SP HELP SP STRING . CRLF  (35)
-
-	CRLF  shift 182
-	.  error
-
-
-state 170
-	cmd : SITE SP UMASK check_login SP . octal_number CRLF  (37)
-
-	NUMBER  shift 183
-	.  error
-
-	octal_number  goto 184
-
-
-state 171
-	cmd : SITE SP UMASK check_login CRLF .  (36)
-
-	.  reduce 36
-
-
-state 172
-	cmd : SITE SP IDLE SP NUMBER . CRLF  (40)
-
-	CRLF  shift 185
-	.  error
-
-
-state 173
-	cmd : SITE SP CHMOD check_login SP . octal_number SP pathname CRLF  (38)
-
-	NUMBER  shift 183
-	.  error
-
-	octal_number  goto 186
-
-
-state 174
-	cmd : STAT check_login SP pathname CRLF .  (20)
-
-	.  reduce 20
-
-
-state 175
-	cmd : MKD check_login SP pathname CRLF .  (30)
-
-	.  reduce 30
-
-
-state 176
-	cmd : RMD check_login SP pathname CRLF .  (31)
-
-	.  reduce 31
-
-
-state 177
-	cmd : STOU check_login SP pathname CRLF .  (41)
-
-	.  reduce 41
-
-
-state 178
-	cmd : SIZE check_login SP pathname CRLF .  (43)
-
-	.  reduce 43
-
-
-state 179
-	cmd : MDTM check_login SP pathname CRLF .  (44)
-
-	.  reduce 44
-
-
-state 180
-	host_port : NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER  (52)
-
-	NUMBER  shift 187
-	.  error
-
-
-state 181
-	cmd : ALLO SP NUMBER SP R SP . NUMBER CRLF  (12)
-
-	NUMBER  shift 188
-	.  error
-
-
-state 182
-	cmd : SITE SP HELP SP STRING CRLF .  (35)
-
-	.  reduce 35
-
-
-state 183
-	octal_number : NUMBER .  (72)
-
-	.  reduce 72
-
-
-state 184
-	cmd : SITE SP UMASK check_login SP octal_number . CRLF  (37)
-
-	CRLF  shift 189
-	.  error
-
-
-state 185
-	cmd : SITE SP IDLE SP NUMBER CRLF .  (40)
-
-	.  reduce 40
-
-
-state 186
-	cmd : SITE SP CHMOD check_login SP octal_number . SP pathname CRLF  (38)
-
-	SP  shift 190
-	.  error
-
-
-state 187
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER  (52)
-
-	COMMA  shift 191
-	.  error
-
-
-state 188
-	cmd : ALLO SP NUMBER SP R SP NUMBER . CRLF  (12)
-
-	CRLF  shift 192
-	.  error
-
-
-state 189
-	cmd : SITE SP UMASK check_login SP octal_number CRLF .  (37)
-
-	.  reduce 37
-
-
-state 190
-	cmd : SITE SP CHMOD check_login SP octal_number SP . pathname CRLF  (38)
-
-	STRING  shift 94
-	.  error
-
-	pathname  goto 193
-	pathstring  goto 96
-
-
-state 191
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER  (52)
-
-	NUMBER  shift 194
-	.  error
-
-
-state 192
-	cmd : ALLO SP NUMBER SP R SP NUMBER CRLF .  (12)
-
-	.  reduce 12
-
-
-state 193
-	cmd : SITE SP CHMOD check_login SP octal_number SP pathname . CRLF  (38)
-
-	CRLF  shift 195
-	.  error
-
-
-state 194
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER  (52)
-
-	COMMA  shift 196
-	.  error
-
-
-state 195
-	cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF .  (38)
-
-	.  reduce 38
-
-
-state 196
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER  (52)
-
-	NUMBER  shift 197
-	.  error
-
-
-state 197
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER  (52)
-
-	COMMA  shift 198
-	.  error
-
-
-state 198
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER  (52)
-
-	NUMBER  shift 199
-	.  error
-
-
-state 199
-	host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER .  (52)
-
-	.  reduce 52
-
-
-65 terminals, 16 nonterminals
-74 grammar rules, 200 states
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/ftp.tab.c
--- a/head/usr.bin/yacc/test/ftp.tab.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1785 +0,0 @@
-#ifndef lint
-static char const yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93";
-#endif
-#include <stdlib.h>
-#define YYBYACC 1
-#define YYMAJOR 1
-#define YYMINOR 9
-#define YYLEX yylex()
-#define YYEMPTY -1
-#define yyclearin (yychar=(YYEMPTY))
-#define yyerrok (yyerrflag=0)
-#define YYRECOVERING (yyerrflag!=0)
-#if defined(c_plusplus) || defined(__cplusplus)
-#include <stdlib.h>
-#else
-extern char *getenv();
-extern void *realloc();
-#endif
-static int yygrowstack();
-#define YYPREFIX "yy"
-#line 26 "ftp.y"
-
-#ifndef lint
-static char sccsid[] = "@(#)ftpcmd.y	5.20.1.1 (Berkeley) 3/2/89";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-
-#include <arpa/ftp.h>
-
-#include <stdio.h>
-#include <signal.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <setjmp.h>
-#include <syslog.h>
-#include <sys/stat.h>
-#include <time.h>
-
-extern	struct sockaddr_in data_dest;
-extern	int logged_in;
-extern	struct passwd *pw;
-extern	int guest;
-extern	int logging;
-extern	int type;
-extern	int form;
-extern	int debug;
-extern	int timeout;
-extern	int maxtimeout;
-extern  int pdata;
-extern	char hostname[], remotehost[];
-extern	char proctitle[];
-extern	char *globerr;
-extern	int usedefault;
-extern  int transflag;
-extern  char tmpline[];
-char	**glob();
-
-static	int cmd_type;
-static	int cmd_form;
-static	int cmd_bytesz;
-char	cbuf[512];
-char	*fromname;
-
-char	*index();
-#line 70 "ftp.tab.c"
-#define A 257
-#define B 258
-#define C 259
-#define E 260
-#define F 261
-#define I 262
-#define L 263
-#define N 264
-#define P 265
-#define R 266
-#define S 267
-#define T 268
-#define SP 269
-#define CRLF 270
-#define COMMA 271
-#define STRING 272
-#define NUMBER 273
-#define USER 274
-#define PASS 275
-#define ACCT 276
-#define REIN 277
-#define QUIT 278
-#define PORT 279
-#define PASV 280
-#define TYPE 281
-#define STRU 282
-#define MODE 283
-#define RETR 284
-#define STOR 285
-#define APPE 286
-#define MLFL 287
-#define MAIL 288
-#define MSND 289
-#define MSOM 290
-#define MSAM 291
-#define MRSQ 292
-#define MRCP 293
-#define ALLO 294
-#define REST 295
-#define RNFR 296
-#define RNTO 297
-#define ABOR 298
-#define DELE 299
-#define CWD 300
-#define LIST 301
-#define NLST 302
-#define SITE 303
-#define STAT 304
-#define HELP 305
-#define NOOP 306
-#define MKD 307
-#define RMD 308
-#define PWD 309
-#define CDUP 310
-#define STOU 311
-#define SMNT 312
-#define SYST 313
-#define SIZE 314
-#define MDTM 315
-#define UMASK 316
-#define IDLE 317
-#define CHMOD 318
-#define LEXERR 319
-#define YYERRCODE 256
-const short yylhs[] = {                                        -1,
-    0,    0,    0,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    1,    1,    1,    1,    2,    3,    4,    4,
-   12,    5,   13,   13,   13,    6,    6,    6,    6,    6,
-    6,    6,    6,    7,    7,    7,    8,    8,    8,   10,
-   14,   11,    9,
-};
-const short yylen[] = {                                         2,
-    0,    2,    2,    4,    4,    4,    2,    4,    4,    4,
-    4,    8,    5,    5,    5,    3,    5,    3,    5,    5,
-    2,    5,    4,    2,    3,    5,    2,    4,    2,    5,
-    5,    3,    3,    4,    6,    5,    7,    9,    4,    6,
-    5,    2,    5,    5,    2,    2,    5,    1,    0,    1,
-    1,   11,    1,    1,    1,    1,    3,    1,    3,    1,
-    1,    3,    2,    1,    1,    1,    1,    1,    1,    1,
-    1,    1,    0,
-};
-const short yydefred[] = {                                      1,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-   73,   73,   73,    0,   73,    0,    0,   73,   73,   73,
-   73,    0,    0,    0,    0,   73,   73,   73,   73,   73,
-    0,   73,   73,    2,    3,   46,    0,    0,   45,    0,
-    7,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-   24,    0,    0,    0,    0,    0,   21,    0,    0,   27,
-   29,    0,    0,    0,    0,    0,   42,    0,    0,   48,
-    0,   50,    0,    0,    0,    0,    0,   60,    0,    0,
-   64,   66,   65,    0,   68,   69,   67,    0,    0,    0,
-    0,    0,    0,   71,    0,   70,    0,    0,   25,    0,
-   18,    0,   16,    0,   73,    0,   73,    0,    0,    0,
-    0,   32,   33,    0,    0,    0,    4,    5,    0,    6,
-    0,    0,    0,   51,   63,    8,    9,   10,    0,    0,
-    0,    0,   11,    0,   23,    0,    0,    0,    0,    0,
-   34,    0,    0,   39,    0,    0,   28,    0,    0,    0,
-    0,    0,    0,   55,   53,   54,   57,   59,   62,   13,
-   14,   15,    0,   47,   22,   26,   19,   17,    0,    0,
-   36,    0,    0,   20,   30,   31,   41,   43,   44,    0,
-    0,   35,   72,    0,   40,    0,    0,    0,   37,    0,
-    0,   12,    0,    0,   38,    0,    0,    0,   52,
-};
-const short yydgoto[] = {                                       1,
-   34,   35,   71,   73,   75,   80,   84,   88,   45,   95,
-  184,  125,  157,   96,
-};
-const short yysindex[] = {                                      0,
- -224, -247, -239, -236, -232, -222, -204, -200, -181, -177,
-    0,    0,    0, -166,    0, -161, -199,    0,    0,    0,
-    0, -160, -159, -264, -158,    0,    0,    0,    0,    0,
- -157,    0,    0,    0,    0,    0, -167, -162,    0, -156,
-    0, -250, -198, -165, -155, -154, -153, -151, -150, -152,
-    0, -145, -252, -229, -217, -302,    0, -144, -146,    0,
-    0, -142, -141, -140, -139, -137,    0, -136, -135,    0,
- -134,    0, -133, -132, -130, -131, -128,    0, -249, -127,
-    0,    0,    0, -126,    0,    0,    0, -125, -152, -152,
- -152, -205, -152,    0, -124,    0, -152, -152,    0, -152,
-    0, -143,    0, -173,    0, -171,    0, -152, -123, -152,
- -152,    0,    0, -152, -152, -152,    0,    0, -138,    0,
- -164, -164, -122,    0,    0,    0,    0,    0, -121, -120,
- -118, -148,    0, -117,    0, -116, -115, -114, -113, -112,
-    0, -163, -111,    0, -110, -109,    0, -107, -106, -105,
- -104, -103, -129,    0,    0,    0,    0,    0,    0,    0,
-    0,    0, -101,    0,    0,    0,    0,    0, -100, -102,
-    0,  -98, -102,    0,    0,    0,    0,    0,    0,  -99,
-  -97,    0,    0,  -95,    0,  -96,  -94,  -92,    0, -152,
-  -93,    0,  -91,  -90,    0,  -88,  -87,  -86,    0,
-};
-const short yyrindex[] = {                                      0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,  -83,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,  -82,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,  -81,  -80,    0, -158,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
-    0,    0,    0,    0,    0,    0,    0,    0,    0,
-};
-const short yygindex[] = {                                      0,
-    0,    0,    0,    0,    0,    0,    0,    0,   16,  -89,
-  -25,   35,   47,    0,
-};
-#define YYTABLESIZE 190
-const short yytable[] = {                                     129,
-  130,  131,  104,  134,   59,   60,   76,  136,  137,   77,
-  138,   78,   79,  105,  106,  107,   98,   99,  146,  123,
-  148,  149,   36,  124,  150,  151,  152,   46,   47,   37,
-   49,    2,   38,   52,   53,   54,   55,   39,   58,  100,
-  101,   62,   63,   64,   65,   66,   40,   68,   69,    3,
-    4,  102,  103,    5,    6,    7,    8,    9,   10,   11,
-   12,   13,   81,  132,  133,   41,   82,   83,   42,   14,
-   51,   15,   16,   17,   18,   19,   20,   21,   22,   23,
-   24,   25,   26,   27,   28,   29,   30,   43,   31,   32,
-   33,   44,   85,   86,  154,  140,  141,  143,  144,  155,
-  193,   87,   48,  156,   70,  170,  171,   50,   56,   72,
-   57,   61,   67,   89,   90,   91,   74,  163,   93,   94,
-  142,   92,  145,   97,  108,  109,  110,  111,  139,  112,
-  113,  114,  115,  116,  153,  117,  118,  121,  119,  120,
-  122,  180,  126,  127,  128,  135,  147,  186,  160,  161,
-  124,  162,  164,  165,  166,  167,  168,  159,  173,  169,
-  174,  172,  175,  176,  177,  178,  179,  181,  158,  182,
-  183,  185,  190,  187,  189,  188,  191,  192,  195,  194,
-  196,    0,    0,  198,  197,   73,  199,   49,   56,   58,
-};
-const short yycheck[] = {                                      89,
-   90,   91,  305,   93,  269,  270,  257,   97,   98,  260,
-  100,  262,  263,  316,  317,  318,  269,  270,  108,  269,
-  110,  111,  270,  273,  114,  115,  116,   12,   13,  269,
-   15,  256,  269,   18,   19,   20,   21,  270,   23,  269,
-  270,   26,   27,   28,   29,   30,  269,   32,   33,  274,
-  275,  269,  270,  278,  279,  280,  281,  282,  283,  284,
-  285,  286,  261,  269,  270,  270,  265,  266,  269,  294,
-  270,  296,  297,  298,  299,  300,  301,  302,  303,  304,
-  305,  306,  307,  308,  309,  310,  311,  269,  313,  314,
-  315,  269,  258,  259,  259,  269,  270,  269,  270,  264,
-  190,  267,  269,  268,  272,  269,  270,  269,  269,  272,
-  270,  270,  270,  269,  269,  269,  273,  266,  269,  272,
-  105,  273,  107,  269,  269,  272,  269,  269,  272,  270,
-  270,  269,  269,  269,  273,  270,  270,  269,  271,  270,
-  269,  271,  270,  270,  270,  270,  270,  173,  270,  270,
-  273,  270,  270,  270,  270,  270,  270,  123,  269,  272,
-  270,  273,  270,  270,  270,  270,  270,  269,  122,  270,
-  273,  270,  269,  273,  270,  273,  271,  270,  270,  273,
-  271,   -1,   -1,  271,  273,  269,  273,  270,  270,  270,
-};
-#define YYFINAL 1
-#ifndef YYDEBUG
-#define YYDEBUG 0
-#elif YYDEBUG
-#include <stdio.h>
-#endif
-#define YYMAXTOKEN 319
-#if YYDEBUG
-const char * const yyname[] = {
-"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"A","B","C","E","F","I","L","N",
-"P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER","PASS","ACCT",
-"REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL",
-"MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR",
-"DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP",
-"STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR",
-};
-const char * const yyrule[] = {
-"$accept : cmd_list",
-"cmd_list :",
-"cmd_list : cmd_list cmd",
-"cmd_list : cmd_list rcmd",
-"cmd : USER SP username CRLF",
-"cmd : PASS SP password CRLF",
-"cmd : PORT SP host_port CRLF",
-"cmd : PASV CRLF",
-"cmd : TYPE SP type_code CRLF",
-"cmd : STRU SP struct_code CRLF",
-"cmd : MODE SP mode_code CRLF",
-"cmd : ALLO SP NUMBER CRLF",
-"cmd : ALLO SP NUMBER SP R SP NUMBER CRLF",
-"cmd : RETR check_login SP pathname CRLF",
-"cmd : STOR check_login SP pathname CRLF",
-"cmd : APPE check_login SP pathname CRLF",
-"cmd : NLST check_login CRLF",
-"cmd : NLST check_login SP STRING CRLF",
-"cmd : LIST check_login CRLF",
-"cmd : LIST check_login SP pathname CRLF",
-"cmd : STAT check_login SP pathname CRLF",
-"cmd : STAT CRLF",
-"cmd : DELE check_login SP pathname CRLF",
-"cmd : RNTO SP pathname CRLF",
-"cmd : ABOR CRLF",
-"cmd : CWD check_login CRLF",
-"cmd : CWD check_login SP pathname CRLF",
-"cmd : HELP CRLF",
-"cmd : HELP SP STRING CRLF",
-"cmd : NOOP CRLF",
-"cmd : MKD check_login SP pathname CRLF",
-"cmd : RMD check_login SP pathname CRLF",
-"cmd : PWD check_login CRLF",
-"cmd : CDUP check_login CRLF",
-"cmd : SITE SP HELP CRLF",
-"cmd : SITE SP HELP SP STRING CRLF",
-"cmd : SITE SP UMASK check_login CRLF",
-"cmd : SITE SP UMASK check_login SP octal_number CRLF",
-"cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF",
-"cmd : SITE SP IDLE CRLF",
-"cmd : SITE SP IDLE SP NUMBER CRLF",
-"cmd : STOU check_login SP pathname CRLF",
-"cmd : SYST CRLF",
-"cmd : SIZE check_login SP pathname CRLF",
-"cmd : MDTM check_login SP pathname CRLF",
-"cmd : QUIT CRLF",
-"cmd : error CRLF",
-"rcmd : RNFR check_login SP pathname CRLF",
-"username : STRING",
-"password :",
-"password : STRING",
-"byte_size : NUMBER",
-"host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER",
-"form_code : N",
-"form_code : T",
-"form_code : C",
-"type_code : A",
-"type_code : A SP form_code",
-"type_code : E",
-"type_code : E SP form_code",
-"type_code : I",
-"type_code : L",
-"type_code : L SP byte_size",
-"type_code : L byte_size",
-"struct_code : F",
-"struct_code : R",
-"struct_code : P",
-"mode_code : S",
-"mode_code : B",
-"mode_code : C",
-"pathname : pathstring",
-"pathstring : STRING",
-"octal_number : NUMBER",
-"check_login :",
-};
-#endif
-#ifndef YYSTYPE
-typedef int YYSTYPE;
-#endif
-#ifdef YYSTACKSIZE
-#undef YYMAXDEPTH
-#define YYMAXDEPTH YYSTACKSIZE
-#else
-#ifdef YYMAXDEPTH
-#define YYSTACKSIZE YYMAXDEPTH
-#else
-#define YYSTACKSIZE 10000
-#define YYMAXDEPTH 10000
-#endif
-#endif
-#define YYINITSTACKSIZE 200
-int yydebug;
-int yynerrs;
-int yyerrflag;
-int yychar;
-short *yyssp;
-YYSTYPE *yyvsp;
-YYSTYPE yyval;
-YYSTYPE yylval;
-short *yyss;
-short *yysslim;
-YYSTYPE *yyvs;
-int yystacksize;
-#line 658 "ftp.y"
-
-extern jmp_buf errcatch;
-
-#define	CMD	0	/* beginning of command */
-#define	ARGS	1	/* expect miscellaneous arguments */
-#define	STR1	2	/* expect SP followed by STRING */
-#define	STR2	3	/* expect STRING */
-#define	OSTR	4	/* optional SP then STRING */
-#define	ZSTR1	5	/* SP then optional STRING */
-#define	ZSTR2	6	/* optional STRING after SP */
-#define	SITECMD	7	/* SITE command */
-#define	NSTR	8	/* Number followed by a string */
-
-struct tab {
-	char	*name;
-	short	token;
-	short	state;
-	short	implemented;	/* 1 if command is implemented */
-	char	*help;
-};
-
-struct tab cmdtab[] = {		/* In order defined in RFC 765 */
-	{ "USER", USER, STR1, 1,	"<sp> username" },
-	{ "PASS", PASS, ZSTR1, 1,	"<sp> password" },
-	{ "ACCT", ACCT, STR1, 0,	"(specify account)" },
-	{ "SMNT", SMNT, ARGS, 0,	"(structure mount)" },
-	{ "REIN", REIN, ARGS, 0,	"(reinitialize server state)" },
-	{ "QUIT", QUIT, ARGS, 1,	"(terminate service)", },
-	{ "PORT", PORT, ARGS, 1,	"<sp> b0, b1, b2, b3, b4" },
-	{ "PASV", PASV, ARGS, 1,	"(set server in passive mode)" },
-	{ "TYPE", TYPE, ARGS, 1,	"<sp> [ A | E | I | L ]" },
-	{ "STRU", STRU, ARGS, 1,	"(specify file structure)" },
-	{ "MODE", MODE, ARGS, 1,	"(specify transfer mode)" },
-	{ "RETR", RETR, STR1, 1,	"<sp> file-name" },
-	{ "STOR", STOR, STR1, 1,	"<sp> file-name" },
-	{ "APPE", APPE, STR1, 1,	"<sp> file-name" },
-	{ "MLFL", MLFL, OSTR, 0,	"(mail file)" },
-	{ "MAIL", MAIL, OSTR, 0,	"(mail to user)" },
-	{ "MSND", MSND, OSTR, 0,	"(mail send to terminal)" },
-	{ "MSOM", MSOM, OSTR, 0,	"(mail send to terminal or mailbox)" },
-	{ "MSAM", MSAM, OSTR, 0,	"(mail send to terminal and mailbox)" },
-	{ "MRSQ", MRSQ, OSTR, 0,	"(mail recipient scheme question)" },
-	{ "MRCP", MRCP, STR1, 0,	"(mail recipient)" },
-	{ "ALLO", ALLO, ARGS, 1,	"allocate storage (vacuously)" },
-	{ "REST", REST, ARGS, 0,	"(restart command)" },
-	{ "RNFR", RNFR, STR1, 1,	"<sp> file-name" },
-	{ "RNTO", RNTO, STR1, 1,	"<sp> file-name" },
-	{ "ABOR", ABOR, ARGS, 1,	"(abort operation)" },
-	{ "DELE", DELE, STR1, 1,	"<sp> file-name" },
-	{ "CWD",  CWD,  OSTR, 1,	"[ <sp> directory-name ]" },
-	{ "XCWD", CWD,	OSTR, 1,	"[ <sp> directory-name ]" },
-	{ "LIST", LIST, OSTR, 1,	"[ <sp> path-name ]" },
-	{ "NLST", NLST, OSTR, 1,	"[ <sp> path-name ]" },
-	{ "SITE", SITE, SITECMD, 1,	"site-cmd [ <sp> arguments ]" },
-	{ "SYST", SYST, ARGS, 1,	"(get type of operating system)" },
-	{ "STAT", STAT, OSTR, 1,	"[ <sp> path-name ]" },
-	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
-	{ "NOOP", NOOP, ARGS, 1,	"" },
-	{ "MKD",  MKD,  STR1, 1,	"<sp> path-name" },
-	{ "XMKD", MKD,  STR1, 1,	"<sp> path-name" },
-	{ "RMD",  RMD,  STR1, 1,	"<sp> path-name" },
-	{ "XRMD", RMD,  STR1, 1,	"<sp> path-name" },
-	{ "PWD",  PWD,  ARGS, 1,	"(return current directory)" },
-	{ "XPWD", PWD,  ARGS, 1,	"(return current directory)" },
-	{ "CDUP", CDUP, ARGS, 1,	"(change to parent directory)" },
-	{ "XCUP", CDUP, ARGS, 1,	"(change to parent directory)" },
-	{ "STOU", STOU, STR1, 1,	"<sp> file-name" },
-	{ "SIZE", SIZE, OSTR, 1,	"<sp> path-name" },
-	{ "MDTM", MDTM, OSTR, 1,	"<sp> path-name" },
-	{ NULL,   0,    0,    0,	0 }
-};
-
-struct tab sitetab[] = {
-	{ "UMASK", UMASK, ARGS, 1,	"[ <sp> umask ]" },
-	{ "IDLE", IDLE, ARGS, 1,	"[ <sp> maximum-idle-time ]" },
-	{ "CHMOD", CHMOD, NSTR, 1,	"<sp> mode <sp> file-name" },
-	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
-	{ NULL,   0,    0,    0,	0 }
-};
-
-struct tab *
-lookup(p, cmd)
-	register struct tab *p;
-	char *cmd;
-{
-
-	for (; p->name != NULL; p++)
-		if (strcmp(cmd, p->name) == 0)
-			return (p);
-	return (0);
-}
-
-#include <arpa/telnet.h>
-
-/*
- * getline - a hacked up version of fgets to ignore TELNET escape codes.
- */
-char *
-getline(s, n, iop)
-	char *s;
-	register FILE *iop;
-{
-	register c;
-	register char *cs;
-
-	cs = s;
-/* tmpline may contain saved command from urgent mode interruption */
-	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
-		*cs++ = tmpline[c];
-		if (tmpline[c] == '\n') {
-			*cs++ = '\0';
-			if (debug)
-				syslog(LOG_DEBUG, "command: %s", s);
-			tmpline[0] = '\0';
-			return(s);
-		}
-		if (c == 0)
-			tmpline[0] = '\0';
-	}
-	while ((c = getc(iop)) != EOF) {
-		c &= 0377;
-		if (c == IAC) {
-		    if ((c = getc(iop)) != EOF) {
-			c &= 0377;
-			switch (c) {
-			case WILL:
-			case WONT:
-				c = getc(iop);
-				printf("%c%c%c", IAC, DONT, 0377&c);
-				(void) fflush(stdout);
-				continue;
-			case DO:
-			case DONT:
-				c = getc(iop);
-				printf("%c%c%c", IAC, WONT, 0377&c);
-				(void) fflush(stdout);
-				continue;
-			case IAC:
-				break;
-			default:
-				continue;	/* ignore command */
-			}
-		    }
-		}
-		*cs++ = c;
-		if (--n <= 0 || c == '\n')
-			break;
-	}
-	if (c == EOF && cs == s)
-		return (NULL);
-	*cs++ = '\0';
-	if (debug)
-		syslog(LOG_DEBUG, "command: %s", s);
-	return (s);
-}
-
-static int
-toolong()
-{
-	time_t now;
-	extern char *ctime();
-	extern time_t time();
-
-	reply(421,
-	  "Timeout (%d seconds): closing control connection.", timeout);
-	(void) time(&now);
-	if (logging) {
-		syslog(LOG_INFO,
-			"User %s timed out after %d seconds at %s",
-			(pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
-	}
-	dologout(1);
-}
-
-yylex()
-{
-	static int cpos, state;
-	register char *cp, *cp2;
-	register struct tab *p;
-	int n;
-	char c, *strpbrk();
-	char *copy();
-
-	for (;;) {
-		switch (state) {
-
-		case CMD:
-			(void) signal(SIGALRM, toolong);
-			(void) alarm((unsigned) timeout);
-			if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
-				reply(221, "You could at least say goodbye.");
-				dologout(0);
-			}
-			(void) alarm(0);
-#ifdef SETPROCTITLE
-			if (strncasecmp(cbuf, "PASS", 4) != NULL)
-				setproctitle("%s: %s", proctitle, cbuf);
-#endif /* SETPROCTITLE */
-			if ((cp = index(cbuf, '\r'))) {
-				*cp++ = '\n';
-				*cp = '\0';
-			}
-			if ((cp = strpbrk(cbuf, " \n")))
-				cpos = cp - cbuf;
-			if (cpos == 0)
-				cpos = 4;
-			c = cbuf[cpos];
-			cbuf[cpos] = '\0';
-			upper(cbuf);
-			p = lookup(cmdtab, cbuf);
-			cbuf[cpos] = c;
-			if (p != 0) {
-				if (p->implemented == 0) {
-					nack(p->name);
-					longjmp(errcatch,0);
-					/* NOTREACHED */
-				}
-				state = p->state;
-				*(char **)&yylval = p->name;
-				return (p->token);
-			}
-			break;
-
-		case SITECMD:
-			if (cbuf[cpos] == ' ') {
-				cpos++;
-				return (SP);
-			}
-			cp = &cbuf[cpos];
-			if ((cp2 = strpbrk(cp, " \n")))
-				cpos = cp2 - cbuf;
-			c = cbuf[cpos];
-			cbuf[cpos] = '\0';
-			upper(cp);
-			p = lookup(sitetab, cp);
-			cbuf[cpos] = c;
-			if (p != 0) {
-				if (p->implemented == 0) {
-					state = CMD;
-					nack(p->name);
-					longjmp(errcatch,0);
-					/* NOTREACHED */
-				}
-				state = p->state;
-				*(char **)&yylval = p->name;
-				return (p->token);
-			}
-			state = CMD;
-			break;
-
-		case OSTR:
-			if (cbuf[cpos] == '\n') {
-				state = CMD;
-				return (CRLF);
-			}
-			/* FALLTHROUGH */
-
-		case STR1:
-		case ZSTR1:
-		dostr1:
-			if (cbuf[cpos] == ' ') {
-				cpos++;
-				state = state == OSTR ? STR2 : ++state;
-				return (SP);
-			}
-			break;
-
-		case ZSTR2:
-			if (cbuf[cpos] == '\n') {
-				state = CMD;
-				return (CRLF);
-			}
-			/* FALLTHROUGH */
-
-		case STR2:
-			cp = &cbuf[cpos];
-			n = strlen(cp);
-			cpos += n - 1;
-			/*
-			 * Make sure the string is nonempty and \n terminated.
-			 */
-			if (n > 1 && cbuf[cpos] == '\n') {
-				cbuf[cpos] = '\0';
-				*(char **)&yylval = copy(cp);
-				cbuf[cpos] = '\n';
-				state = ARGS;
-				return (STRING);
-			}
-			break;
-
-		case NSTR:
-			if (cbuf[cpos] == ' ') {
-				cpos++;
-				return (SP);
-			}
-			if (isdigit(cbuf[cpos])) {
-				cp = &cbuf[cpos];
-				while (isdigit(cbuf[++cpos]))
-					;
-				c = cbuf[cpos];
-				cbuf[cpos] = '\0';
-				yylval = atoi(cp);
-				cbuf[cpos] = c;
-				state = STR1;
-				return (NUMBER);
-			}
-			state = STR1;
-			goto dostr1;
-
-		case ARGS:
-			if (isdigit(cbuf[cpos])) {
-				cp = &cbuf[cpos];
-				while (isdigit(cbuf[++cpos]))
-					;
-				c = cbuf[cpos];
-				cbuf[cpos] = '\0';
-				yylval = atoi(cp);
-				cbuf[cpos] = c;
-				return (NUMBER);
-			}
-			switch (cbuf[cpos++]) {
-
-			case '\n':
-				state = CMD;
-				return (CRLF);
-
-			case ' ':
-				return (SP);
-
-			case ',':
-				return (COMMA);
-
-			case 'A':
-			case 'a':
-				return (A);
-
-			case 'B':
-			case 'b':
-				return (B);
-
-			case 'C':
-			case 'c':
-				return (C);
-
-			case 'E':
-			case 'e':
-				return (E);
-
-			case 'F':
-			case 'f':
-				return (F);
-
-			case 'I':
-			case 'i':
-				return (I);
-
-			case 'L':
-			case 'l':
-				return (L);
-
-			case 'N':
-			case 'n':
-				return (N);
-
-			case 'P':
-			case 'p':
-				return (P);
-
-			case 'R':
-			case 'r':
-				return (R);
-
-			case 'S':
-			case 's':
-				return (S);
-
-			case 'T':
-			case 't':
-				return (T);
-
-			}
-			break;
-
-		default:
-			fatal("Unknown state in scanner.");
-		}
-		yyerror((char *) 0);
-		state = CMD;
-		longjmp(errcatch,0);
-	}
-}
-
-upper(s)
-	register char *s;
-{
-	while (*s != '\0') {
-		if (islower(*s))
-			*s = toupper(*s);
-		s++;
-	}
-}
-
-char *
-copy(s)
-	char *s;
-{
-	char *p;
-	extern char *malloc(), *strcpy();
-
-	p = malloc((unsigned) strlen(s) + 1);
-	if (p == NULL)
-		fatal("Ran out of memory.");
-	(void) strcpy(p, s);
-	return (p);
-}
-
-help(ctab, s)
-	struct tab *ctab;
-	char *s;
-{
-	register struct tab *c;
-	register int width, NCMDS;
-	char *type;
-
-	if (ctab == sitetab)
-		type = "SITE ";
-	else
-		type = "";
-	width = 0, NCMDS = 0;
-	for (c = ctab; c->name != NULL; c++) {
-		int len = strlen(c->name);
-
-		if (len > width)
-			width = len;
-		NCMDS++;
-	}
-	width = (width + 8) &~ 7;
-	if (s == 0) {
-		register int i, j, w;
-		int columns, lines;
-
-		lreply(214, "The following %scommands are recognized %s.",
-		    type, "(* =>'s unimplemented)");
-		columns = 76 / width;
-		if (columns == 0)
-			columns = 1;
-		lines = (NCMDS + columns - 1) / columns;
-		for (i = 0; i < lines; i++) {
-			printf("   ");
-			for (j = 0; j < columns; j++) {
-				c = ctab + j * lines + i;
-				printf("%s%c", c->name,
-					c->implemented ? ' ' : '*');
-				if (c + lines >= &ctab[NCMDS])
-					break;
-				w = strlen(c->name) + 1;
-				while (w < width) {
-					putchar(' ');
-					w++;
-				}
-			}
-			printf("\r\n");
-		}
-		(void) fflush(stdout);
-		reply(214, "Direct comments to [email protected]%s.", hostname);
-		return;
-	}
-	upper(s);
-	c = lookup(ctab, s);
-	if (c == (struct tab *)0) {
-		reply(502, "Unknown command %s.", s);
-		return;
-	}
-	if (c->implemented)
-		reply(214, "Syntax: %s%s %s", type, c->name, c->help);
-	else
-		reply(214, "%s%-*s\t%s; unimplemented.", type, width,
-		    c->name, c->help);
-}
-
-sizecmd(filename)
-char *filename;
-{
-	switch (type) {
-	case TYPE_L:
-	case TYPE_I: {
-		struct stat stbuf;
-		if (stat(filename, &stbuf) < 0 ||
-		    (stbuf.st_mode&S_IFMT) != S_IFREG)
-			reply(550, "%s: not a plain file.", filename);
-		else
-			reply(213, "%lu", stbuf.st_size);
-		break;}
-	case TYPE_A: {
-		FILE *fin;
-		register int c, count;
-		struct stat stbuf;
-		fin = fopen(filename, "r");
-		if (fin == NULL) {
-			perror_reply(550, filename);
-			return;
-		}
-		if (fstat(fileno(fin), &stbuf) < 0 ||
-		    (stbuf.st_mode&S_IFMT) != S_IFREG) {
-			reply(550, "%s: not a plain file.", filename);
-			(void) fclose(fin);
-			return;
-		}
-
-		count = 0;
-		while((c=getc(fin)) != EOF) {
-			if (c == '\n')	/* will get expanded to \r\n */
-				count++;
-			count++;
-		}
-		(void) fclose(fin);
-
-		reply(213, "%ld", count);
-		break;}
-	default:
-		reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
-	}
-}
-#line 920 "ftp.tab.c"
-/* allocate initial stack or double stack size, up to YYMAXDEPTH */
-static int yygrowstack()
-{
-    int newsize, i;
-    short *newss;
-    YYSTYPE *newvs;
-
-    if ((newsize = yystacksize) == 0)
-        newsize = YYINITSTACKSIZE;
-    else if (newsize >= YYMAXDEPTH)
-        return -1;
-    else if ((newsize *= 2) > YYMAXDEPTH)
-        newsize = YYMAXDEPTH;
-    i = yyssp - yyss;
-    if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)
-        return -1;
-    yyss = newss;
-    yyssp = newss + i;
-    if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)
-        return -1;
-    yyvs = newvs;
-    yyvsp = newvs + i;
-    yystacksize = newsize;
-    yysslim = yyss + newsize - 1;
-    return 0;
-}
-
-#define YYABORT goto yyabort
-#define YYREJECT goto yyabort
-#define YYACCEPT goto yyaccept
-#define YYERROR goto yyerrlab
-
-int
-yyparse()
-{
-    register int yym, yyn, yystate;
-#if YYDEBUG
-    register const char *yys;
-
-    if ((yys = getenv("YYDEBUG")))
-    {
-        yyn = *yys;
-        if (yyn >= '0' && yyn <= '9')
-            yydebug = yyn - '0';
-    }
-#endif
-
-    yynerrs = 0;
-    yyerrflag = 0;
-    yychar = (-1);
-
-    if (yyss == NULL && yygrowstack()) goto yyoverflow;
-    yyssp = yyss;
-    yyvsp = yyvs;
-    *yyssp = yystate = 0;
-
-yyloop:
-    if ((yyn = yydefred[yystate])) goto yyreduce;
-    if (yychar < 0)
-    {
-        if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
-        if (yydebug)
-        {
-            yys = 0;
-            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-            if (!yys) yys = "illegal-symbol";
-            printf("%sdebug: state %d, reading %d (%s)\n",
-                    YYPREFIX, yystate, yychar, yys);
-        }
-#endif
-    }
-    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
-    {
-#if YYDEBUG
-        if (yydebug)
-            printf("%sdebug: state %d, shifting to state %d\n",
-                    YYPREFIX, yystate, yytable[yyn]);
-#endif
-        if (yyssp >= yysslim && yygrowstack())
-        {
-            goto yyoverflow;
-        }
-        *++yyssp = yystate = yytable[yyn];
-        *++yyvsp = yylval;
-        yychar = (-1);
-        if (yyerrflag > 0)  --yyerrflag;
-        goto yyloop;
-    }
-    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
-    {
-        yyn = yytable[yyn];
-        goto yyreduce;
-    }
-    if (yyerrflag) goto yyinrecovery;
-#if defined(lint) || defined(__GNUC__)
-    goto yynewerror;
-#endif
-yynewerror:
-    yyerror("syntax error");
-#if defined(lint) || defined(__GNUC__)
-    goto yyerrlab;
-#endif
-yyerrlab:
-    ++yynerrs;
-yyinrecovery:
-    if (yyerrflag < 3)
-    {
-        yyerrflag = 3;
-        for (;;)
-        {
-            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
-                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
-            {
-#if YYDEBUG
-                if (yydebug)
-                    printf("%sdebug: state %d, error recovery shifting\
- to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
-#endif
-                if (yyssp >= yysslim && yygrowstack())
-                {
-                    goto yyoverflow;
-                }
-                *++yyssp = yystate = yytable[yyn];
-                *++yyvsp = yylval;
-                goto yyloop;
-            }
-            else
-            {
-#if YYDEBUG
-                if (yydebug)
-                    printf("%sdebug: error recovery discarding state %d\n",
-                            YYPREFIX, *yyssp);
-#endif
-                if (yyssp <= yyss) goto yyabort;
-                --yyssp;
-                --yyvsp;
-            }
-        }
-    }
-    else
-    {
-        if (yychar == 0) goto yyabort;
-#if YYDEBUG
-        if (yydebug)
-        {
-            yys = 0;
-            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-            if (!yys) yys = "illegal-symbol";
-            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
-                    YYPREFIX, yystate, yychar, yys);
-        }
-#endif
-        yychar = (-1);
-        goto yyloop;
-    }
-yyreduce:
-#if YYDEBUG
-    if (yydebug)
-        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
-                YYPREFIX, yystate, yyn, yyrule[yyn]);
-#endif
-    yym = yylen[yyn];
-    yyval = yyvsp[1-yym];
-    switch (yyn)
-    {
-case 2:
-#line 99 "ftp.y"
- {
-			fromname = (char *) 0;
-		}
-break;
-case 4:
-#line 106 "ftp.y"
- {
-			user((char *) yyvsp[-1]);
-			free((char *) yyvsp[-1]);
-		}
-break;
-case 5:
-#line 111 "ftp.y"
- {
-			pass((char *) yyvsp[-1]);
-			free((char *) yyvsp[-1]);
-		}
-break;
-case 6:
-#line 116 "ftp.y"
- {
-			usedefault = 0;
-			if (pdata >= 0) {
-				(void) close(pdata);
-				pdata = -1;
-			}
-			reply(200, "PORT command successful.");
-		}
-break;
-case 7:
-#line 125 "ftp.y"
- {
-			passive();
-		}
-break;
-case 8:
-#line 129 "ftp.y"
- {
-			switch (cmd_type) {
-
-			case TYPE_A:
-				if (cmd_form == FORM_N) {
-					reply(200, "Type set to A.");
-					type = cmd_type;
-					form = cmd_form;
-				} else
-					reply(504, "Form must be N.");
-				break;
-
-			case TYPE_E:
-				reply(504, "Type E not implemented.");
-				break;
-
-			case TYPE_I:
-				reply(200, "Type set to I.");
-				type = cmd_type;
-				break;
-
-			case TYPE_L:
-#if NBBY == 8
-				if (cmd_bytesz == 8) {
-					reply(200,
-					    "Type set to L (byte size 8).");
-					type = cmd_type;
-				} else
-					reply(504, "Byte size must be 8.");
-#else /* NBBY == 8 */
-				UNIMPLEMENTED for NBBY != 8
-#endif /* NBBY == 8 */
-			}
-		}
-break;
-case 9:
-#line 164 "ftp.y"
- {
-			switch (yyvsp[-1]) {
-
-			case STRU_F:
-				reply(200, "STRU F ok.");
-				break;
-
-			default:
-				reply(504, "Unimplemented STRU type.");
-			}
-		}
-break;
-case 10:
-#line 176 "ftp.y"
- {
-			switch (yyvsp[-1]) {
-
-			case MODE_S:
-				reply(200, "MODE S ok.");
-				break;
-
-			default:
-				reply(502, "Unimplemented MODE type.");
-			}
-		}
-break;
-case 11:
-#line 188 "ftp.y"
- {
-			reply(202, "ALLO command ignored.");
-		}
-break;
-case 12:
-#line 192 "ftp.y"
- {
-			reply(202, "ALLO command ignored.");
-		}
-break;
-case 13:
-#line 196 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				retrieve((char *) 0, (char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 14:
-#line 203 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				store((char *) yyvsp[-1], "w", 0);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 15:
-#line 210 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				store((char *) yyvsp[-1], "a", 0);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 16:
-#line 217 "ftp.y"
- {
-			if (yyvsp[-1])
-				send_file_list(".");
-		}
-break;
-case 17:
-#line 222 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL) 
-				send_file_list((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 18:
-#line 229 "ftp.y"
- {
-			if (yyvsp[-1])
-				retrieve("/bin/ls -lgA", "");
-		}
-break;
-case 19:
-#line 234 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				retrieve("/bin/ls -lgA %s", (char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 20:
-#line 241 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				statfilecmd((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 21:
-#line 248 "ftp.y"
- {
-			statcmd();
-		}
-break;
-case 22:
-#line 252 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				delete((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 23:
-#line 259 "ftp.y"
- {
-			if (fromname) {
-				renamecmd(fromname, (char *) yyvsp[-1]);
-				free(fromname);
-				fromname = (char *) 0;
-			} else {
-				reply(503, "Bad sequence of commands.");
-			}
-			free((char *) yyvsp[-1]);
-		}
-break;
-case 24:
-#line 270 "ftp.y"
- {
-			reply(225, "ABOR command successful.");
-		}
-break;
-case 25:
-#line 274 "ftp.y"
- {
-			if (yyvsp[-1])
-				cwd(pw->pw_dir);
-		}
-break;
-case 26:
-#line 279 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				cwd((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 27:
-#line 286 "ftp.y"
- {
-			help(cmdtab, (char *) 0);
-		}
-break;
-case 28:
-#line 290 "ftp.y"
- {
-			register char *cp = (char *)yyvsp[-1];
-
-			if (strncasecmp(cp, "SITE", 4) == 0) {
-				cp = (char *)yyvsp[-1] + 4;
-				if (*cp == ' ')
-					cp++;
-				if (*cp)
-					help(sitetab, cp);
-				else
-					help(sitetab, (char *) 0);
-			} else
-				help(cmdtab, (char *) yyvsp[-1]);
-		}
-break;
-case 29:
-#line 305 "ftp.y"
- {
-			reply(200, "NOOP command successful.");
-		}
-break;
-case 30:
-#line 309 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				makedir((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 31:
-#line 316 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				removedir((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 32:
-#line 323 "ftp.y"
- {
-			if (yyvsp[-1])
-				pwd();
-		}
-break;
-case 33:
-#line 328 "ftp.y"
- {
-			if (yyvsp[-1])
-				cwd("..");
-		}
-break;
-case 34:
-#line 333 "ftp.y"
- {
-			help(sitetab, (char *) 0);
-		}
-break;
-case 35:
-#line 337 "ftp.y"
- {
-			help(sitetab, (char *) yyvsp[-1]);
-		}
-break;
-case 36:
-#line 341 "ftp.y"
- {
-			int oldmask;
-
-			if (yyvsp[-1]) {
-				oldmask = umask(0);
-				(void) umask(oldmask);
-				reply(200, "Current UMASK is %03o", oldmask);
-			}
-		}
-break;
-case 37:
-#line 351 "ftp.y"
- {
-			int oldmask;
-
-			if (yyvsp[-3]) {
-				if ((yyvsp[-1] == -1) || (yyvsp[-1] > 0777)) {
-					reply(501, "Bad UMASK value");
-				} else {
-					oldmask = umask(yyvsp[-1]);
-					reply(200,
-					    "UMASK set to %03o (was %03o)",
-					    yyvsp[-1], oldmask);
-				}
-			}
-		}
-break;
-case 38:
-#line 366 "ftp.y"
- {
-			if (yyvsp[-5] && (yyvsp[-1] != NULL)) {
-				if (yyvsp[-3] > 0777)
-					reply(501,
-				"CHMOD: Mode value must be between 0 and 0777");
-				else if (chmod((char *) yyvsp[-1], yyvsp[-3]) < 0)
-					perror_reply(550, (char *) yyvsp[-1]);
-				else
-					reply(200, "CHMOD command successful.");
-			}
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 39:
-#line 380 "ftp.y"
- {
-			reply(200,
-			    "Current IDLE time limit is %d seconds; max %d",
-				timeout, maxtimeout);
-		}
-break;
-case 40:
-#line 386 "ftp.y"
- {
-			if (yyvsp[-1] < 30 || yyvsp[-1] > maxtimeout) {
-				reply(501,
-			"Maximum IDLE time must be between 30 and %d seconds",
-				    maxtimeout);
-			} else {
-				timeout = yyvsp[-1];
-				(void) alarm((unsigned) timeout);
-				reply(200,
-				    "Maximum IDLE time set to %d seconds",
-				    timeout);
-			}
-		}
-break;
-case 41:
-#line 400 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				store((char *) yyvsp[-1], "w", 1);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 42:
-#line 407 "ftp.y"
- {
-#ifdef unix
-#ifdef BSD
-			reply(215, "UNIX Type: L%d Version: BSD-%d",
-				NBBY, BSD);
-#else /* BSD */
-			reply(215, "UNIX Type: L%d", NBBY);
-#endif /* BSD */
-#else /* unix */
-			reply(215, "UNKNOWN Type: L%d", NBBY);
-#endif /* unix */
-		}
-break;
-case 43:
-#line 428 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL)
-				sizecmd((char *) yyvsp[-1]);
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 44:
-#line 445 "ftp.y"
- {
-			if (yyvsp[-3] && yyvsp[-1] != NULL) {
-				struct stat stbuf;
-				if (stat((char *) yyvsp[-1], &stbuf) < 0)
-					perror_reply(550, "%s", (char *) yyvsp[-1]);
-				else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
-					reply(550, "%s: not a plain file.",
-						(char *) yyvsp[-1]);
-				} else {
-					register struct tm *t;
-					struct tm *gmtime();
-					t = gmtime(&stbuf.st_mtime);
-					reply(213,
-					    "%d%02d%02d%02d%02d%02d",
-					    t->tm_year+1900, t->tm_mon+1, t->tm_mday,
-					    t->tm_hour, t->tm_min, t->tm_sec);
-				}
-			}
-			if (yyvsp[-1] != NULL)
-				free((char *) yyvsp[-1]);
-		}
-break;
-case 45:
-#line 467 "ftp.y"
- {
-			reply(221, "Goodbye.");
-			dologout(0);
-		}
-break;
-case 46:
-#line 472 "ftp.y"
- {
-			yyerrok;
-		}
-break;
-case 47:
-#line 477 "ftp.y"
- {
-			char *renamefrom();
-
-			if (yyvsp[-3] && yyvsp[-1]) {
-				fromname = renamefrom((char *) yyvsp[-1]);
-				if (fromname == (char *) 0 && yyvsp[-1]) {
-					free((char *) yyvsp[-1]);
-				}
-			}
-		}
-break;
-case 49:
-#line 493 "ftp.y"
- {
-			*(char **)&(yyval) = "";
-		}
-break;
-case 52:
-#line 504 "ftp.y"
- {
-			register char *a, *p;
-
-			a = (char *)&data_dest.sin_addr;
-			a[0] = yyvsp[-10]; a[1] = yyvsp[-8]; a[2] = yyvsp[-6]; a[3] = yyvsp[-4];
-			p = (char *)&data_dest.sin_port;
-			p[0] = yyvsp[-2]; p[1] = yyvsp[0];
-			data_dest.sin_family = AF_INET;
-		}
-break;
-case 53:
-#line 516 "ftp.y"
- {
-		yyval = FORM_N;
-	}
-break;
-case 54:
-#line 520 "ftp.y"
- {
-		yyval = FORM_T;
-	}
-break;
-case 55:
-#line 524 "ftp.y"
- {
-		yyval = FORM_C;
-	}
-break;
-case 56:
-#line 530 "ftp.y"
- {
-		cmd_type = TYPE_A;
-		cmd_form = FORM_N;
-	}
-break;
-case 57:
-#line 535 "ftp.y"
- {
-		cmd_type = TYPE_A;
-		cmd_form = yyvsp[0];
-	}
-break;
-case 58:
-#line 540 "ftp.y"
- {
-		cmd_type = TYPE_E;
-		cmd_form = FORM_N;
-	}
-break;
-case 59:
-#line 545 "ftp.y"
- {
-		cmd_type = TYPE_E;
-		cmd_form = yyvsp[0];
-	}
-break;
-case 60:
-#line 550 "ftp.y"
- {
-		cmd_type = TYPE_I;
-	}
-break;
-case 61:
-#line 554 "ftp.y"
- {
-		cmd_type = TYPE_L;
-		cmd_bytesz = NBBY;
-	}
-break;
-case 62:
-#line 559 "ftp.y"
- {
-		cmd_type = TYPE_L;
-		cmd_bytesz = yyvsp[0];
-	}
-break;
-case 63:
-#line 565 "ftp.y"
- {
-		cmd_type = TYPE_L;
-		cmd_bytesz = yyvsp[0];
-	}
-break;
-case 64:
-#line 572 "ftp.y"
- {
-		yyval = STRU_F;
-	}
-break;
-case 65:
-#line 576 "ftp.y"
- {
-		yyval = STRU_R;
-	}
-break;
-case 66:
-#line 580 "ftp.y"
- {
-		yyval = STRU_P;
-	}
-break;
-case 67:
-#line 586 "ftp.y"
- {
-		yyval = MODE_S;
-	}
-break;
-case 68:
-#line 590 "ftp.y"
- {
-		yyval = MODE_B;
-	}
-break;
-case 69:
-#line 594 "ftp.y"
- {
-		yyval = MODE_C;
-	}
-break;
-case 70:
-#line 600 "ftp.y"
- {
-		/*
-		 * Problem: this production is used for all pathname
-		 * processing, but only gives a 550 error reply.
-		 * This is a valid reply in some cases but not in others.
-		 */
-		if (logged_in && yyvsp[0] && strncmp((char *) yyvsp[0], "~", 1) == 0) {
-			*(char **)&(yyval) = *glob((char *) yyvsp[0]);
-			if (globerr != NULL) {
-				reply(550, globerr);
-				yyval = NULL;
-			}
-			free((char *) yyvsp[0]);
-		} else
-			yyval = yyvsp[0];
-	}
-break;
-case 72:
-#line 622 "ftp.y"
- {
-		register int ret, dec, multby, digit;
-
-		/*
-		 * Convert a number that was read as decimal number
-		 * to what it would be if it had been read as octal.
-		 */
-		dec = yyvsp[0];
-		multby = 1;
-		ret = 0;
-		while (dec) {
-			digit = dec%10;
-			if (digit > 7) {
-				ret = -1;
-				break;
-			}
-			ret += digit * multby;
-			multby *= 8;
-			dec /= 10;
-		}
-		yyval = ret;
-	}
-break;
-case 73:
-#line 647 "ftp.y"
- {
-		if (logged_in)
-			yyval = 1;
-		else {
-			reply(530, "Please login with USER and PASS.");
-			yyval = 0;
-		}
-	}
-break;
-#line 1728 "ftp.tab.c"
-    }
-    yyssp -= yym;
-    yystate = *yyssp;
-    yyvsp -= yym;
-    yym = yylhs[yyn];
-    if (yystate == 0 && yym == 0)
-    {
-#if YYDEBUG
-        if (yydebug)
-            printf("%sdebug: after reduction, shifting from state 0 to\
- state %d\n", YYPREFIX, YYFINAL);
-#endif
-        yystate = YYFINAL;
-        *++yyssp = YYFINAL;
-        *++yyvsp = yyval;
-        if (yychar < 0)
-        {
-            if ((yychar = yylex()) < 0) yychar = 0;
-#if YYDEBUG
-            if (yydebug)
-            {
-                yys = 0;
-                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
-                if (!yys) yys = "illegal-symbol";
-                printf("%sdebug: state %d, reading %d (%s)\n",
-                        YYPREFIX, YYFINAL, yychar, yys);
-            }
-#endif
-        }
-        if (yychar == 0) goto yyaccept;
-        goto yyloop;
-    }
-    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
-            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
-        yystate = yytable[yyn];
-    else
-        yystate = yydgoto[yym];
-#if YYDEBUG
-    if (yydebug)
-        printf("%sdebug: after reduction, shifting from state %d \
-to state %d\n", YYPREFIX, *yyssp, yystate);
-#endif
-    if (yyssp >= yysslim && yygrowstack())
-    {
-        goto yyoverflow;
-    }
-    *++yyssp = yystate;
-    *++yyvsp = yyval;
-    goto yyloop;
-yyoverflow:
-    yyerror("yacc stack overflow");
-yyabort:
-    return (1);
-yyaccept:
-    return (0);
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/ftp.tab.h
--- a/head/usr.bin/yacc/test/ftp.tab.h	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-#define A 257
-#define B 258
-#define C 259
-#define E 260
-#define F 261
-#define I 262
-#define L 263
-#define N 264
-#define P 265
-#define R 266
-#define S 267
-#define T 268
-#define SP 269
-#define CRLF 270
-#define COMMA 271
-#define STRING 272
-#define NUMBER 273
-#define USER 274
-#define PASS 275
-#define ACCT 276
-#define REIN 277
-#define QUIT 278
-#define PORT 279
-#define PASV 280
-#define TYPE 281
-#define STRU 282
-#define MODE 283
-#define RETR 284
-#define STOR 285
-#define APPE 286
-#define MLFL 287
-#define MAIL 288
-#define MSND 289
-#define MSOM 290
-#define MSAM 291
-#define MRSQ 292
-#define MRCP 293
-#define ALLO 294
-#define REST 295
-#define RNFR 296
-#define RNTO 297
-#define ABOR 298
-#define DELE 299
-#define CWD 300
-#define LIST 301
-#define NLST 302
-#define SITE 303
-#define STAT 304
-#define HELP 305
-#define NOOP 306
-#define MKD 307
-#define RMD 308
-#define PWD 309
-#define CDUP 310
-#define STOU 311
-#define SMNT 312
-#define SYST 313
-#define SIZE 314
-#define MDTM 315
-#define UMASK 316
-#define IDLE 317
-#define CHMOD 318
-#define LEXERR 319
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/test/ftp.y
--- a/head/usr.bin/yacc/test/ftp.y	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1180 +0,0 @@
-/*
- * Copyright (c) 1985, 1988 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- *	@(#)ftpcmd.y	5.20.1.1 (Berkeley) 3/2/89
- */
-
-/*
- * Grammar for FTP commands.
- * See RFC 959.
- */
-
-%{
-
-#ifndef lint
-static char sccsid[] = "@(#)ftpcmd.y	5.20.1.1 (Berkeley) 3/2/89";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-
-#include <arpa/ftp.h>
-
-#include <stdio.h>
-#include <signal.h>
-#include <ctype.h>
-#include <pwd.h>
-#include <setjmp.h>
-#include <syslog.h>
-#include <sys/stat.h>
-#include <time.h>
-
-extern	struct sockaddr_in data_dest;
-extern	int logged_in;
-extern	struct passwd *pw;
-extern	int guest;
-extern	int logging;
-extern	int type;
-extern	int form;
-extern	int debug;
-extern	int timeout;
-extern	int maxtimeout;
-extern  int pdata;
-extern	char hostname[], remotehost[];
-extern	char proctitle[];
-extern	char *globerr;
-extern	int usedefault;
-extern  int transflag;
-extern  char tmpline[];
-char	**glob();
-
-static	int cmd_type;
-static	int cmd_form;
-static	int cmd_bytesz;
-char	cbuf[512];
-char	*fromname;
-
-char	*index();
-%}
-
-%token
-	A	B	C	E	F	I
-	L	N	P	R	S	T
-
-	SP	CRLF	COMMA	STRING	NUMBER
-
-	USER	PASS	ACCT	REIN	QUIT	PORT
-	PASV	TYPE	STRU	MODE	RETR	STOR
-	APPE	MLFL	MAIL	MSND	MSOM	MSAM
-	MRSQ	MRCP	ALLO	REST	RNFR	RNTO
-	ABOR	DELE	CWD	LIST	NLST	SITE
-	STAT	HELP	NOOP	MKD	RMD	PWD
-	CDUP	STOU	SMNT	SYST	SIZE	MDTM
-
-	UMASK	IDLE	CHMOD
-
-	LEXERR
-
-%start	cmd_list
-
-%%
-
-cmd_list:	/* empty */
-	|	cmd_list cmd
-		= {
-			fromname = (char *) 0;
-		}
-	|	cmd_list rcmd
-	;
-
-cmd:		USER SP username CRLF
-		= {
-			user((char *) $3);
-			free((char *) $3);
-		}
-	|	PASS SP password CRLF
-		= {
-			pass((char *) $3);
-			free((char *) $3);
-		}
-	|	PORT SP host_port CRLF
-		= {
-			usedefault = 0;
-			if (pdata >= 0) {
-				(void) close(pdata);
-				pdata = -1;
-			}
-			reply(200, "PORT command successful.");
-		}
-	|	PASV CRLF
-		= {
-			passive();
-		}
-	|	TYPE SP type_code CRLF
-		= {
-			switch (cmd_type) {
-
-			case TYPE_A:
-				if (cmd_form == FORM_N) {
-					reply(200, "Type set to A.");
-					type = cmd_type;
-					form = cmd_form;
-				} else
-					reply(504, "Form must be N.");
-				break;
-
-			case TYPE_E:
-				reply(504, "Type E not implemented.");
-				break;
-
-			case TYPE_I:
-				reply(200, "Type set to I.");
-				type = cmd_type;
-				break;
-
-			case TYPE_L:
-#if NBBY == 8
-				if (cmd_bytesz == 8) {
-					reply(200,
-					    "Type set to L (byte size 8).");
-					type = cmd_type;
-				} else
-					reply(504, "Byte size must be 8.");
-#else /* NBBY == 8 */
-				UNIMPLEMENTED for NBBY != 8
-#endif /* NBBY == 8 */
-			}
-		}
-	|	STRU SP struct_code CRLF
-		= {
-			switch ($3) {
-
-			case STRU_F:
-				reply(200, "STRU F ok.");
-				break;
-
-			default:
-				reply(504, "Unimplemented STRU type.");
-			}
-		}
-	|	MODE SP mode_code CRLF
-		= {
-			switch ($3) {
-
-			case MODE_S:
-				reply(200, "MODE S ok.");
-				break;
-
-			default:
-				reply(502, "Unimplemented MODE type.");
-			}
-		}
-	|	ALLO SP NUMBER CRLF
-		= {
-			reply(202, "ALLO command ignored.");
-		}
-	|	ALLO SP NUMBER SP R SP NUMBER CRLF
-		= {
-			reply(202, "ALLO command ignored.");
-		}
-	|	RETR check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				retrieve((char *) 0, (char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	STOR check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				store((char *) $4, "w", 0);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	APPE check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				store((char *) $4, "a", 0);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	NLST check_login CRLF
-		= {
-			if ($2)
-				send_file_list(".");
-		}
-	|	NLST check_login SP STRING CRLF
-		= {
-			if ($2 && $4 != NULL) 
-				send_file_list((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	LIST check_login CRLF
-		= {
-			if ($2)
-				retrieve("/bin/ls -lgA", "");
-		}
-	|	LIST check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				retrieve("/bin/ls -lgA %s", (char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	STAT check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				statfilecmd((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	STAT CRLF
-		= {
-			statcmd();
-		}
-	|	DELE check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				delete((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	RNTO SP pathname CRLF
-		= {
-			if (fromname) {
-				renamecmd(fromname, (char *) $3);
-				free(fromname);
-				fromname = (char *) 0;
-			} else {
-				reply(503, "Bad sequence of commands.");
-			}
-			free((char *) $3);
-		}
-	|	ABOR CRLF
-		= {
-			reply(225, "ABOR command successful.");
-		}
-	|	CWD check_login CRLF
-		= {
-			if ($2)
-				cwd(pw->pw_dir);
-		}
-	|	CWD check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				cwd((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	HELP CRLF
-		= {
-			help(cmdtab, (char *) 0);
-		}
-	|	HELP SP STRING CRLF
-		= {
-			register char *cp = (char *)$3;
-
-			if (strncasecmp(cp, "SITE", 4) == 0) {
-				cp = (char *)$3 + 4;
-				if (*cp == ' ')
-					cp++;
-				if (*cp)
-					help(sitetab, cp);
-				else
-					help(sitetab, (char *) 0);
-			} else
-				help(cmdtab, (char *) $3);
-		}
-	|	NOOP CRLF
-		= {
-			reply(200, "NOOP command successful.");
-		}
-	|	MKD check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				makedir((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	RMD check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				removedir((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	PWD check_login CRLF
-		= {
-			if ($2)
-				pwd();
-		}
-	|	CDUP check_login CRLF
-		= {
-			if ($2)
-				cwd("..");
-		}
-	|	SITE SP HELP CRLF
-		= {
-			help(sitetab, (char *) 0);
-		}
-	|	SITE SP HELP SP STRING CRLF
-		= {
-			help(sitetab, (char *) $5);
-		}
-	|	SITE SP UMASK check_login CRLF
-		= {
-			int oldmask;
-
-			if ($4) {
-				oldmask = umask(0);
-				(void) umask(oldmask);
-				reply(200, "Current UMASK is %03o", oldmask);
-			}
-		}
-	|	SITE SP UMASK check_login SP octal_number CRLF
-		= {
-			int oldmask;
-
-			if ($4) {
-				if (($6 == -1) || ($6 > 0777)) {
-					reply(501, "Bad UMASK value");
-				} else {
-					oldmask = umask($6);
-					reply(200,
-					    "UMASK set to %03o (was %03o)",
-					    $6, oldmask);
-				}
-			}
-		}
-	|	SITE SP CHMOD check_login SP octal_number SP pathname CRLF
-		= {
-			if ($4 && ($8 != NULL)) {
-				if ($6 > 0777)
-					reply(501,
-				"CHMOD: Mode value must be between 0 and 0777");
-				else if (chmod((char *) $8, $6) < 0)
-					perror_reply(550, (char *) $8);
-				else
-					reply(200, "CHMOD command successful.");
-			}
-			if ($8 != NULL)
-				free((char *) $8);
-		}
-	|	SITE SP IDLE CRLF
-		= {
-			reply(200,
-			    "Current IDLE time limit is %d seconds; max %d",
-				timeout, maxtimeout);
-		}
-	|	SITE SP IDLE SP NUMBER CRLF
-		= {
-			if ($5 < 30 || $5 > maxtimeout) {
-				reply(501,
-			"Maximum IDLE time must be between 30 and %d seconds",
-				    maxtimeout);
-			} else {
-				timeout = $5;
-				(void) alarm((unsigned) timeout);
-				reply(200,
-				    "Maximum IDLE time set to %d seconds",
-				    timeout);
-			}
-		}
-	|	STOU check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				store((char *) $4, "w", 1);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	SYST CRLF
-		= {
-#ifdef unix
-#ifdef BSD
-			reply(215, "UNIX Type: L%d Version: BSD-%d",
-				NBBY, BSD);
-#else /* BSD */
-			reply(215, "UNIX Type: L%d", NBBY);
-#endif /* BSD */
-#else /* unix */
-			reply(215, "UNKNOWN Type: L%d", NBBY);
-#endif /* unix */
-		}
-
-		/*
-		 * SIZE is not in RFC959, but Postel has blessed it and
-		 * it will be in the updated RFC.
-		 *
-		 * Return size of file in a format suitable for
-		 * using with RESTART (we just count bytes).
-		 */
-	|	SIZE check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL)
-				sizecmd((char *) $4);
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-
-		/*
-		 * MDTM is not in RFC959, but Postel has blessed it and
-		 * it will be in the updated RFC.
-		 *
-		 * Return modification time of file as an ISO 3307
-		 * style time. E.g. YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx
-		 * where xxx is the fractional second (of any precision,
-		 * not necessarily 3 digits)
-		 */
-	|	MDTM check_login SP pathname CRLF
-		= {
-			if ($2 && $4 != NULL) {
-				struct stat stbuf;
-				if (stat((char *) $4, &stbuf) < 0)
-					perror_reply(550, "%s", (char *) $4);
-				else if ((stbuf.st_mode&S_IFMT) != S_IFREG) {
-					reply(550, "%s: not a plain file.",
-						(char *) $4);
-				} else {
-					register struct tm *t;
-					struct tm *gmtime();
-					t = gmtime(&stbuf.st_mtime);
-					reply(213,
-					    "%d%02d%02d%02d%02d%02d",
-					    t->tm_year+1900, t->tm_mon+1, t->tm_mday,
-					    t->tm_hour, t->tm_min, t->tm_sec);
-				}
-			}
-			if ($4 != NULL)
-				free((char *) $4);
-		}
-	|	QUIT CRLF
-		= {
-			reply(221, "Goodbye.");
-			dologout(0);
-		}
-	|	error CRLF
-		= {
-			yyerrok;
-		}
-	;
-rcmd:		RNFR check_login SP pathname CRLF
-		= {
-			char *renamefrom();
-
-			if ($2 && $4) {
-				fromname = renamefrom((char *) $4);
-				if (fromname == (char *) 0 && $4) {
-					free((char *) $4);
-				}
-			}
-		}
-	;
-		
-username:	STRING
-	;
-
-password:	/* empty */
-		= {
-			*(char **)&($$) = "";
-		}
-	|	STRING
-	;
-
-byte_size:	NUMBER
-	;
-
-host_port:	NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA 
-		NUMBER COMMA NUMBER
-		= {
-			register char *a, *p;
-
-			a = (char *)&data_dest.sin_addr;
-			a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
-			p = (char *)&data_dest.sin_port;
-			p[0] = $9; p[1] = $11;
-			data_dest.sin_family = AF_INET;
-		}
-	;
-
-form_code:	N
-	= {
-		$$ = FORM_N;
-	}
-	|	T
-	= {
-		$$ = FORM_T;
-	}
-	|	C
-	= {
-		$$ = FORM_C;
-	}
-	;
-
-type_code:	A
-	= {
-		cmd_type = TYPE_A;
-		cmd_form = FORM_N;
-	}
-	|	A SP form_code
-	= {
-		cmd_type = TYPE_A;
-		cmd_form = $3;
-	}
-	|	E
-	= {
-		cmd_type = TYPE_E;
-		cmd_form = FORM_N;
-	}
-	|	E SP form_code
-	= {
-		cmd_type = TYPE_E;
-		cmd_form = $3;
-	}
-	|	I
-	= {
-		cmd_type = TYPE_I;
-	}
-	|	L
-	= {
-		cmd_type = TYPE_L;
-		cmd_bytesz = NBBY;
-	}
-	|	L SP byte_size
-	= {
-		cmd_type = TYPE_L;
-		cmd_bytesz = $3;
-	}
-	/* this is for a bug in the BBN ftp */
-	|	L byte_size
-	= {
-		cmd_type = TYPE_L;
-		cmd_bytesz = $2;
-	}
-	;
-
-struct_code:	F
-	= {
-		$$ = STRU_F;
-	}
-	|	R
-	= {
-		$$ = STRU_R;
-	}
-	|	P
-	= {
-		$$ = STRU_P;
-	}
-	;
-
-mode_code:	S
-	= {
-		$$ = MODE_S;
-	}
-	|	B
-	= {
-		$$ = MODE_B;
-	}
-	|	C
-	= {
-		$$ = MODE_C;
-	}
-	;
-
-pathname:	pathstring
-	= {
-		/*
-		 * Problem: this production is used for all pathname
-		 * processing, but only gives a 550 error reply.
-		 * This is a valid reply in some cases but not in others.
-		 */
-		if (logged_in && $1 && strncmp((char *) $1, "~", 1) == 0) {
-			*(char **)&($$) = *glob((char *) $1);
-			if (globerr != NULL) {
-				reply(550, globerr);
-				$$ = NULL;
-			}
-			free((char *) $1);
-		} else
-			$$ = $1;
-	}
-	;
-
-pathstring:	STRING
-	;
-
-octal_number:	NUMBER
-	= {
-		register int ret, dec, multby, digit;
-
-		/*
-		 * Convert a number that was read as decimal number
-		 * to what it would be if it had been read as octal.
-		 */
-		dec = $1;
-		multby = 1;
-		ret = 0;
-		while (dec) {
-			digit = dec%10;
-			if (digit > 7) {
-				ret = -1;
-				break;
-			}
-			ret += digit * multby;
-			multby *= 8;
-			dec /= 10;
-		}
-		$$ = ret;
-	}
-	;
-
-check_login:	/* empty */
-	= {
-		if (logged_in)
-			$$ = 1;
-		else {
-			reply(530, "Please login with USER and PASS.");
-			$$ = 0;
-		}
-	}
-	;
-
-%%
-
-extern jmp_buf errcatch;
-
-#define	CMD	0	/* beginning of command */
-#define	ARGS	1	/* expect miscellaneous arguments */
-#define	STR1	2	/* expect SP followed by STRING */
-#define	STR2	3	/* expect STRING */
-#define	OSTR	4	/* optional SP then STRING */
-#define	ZSTR1	5	/* SP then optional STRING */
-#define	ZSTR2	6	/* optional STRING after SP */
-#define	SITECMD	7	/* SITE command */
-#define	NSTR	8	/* Number followed by a string */
-
-struct tab {
-	char	*name;
-	short	token;
-	short	state;
-	short	implemented;	/* 1 if command is implemented */
-	char	*help;
-};
-
-struct tab cmdtab[] = {		/* In order defined in RFC 765 */
-	{ "USER", USER, STR1, 1,	"<sp> username" },
-	{ "PASS", PASS, ZSTR1, 1,	"<sp> password" },
-	{ "ACCT", ACCT, STR1, 0,	"(specify account)" },
-	{ "SMNT", SMNT, ARGS, 0,	"(structure mount)" },
-	{ "REIN", REIN, ARGS, 0,	"(reinitialize server state)" },
-	{ "QUIT", QUIT, ARGS, 1,	"(terminate service)", },
-	{ "PORT", PORT, ARGS, 1,	"<sp> b0, b1, b2, b3, b4" },
-	{ "PASV", PASV, ARGS, 1,	"(set server in passive mode)" },
-	{ "TYPE", TYPE, ARGS, 1,	"<sp> [ A | E | I | L ]" },
-	{ "STRU", STRU, ARGS, 1,	"(specify file structure)" },
-	{ "MODE", MODE, ARGS, 1,	"(specify transfer mode)" },
-	{ "RETR", RETR, STR1, 1,	"<sp> file-name" },
-	{ "STOR", STOR, STR1, 1,	"<sp> file-name" },
-	{ "APPE", APPE, STR1, 1,	"<sp> file-name" },
-	{ "MLFL", MLFL, OSTR, 0,	"(mail file)" },
-	{ "MAIL", MAIL, OSTR, 0,	"(mail to user)" },
-	{ "MSND", MSND, OSTR, 0,	"(mail send to terminal)" },
-	{ "MSOM", MSOM, OSTR, 0,	"(mail send to terminal or mailbox)" },
-	{ "MSAM", MSAM, OSTR, 0,	"(mail send to terminal and mailbox)" },
-	{ "MRSQ", MRSQ, OSTR, 0,	"(mail recipient scheme question)" },
-	{ "MRCP", MRCP, STR1, 0,	"(mail recipient)" },
-	{ "ALLO", ALLO, ARGS, 1,	"allocate storage (vacuously)" },
-	{ "REST", REST, ARGS, 0,	"(restart command)" },
-	{ "RNFR", RNFR, STR1, 1,	"<sp> file-name" },
-	{ "RNTO", RNTO, STR1, 1,	"<sp> file-name" },
-	{ "ABOR", ABOR, ARGS, 1,	"(abort operation)" },
-	{ "DELE", DELE, STR1, 1,	"<sp> file-name" },
-	{ "CWD",  CWD,  OSTR, 1,	"[ <sp> directory-name ]" },
-	{ "XCWD", CWD,	OSTR, 1,	"[ <sp> directory-name ]" },
-	{ "LIST", LIST, OSTR, 1,	"[ <sp> path-name ]" },
-	{ "NLST", NLST, OSTR, 1,	"[ <sp> path-name ]" },
-	{ "SITE", SITE, SITECMD, 1,	"site-cmd [ <sp> arguments ]" },
-	{ "SYST", SYST, ARGS, 1,	"(get type of operating system)" },
-	{ "STAT", STAT, OSTR, 1,	"[ <sp> path-name ]" },
-	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
-	{ "NOOP", NOOP, ARGS, 1,	"" },
-	{ "MKD",  MKD,  STR1, 1,	"<sp> path-name" },
-	{ "XMKD", MKD,  STR1, 1,	"<sp> path-name" },
-	{ "RMD",  RMD,  STR1, 1,	"<sp> path-name" },
-	{ "XRMD", RMD,  STR1, 1,	"<sp> path-name" },
-	{ "PWD",  PWD,  ARGS, 1,	"(return current directory)" },
-	{ "XPWD", PWD,  ARGS, 1,	"(return current directory)" },
-	{ "CDUP", CDUP, ARGS, 1,	"(change to parent directory)" },
-	{ "XCUP", CDUP, ARGS, 1,	"(change to parent directory)" },
-	{ "STOU", STOU, STR1, 1,	"<sp> file-name" },
-	{ "SIZE", SIZE, OSTR, 1,	"<sp> path-name" },
-	{ "MDTM", MDTM, OSTR, 1,	"<sp> path-name" },
-	{ NULL,   0,    0,    0,	0 }
-};
-
-struct tab sitetab[] = {
-	{ "UMASK", UMASK, ARGS, 1,	"[ <sp> umask ]" },
-	{ "IDLE", IDLE, ARGS, 1,	"[ <sp> maximum-idle-time ]" },
-	{ "CHMOD", CHMOD, NSTR, 1,	"<sp> mode <sp> file-name" },
-	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
-	{ NULL,   0,    0,    0,	0 }
-};
-
-struct tab *
-lookup(p, cmd)
-	register struct tab *p;
-	char *cmd;
-{
-
-	for (; p->name != NULL; p++)
-		if (strcmp(cmd, p->name) == 0)
-			return (p);
-	return (0);
-}
-
-#include <arpa/telnet.h>
-
-/*
- * getline - a hacked up version of fgets to ignore TELNET escape codes.
- */
-char *
-getline(s, n, iop)
-	char *s;
-	register FILE *iop;
-{
-	register c;
-	register char *cs;
-
-	cs = s;
-/* tmpline may contain saved command from urgent mode interruption */
-	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
-		*cs++ = tmpline[c];
-		if (tmpline[c] == '\n') {
-			*cs++ = '\0';
-			if (debug)
-				syslog(LOG_DEBUG, "command: %s", s);
-			tmpline[0] = '\0';
-			return(s);
-		}
-		if (c == 0)
-			tmpline[0] = '\0';
-	}
-	while ((c = getc(iop)) != EOF) {
-		c &= 0377;
-		if (c == IAC) {
-		    if ((c = getc(iop)) != EOF) {
-			c &= 0377;
-			switch (c) {
-			case WILL:
-			case WONT:
-				c = getc(iop);
-				printf("%c%c%c", IAC, DONT, 0377&c);
-				(void) fflush(stdout);
-				continue;
-			case DO:
-			case DONT:
-				c = getc(iop);
-				printf("%c%c%c", IAC, WONT, 0377&c);
-				(void) fflush(stdout);
-				continue;
-			case IAC:
-				break;
-			default:
-				continue;	/* ignore command */
-			}
-		    }
-		}
-		*cs++ = c;
-		if (--n <= 0 || c == '\n')
-			break;
-	}
-	if (c == EOF && cs == s)
-		return (NULL);
-	*cs++ = '\0';
-	if (debug)
-		syslog(LOG_DEBUG, "command: %s", s);
-	return (s);
-}
-
-static int
-toolong()
-{
-	time_t now;
-	extern char *ctime();
-	extern time_t time();
-
-	reply(421,
-	  "Timeout (%d seconds): closing control connection.", timeout);
-	(void) time(&now);
-	if (logging) {
-		syslog(LOG_INFO,
-			"User %s timed out after %d seconds at %s",
-			(pw ? pw -> pw_name : "unknown"), timeout, ctime(&now));
-	}
-	dologout(1);
-}
-
-yylex()
-{
-	static int cpos, state;
-	register char *cp, *cp2;
-	register struct tab *p;
-	int n;
-	char c, *strpbrk();
-	char *copy();
-
-	for (;;) {
-		switch (state) {
-
-		case CMD:
-			(void) signal(SIGALRM, toolong);
-			(void) alarm((unsigned) timeout);
-			if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
-				reply(221, "You could at least say goodbye.");
-				dologout(0);
-			}
-			(void) alarm(0);
-#ifdef SETPROCTITLE
-			if (strncasecmp(cbuf, "PASS", 4) != NULL)
-				setproctitle("%s: %s", proctitle, cbuf);
-#endif /* SETPROCTITLE */
-			if ((cp = index(cbuf, '\r'))) {
-				*cp++ = '\n';
-				*cp = '\0';
-			}
-			if ((cp = strpbrk(cbuf, " \n")))
-				cpos = cp - cbuf;
-			if (cpos == 0)
-				cpos = 4;
-			c = cbuf[cpos];
-			cbuf[cpos] = '\0';
-			upper(cbuf);
-			p = lookup(cmdtab, cbuf);
-			cbuf[cpos] = c;
-			if (p != 0) {
-				if (p->implemented == 0) {
-					nack(p->name);
-					longjmp(errcatch,0);
-					/* NOTREACHED */
-				}
-				state = p->state;
-				*(char **)&yylval = p->name;
-				return (p->token);
-			}
-			break;
-
-		case SITECMD:
-			if (cbuf[cpos] == ' ') {
-				cpos++;
-				return (SP);
-			}
-			cp = &cbuf[cpos];
-			if ((cp2 = strpbrk(cp, " \n")))
-				cpos = cp2 - cbuf;
-			c = cbuf[cpos];
-			cbuf[cpos] = '\0';
-			upper(cp);
-			p = lookup(sitetab, cp);
-			cbuf[cpos] = c;
-			if (p != 0) {
-				if (p->implemented == 0) {
-					state = CMD;
-					nack(p->name);
-					longjmp(errcatch,0);
-					/* NOTREACHED */
-				}
-				state = p->state;
-				*(char **)&yylval = p->name;
-				return (p->token);
-			}
-			state = CMD;
-			break;
-
-		case OSTR:
-			if (cbuf[cpos] == '\n') {
-				state = CMD;
-				return (CRLF);
-			}
-			/* FALLTHROUGH */
-
-		case STR1:
-		case ZSTR1:
-		dostr1:
-			if (cbuf[cpos] == ' ') {
-				cpos++;
-				state = state == OSTR ? STR2 : ++state;
-				return (SP);
-			}
-			break;
-
-		case ZSTR2:
-			if (cbuf[cpos] == '\n') {
-				state = CMD;
-				return (CRLF);
-			}
-			/* FALLTHROUGH */
-
-		case STR2:
-			cp = &cbuf[cpos];
-			n = strlen(cp);
-			cpos += n - 1;
-			/*
-			 * Make sure the string is nonempty and \n terminated.
-			 */
-			if (n > 1 && cbuf[cpos] == '\n') {
-				cbuf[cpos] = '\0';
-				*(char **)&yylval = copy(cp);
-				cbuf[cpos] = '\n';
-				state = ARGS;
-				return (STRING);
-			}
-			break;
-
-		case NSTR:
-			if (cbuf[cpos] == ' ') {
-				cpos++;
-				return (SP);
-			}
-			if (isdigit(cbuf[cpos])) {
-				cp = &cbuf[cpos];
-				while (isdigit(cbuf[++cpos]))
-					;
-				c = cbuf[cpos];
-				cbuf[cpos] = '\0';
-				yylval = atoi(cp);
-				cbuf[cpos] = c;
-				state = STR1;
-				return (NUMBER);
-			}
-			state = STR1;
-			goto dostr1;
-
-		case ARGS:
-			if (isdigit(cbuf[cpos])) {
-				cp = &cbuf[cpos];
-				while (isdigit(cbuf[++cpos]))
-					;
-				c = cbuf[cpos];
-				cbuf[cpos] = '\0';
-				yylval = atoi(cp);
-				cbuf[cpos] = c;
-				return (NUMBER);
-			}
-			switch (cbuf[cpos++]) {
-
-			case '\n':
-				state = CMD;
-				return (CRLF);
-
-			case ' ':
-				return (SP);
-
-			case ',':
-				return (COMMA);
-
-			case 'A':
-			case 'a':
-				return (A);
-
-			case 'B':
-			case 'b':
-				return (B);
-
-			case 'C':
-			case 'c':
-				return (C);
-
-			case 'E':
-			case 'e':
-				return (E);
-
-			case 'F':
-			case 'f':
-				return (F);
-
-			case 'I':
-			case 'i':
-				return (I);
-
-			case 'L':
-			case 'l':
-				return (L);
-
-			case 'N':
-			case 'n':
-				return (N);
-
-			case 'P':
-			case 'p':
-				return (P);
-
-			case 'R':
-			case 'r':
-				return (R);
-
-			case 'S':
-			case 's':
-				return (S);
-
-			case 'T':
-			case 't':
-				return (T);
-
-			}
-			break;
-
-		default:
-			fatal("Unknown state in scanner.");
-		}
-		yyerror((char *) 0);
-		state = CMD;
-		longjmp(errcatch,0);
-	}
-}
-
-upper(s)
-	register char *s;
-{
-	while (*s != '\0') {
-		if (islower(*s))
-			*s = toupper(*s);
-		s++;
-	}
-}
-
-char *
-copy(s)
-	char *s;
-{
-	char *p;
-	extern char *malloc(), *strcpy();
-
-	p = malloc((unsigned) strlen(s) + 1);
-	if (p == NULL)
-		fatal("Ran out of memory.");
-	(void) strcpy(p, s);
-	return (p);
-}
-
-help(ctab, s)
-	struct tab *ctab;
-	char *s;
-{
-	register struct tab *c;
-	register int width, NCMDS;
-	char *type;
-
-	if (ctab == sitetab)
-		type = "SITE ";
-	else
-		type = "";
-	width = 0, NCMDS = 0;
-	for (c = ctab; c->name != NULL; c++) {
-		int len = strlen(c->name);
-
-		if (len > width)
-			width = len;
-		NCMDS++;
-	}
-	width = (width + 8) &~ 7;
-	if (s == 0) {
-		register int i, j, w;
-		int columns, lines;
-
-		lreply(214, "The following %scommands are recognized %s.",
-		    type, "(* =>'s unimplemented)");
-		columns = 76 / width;
-		if (columns == 0)
-			columns = 1;
-		lines = (NCMDS + columns - 1) / columns;
-		for (i = 0; i < lines; i++) {
-			printf("   ");
-			for (j = 0; j < columns; j++) {
-				c = ctab + j * lines + i;
-				printf("%s%c", c->name,
-					c->implemented ? ' ' : '*');
-				if (c + lines >= &ctab[NCMDS])
-					break;
-				w = strlen(c->name) + 1;
-				while (w < width) {
-					putchar(' ');
-					w++;
-				}
-			}
-			printf("\r\n");
-		}
-		(void) fflush(stdout);
-		reply(214, "Direct comments to [email protected]%s.", hostname);
-		return;
-	}
-	upper(s);
-	c = lookup(ctab, s);
-	if (c == (struct tab *)0) {
-		reply(502, "Unknown command %s.", s);
-		return;
-	}
-	if (c->implemented)
-		reply(214, "Syntax: %s%s %s", type, c->name, c->help);
-	else
-		reply(214, "%s%-*s\t%s; unimplemented.", type, width,
-		    c->name, c->help);
-}
-
-sizecmd(filename)
-char *filename;
-{
-	switch (type) {
-	case TYPE_L:
-	case TYPE_I: {
-		struct stat stbuf;
-		if (stat(filename, &stbuf) < 0 ||
-		    (stbuf.st_mode&S_IFMT) != S_IFREG)
-			reply(550, "%s: not a plain file.", filename);
-		else
-			reply(213, "%lu", stbuf.st_size);
-		break;}
-	case TYPE_A: {
-		FILE *fin;
-		register int c, count;
-		struct stat stbuf;
-		fin = fopen(filename, "r");
-		if (fin == NULL) {
-			perror_reply(550, filename);
-			return;
-		}
-		if (fstat(fileno(fin), &stbuf) < 0 ||
-		    (stbuf.st_mode&S_IFMT) != S_IFREG) {
-			reply(550, "%s: not a plain file.", filename);
-			(void) fclose(fin);
-			return;
-		}
-
-		count = 0;
-		while((c=getc(fin)) != EOF) {
-			if (c == '\n')	/* will get expanded to \r\n */
-				count++;
-			count++;
-		}
-		(void) fclose(fin);
-
-		reply(213, "%ld", count);
-		break;}
-	default:
-		reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
-	}
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/verbose.c
--- a/head/usr.bin/yacc/verbose.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,381 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)verbose.c	5.3 (Berkeley) 1/20/91";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdlib.h>
-#include "defs.h"
-
-static short *null_rules;
-
-static void log_unused(void);
-static void log_conflicts(void);
-static void print_actions(int);
-static void print_conflicts(int);
-static void print_core(int);
-static void print_gotos(int);
-static void print_nulls(int);
-static void print_reductions(action *, register int);
-static void print_shifts(action *);
-static void print_state(int);
-
-void
-verbose(void)
-{
-    int i;
-
-    if (!vflag) return;
-
-    null_rules = malloc(nrules*sizeof(short));
-    if (null_rules == 0) no_space();
-    fprintf(verbose_file, "\f\n");
-    for (i = 0; i < nstates; i++)
-	print_state(i);
-    free(null_rules);
-
-    if (nunused)
-	log_unused();
-    if (SRtotal || RRtotal)
-	log_conflicts();
-
-    fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
-	    nvars);
-    fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
-}
-
-
-static void
-log_unused(void)
-{
-    int i;
-    short *p;
-
-    fprintf(verbose_file, "\n\nRules never reduced:\n");
-    for (i = 3; i < nrules; ++i)
-    {
-	if (!rules_used[i])
-	{
-	    fprintf(verbose_file, "\t%s :", symbol_name[rlhs[i]]);
-	    for (p = ritem + rrhs[i]; *p >= 0; ++p)
-		fprintf(verbose_file, " %s", symbol_name[*p]);
-	    fprintf(verbose_file, "  (%d)\n", i - 2);
-	}
-    }
-}
-
-
-static void
-log_conflicts(void)
-{
-    int i;
-
-    fprintf(verbose_file, "\n\n");
-    for (i = 0; i < nstates; i++)
-    {
-	if (SRconflicts[i] || RRconflicts[i])
-	{
-	    fprintf(verbose_file, "State %d contains ", i);
-	    if (SRconflicts[i] == 1)
-		fprintf(verbose_file, "1 shift/reduce conflict");
-	    else if (SRconflicts[i] > 1)
-		fprintf(verbose_file, "%d shift/reduce conflicts",
-			SRconflicts[i]);
-	    if (SRconflicts[i] && RRconflicts[i])
-		fprintf(verbose_file, ", ");
-	    if (RRconflicts[i] == 1)
-		fprintf(verbose_file, "1 reduce/reduce conflict");
-	    else if (RRconflicts[i] > 1)
-		fprintf(verbose_file, "%d reduce/reduce conflicts",
-			RRconflicts[i]);
-	    fprintf(verbose_file, ".\n");
-	}
-    }
-}
-
-
-static void
-print_state(int state)
-{
-    if (state)
-	fprintf(verbose_file, "\n\n");
-    if (SRconflicts[state] || RRconflicts[state])
-	print_conflicts(state);
-    fprintf(verbose_file, "state %d\n", state);
-    print_core(state);
-    print_nulls(state);
-    print_actions(state);
-}
-
-
-static void
-print_conflicts(int state)
-{
-    int symbol, act = 0, number = 0;
-    action *p;
-
-    symbol = -1;
-    for (p = parser[state]; p; p = p->next)
-    {
-	if (p->suppressed == 2)
-	    continue;
-
-	if (p->symbol != symbol)
-	{
-	    symbol = p->symbol;
-	    number = p->number;
-	    if (p->action_code == SHIFT)
-		act = SHIFT;
-	    else
-		act = REDUCE;
-	}
-	else if (p->suppressed == 1)
-	{
-	    if (state == final_state && symbol == 0)
-	    {
-		fprintf(verbose_file, "%d: shift/reduce conflict \
-(accept, reduce %d) on $end\n", state, p->number - 2);
-	    }
-	    else
-	    {
-		if (act == SHIFT)
-		{
-		    fprintf(verbose_file, "%d: shift/reduce conflict \
-(shift %d, reduce %d) on %s\n", state, number, p->number - 2,
-			    symbol_name[symbol]);
-		}
-		else
-		{
-		    fprintf(verbose_file, "%d: reduce/reduce conflict \
-(reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2,
-			    symbol_name[symbol]);
-		}
-	    }
-	}
-    }
-}
-
-
-static void
-print_core(int state)
-{
-    int i;
-    int k;
-    int rule;
-    core *statep;
-    short *sp;
-    short *sp1;
-
-    statep = state_table[state];
-    k = statep->nitems;
-
-    for (i = 0; i < k; i++)
-    {
-	sp1 = sp = ritem + statep->items[i];
-
-	while (*sp >= 0) ++sp;
-	rule = -(*sp);
-	fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]);
-
-        for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
-	    fprintf(verbose_file, "%s ", symbol_name[*sp]);
-
-	putc('.', verbose_file);
-
-	while (*sp >= 0)
-	{
-	    fprintf(verbose_file, " %s", symbol_name[*sp]);
-	    sp++;
-	}
-	fprintf(verbose_file, "  (%d)\n", -2 - *sp);
-    }
-}
-
-
-static void
-print_nulls(int state)
-{
-    action *p;
-    int i, j, k, nnulls;
-
-    nnulls = 0;
-    for (p = parser[state]; p; p = p->next)
-    {
-	if (p->action_code == REDUCE &&
-		(p->suppressed == 0 || p->suppressed == 1))
-	{
-	    i = p->number;
-	    if (rrhs[i] + 1 == rrhs[i+1])
-	    {
-		for (j = 0; j < nnulls && i > null_rules[j]; ++j)
-		    continue;
-
-		if (j == nnulls)
-		{
-		    ++nnulls;
-		    null_rules[j] = i;
-		}
-		else if (i != null_rules[j])
-		{
-		    ++nnulls;
-		    for (k = nnulls - 1; k > j; --k)
-			null_rules[k] = null_rules[k-1];
-		    null_rules[j] = i;
-		}
-	    }
-	}
-    }
-
-    for (i = 0; i < nnulls; ++i)
-    {
-	j = null_rules[i];
-	fprintf(verbose_file, "\t%s : .  (%d)\n", symbol_name[rlhs[j]],
-		j - 2);
-    }
-    fprintf(verbose_file, "\n");
-}
-
-
-static void
-print_actions(int stateno)
-{
-    action *p;
-    shifts *sp;
-    int as;
-
-    if (stateno == final_state)
-	fprintf(verbose_file, "\t$end  accept\n");
-
-    p = parser[stateno];
-    if (p)
-    {
-	print_shifts(p);
-	print_reductions(p, defred[stateno]);
-    }
-
-    sp = shift_table[stateno];
-    if (sp && sp->nshifts > 0)
-    {
-	as = accessing_symbol[sp->shift[sp->nshifts - 1]];
-	if (ISVAR(as))
-	    print_gotos(stateno);
-    }
-}
-
-
-static void
-print_shifts(action *p)
-{
-    int count;
-    action *q;
-
-    count = 0;
-    for (q = p; q; q = q->next)
-    {
-	if (q->suppressed < 2 && q->action_code == SHIFT)
-	    ++count;
-    }
-
-    if (count > 0)
-    {
-	for (; p; p = p->next)
-	{
-	    if (p->action_code == SHIFT && p->suppressed == 0)
-		fprintf(verbose_file, "\t%s  shift %d\n",
-			    symbol_name[p->symbol], p->number);
-	}
-    }
-}
-
-
-static void
-print_reductions(action *p, int defreduct)
-{
-    int k, anyreds;
-    action *q;
-
-    anyreds = 0;
-    for (q = p; q ; q = q->next)
-    {
-	if (q->action_code == REDUCE && q->suppressed < 2)
-	{
-	    anyreds = 1;
-	    break;
-	}
-    }
-
-    if (anyreds == 0)
-	fprintf(verbose_file, "\t.  error\n");
-    else
-    {
-	for (; p; p = p->next)
-	{
-	    if (p->action_code == REDUCE && p->number != defreduct)
-	    {
-		k = p->number - 2;
-		if (p->suppressed == 0)
-		    fprintf(verbose_file, "\t%s  reduce %d\n",
-			    symbol_name[p->symbol], k);
-	    }
-	}
-
-        if (defreduct > 0)
-	    fprintf(verbose_file, "\t.  reduce %d\n", defreduct - 2);
-    }
-}
-
-
-static void
-print_gotos(int stateno)
-{
-    int i, k;
-    int as;
-    short *tostate;
-    shifts *sp;
-
-    putc('\n', verbose_file);
-    sp = shift_table[stateno];
-    tostate = sp->shift;
-    for (i = 0; i < sp->nshifts; ++i)
-    {
-	k = tostate[i];
-	as = accessing_symbol[k];
-	if (ISVAR(as))
-	    fprintf(verbose_file, "\t%s  goto %d\n", symbol_name[as], k);
-    }
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/warshall.c
--- a/head/usr.bin/yacc/warshall.c	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Robert Paul Corbett.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)warshall.c	5.4 (Berkeley) 5/24/93";
-#endif
-#endif
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "defs.h"
-
-static void transitive_closure(unsigned *, int);
-
-static void
-transitive_closure(unsigned *R, int n)
-{
-    int rowsize;
-    unsigned i;
-    unsigned *rowj;
-    unsigned *rp;
-    unsigned *rend;
-    unsigned *ccol;
-    unsigned *relend;
-    unsigned *cword;
-    unsigned *rowi;
-
-    rowsize = WORDSIZE(n);
-    relend = R + n*rowsize;
-
-    cword = R;
-    i = 0;
-    rowi = R;
-    while (rowi < relend)
-    {
-	ccol = cword;
-	rowj = R;
-
-	while (rowj < relend)
-	{
-	    if (*ccol & (1 << i))
-	    {
-		rp = rowi;
-		rend = rowj + rowsize;
-		while (rowj < rend)
-		    *rowj++ |= *rp++;
-	    }
-	    else
-	    {
-		rowj += rowsize;
-	    }
-
-	    ccol += rowsize;
-	}
-
-	if (++i >= BITS_PER_WORD)
-	{
-	    i = 0;
-	    cword++;
-	}
-
-	rowi += rowsize;
-    }
-}
-
-void
-reflexive_transitive_closure(unsigned *R, int n)
-{
-    int rowsize;
-    unsigned i;
-    unsigned *rp;
-    unsigned *relend;
-
-    transitive_closure(R, n);
-
-    rowsize = WORDSIZE(n);
-    relend = R + n*rowsize;
-
-    i = 0;
-    rp = R;
-    while (rp < relend)
-    {
-	*rp |= (1 << i);
-	if (++i >= BITS_PER_WORD)
-	{
-	    i = 0;
-	    rp++;
-	}
-
-	rp += rowsize;
-    }
-}
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/yacc.1
--- a/head/usr.bin/yacc/yacc.1	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +0,0 @@
-.\" Copyright (c) 1989, 1990 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Robert Paul Corbett.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)yacc.1	5.8 (Berkeley) 5/24/93
-.\" $FreeBSD$
-.\"	$OpenBSD: yacc.1,v 1.14 2001/05/01 17:58:05 aaron Exp $
-.\"
-.Dd May 24, 1993
-.Dt YACC 1
-.Os
-.Sh NAME
-.Nm yacc
-.Nd an LALR(1) parser generator
-.Sh SYNOPSIS
-.Nm
-.Op Fl dlrtvy
-.Op Fl b Ar file_prefix
-.Op Fl o Ar output_filename
-.Op Fl p Ar symbol_prefix
-.Ar filename
-.Sh DESCRIPTION
-The
-.Nm
-utility reads the grammar specification in the file
-.Ar filename
-and generates an LR(1) parser for it.
-The parsers consist of a set of LALR(1) parsing tables and a driver routine
-written in the C programming language.
-The
-.Nm
-utility normally writes the parse tables and the driver routine to the file
-.Pa y.tab.c .
-.Pp
-The following options are available:
-.Bl -tag -width indent
-.It Fl b Ar file_prefix
-Change the prefix prepended to the output file names to
-the string denoted by
-.Ar file_prefix .
-The default prefix is the character
-.Pa y .
-.It Fl d
-Cause the header file
-.Pa y.tab.h
-to be written.
-.It Fl l
-If the
-.Fl l
-option is not specified,
-.Nm
-will insert #line directives in the generated code.
-The #line directives let the C compiler relate errors in the
-generated code to the user's original code.
-If the
-.Fl l
-option is specified,
-.Nm
-will not insert the #line directives.
-Any #line directives specified by the user will be retained.
-.It Fl o Ar output_filename
-Cause
-.Nm
-to write the generated code to
-.Ar output_filename
-instead of the default file,
-.Pa y.tab.c .
-.It Fl p Ar symbol_prefix
-Change the prefix prepended to yacc-generated symbols to
-the string denoted by
-.Ar symbol_prefix .
-The default prefix is the string
-.Pa yy .
-.It Fl r
-Cause
-.Nm
-to produce separate files for code and tables.
-The code file
-is named
-.Pa y.code.c ,
-and the tables file is named
-.Pa y.tab.c .
-.It Fl t
-Change the preprocessor directives generated by
-.Nm
-so that debugging statements will be incorporated in the compiled code.
-.It Fl v
-Cause a human-readable description of the generated parser to
-be written to the file
-.Pa y.output .
-.It Fl y
-NOOP for bison compatibility.
-.Nm
-is already designed to be POSIX yacc compatible.
-.El
-.Sh ENVIRONMENT
-.Bl -tag -width ".Ev TMPDIR"
-.It Ev TMPDIR
-Name of directory where temporary files are to be created.
-.El
-.Sh TABLES
-The names of the tables generated by this version of
-.Nm
-are
-.Va yylhs , yylen , yydefred , yydgoto , yysindex ,
-.Va yyrindex , yygindex , yytable ,
-and
-.Va yycheck .
-Two additional tables,
-.Va yyname
-and
-.Va yyrule ,
-are created if
-.Dv YYDEBUG
-is defined and non-zero.
-.Sh FILES
-.Bl -tag -width "Pa /tmp/yacc.aXXXXXXXXXX" -compact
-.It Pa y.code.c
-.It Pa y.tab.c
-.It Pa y.tab.h
-.It Pa y.output
-.It Pa /tmp/yacc.aXXXXXXXXXX
-.It Pa /tmp/yacc.tXXXXXXXXXX
-.It Pa /tmp/yacc.uXXXXXXXXXX
-.El
-.Sh DIAGNOSTICS
-If there are rules that are never reduced,
-the number of such rules is reported on standard error.
-If there are any
-.Tn LALR(1)
-conflicts,
-the number of conflicts is reported on standard error.
-.Sh SEE ALSO
-.Xr yyfix 1
-.Sh STANDARDS
-The
-.Nm
-utility conforms to
-.St -p1003.2 .
-.Sh HISTORY
-A
-.Nm
-command appeared in PWB UNIX.
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/yyfix.1
--- a/head/usr.bin/yacc/yyfix.1	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-.\" Copyright (c) 1990, 1991 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\"    may be used to endorse or promote products derived from this software
-.\"    without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)yyfix.1	5.4 (Berkeley) 3/23/93
-.\" $FreeBSD$
-.\"
-.Dd March 23, 1993
-.Dt YYFIX 1
-.Os
-.Sh NAME
-.Nm yyfix
-.Nd extract tables from y.tab.c
-.Sh SYNOPSIS
-.Nm
-.Ar file
-.Op Ar tables
-.Sh DESCRIPTION
-Programs have historically used a script (often named
-.Dq :yyfix )
-to extract tables from the
-.Xr yacc 1
-generated file
-.Pa y.tab.c .
-As the names of the tables generated by the current version of
-.Xr yacc 1
-are different from those of historical versions of
-.Xr yacc 1 ,
-the shell script
-.Nm
-is provided to simplify the transition.
-.Pp
-The first (and required) argument to
-.Nm
-is the name of the file where the extracted tables should be stored.
-.Pp
-If further command line arguments are specified, they are taken as
-the list of tables to be extracted.
-Otherwise,
-.Nm
-attempts to determine if the
-.Pa y.tab.c
-file is from an old or new
-.Xr yacc 1 ,
-and extracts the appropriate tables.
-.Pp
-The tables
-.Dq yyexca ,
-.Dq yyact ,
-.Dq yypact ,
-.Dq yypgo ,
-.Dq yyr1 ,
-.Dq yyr2 ,
-.Dq yychk ,
-and
-.Dq yydef
-are extracted
-from historical versions of
-.Xr yacc 1 .
-.Pp
-The tables
-.Dq yylhs ,
-.Dq yylen ,
-.Dq yydefred ,
-.Dq yydgoto ,
-.Dq yysindex ,
-.Dq yyrindex ,
-.Dq yygindex ,
-.Dq yytable ,
-.Dq yyname ,
-.Dq yyrule ,
-and
-.Dq yycheck ,
-are extracted from the current version of
-.Xr yacc 1 .
-.Sh FILES
-.Bl -tag -width y.tab.c
-.It Pa y.tab.c
-File from which tables are extracted.
-.El
-.Sh SEE ALSO
-.Xr yacc 1
-.Sh HISTORY
-The
-.Nm
-command first appeared in
-.Bx 4.4 .
diff -r 91983250c121 -r 49f3e3227aef head/usr.bin/yacc/yyfix.sh
--- a/head/usr.bin/yacc/yyfix.sh	Wed Jul 25 16:29:58 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1990 The Regents of the University of California.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# $FreeBSD$
-#
-#	@(#)yyfix.sh	5.2 (Berkeley) 5/12/90
-#
-OLDYACC="yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef"
-NEWYACC="yylhs yylen yydefred yydgoto yysindex yyrindex yygindex \
-	 yytable yycheck"
-
-if [ $# -eq 0 ]; then
-	echo "usage: $0 file [tables]" >&2
-	exit 1
-fi
-
-file=$1
->$file
-shift
-
-if [ $# -eq 0 ] ; then
-	if grep yylhs y.tab.c > /dev/null ; then
-		if grep yyname y.tab.c > /dev/null ; then
-			NEWYACC="$NEWYACC yyname"
-		fi
-		if grep yyrule y.tab.c > /dev/null ; then
-			NEWYACC="$NEWYACC yyrule"
-		fi
-		set $NEWYACC
-	else
-		set $OLDYACC
-	fi
-fi
-
-for i
-do
-ed - y.tab.c << END
-/^\(.*\)$i[ 	]*\[]/s//extern \1 $i[];\\
-\1 $i []/
-.ka
-/}/kb
-'br $file
-'a,.w $file
-'a,.d
-w
-q
-END
-done



More information about the Zrouter-src-freebsd mailing list