From owner-freebsd-current@FreeBSD.ORG Sat Jan 29 02:08:50 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 64B7716A4CF for ; Sat, 29 Jan 2005 02:08:50 +0000 (GMT) Received: from mail.gmx.net (pop.gmx.de [213.165.64.20]) by mx1.FreeBSD.org (Postfix) with SMTP id 67FA043D39 for ; Sat, 29 Jan 2005 02:08:49 +0000 (GMT) (envelope-from m@MHoerich.de) Received: (qmail invoked by alias); 29 Jan 2005 02:08:45 -0000 Received: from p508A59AC.dip.t-dialin.net (EHLO localhost) (80.138.89.172) by mail.gmx.net (mp017) with SMTP; 29 Jan 2005 03:08:45 +0100 X-Authenticated: #5114400 Date: Sat, 29 Jan 2005 03:08:36 +0100 From: Mario Hoerich To: Kris Kennaway Message-ID: <20050129020836.GA75340@Pandora.MHoerich.de> Mail-Followup-To: Kris Kennaway , Tim Robbins , Scot Hetzel , freebsd-current@freebsd.org References: <790a9fff05012509511b64e3ad@mail.gmail.com> <20050125221047.GA339@cat.robbins.dropbear.id.au> <20050125223834.GA28389@xor.obsecurity.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050125223834.GA28389@xor.obsecurity.org> User-Agent: Mutt/1.4.2.1i Organization: not organized X-Y-GMX-Trusted: 0 cc: Scot Hetzel cc: Tim Robbins cc: freebsd-current@freebsd.org Subject: comm(1) (was: Re: uniq truncates lines > 2048 bytes) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jan 2005 02:08:50 -0000 # Kris Kennaway: > On Wed, Jan 26, 2005 at 09:10:47AM +1100, Tim Robbins wrote: > > > > I was planning on going through all text-processing utilities in the base > > system some time and either fixing line length problems or documenting them, > > similar to what I did with multibyte character support. I may make a start > > at that today. > > If someone could fix comm(1) that would be a big help for me, because > I have a local hack I have to carry around in all of my local package > source trees. Does this patch help? I haven't made any contributions before, so I just hope I'm not making a fool of myself with this... HTH, Mario Index: comm.c =================================================================== RCS file: /home/ncvs/src/usr.bin/comm/comm.c,v retrieving revision 1.21 diff -u -r1.21 comm.c --- comm.c 2 Jul 2004 22:48:29 -0000 1.21 +++ comm.c 29 Jan 2005 01:30:13 -0000 @@ -66,6 +66,8 @@ FILE *file(const char *); void show(FILE *, const char *, const wchar_t *, wchar_t *); int wcsicoll(const wchar_t *, const wchar_t *); +wchar_t *fgetwla(FILE *); + static void usage(void); int @@ -75,7 +77,7 @@ int ch, flag1, flag2, flag3, iflag; FILE *fp1, *fp2; const wchar_t *col1, *col2, *col3; - wchar_t line1[MAXLINELEN], line2[MAXLINELEN]; + wchar_t *line1, *line2; const wchar_t **p; flag1 = flag2 = flag3 = 1; @@ -123,12 +125,14 @@ for (read1 = read2 = 1;;) { /* read next line, check for EOF */ if (read1) { - file1done = !fgetws(line1, MAXLINELEN, fp1); + line1 = fgetwla(fp1); + file1done = (line1 == NULL); if (file1done && ferror(fp1)) err(1, "%s", argv[0]); } if (read2) { - file2done = !fgetws(line2, MAXLINELEN, fp2); + line2 = fgetwla(fp2); + file2done = (line2 == NULL); if (file2done && ferror(fp2)) err(1, "%s", argv[1]); } @@ -170,6 +174,10 @@ if (col2) (void)printf("%ls%ls", col2, line2); } + if (read1) + free(line1); + if (read2) + free(line2); } exit(0); } @@ -177,10 +185,15 @@ void show(FILE *fp, const char *fn, const wchar_t *offset, wchar_t *buf) { + wchar_t *line; + + line = buf; do { - (void)printf("%ls%ls", offset, buf); - } while (fgetws(buf, MAXLINELEN, fp)); + (void)printf("%ls%ls", offset, line); + free(line); + line = fgetwla(fp); + } while (line != NULL); if (ferror(fp)) err(1, "%s", fn); } @@ -208,7 +221,13 @@ int wcsicoll(const wchar_t *s1, const wchar_t *s2) { - wchar_t *p, line1[MAXLINELEN], line2[MAXLINELEN]; + wchar_t *p, *line1, *line2; + int comp; + + if( (line1 = malloc(wcslen(s1) + 1)) == NULL) + err(1, "%s", __func__); + if( (line2 = malloc(wcslen(s2) + 1)) == NULL) + err(1, "%s", __func__); for (p = line1; *s1; s1++) *p++ = towlower(*s1); @@ -216,5 +235,28 @@ for (p = line2; *s2; s2++) *p++ = towlower(*s2); *p = '\0'; - return (wcscoll(line1, line2)); + + comp = wcscoll(line1, line2); + free(line1); + free(line2); + + return comp; +} + +wchar_t * +fgetwla(FILE *fp) +{ + wchar_t *line, *wtmp; + size_t len; + + if ( (wtmp=fgetwln(fp, &len)) == NULL) + return NULL; + + if ( (line=malloc((len + 1) * sizeof(wchar_t))) == NULL) + err(1, "%s", __func__); + + wcsncpy(line, wtmp, len); + line[len] = L'\0'; + + return line; } --