From owner-freebsd-standards Sat Oct 26 9:39:53 2002 Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DBDAA37B404 for ; Sat, 26 Oct 2002 09:39:41 -0700 (PDT) Received: from thuvia.demon.co.uk (thuvia.demon.co.uk [193.237.34.248]) by mx1.FreeBSD.org (Postfix) with ESMTP id 20A1043E3B for ; Sat, 26 Oct 2002 09:39:38 -0700 (PDT) (envelope-from mark@thuvia.demon.co.uk) Received: from dotar.thuvia.org (dotar.thuvia.org [10.0.0.4]) by phaidor.thuvia.org (8.12.3/8.12.3) with ESMTP id g9QGdZcF053867 for ; Sat, 26 Oct 2002 17:39:36 +0100 (BST) (envelope-from mark@thuvia.demon.co.uk) Received: from dotar.thuvia.org (localhost [IPv6:::1]) by dotar.thuvia.org (8.12.6/8.12.6) with ESMTP id g9QGdZH5008951 for ; Sat, 26 Oct 2002 17:39:35 +0100 (BST) (envelope-from mark@dotar.thuvia.org) Received: (from mark@localhost) by dotar.thuvia.org (8.12.6/8.12.6/Submit) id g9QGdZ8F008950 for freebsd-standards@freebsd.org; Sat, 26 Oct 2002 17:39:35 +0100 (BST) Date: Sat, 26 Oct 2002 17:39:35 +0100 (BST) From: Mark Valentine Message-Id: <200210261639.g9QGdZ8F008950@dotar.thuvia.org> X-Mailer: Mail User's Shell (7.2.6 beta(5) 10/07/98) To: freebsd-standards@freebsd.org Subject: /usr/posix: a first cut Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG The following patch implements a /usr/posix directory where POSIX.1 versions of utilities which conflict with traditional BSD behaviour can be installed. It installs versions of expr(1) and sort(1) there, reverts /bin/expr to being BSD-compatible, and enables the new /usr/posix/sort behaviour by bumping _POSIX2_VERSION in back to 200112. In actual fact the /usr/posix binaries are exactly what were /bin/expr and /usr/bin/sort, which are replaced by one-line scripts which call the /usr/posix versions with the appropriate existing compatibility environment variable set. The patch updates heir(7) and adds an initial stab at a posix(7) page. NOTES: 1. I chose /usr/posix instead of /usr/posix/bin which has been mentioned to align with historical BSD practice: /usr/ucb, /usr/games, /usr/contrib and so on; also, I'd expect any POSIX-specific libraries to go under /usr/lib/posix or similar, rather than /usr/posix/lib. It's not like this is a separate subsystem. This is a point for discussion. 2. /usr/posix/expr still obeys the EXPR_COMPAT environment variable, which makes the manual page a little messy. The alternative is to compile separate binaries with and without -DEXPR_COMPAT (once I implement that) instead - it's probably tidier, but let's see what people think. 3. The GNU sort manual page is somewhat lacking - it seems a shame to take it off the vendor branch to add the pathetic attempt I've made at documenting the two versions. All ideas welcome. 4. Were any other things affected unduly by the previous bump of _POSIX2_VERSION to 200112? If so, I'll need to look at what to do with those. 5. /usr/posix/sort still obeys the _POSIX2_VERSION environment variable. I think that's fine. This is just a first cut to get a feel for whether people think something like this is useful. Any and all comments are welcome. Documentation improvements from those more familiar with the standards are especially welcome. Cheers, Mark. Index: bin/expr/Makefile =================================================================== RCS file: /usr/cvs/src/bin/expr/Makefile,v retrieving revision 1.17 diff -u -u -r1.17 Makefile --- bin/expr/Makefile 23 Mar 2002 00:44:00 -0000 1.17 +++ bin/expr/Makefile 26 Oct 2002 11:14:55 -0000 @@ -1,8 +1,12 @@ # $FreeBSD: src/bin/expr/Makefile,v 1.17 2002/03/23 00:44:00 wollman Exp $ +BINDIR= /usr/posix + PROG= expr SRCS= expr.y YFLAGS= + +SUBDIR= compat NO_WERROR= "GCC can't handle C99 printf formats." Index: bin/expr/expr.1 =================================================================== RCS file: /usr/cvs/src/bin/expr/expr.1,v retrieving revision 1.20 diff -u -u -r1.20 expr.1 --- bin/expr/expr.1 29 May 2002 15:18:35 -0000 1.20 +++ bin/expr/expr.1 26 Oct 2002 14:24:56 -0000 @@ -30,14 +30,16 @@ .\" .\" $FreeBSD: src/bin/expr/expr.1,v 1.20 2002/05/29 15:18:35 ru Exp $ .\" -.Dd May 10, 2002 +.Dd October 26, 2002 .Dt EXPR 1 .Os .Sh NAME .Nm expr .Nd evaluate expression .Sh SYNOPSIS -.Nm +.Nm /bin/expr +.Ar expression +.Nm /usr/posix/expr .Op Fl e .Ar expression .Sh DESCRIPTION @@ -51,6 +53,17 @@ Several of the operators have special meaning to command interpreters and must therefore be quoted appropriately. All integer operands are interpreted in base 10. +.Ss Nm /bin/expr +.Pp +Arithmetic operations are performed using signed integer math. +Arithmetic uses the C +.Vt intmax_t +data type (the largest integral type available), and +.Nm +will detect arithmetic overflow and return an error indication. +If a numeric operand is specified which is so large as to overflow +conversion to an integer, it is parsed as a string instead. +.Ss Nm /usr/posix/expr .Pp Arithmetic operations are performed using signed integer math. If the @@ -120,6 +133,7 @@ .El .Pp Parentheses are used for grouping in the usual manner. +.Ss Nm /usr/posix/expr .Pp Unless the .Ev EXPR_COMPAT @@ -134,17 +148,17 @@ syntax may be used to prevent this interpretation. However, many historic implementations of .Nm , -including the one in previous versions of -.Fx , +including +.Nm /bin/expr +for compatibility reasons, will not permit this syntax. See the examples below for portable ways to guarantee the correct interpretation. The -.Ev EXPR_COMPAT -variable is intended for use as a transition and debugging aid, when -.Nm -is used in complex scripts which cannot easily be recast to avoid the -non-portable usage. +.Nm /bin/expr +utility in future versions of +.Fx +may adopt the \*[Px] syntax and conventions. Defining .Ev EXPR_COMPAT also implicitly enables the @@ -168,10 +182,11 @@ New applications are advised to use shell arithmetic rather than .Nm . .Sh ENVIRONMENT +.Ss Nm /usr/posix/expr .Bl -tag -width ".Ev EXPR_COMPAT" .It Ev EXPR_COMPAT If set, -.Nm +.Nm /usr/posix/expr will emulate historic .Nm implementations which did not obey the Utility Syntax Guidelines. @@ -179,6 +194,10 @@ .Fl e . .El .Sh EXAMPLES +The following examples will work with both +.Nm /bin/expr +and +.Nm /usr/posix/expr . .Bl -bullet .It The following example (in @@ -216,21 +235,23 @@ .Pp The following examples output the number of characters in variable .Va a . +.Bl -bullet +.It +The +.Nm /bin/expr +command does not interpret leading hyphens as options: +.Dl "expr \*q$a\*q \&: \*q.*\*q" +.It Again, if .Va a might begin with a hyphen, it is necessary to prevent it from being interpreted as an option to -.Nm . -.Bl -bullet -.It -If the -.Nm -command conforms to -.St -p1003.1-2001 , -this is simple: +.Nm /usr/posix/expr : .Dl "expr -- \*q$a\*q \&: \*q.*\*q" .It -For portability to older systems, however, a more complicated command +For portability to both versions of +.Nm , +however, a more complicated command is required: .Dl "expr \e( \*qX$a\*q \&: \*q.*\*q \e) - 1" .El @@ -248,10 +269,11 @@ .El .Sh SEE ALSO .Xr sh 1 , -.Xr test 1 +.Xr test 1 , +.Xr posix 7 .Sh STANDARDS The -.Nm +.Nm /usr/posix/expr utility conforms to .St -p1003.1-2001 , provided that the Index: bin/expr/compat/Makefile =================================================================== RCS file: bin/expr/compat/Makefile diff -N bin/expr/compat/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bin/expr/compat/Makefile 26 Oct 2002 15:54:45 -0000 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +SCRIPTSDIR=/bin +SCRIPTS= expr + +.include Index: bin/expr/compat/expr.sh =================================================================== RCS file: bin/expr/compat/expr.sh diff -N bin/expr/compat/expr.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bin/expr/compat/expr.sh 26 Oct 2002 15:55:26 -0000 @@ -0,0 +1,5 @@ +#! /bin/sh +# +# $FreeBSD$ + +EXPR_COMPAT=true exec /usr/posix/expr "$@" Index: contrib/gnu-sort/man/sort.1 =================================================================== RCS file: /usr/cvs/src/contrib/gnu-sort/man/sort.1,v retrieving revision 1.1.1.1 diff -u -u -r1.1.1.1 sort.1 --- contrib/gnu-sort/man/sort.1 8 Jun 2002 07:47:23 -0000 1.1.1.1 +++ contrib/gnu-sort/man/sort.1 26 Oct 2002 15:45:59 -0000 @@ -3,7 +3,10 @@ .SH NAME sort \- sort lines of text files .SH SYNOPSIS -.B sort +.B /usr/bin/sort +[\fIOPTION\fR]... [\fIFILE\fR]... +.PP +.B /usr/posix/sort [\fIOPTION\fR]... [\fIFILE\fR]... .SH DESCRIPTION .\" Add any additional description here @@ -85,6 +88,13 @@ % 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y. .PP With no FILE, or when FILE is -, read standard input. +.PP +The +.B /usr/bin/sort +command accepts the traditional \fB+\fRPOS syntax (obsoleted by \fB-k\fR); +the +.B /usr/posix/sort +command treats an argument starting with a \fB+\fR as a FILE. .PP *** WARNING *** The locale specified by the environment affects sort order. Index: gnu/usr.bin/sort/Makefile =================================================================== RCS file: /usr/cvs/src/gnu/usr.bin/sort/Makefile,v retrieving revision 1.7 diff -u -u -r1.7 Makefile --- gnu/usr.bin/sort/Makefile 8 Jun 2002 10:34:12 -0000 1.7 +++ gnu/usr.bin/sort/Makefile 26 Oct 2002 14:28:24 -0000 @@ -1,5 +1,7 @@ # $FreeBSD: src/gnu/usr.bin/sort/Makefile,v 1.7 2002/06/08 10:34:12 ache Exp $ +BINDIR= /usr/posix + SORTDIR= ${.CURDIR}/../../../contrib/gnu-sort .PATH: ${SORTDIR}/lib ${SORTDIR}/src ${SORTDIR}/man @@ -26,5 +28,7 @@ xstrtoumax.c CFLAGS+=-I${.CURDIR} -I${SORTDIR}/lib -DHAVE_CONFIG_H + +SUBDIR= compat .include Index: gnu/usr.bin/sort/compat/Makefile =================================================================== RCS file: gnu/usr.bin/sort/compat/Makefile diff -N gnu/usr.bin/sort/compat/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/sort/compat/Makefile 26 Oct 2002 15:56:47 -0000 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +SCRIPTSDIR=/usr/bin +SCRIPTS= sort + +.include Index: gnu/usr.bin/sort/compat/sort.sh =================================================================== RCS file: gnu/usr.bin/sort/compat/sort.sh diff -N gnu/usr.bin/sort/compat/sort.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/sort/compat/sort.sh 26 Oct 2002 15:56:56 -0000 @@ -0,0 +1,5 @@ +#! /bin/sh +# +# $FreeBSD$ + +_POSIX2_VERSION=199212 exec /usr/posix/sort "$@" Index: include/unistd.h =================================================================== RCS file: /usr/cvs/src/include/unistd.h,v retrieving revision 1.61 diff -u -u -r1.61 unistd.h --- include/unistd.h 13 Oct 2002 14:25:01 -0000 1.61 +++ include/unistd.h 26 Oct 2002 14:34:36 -0000 @@ -144,7 +144,7 @@ #endif /* Define the POSIX.2 version we target for compliance. */ -#define _POSIX2_VERSION 199212L +#define _POSIX2_VERSION 200112L /* * POSIX-style system configuration variable accessors (for the Index: share/man/man7/Makefile =================================================================== RCS file: /usr/cvs/src/share/man/man7/Makefile,v retrieving revision 1.24 diff -u -u -r1.24 Makefile --- share/man/man7/Makefile 6 Jul 2002 20:30:29 -0000 1.24 +++ share/man/man7/Makefile 26 Oct 2002 15:04:17 -0000 @@ -3,7 +3,7 @@ #MISSING: eqnchar.7 ms.7 term.7 MAN= ascii.7 build.7 clocks.7 environ.7 firewall.7 ffs.7 hier.7 \ - hostname.7 intro.7 mailaddr.7 operator.7 ports.7 release.7 \ + hostname.7 intro.7 mailaddr.7 operator.7 ports.7 posix.7 release.7 \ sdoc.7 security.7 sprog.7 stdint.7 tuning.7 MLINKS= intro.7 miscellaneous.7 Index: share/man/man7/hier.7 =================================================================== RCS file: /usr/cvs/src/share/man/man7/hier.7,v retrieving revision 1.77 diff -u -u -r1.77 hier.7 --- share/man/man7/hier.7 22 Oct 2002 10:37:07 -0000 1.77 +++ share/man/man7/hier.7 26 Oct 2002 15:02:49 -0000 @@ -419,6 +419,10 @@ The .Fx ports collection (optional). +.It Pa posix/ +POSIX-compatible versions of certain utilities; +see +.Xr posix 7 .It Pa sbin/ system daemons & system utilities (executed by users) .It Pa share/ Index: share/man/man7/posix.7 =================================================================== RCS file: share/man/man7/posix.7 diff -N share/man/man7/posix.7 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ share/man/man7/posix.7 26 Oct 2002 15:21:08 -0000 @@ -0,0 +1,46 @@ +.\" Copyright (c) 2002 Thuvia Labs Limited +.\" +.\" 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 author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" 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$ +.\" +.Dd October 26, 2002 +.Os +.Dt POSIX 7 +.Sh NAME +.Nm ports +.Nd POSIX conformance notes +.Sh DESCRIPTION +.Fx attempts to be compatible with various applicable standards, including +.St -p1003.1-2001 . +In certain cases, where the behaviour specified by \*[Px] conflicts +with traditional BSD behaviour, a more standards compliant version +of the utility may be found in the +.Pa /usr/posix +directory. +.Sh SEE ALSO +.Xr expr 1 , +.Xr sort 1 , +.Xr hier 7 -- Mark Valentine, Thuvia Labs "Tigers will do ANYTHING for a tuna fish sandwich." Mark Valentine uses "We're kind of stupid that way." *munch* *munch* and endorses FreeBSD -- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message