From owner-freebsd-standards Mon Mar 18 18:40:33 2002 Delivered-To: freebsd-standards@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id D9FD137B41A for ; Mon, 18 Mar 2002 18:40:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2J2e2574659; Mon, 18 Mar 2002 18:40:02 -0800 (PST) (envelope-from gnats) Received: from descent.robbins.dropbear.id.au (044.a.006.mel.iprimus.net.au [210.50.44.44]) by hub.freebsd.org (Postfix) with ESMTP id B8DD937B405 for ; Mon, 18 Mar 2002 18:38:30 -0800 (PST) Received: (from tim@localhost) by descent.robbins.dropbear.id.au (8.11.6/8.11.6) id g2J2ahn00531; Tue, 19 Mar 2002 13:36:43 +1100 (EST) (envelope-from tim) Message-Id: <200203190236.g2J2ahn00531@descent.robbins.dropbear.id.au> Date: Tue, 19 Mar 2002 13:36:43 +1100 (EST) From: "Tim J. Robbins" Reply-To: "Tim J. Robbins" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: standards/36072: P1003.1-2001 join(1) -o 0 option 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 >Number: 36072 >Category: standards >Synopsis: P1003.1-2001 join(1) -o 0 option >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Mar 18 18:40:02 PST 2002 >Closed-Date: >Last-Modified: >Originator: Tim J. Robbins >Release: FreeBSD 4.5-STABLE i386 >Organization: >Environment: System: FreeBSD descent.robbins.dropbear.id.au 4.5-STABLE FreeBSD 4.5-STABLE #8: Tue Mar 19 08:46:39 EST 2002 tim@descent.robbins.dropbear.id.au:/usr/obj/usr/src/sys/DESCENT i386 >Description: -o 0 cannot be used with FreeBSD join(1) to specify that the join field be output. NOTE: This patch does not bring join(1) up to conformance; see the note I added to the STANDARDS section. As the example below shows, join is supposed to accept eg. -a 2 and -a2, whereas our join only accepts the latter. >How-To-Repeat: From the standard: The -o 0 field essentially selects the union of the join fields. For example, given file phone: !Name Phone Number Don +1 123-456-7890 Hal +1 234-567-8901 Yasushi +2 345-678-9012 and file fax: !Name Fax Number Don +1 123-456-7899 Keith +1 456-789-0122 Yasushi +2 345-678-9011 (where the large expanses of white space are meant to each represent a single ), the command: join -t "" -a 1 -a 2 -e '(unknown)' -o 0,1.2,2.2 phone fax would produce: !Name Phone Number Fax Number Don +1 123-456-7890 +1 123-456-7899 Hal +1 234-567-8901 (unknown) Keith (unknown) +1 456-789-0122 Yasushi +2 345-678-9012 +2 345-678-9011 >Fix: Index: join.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/join/join.1,v retrieving revision 1.7 diff -u -r1.7 join.1 --- join.1 2001/08/15 09:09:41 1.7 +++ join.1 2002/03/19 02:31:38 @@ -106,13 +106,16 @@ each line with matching join fields. Each element of .Ar list -has the form +has the either the form .Ql file_number.field , where .Ar file_number is a file number and .Ar field -is a field number. +is a field number, or the form +.Ql 0 +.Pq zero , +representing the join field. The elements of list must be either comma .Pf ( Dq , Ns ) or whitespace separated. @@ -216,9 +219,11 @@ .Sh STANDARDS The .Nm -command is expected to be -.St -p1003.2 -compatible. +command conforms to +.St -p1003.1-2001 +except for the requirement that there be no space between the +.Fl a +option and its argument. .Sh SEE ALSO .Xr awk 1 , .Xr comm 1 , Index: join.c =================================================================== RCS file: /home/ncvs/src/usr.bin/join/join.c,v retrieving revision 1.10 diff -u -r1.10 join.c --- join.c 1999/08/28 01:02:19 1.10 +++ join.c 2002/03/19 02:31:41 @@ -405,6 +405,8 @@ for (cnt = 0; cnt < olistcnt; ++cnt) { if (olist[cnt].filenum == F->number) outfield(lp, olist[cnt].fieldno, 0); + else if (olist[cnt].filenum == 0) + outfield(lp, F->joinf, 0); else outfield(lp, 0, 1); } @@ -427,7 +429,12 @@ /* Output a pair of lines according to the join list (if any). */ if (olist) for (cnt = 0; cnt < olistcnt; ++cnt) - if (olist[cnt].filenum == 1) + if (olist[cnt].filenum == 0) { + if (lp1->fieldcnt >= F1->joinf) + outfield(lp1, F1->joinf, 0); + else + outfield(lp2, F2->joinf, 0); + } else if (olist[cnt].filenum == 1) outfield(lp1, olist[cnt].fieldno, 0); else /* if (olist[cnt].filenum == 2) */ outfield(lp2, olist[cnt].fieldno, 0); @@ -480,27 +487,33 @@ fieldarg(option) char *option; { - u_long fieldno; + u_long fieldno, filenum; char *end, *token; while ((token = strsep(&option, ", \t")) != NULL) { if (*token == '\0') continue; - if (token[0] != '1' && token[0] != '2' || token[1] != '.') - errx(1, "malformed -o option field"); - fieldno = strtol(token + 2, &end, 10); - if (*end) + if (token[0] == '0') + filenum = fieldno = 0; + else if ((token[0] == '1' || token[0] == '2') && + token[1] == '.') { + filenum = token[0] - '0'; + fieldno = strtol(token + 2, &end, 10); + if (*end) + errx(1, "malformed -o option field"); + if (fieldno == 0) + errx(1, "field numbers are 1 based"); + --fieldno; + } else errx(1, "malformed -o option field"); - if (fieldno == 0) - errx(1, "field numbers are 1 based"); if (olistcnt == olistalloc) { olistalloc += 50; if ((olist = realloc(olist, olistalloc * sizeof(OLIST))) == NULL) err(1, NULL); } - olist[olistcnt].filenum = token[0] - '0'; - olist[olistcnt].fieldno = fieldno - 1; + olist[olistcnt].filenum = filenum; + olist[olistcnt].fieldno = fieldno; ++olistcnt; } } @@ -567,6 +580,8 @@ if (ap[2] != '\0') break; for (p = argv + 2; *p; ++p) { + if (p[0][0] == '0') + break; if (p[0][0] != '1' && p[0][0] != '2' || p[0][1] != '.') break; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message