From fcb113145cd718429042b550bf7bd3280ddaa6d1 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Sat, 20 Apr 2002 01:55:19 +0000 Subject: [PATCH] Allow space between -a and its argument. Honour locale collating order by using strcoll() instead of strcmp(). PR: 36270 Reviewed by: mike --- usr.bin/join/join.1 | 16 ++-------------- usr.bin/join/join.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/usr.bin/join/join.1 b/usr.bin/join/join.1 index 10e00f0de40d..9a0084948f5b 100644 --- a/usr.bin/join/join.1 +++ b/usr.bin/join/join.1 @@ -35,7 +35,7 @@ .\" @(#)join.1 8.3 (Berkeley) 4/28/95 .\" $FreeBSD$ .\" -.Dd April 28, 1995 +.Dd April 18, 2002 .Dt JOIN 1 .Os .Sh NAME @@ -91,11 +91,6 @@ The following options are available: In addition to the default output, produce a line for each unpairable line in file .Ar file_number . -(The argument to -.Fl a -must not be preceded by a space; see the -.Sx COMPATIBILITY -section.) .It Fl e Ar string Replace empty output fields with .Ar string . @@ -182,10 +177,6 @@ the following options are available: .It Fl a In addition to the default output, produce a line for each unpairable line in both file 1 and file 2. -(To distinguish between this and -.Fl a Ar file_number , -.Nm -currently requires that the latter not include any white space.) .It Fl j1 Ar field Join on the .Ar field Ns 'th @@ -220,10 +211,7 @@ modification and should not be used. The .Nm command conforms to -.St -p1003.1-2001 -except for the requirement that there be no space between the -.Fl a -option and its argument. +.St -p1003.1-2001 . .Sh SEE ALSO .Xr awk 1 , .Xr comm 1 , diff --git a/usr.bin/join/join.c b/usr.bin/join/join.c index 84ea61b31e49..77d680126737 100644 --- a/usr.bin/join/join.c +++ b/usr.bin/join/join.c @@ -54,6 +54,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -121,6 +122,8 @@ main(argc, argv) int aflag, ch, cval, vflag; char *end; + setlocale(LC_ALL, ""); + F1 = &input1; F2 = &input2; @@ -365,7 +368,7 @@ cmp(lp1, fieldno1, lp2, fieldno2) return (lp2->fieldcnt <= fieldno2 ? 0 : 1); if (lp2->fieldcnt <= fieldno2) return (-1); - return (strcmp(lp1->fields[fieldno1], lp2->fields[fieldno2])); + return (strcoll(lp1->fields[fieldno1], lp2->fields[fieldno2])); } void @@ -543,8 +546,13 @@ obsolete(argv) * on the command line. (Well, we could reallocate * the argv array, but that hardly seems worthwhile.) */ - if (ap[2] == '\0') + if (ap[2] == '\0' && (argv[1] == NULL || + (strcmp(argv[1], "1") != 0 && + strcmp(argv[1], "2") != 0))) { ap[1] = '\01'; + warnx("-a option used without an argument; " + "reverting to historical behavior"); + } break; case 'j': /*