From c75b1a90ccf3af8322703f92c414035b68036e2e Mon Sep 17 00:00:00 2001 From: "J.T. Conklin" Date: Tue, 23 Nov 1993 00:20:04 +0000 Subject: [PATCH] POSIX.2ification, from my work with NetBSD. --- usr.bin/comm/comm.1 | 16 +++++++++++++--- usr.bin/comm/comm.c | 37 +++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/usr.bin/comm/comm.1 b/usr.bin/comm/comm.1 index 3f743469ea..0983293604 100644 --- a/usr.bin/comm/comm.1 +++ b/usr.bin/comm/comm.1 @@ -32,7 +32,8 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)comm.1 6.7 (Berkeley) 6/27/91 +.\" from: @(#)comm.1 6.7 (Berkeley) 6/27/91 +.\" $Id: comm.1,v 1.3 1993/09/21 23:20:34 jtc Exp $ .\" .Dd June 27, 1991 .Os @@ -80,7 +81,15 @@ printed in column number three will have one. .Nm Comm assumes that the files are lexically sorted; all characters participate in line comparisons. -.Pp +.\" .Sh ENVIRONMENT +.\" .Bl -tag -width indent +.\" .It Ev LANG +.\" .It Ev LC_ALL +.\" .It Ev LC_CTYPE +.\" .It Ev LC_COLLATE +.\" .It Ev LC_MESSAGES +.\" .El +.Sh DIAGNOSTICS .Nm Comm exits 0 on success, >0 if an error occurred. .Sh SEE ALSO @@ -91,4 +100,5 @@ exits 0 on success, >0 if an error occurred. .Sh STANDARDS The .Nm comm -command is expected to be POSIX 1003.2 compatible. +utility conforms to +.St -p1003.2-92 . diff --git a/usr.bin/comm/comm.c b/usr.bin/comm/comm.c index e09e1a0f60..a32d57dab6 100644 --- a/usr.bin/comm/comm.c +++ b/usr.bin/comm/comm.c @@ -41,34 +41,41 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)comm.c 5.7 (Berkeley) 11/1/90"; +/*static char sccsid[] = "from: @(#)comm.c 5.7 (Berkeley) 11/1/90";*/ +static char rcsid[] = "$Id: comm.c,v 1.4 1993/10/13 18:33:45 jtc Exp $"; #endif /* not lint */ -#include -#include #include +#include +#include +#include +#include +#include #define MAXLINELEN (_POSIX2_LINE_MAX + 1) char *tabs[] = { "", "\t", "\t\t" }; +FILE *file __P((const char *)); +void show __P((FILE *, char *, char *)); +void usage __P((void)); + +int main(argc,argv) int argc; - char *argv[]; + char **argv; { register int comp, file1done, file2done, read1, read2; register char *col1, *col2, *col3; int ch, flag1, flag2, flag3; - FILE *fp1, *fp2, *file(); + FILE *fp1, *fp2; char **p, line1[MAXLINELEN], line2[MAXLINELEN]; - extern int optind; + + setlocale(LC_ALL, ""); flag1 = flag2 = flag3 = 1; - while ((ch = getopt(argc, argv, "-123")) != EOF) + while ((ch = getopt(argc, argv, "123")) != -1) switch(ch) { - case '-': - --optind; - goto done; case '1': flag1 = 0; break; @@ -82,7 +89,7 @@ main(argc,argv) default: usage(); } -done: argc -= optind; + argc -= optind; argv += optind; if (argc != 2) @@ -121,7 +128,7 @@ done: argc -= optind; } /* lines are the same */ - if (!(comp = strcmp(line1, line2))) { + if (!(comp = strcoll(line1, line2))) { read1 = read2 = 1; if (col3) (void)printf("%s%s", col3, line1); @@ -144,6 +151,7 @@ done: argc -= optind; exit(0); } +void show(fp, offset, buf) FILE *fp; char *offset, *buf; @@ -155,7 +163,7 @@ show(fp, offset, buf) FILE * file(name) - char *name; + const char *name; { FILE *fp; @@ -168,8 +176,9 @@ file(name) return(fp); } +void usage() { - (void)fprintf(stderr, "usage: comm [-123] [ - ] file1 file2\n"); + (void)fprintf(stderr, "usage: comm [-123] file1 file2\n"); exit(1); } -- 2.20.1